test: adding test condition to mustFail=false in TestBlockNumberJSONUnmarshal for valid number input

This commit is contained in:
Tarun Sharma 2025-05-12 17:34:01 +04:00
parent 78e82ac8a9
commit cccfefa669
2 changed files with 12 additions and 11 deletions

View file

@ -107,7 +107,7 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
if hexutil.IsValidHexString(input) { if hexutil.IsValidHexString(input) {
blckNum, err = hexutil.DecodeUint64(input) blckNum, err = hexutil.DecodeUint64(input)
} else { } else {
//Try converting input directly into uint64 value //Else try converting input directly into uint64 value
blckNum, err = strconv.ParseUint(input, 10, 64) blckNum, err = strconv.ParseUint(input, 10, 64)
} }

View file

@ -42,16 +42,17 @@ func TestBlockNumberJSONUnmarshal(t *testing.T) {
6: {`"0x12"`, false, BlockNumber(18)}, 6: {`"0x12"`, false, BlockNumber(18)},
7: {`"0x7fffffffffffffff"`, false, BlockNumber(math.MaxInt64)}, 7: {`"0x7fffffffffffffff"`, false, BlockNumber(math.MaxInt64)},
8: {`"0x8000000000000000"`, true, BlockNumber(0)}, 8: {`"0x8000000000000000"`, true, BlockNumber(0)},
9: {`"ff"`, true, BlockNumber(0)}, 9: {"0", false, BlockNumber(0)},
10: {`"pending"`, false, PendingBlockNumber}, 10: {`"ff"`, true, BlockNumber(0)},
11: {`"latest"`, false, LatestBlockNumber}, 11: {`"pending"`, false, PendingBlockNumber},
12: {`"earliest"`, false, EarliestBlockNumber}, 12: {`"latest"`, false, LatestBlockNumber},
13: {`"committed"`, false, CommittedBlockNumber}, 13: {`"earliest"`, false, EarliestBlockNumber},
14: {`"finalized"`, false, CommittedBlockNumber}, 14: {`"committed"`, false, CommittedBlockNumber},
15: {`someString`, true, BlockNumber(0)}, 15: {`"finalized"`, false, CommittedBlockNumber},
16: {`""`, true, BlockNumber(0)}, 16: {`someString`, true, BlockNumber(0)},
17: {``, true, BlockNumber(0)}, 17: {`""`, true, BlockNumber(0)},
18: {`88439993`, false, BlockNumber(88439993)}, 18: {``, true, BlockNumber(0)},
19: {`88439993`, false, BlockNumber(88439993)},
} }
for i, test := range tests { for i, test := range tests {