@@ -41,18 +41,18 @@ type rootJSONChainConfigExtra struct {
4141
4242func  TestChainConfigJSONRoundTrip (t  * testing.T ) {
4343	tests  :=  []struct  {
44- 		name          string 
45- 		register      func ()
46- 		jsonInput     string 
47- 		wantDecoded  * ChainConfig 
44+ 		name       string 
45+ 		register   func ()
46+ 		jsonInput  string 
47+ 		want        * ChainConfig 
4848	}{
4949		{
5050			name :     "no registered extras" ,
5151			register : func () {},
5252			jsonInput : `{ 
5353				"chainId": 1234 
5454			}` ,
55- 			wantDecoded : & ChainConfig {
55+ 			want : & ChainConfig {
5656				ChainID : big .NewInt (1234 ),
5757			},
5858		},
@@ -67,7 +67,7 @@ func TestChainConfigJSONRoundTrip(t *testing.T) {
6767				"chainId": 5678, 
6868				"foo": "hello" 
6969			}` ,
70- 			wantDecoded : & ChainConfig {
70+ 			want : & ChainConfig {
7171				ChainID : big .NewInt (5678 ),
7272				extra :   pseudo .From (rootJSONChainConfigExtra {TopLevelFoo : "hello" }).Type ,
7373			},
@@ -83,7 +83,7 @@ func TestChainConfigJSONRoundTrip(t *testing.T) {
8383				"chainId": 5678, 
8484				"foo": "hello" 
8585			}` ,
86- 			wantDecoded : & ChainConfig {
86+ 			want : & ChainConfig {
8787				ChainID : big .NewInt (5678 ),
8888				extra :   pseudo .From (& rootJSONChainConfigExtra {TopLevelFoo : "hello" }).Type ,
8989			},
@@ -99,7 +99,7 @@ func TestChainConfigJSONRoundTrip(t *testing.T) {
9999				"chainId": 42, 
100100				"extra": {"foo": "world"} 
101101			}` ,
102- 			wantDecoded : & ChainConfig {
102+ 			want : & ChainConfig {
103103				ChainID : big .NewInt (42 ),
104104				extra :   pseudo .From (nestedChainConfigExtra {NestedFoo : "world" }).Type ,
105105			},
@@ -115,7 +115,7 @@ func TestChainConfigJSONRoundTrip(t *testing.T) {
115115				"chainId": 42, 
116116				"extra": {"foo": "world"} 
117117			}` ,
118- 			wantDecoded : & ChainConfig {
118+ 			want : & ChainConfig {
119119				ChainID : big .NewInt (42 ),
120120				extra :   pseudo .From (& nestedChainConfigExtra {NestedFoo : "world" }).Type ,
121121			},
@@ -128,19 +128,20 @@ func TestChainConfigJSONRoundTrip(t *testing.T) {
128128			t .Cleanup (TestOnlyClearRegisteredExtras )
129129			tt .register ()
130130
131- 			buffer  :=  bytes .NewBuffer (nil )
132- 			err  :=  json .Compact (buffer , []byte (tt .jsonInput ))
133- 			require .NoError (t , err )
134- 			wantEncoded  :=  buffer .String ()
131+ 			t .Run ("json.Unmarshal()" , func (t  * testing.T ) {
132+ 				got  :=  new (ChainConfig )
133+ 				require .NoError (t , json .Unmarshal ([]byte (tt .jsonInput ), got ))
134+ 				require .Equal (t , tt .want , got )
135+ 			})
135136
136- 			gotEncoded ,  err   :=   json .Marshal (tt . wantDecoded ) 
137- 			require . NoError ( t ,  err ,  "json.Marshal()" ) 
138- 			require .Equal (t , wantEncoded ,  string ( gotEncoded ) )
137+ 			t . Run ( " json.Marshal()" ,  func ( t   * testing. T ) { 
138+ 				 var   want  bytes. Buffer 
139+ 				 require .NoError (t , json . Compact ( & want , [] byte ( tt . jsonInput )),  "json.Compact()" )
139140
140- 			gotDecoded   :=  new ( ChainConfig )
141- 			err   =   json .Unmarshal ( gotEncoded ,  gotDecoded )
142- 			require .NoError (t , err ,  "json.Unmarshal()" )
143- 			require . Equal ( t ,  tt . wantDecoded ,  gotDecoded )
141+ 				 got ,  err   :=  json . Marshal ( tt . want )
142+ 				 require . NoError ( t ,  err ,  " json.Marshal()"  )
143+ 				 require .Equal (t , want . String (),  string ( got ) )
144+ 			} )
144145		})
145146	}
146147}
0 commit comments