Skip to content

Commit

Permalink
New unit tests focus on error cases only
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Jan 8, 2025
1 parent 2ff6f69 commit 0d06fe7
Showing 1 changed file with 2 additions and 46 deletions.
48 changes: 2 additions & 46 deletions params/json.libevm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestChainConfigJSONRoundTrip(t *testing.T) {
}
}

func TestUnmarshalChainConfigJSON(t *testing.T) {
func TestUnmarshalChainConfigJSON_Errors(t *testing.T) {
t.Parallel()

type testExtra struct {
Expand Down Expand Up @@ -178,19 +178,6 @@ func TestUnmarshalChainConfigJSON(t *testing.T) {
wantExtra: (*testExtra)(nil),
wantErrRegex: `^\*.+\.testExtra argument is nil; use \*.+\.ChainConfig.UnmarshalJSON\(\) directly$`,
},
"no_extra_at_extra_key": {
jsonData: `{"chainId": 1}`,
extra: &testExtra{},
wantConfig: ChainConfig{ChainID: big.NewInt(1)},
wantExtra: &testExtra{},
},
"no_extra_at_root_depth": {
jsonData: `{"chainId": 1}`,
extra: &testExtra{},
reuseJSONRoot: true,
wantConfig: ChainConfig{ChainID: big.NewInt(1)},
wantExtra: &testExtra{},
},
"wrong_extra_type_at_extra_key": {
jsonData: `{"chainId": 1, "extra": 1}`,
extra: &testExtra{},
Expand All @@ -206,19 +193,6 @@ func TestUnmarshalChainConfigJSON(t *testing.T) {
wantExtra: &testExtra{},
wantErrRegex: `^decoding JSON into \*.+\.testExtra: .+`,
},
"extra_success_at_extra_key": {
jsonData: `{"chainId": 1, "extra": {"field":"value"}}`,
extra: &testExtra{},
wantConfig: ChainConfig{ChainID: big.NewInt(1)},
wantExtra: &testExtra{Field: "value"},
},
"extra_success_at_root_depth": {
jsonData: `{"chainId": 1, "field":"value"}`,
extra: &testExtra{},
reuseJSONRoot: true,
wantConfig: ChainConfig{ChainID: big.NewInt(1)},
wantExtra: &testExtra{Field: "value"},
},
}

for name, testCase := range testCases {
Expand All @@ -241,7 +215,7 @@ func TestUnmarshalChainConfigJSON(t *testing.T) {
}
}

func TestMarshalChainConfigJSON(t *testing.T) {
func TestMarshalChainConfigJSON_Errors(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
Expand All @@ -260,12 +234,6 @@ func TestMarshalChainConfigJSON(t *testing.T) {
"nil_extra_at_extra_key": {
wantJSONData: `{"chainId":null}`,
},
"extra_at_extra_key": {
extra: struct {
Field string `json:"field"`
}{Field: "value"},
wantJSONData: `{"chainId":null,"extra":{"field":"value"}}`,
},
"invalid_extra_at_root_depth": {
extra: struct {
Field chan struct{} `json:"field"`
Expand All @@ -280,18 +248,6 @@ func TestMarshalChainConfigJSON(t *testing.T) {
reuseJSONRoot: true,
wantErrRegex: `^duplicate JSON key "chainId" in ChainConfig and extra struct .+$`,
},
"nil_extra_at_root_depth": {
extra: nil,
reuseJSONRoot: true,
wantJSONData: `{"chainId":null}`,
},
"extra_at_root_depth": {
extra: struct {
Field string `json:"field"`
}{},
reuseJSONRoot: true,
wantJSONData: `{"chainId":null,"field":""}`,
},
}

for name, testCase := range testCases {
Expand Down

0 comments on commit 0d06fe7

Please sign in to comment.