mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Revert "rpc: use correct stringer-method for serializing BlockNumberOrHash (#28358)"
This reverts commit b7be93f9e3.
This commit is contained in:
parent
c03f863ee3
commit
d1a79dc19c
2 changed files with 2 additions and 22 deletions
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -220,7 +221,7 @@ func (bnh *BlockNumberOrHash) Number() (BlockNumber, bool) {
|
||||||
|
|
||||||
func (bnh *BlockNumberOrHash) String() string {
|
func (bnh *BlockNumberOrHash) String() string {
|
||||||
if bnh.BlockNumber != nil {
|
if bnh.BlockNumber != nil {
|
||||||
return bnh.BlockNumber.String()
|
return strconv.Itoa(int(*bnh.BlockNumber))
|
||||||
}
|
}
|
||||||
if bnh.BlockHash != nil {
|
if bnh.BlockHash != nil {
|
||||||
return bnh.BlockHash.String()
|
return bnh.BlockHash.String()
|
||||||
|
|
|
||||||
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue