@@ -51,72 +51,66 @@ func TestStateAccountExtraViaTrieStorage(t *testing.T) {
5151 arbitrary = common .HexToHash ("0x94eecff1444ab69437636630918c15596e001b30b973f03e06006ae20aa6e307" )
5252 )
5353
54+ // An assertion is the actual test to be performed. It is returned upon
55+ // registration, instead of being a standalone field in the test, because
56+ // each one uses a different generic parameter.
57+ type assertion func (* testing.T , * types.StateAccount )
5458 tests := []struct {
5559 name string
56- registerAndSetExtra func (* types.StateAccount ) * types.StateAccount
57- assertExtra func (* testing.T , * types.StateAccount )
60+ registerAndSetExtra func (* types.StateAccount ) (* types.StateAccount , assertion )
5861 wantTrieHash common.Hash
5962 }{
6063 {
6164 name : "vanilla geth" ,
62- registerAndSetExtra : func (a * types.StateAccount ) * types.StateAccount {
63- return a
64- },
65- assertExtra : func (t * testing.T , a * types.StateAccount ) {
66- t .Helper ()
67- assert .Truef (t , a .Extra .Equal (nil ), "%T.%T.IsEmpty()" , a , a .Extra )
65+ registerAndSetExtra : func (a * types.StateAccount ) (* types.StateAccount , assertion ) {
66+ return a , func (t * testing.T , got * types.StateAccount ) {
67+ assert .Truef (t , a .Extra .Equal (nil ), "%T.%T.IsEmpty()" , a , a .Extra )
68+ }
6869 },
6970 wantTrieHash : vanillaGeth ,
7071 },
7172 {
7273 name : "true-boolean payload" ,
73- registerAndSetExtra : func (a * types.StateAccount ) * types.StateAccount {
74- types .RegisterExtras [bool ]().SetOnPayloadCarrier (a , true )
75- return a
76- },
77- assertExtra : func (t * testing.T , sa * types.StateAccount ) {
78- t .Helper ()
79- assert .Truef (t , types.ExtraPayloads [bool ]{}.FromPayloadCarrier (sa ), "" )
74+ registerAndSetExtra : func (a * types.StateAccount ) (* types.StateAccount , assertion ) {
75+ e := types .RegisterExtras [bool ]()
76+ e .SetOnPayloadCarrier (a , true )
77+ return a , func (t * testing.T , got * types.StateAccount ) {
78+ assert .Truef (t , e .FromPayloadCarrier (got ), "" )
79+ }
8080 },
8181 wantTrieHash : trueBool ,
8282 },
8383 {
8484 name : "explicit false-boolean payload" ,
85- registerAndSetExtra : func (a * types.StateAccount ) * types.StateAccount {
86- p := types .RegisterExtras [bool ]()
87- p .SetOnPayloadCarrier (a , false ) // the explicit part
88- return a
89- },
90- assertExtra : func (t * testing.T , sa * types.StateAccount ) {
91- t .Helper ()
92- assert .Falsef (t , types.ExtraPayloads [bool ]{}.FromPayloadCarrier (sa ), "" )
85+ registerAndSetExtra : func (a * types.StateAccount ) (* types.StateAccount , assertion ) {
86+ e := types .RegisterExtras [bool ]()
87+ e .SetOnPayloadCarrier (a , false ) // the explicit part
88+ return a , func (t * testing.T , got * types.StateAccount ) {
89+ assert .Falsef (t , e .FromPayloadCarrier (got ), "" )
90+ }
9391 },
9492 wantTrieHash : falseBool ,
9593 },
9694 {
9795 name : "implicit false-boolean payload" ,
98- registerAndSetExtra : func (a * types.StateAccount ) * types.StateAccount {
99- types .RegisterExtras [bool ]()
96+ registerAndSetExtra : func (a * types.StateAccount ) ( * types.StateAccount , assertion ) {
97+ e := types .RegisterExtras [bool ]()
10098 // Note that `a` is reflected, unchanged (the implicit part).
101- return a
102- },
103- assertExtra : func (t * testing.T , sa * types.StateAccount ) {
104- t .Helper ()
105- assert .Falsef (t , types.ExtraPayloads [bool ]{}.FromPayloadCarrier (sa ), "" )
99+ return a , func (t * testing.T , got * types.StateAccount ) {
100+ assert .Falsef (t , e .FromPayloadCarrier (got ), "" )
101+ }
106102 },
107103 wantTrieHash : falseBool ,
108104 },
109105 {
110106 name : "arbitrary payload" ,
111- registerAndSetExtra : func (a * types.StateAccount ) * types.StateAccount {
107+ registerAndSetExtra : func (a * types.StateAccount ) (* types.StateAccount , assertion ) {
108+ e := types .RegisterExtras [arbitraryPayload ]()
112109 p := arbitraryPayload {arbitraryData }
113- types .RegisterExtras [arbitraryPayload ]().SetOnPayloadCarrier (a , p )
114- return a
115- },
116- assertExtra : func (t * testing.T , sa * types.StateAccount ) {
117- t .Helper ()
118- got := types.ExtraPayloads [arbitraryPayload ]{}.FromPayloadCarrier (sa )
119- assert .Equalf (t , arbitraryPayload {arbitraryData }, got , "" )
110+ e .SetOnPayloadCarrier (a , p )
111+ return a , func (t * testing.T , got * types.StateAccount ) {
112+ assert .Equalf (t , arbitraryPayload {arbitraryData }, e .FromPayloadCarrier (got ), "" )
113+ }
120114 },
121115 wantTrieHash : arbitrary ,
122116 },
@@ -127,7 +121,7 @@ func TestStateAccountExtraViaTrieStorage(t *testing.T) {
127121 types .TestOnlyClearRegisteredExtras ()
128122 t .Cleanup (types .TestOnlyClearRegisteredExtras )
129123
130- acct := tt .registerAndSetExtra (& types.StateAccount {
124+ acct , asserter := tt .registerAndSetExtra (& types.StateAccount {
131125 Nonce : 42 ,
132126 Balance : uint256 .NewInt (314159 ),
133127 Root : types .EmptyRootHash ,
@@ -147,7 +141,7 @@ func TestStateAccountExtraViaTrieStorage(t *testing.T) {
147141 if diff := cmp .Diff (acct , got ); diff != "" {
148142 t .Errorf ("%T.GetAccount() not equal to value passed to %[1]T.UpdateAccount(); diff (-want +got):\n %s" , state , diff )
149143 }
150- tt . assertExtra (t , got )
144+ asserter (t , got )
151145 })
152146 }
153147}
0 commit comments