Skip to content

Commit

Permalink
Revert "rpc: use correct stringer-method for serializing BlockNumberO…
Browse files Browse the repository at this point in the history
…rHash (ethereum#28358)"

This reverts commit b7be93f.
  • Loading branch information
devopsbo3 authored Nov 10, 2023
1 parent 3425d83 commit 6878e96
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
3 changes: 2 additions & 1 deletion rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"math"
"strconv"
"strings"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -220,7 +221,7 @@ func (bnh *BlockNumberOrHash) Number() (BlockNumber, bool) {

func (bnh *BlockNumberOrHash) String() string {
if bnh.BlockNumber != nil {
return bnh.BlockNumber.String()
return strconv.Itoa(int(*bnh.BlockNumber))
}
if bnh.BlockHash != nil {
return bnh.BlockHash.String()
Expand Down
21 changes: 0 additions & 21 deletions rpc/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,3 @@ func TestBlockNumberOrHash_WithNumber_MarshalAndUnmarshal(t *testing.T) {
})
}
}

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 _, 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(want, have) {
t.Fatalf("wrong result: have %v, want %v", have, want)
}
}
}

0 comments on commit 6878e96

Please sign in to comment.