@@ -51,72 +51,68 @@ 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+ //nolint:thelper // It's more useful if this test failure shows this line instead of its call site
67+ return a , func (t * testing.T , got * types.StateAccount ) {
68+ assert .Truef (t , a .Extra .Equal (nil ), "%T.%T.IsEmpty()" , a , a .Extra )
69+ }
6870 },
6971 wantTrieHash : vanillaGeth ,
7072 },
7173 {
7274 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 ), "" )
75+ registerAndSetExtra : func (a * types.StateAccount ) (* types.StateAccount , assertion ) {
76+ e := types .RegisterExtras [bool ]()
77+ e .StateAccount .Set (a , true )
78+ return a , func (t * testing.T , got * types.StateAccount ) { //nolint:thelper
79+ assert .Truef (t , e .StateAccount .Get (got ), "" )
80+ }
8081 },
8182 wantTrieHash : trueBool ,
8283 },
8384 {
8485 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 ), "" )
86+ registerAndSetExtra : func (a * types.StateAccount ) (* types.StateAccount , assertion ) {
87+ e := types .RegisterExtras [bool ]()
88+ e .StateAccount .Set (a , false ) // the explicit part
89+
90+ return a , func (t * testing.T , got * types.StateAccount ) { //nolint:thelper
91+ assert .Falsef (t , e .StateAccount .Get (got ), "" )
92+ }
9393 },
9494 wantTrieHash : falseBool ,
9595 },
9696 {
9797 name : "implicit false-boolean payload" ,
98- registerAndSetExtra : func (a * types.StateAccount ) * types.StateAccount {
99- types .RegisterExtras [bool ]()
98+ registerAndSetExtra : func (a * types.StateAccount ) ( * types.StateAccount , assertion ) {
99+ e := types .RegisterExtras [bool ]()
100100 // 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 ), "" )
101+ return a , func (t * testing.T , got * types.StateAccount ) { //nolint:thelper
102+ assert .Falsef (t , e .StateAccount .Get (got ), "" )
103+ }
106104 },
107105 wantTrieHash : falseBool ,
108106 },
109107 {
110108 name : "arbitrary payload" ,
111- registerAndSetExtra : func (a * types.StateAccount ) * types.StateAccount {
109+ registerAndSetExtra : func (a * types.StateAccount ) (* types.StateAccount , assertion ) {
110+ e := types .RegisterExtras [arbitraryPayload ]()
112111 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 , "" )
112+ e .StateAccount .Set (a , p )
113+ return a , func (t * testing.T , got * types.StateAccount ) { //nolint:thelper
114+ assert .Equalf (t , arbitraryPayload {arbitraryData }, e .StateAccount .Get (got ), "" )
115+ }
120116 },
121117 wantTrieHash : arbitrary ,
122118 },
@@ -127,7 +123,7 @@ func TestStateAccountExtraViaTrieStorage(t *testing.T) {
127123 types .TestOnlyClearRegisteredExtras ()
128124 t .Cleanup (types .TestOnlyClearRegisteredExtras )
129125
130- acct := tt .registerAndSetExtra (& types.StateAccount {
126+ acct , asserter := tt .registerAndSetExtra (& types.StateAccount {
131127 Nonce : 42 ,
132128 Balance : uint256 .NewInt (314159 ),
133129 Root : types .EmptyRootHash ,
@@ -147,7 +143,7 @@ func TestStateAccountExtraViaTrieStorage(t *testing.T) {
147143 if diff := cmp .Diff (acct , got ); diff != "" {
148144 t .Errorf ("%T.GetAccount() not equal to value passed to %[1]T.UpdateAccount(); diff (-want +got):\n %s" , state , diff )
149145 }
150- tt . assertExtra (t , got )
146+ asserter (t , got )
151147 })
152148 }
153149}
0 commit comments