mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
ethclient: Simplify new test to match typical style.
This commit is contained in:
parent
488f52565c
commit
dc81db030d
1 changed files with 17 additions and 26 deletions
|
|
@ -154,32 +154,23 @@ func TestBlockNumberOrHash_WithNumber_MarshalAndUnmarshal(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBlockNumberOrHash_WithNumber_StringAndUnmarshal(t *testing.T) {
|
func TestBlockNumberOrHash_StringAndUnmarshal(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []BlockNumberOrHash{
|
||||||
name string
|
BlockNumberOrHashWithNumber(math.MaxInt64),
|
||||||
value BlockNumberOrHash
|
BlockNumberOrHashWithNumber(PendingBlockNumber),
|
||||||
}{
|
BlockNumberOrHashWithNumber(LatestBlockNumber),
|
||||||
{"max", BlockNumberOrHashWithNumber(math.MaxInt64)},
|
BlockNumberOrHashWithNumber(EarliestBlockNumber),
|
||||||
{"pending", BlockNumberOrHashWithNumber(PendingBlockNumber)},
|
BlockNumberOrHashWithNumber(32),
|
||||||
{"latest", BlockNumberOrHashWithNumber(LatestBlockNumber)},
|
BlockNumberOrHashWithHash(common.Hash{0xaa}, false),
|
||||||
{"earliest", BlockNumberOrHashWithNumber(EarliestBlockNumber)},
|
|
||||||
{"0x20", BlockNumberOrHashWithNumber(32)},
|
|
||||||
{"hash", BlockNumberOrHashWithHash(common.Hash{0xaa}, false)},
|
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, want := range tests {
|
||||||
test := test
|
marshalled, _ := json.Marshal(want.String())
|
||||||
t.Run(test.name, func(t *testing.T) {
|
var have BlockNumberOrHash
|
||||||
bnh := test.value
|
if err := json.Unmarshal(marshalled, &have); err != nil {
|
||||||
// Wrap the string value in quotes to make it a JSON string.
|
|
||||||
marshalled := []byte("\"" + bnh.String() + "\"")
|
|
||||||
var unmarshalled BlockNumberOrHash
|
|
||||||
err := json.Unmarshal(marshalled, &unmarshalled)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("cannot unmarshal (%v): %v", string(marshalled), err)
|
t.Fatalf("cannot unmarshal (%v): %v", string(marshalled), err)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(bnh, unmarshalled) {
|
if !reflect.DeepEqual(want, have) {
|
||||||
t.Fatalf("wrong result: expected %v, got %v", bnh, unmarshalled)
|
t.Fatalf("wrong result: have %v, want %v", have, want)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue