You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/state/state.libevm_test.go
+33-6Lines changed: 33 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,7 @@ package state_test
18
18
19
19
import (
20
20
"fmt"
21
+
"reflect"
21
22
"testing"
22
23
23
24
"github.com/google/go-cmp/cmp"
@@ -35,25 +36,34 @@ import (
35
36
)
36
37
37
38
funcTestGetSetExtra(t*testing.T) {
39
+
typeaccountExtrastruct {
40
+
// Data is a pointer to test deep copying.
41
+
Data*[]byte// MUST be exported; I spent 20 minutes investigating failing tests because I'm an idiot
42
+
}
43
+
38
44
types.TestOnlyClearRegisteredExtras()
39
45
t.Cleanup(types.TestOnlyClearRegisteredExtras)
40
-
payloads:=types.RegisterExtras[[]byte]()
46
+
// Just as its Data field is a pointer, the registered type is a pointer to
47
+
// test deep copying.
48
+
payloads:=types.RegisterExtras[*accountExtra]()
41
49
42
50
rng:=ethtest.NewPseudoRand(42)
43
51
addr:=rng.Address()
44
52
nonce:=rng.Uint64()
45
53
balance:=rng.Uint256()
46
-
extra:=rng.Bytes(8)
54
+
buf:=rng.Bytes(8)
55
+
extra:=&accountExtra{Data: &buf}
47
56
48
57
views:=newWithSnaps(t)
49
58
stateDB:=views.newStateDB(t, types.EmptyRootHash)
59
+
50
60
assert.Nilf(t, state.GetExtra(stateDB, payloads, addr), "state.GetExtra() returns zero-value %T if before account creation", extra)
51
61
stateDB.CreateAccount(addr)
52
62
stateDB.SetNonce(addr, nonce)
53
63
stateDB.SetBalance(addr, balance)
54
64
assert.Nilf(t, state.GetExtra(stateDB, payloads, addr), "state.GetExtra() returns zero-value %T if after account creation but before SetExtra()", extra)
55
65
state.SetExtra(stateDB, payloads, addr, extra)
56
-
assert.Equal(t, extra, state.GetExtra(stateDB, payloads, addr), "state.GetExtra() immediately after SetExtra()")
66
+
require.Equal(t, extra, state.GetExtra(stateDB, payloads, addr), "state.GetExtra() immediately after SetExtra()")
57
67
58
68
root, err:=stateDB.Commit(1, false) // arbitrary block number
0 commit comments