-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: support multiple balance formats in targetContractsBalances #580
base: master
Are you sure you want to change the base?
WIP: support multiple balance formats in targetContractsBalances #580
Conversation
fuzzing/config/config.go
Outdated
@@ -77,7 +76,7 @@ type FuzzingConfig struct { | |||
|
|||
// TargetContractsBalances holds the amount of wei that should be sent during deployment for one or more contracts in | |||
// TargetContracts | |||
TargetContractsBalances []*big.Int `json:"targetContractsBalances"` | |||
TargetContractsBalances []string `json:"targetContractsBalances"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the beauty of using go generate
is that we can still represent TargetContractBalances
as []*big.Int
but marshal/unmarshal it as strings. So, you actually do not need this change. You can keep it as the original.
fuzzing/fuzzer.go
Outdated
_, success := contractBalance.SetString(balances[i], 10) | ||
if !success { | ||
contractBalance = big.NewInt(0) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You won't need this logic once the change in config.go is made
fuzzing/config/config.go
Outdated
@@ -116,7 +115,7 @@ type FuzzingConfig struct { | |||
// have its custom marshaling methods auto-generated and will handle type conversions for serialization purposes. | |||
// For example, this enables serialization of big.Int but specifying a different field type to control serialization. | |||
type fuzzingConfigMarshaling struct { | |||
TargetContractsBalances []*hexutil.Big | |||
TargetContractsBalances []string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So technically the only change you have to make for this PR is this (and the update to the documentation). Everything else should click into place once go generate
is run in the config/
directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anishnaik I'm getting the following error when running go generate
from config
dir:
rebase@MacBookPro config % go generate
-: invalid field override: slice element type string is not convertible to *math/big.Int
exit status 1
config.go:22: running "go": exit status 1
@0xZRA provided some feedback. Lmk if you have any questions. I'll run the CI when you make those changes and I can investigate if/why the tests are failing. |
Hey @0xZRA, will provide some more feedback soon. Sorry for the delay. |
Hey @0xZRA okay so I think we need to change our approach. Tbh I didn't expect Doing it this way will remove any requirement for I would like to take it one more step than what is mentioned in the stack overflow post. I would like to be able to unmarshal any three of these string possibilities:
Let me know if you have any questions. Also, about the failing tests: We have some challenging unit tests that sometimes takes medusa a while to solve. That's why sometimes the tests may fail to run. Usually, re-running it does the trick but I do need to investigate why it is happening more frequently nowadays. |
@anishnaik I appreciate your response and I think it makes sense so far. Just wanted to clarify one point in your approach regarding the unmarshalling of the 3 string possibilities. Does the proposed approach still involve maintaining the current hexadecimal notation for setting initial balances, while adding the option to use base-10 strings, including scientific notation? So if we take it straight to the docs, the new version will look like:
|
Technically, you can also mix and match: Like the Also, for This PR became more complicated than I expected :) |
I hadn't thought of mix and match, you're right. I'll take a shot at it. |
This is still WIP, as I haven't tested the actual runs with different balance formats. @anishnaik let me know if I captured the requirements correctly |
This is to address issue #306
Relies on running
go generate
command to automatically generate code generate JSON marshaling code from template forFuzzingConfig
@anishnaik
I'm running into an issue where tests are failing locally on my machine, even on the
master
branch. I wanted to flag this early - I'm using Sequoia version 15.1.1, so it's unclear if my changes are implemented correctly.go test -v ./fuzzing
At the same time, when running following tests individually thru VSCode, both are passing: