github.com/lmittmann/w3@v0.20.0/w3types/rpc_test.go (about) 1 package w3types_test 2 3 import ( 4 "math/big" 5 "strconv" 6 "testing" 7 8 "github.com/ethereum/go-ethereum/common" 9 "github.com/google/go-cmp/cmp" 10 "github.com/lmittmann/w3/w3types" 11 ) 12 13 func TestBlockOverrides_MarshalJSON(t *testing.T) { 14 tests := []struct { 15 Overrides *w3types.BlockOverrides 16 Want string 17 }{ 18 { 19 Overrides: &w3types.BlockOverrides{}, 20 Want: `{}`, 21 }, 22 { 23 Overrides: &w3types.BlockOverrides{ 24 Number: big.NewInt(1), 25 }, 26 Want: `{"number":"0x1"}`, 27 }, 28 { 29 Overrides: &w3types.BlockOverrides{ 30 FeeRecipient: common.Address{0xc0, 0xfe}, 31 }, 32 Want: `{"feeRecipient":"0xc0fe000000000000000000000000000000000000"}`, 33 }, 34 } 35 36 for i, test := range tests { 37 t.Run(strconv.Itoa(i), func(t *testing.T) { 38 got, err := test.Overrides.MarshalJSON() 39 if err != nil { 40 t.Fatalf("Err: %v", err) 41 } 42 if diff := cmp.Diff(test.Want, string(got)); diff != "" { 43 t.Fatalf("(-want, +got)\n%s", diff) 44 } 45 }) 46 } 47 }