-
Notifications
You must be signed in to change notification settings - Fork 840
test: Use predictable accounts for TestTracingwithOverrides #4666
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
base: master
Are you sure you want to change the base?
Changes from all commits
995f5bb
676f2d6
e3d0a5e
f45d514
fef9ae9
9f278ab
432e6c5
a55d7af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -30,6 +30,7 @@ package tracers | |||||||||||||||||
| import ( | ||||||||||||||||||
| "context" | ||||||||||||||||||
| "crypto/ecdsa" | ||||||||||||||||||
| "encoding/binary" | ||||||||||||||||||
| "encoding/json" | ||||||||||||||||||
| "errors" | ||||||||||||||||||
| "fmt" | ||||||||||||||||||
|
|
@@ -54,6 +55,7 @@ import ( | |||||||||||||||||
| "github.com/ava-labs/libevm/crypto" | ||||||||||||||||||
| "github.com/ava-labs/libevm/eth/tracers/logger" | ||||||||||||||||||
| "github.com/ava-labs/libevm/ethdb" | ||||||||||||||||||
| "github.com/ava-labs/libevm/libevm/ethtest" | ||||||||||||||||||
| ethparams "github.com/ava-labs/libevm/params" | ||||||||||||||||||
| "golang.org/x/exp/slices" | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
@@ -630,7 +632,9 @@ func TestTracingWithOverrides(t *testing.T) { | |||||||||||||||||
|
|
||||||||||||||||||
| func testTracingWithOverrides(t *testing.T, scheme string) { | ||||||||||||||||||
| // Initialize test accounts | ||||||||||||||||||
| accounts := newAccounts(3) | ||||||||||||||||||
| // This test requires deterministic block hashes, since it will fail 1/256 times, | ||||||||||||||||||
| // when the final block hash starts with 0xef. | ||||||||||||||||||
| accounts := UNSAFEDeterministicAccounts(t, 3) | ||||||||||||||||||
| storageAccount := common.Address{0x13, 37} | ||||||||||||||||||
| genesis := &core.Genesis{ | ||||||||||||||||||
| Config: params.TestChainConfig, | ||||||||||||||||||
|
|
@@ -996,6 +1000,19 @@ func newAccounts(n int) (accounts []Account) { | |||||||||||||||||
| return accounts | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // WARNING: only use for tests that require deterministic accounts | ||||||||||||||||||
| func UNSAFEDeterministicAccounts(t *testing.T, n int) (accounts []Account) { | ||||||||||||||||||
| seed := make([]byte, 8) // int64 size | ||||||||||||||||||
| for i := 0; i < n; i++ { | ||||||||||||||||||
| binary.BigEndian.PutUint64(seed, uint64(i)) | ||||||||||||||||||
|
Comment on lines
+1004
to
+1007
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
| key := ethtest.UNSAFEDeterministicPrivateKey(t, seed) | ||||||||||||||||||
| addr := crypto.PubkeyToAddress(key.PublicKey) | ||||||||||||||||||
| accounts = append(accounts, Account{key: key, addr: addr}) | ||||||||||||||||||
| } | ||||||||||||||||||
| slices.SortFunc(accounts, func(a, b Account) int { return a.addr.Cmp(b.addr) }) | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why sort them? |
||||||||||||||||||
| return accounts | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| func newRPCBalance(balance *big.Int) **hexutil.Big { | ||||||||||||||||||
| rpcBalance := (*hexutil.Big)(balance) | ||||||||||||||||||
| return &rpcBalance | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -30,6 +30,7 @@ package tracers | |||||||||||||||||
| import ( | ||||||||||||||||||
| "context" | ||||||||||||||||||
| "crypto/ecdsa" | ||||||||||||||||||
| "encoding/binary" | ||||||||||||||||||
| "encoding/json" | ||||||||||||||||||
| "errors" | ||||||||||||||||||
| "fmt" | ||||||||||||||||||
|
|
@@ -54,6 +55,7 @@ import ( | |||||||||||||||||
| "github.com/ava-labs/libevm/crypto" | ||||||||||||||||||
| "github.com/ava-labs/libevm/eth/tracers/logger" | ||||||||||||||||||
| "github.com/ava-labs/libevm/ethdb" | ||||||||||||||||||
| "github.com/ava-labs/libevm/libevm/ethtest" | ||||||||||||||||||
| ethparams "github.com/ava-labs/libevm/params" | ||||||||||||||||||
| "golang.org/x/exp/slices" | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
@@ -628,7 +630,9 @@ func TestTracingWithOverrides(t *testing.T) { | |||||||||||||||||
|
|
||||||||||||||||||
| func testTracingWithOverrides(t *testing.T, scheme string) { | ||||||||||||||||||
| // Initialize test accounts | ||||||||||||||||||
| accounts := newAccounts(3) | ||||||||||||||||||
| // This test requires deterministic block hashes, since it will fail 1/256 times,Expand commentComment on line R635ResolvedCode has comments. Press enter to view. | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
? |
||||||||||||||||||
| // when the final block hash starts with 0xef. | ||||||||||||||||||
| accounts := UNSAFEDeterministicAccounts(t, 3) | ||||||||||||||||||
| storageAccount := common.Address{0x13, 37} | ||||||||||||||||||
| genesis := &core.Genesis{ | ||||||||||||||||||
| Config: params.TestChainConfig, | ||||||||||||||||||
|
|
@@ -994,6 +998,19 @@ func newAccounts(n int) (accounts []Account) { | |||||||||||||||||
| return accounts | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // WARNING: only use for tests that require deterministic accounts | ||||||||||||||||||
| func UNSAFEDeterministicAccounts(t *testing.T, n int) (accounts []Account) { | ||||||||||||||||||
| seed := make([]byte, 8) // int64 size | ||||||||||||||||||
| for i := 0; i < n; i++ { | ||||||||||||||||||
| binary.BigEndian.PutUint64(seed, uint64(i)) | ||||||||||||||||||
|
Comment on lines
+1002
to
+1005
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
| key := ethtest.UNSAFEDeterministicPrivateKey(t, seed) | ||||||||||||||||||
| addr := crypto.PubkeyToAddress(key.PublicKey) | ||||||||||||||||||
| accounts = append(accounts, Account{key: key, addr: addr}) | ||||||||||||||||||
| } | ||||||||||||||||||
| slices.SortFunc(accounts, func(a, b Account) int { return a.addr.Cmp(b.addr) }) | ||||||||||||||||||
| return accounts | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| func newRPCBalance(balance *big.Int) **hexutil.Big { | ||||||||||||||||||
| rpcBalance := (*hexutil.Big)(balance) | ||||||||||||||||||
| return &rpcBalance | ||||||||||||||||||
|
|
||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.