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) {
|
||||
tests := []struct {
|
||||
name string
|
||||
value BlockNumberOrHash
|
||||
}{
|
||||
{"max", BlockNumberOrHashWithNumber(math.MaxInt64)},
|
||||
{"pending", BlockNumberOrHashWithNumber(PendingBlockNumber)},
|
||||
{"latest", BlockNumberOrHashWithNumber(LatestBlockNumber)},
|
||||
{"earliest", BlockNumberOrHashWithNumber(EarliestBlockNumber)},
|
||||
{"0x20", BlockNumberOrHashWithNumber(32)},
|
||||
{"hash", BlockNumberOrHashWithHash(common.Hash{0xaa}, false)},
|
||||
func TestBlockNumberOrHash_StringAndUnmarshal(t *testing.T) {
|
||||
tests := []BlockNumberOrHash{
|
||||
BlockNumberOrHashWithNumber(math.MaxInt64),
|
||||
BlockNumberOrHashWithNumber(PendingBlockNumber),
|
||||
BlockNumberOrHashWithNumber(LatestBlockNumber),
|
||||
BlockNumberOrHashWithNumber(EarliestBlockNumber),
|
||||
BlockNumberOrHashWithNumber(32),
|
||||
BlockNumberOrHashWithHash(common.Hash{0xaa}, false),
|
||||
}
|
||||
for _, test := range tests {
|
||||
test := test
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
bnh := test.value
|
||||
// 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 {
|
||||
for _, want := range tests {
|
||||
marshalled, _ := json.Marshal(want.String())
|
||||
var have BlockNumberOrHash
|
||||
if err := json.Unmarshal(marshalled, &have); err != nil {
|
||||
t.Fatalf("cannot unmarshal (%v): %v", string(marshalled), err)
|
||||
}
|
||||
if !reflect.DeepEqual(bnh, unmarshalled) {
|
||||
t.Fatalf("wrong result: expected %v, got %v", bnh, unmarshalled)
|
||||
if !reflect.DeepEqual(want, have) {
|
||||
t.Fatalf("wrong result: have %v, want %v", have, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue