This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update query parameters for the getBalance method * Add backward compatibility for EIP-1898 getBalance method * Update tests for getting account balance * Add sanity check for block number value * Add e2e tests for getBalance method * Add EIP 1898 support for getTransactionCount method * Add EIP 1898 support for getCode method * Add EIP 1898 support for getStorageAt method * Add EIP 1898 support for getCall method * Add sanity check in the json-rpc filter value extraction * Remove interface parameters of EIP-1898 methods * Remove unused JSON-RPC codec method * Add tests for EIP-1898 JSON-RPC parameter * Update unmarshal method for BlockNumberOrHash * Add unit tests for EIP-1898 implementation of eth_getBalance * Add unit tests for EIP-1898 implementation of eth_getTransactionCount * Add unit tests for EIP-1898 implementation of eth_getCode * Add unit tests for EIP-1898 implementation of eth_getStorageAt * Remove e2e tests for EIP-1898 * Remove unused mock in unit tests
- Loading branch information
1 parent
9e51892
commit 8c076ec
Showing
4 changed files
with
675 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package jsonrpc | ||
|
||
import ( | ||
"github.com/0xPolygon/polygon-sdk/types" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestBlockNumberOrHash_UnmarshalJSON(t *testing.T) { | ||
var blockHash types.Hash | ||
err := blockHash.UnmarshalText([]byte("0xe0ee62fd4a39a6988e24df0b406b90af71932e1b01d5561400a8eab943a33d68")) | ||
assert.NoError(t, err) | ||
|
||
blockNumberZero := BlockNumber(0x0) | ||
blockNumberLatest := LatestBlockNumber | ||
|
||
tests := []struct { | ||
name string | ||
rawRequest string | ||
shouldFail bool | ||
expectedBnh BlockNumberOrHash | ||
}{ | ||
{ | ||
"should return an error for non existing json fields", | ||
`{"blockHash": "", "blockNumber": ""}`, | ||
true, | ||
BlockNumberOrHash{}, | ||
}, | ||
{ | ||
"should return an error for too many json fields", | ||
`{"blockHash": "0xe0ee62fd4a39a6988e24df0b406b90af71932e1b01d5561400a8eab943a33d68", "blockNumber": "0x0"}`, | ||
true, | ||
BlockNumberOrHash{ | ||
BlockNumber: &blockNumberZero, | ||
BlockHash: &blockHash, | ||
}, | ||
}, | ||
{ | ||
"should return an error for invalid block number #1", | ||
`{"blockNumber": "abc"}`, | ||
true, | ||
BlockNumberOrHash{}, | ||
}, | ||
{ | ||
"should return an error for invalid block number #2", | ||
`{"blockNumber": ""}`, | ||
true, | ||
BlockNumberOrHash{}, | ||
}, | ||
{ | ||
"should unmarshal latest block number properly", | ||
`"latest"`, | ||
false, | ||
BlockNumberOrHash{ | ||
BlockNumber: &blockNumberLatest, | ||
}, | ||
}, | ||
{ | ||
"should unmarshal block number 0 properly #1", | ||
`{"blockNumber": "0x0"}`, | ||
false, | ||
BlockNumberOrHash{ | ||
BlockNumber: &blockNumberZero, | ||
}, | ||
}, | ||
{ | ||
"should unmarshal block number 0 properly #2", | ||
`"0x0"`, | ||
false, | ||
BlockNumberOrHash{ | ||
BlockNumber: &blockNumberZero, | ||
}, | ||
}, | ||
{ | ||
"should unmarshal block hash properly", | ||
`{"blockHash": "0xe0ee62fd4a39a6988e24df0b406b90af71932e1b01d5561400a8eab943a33d68"}`, | ||
false, | ||
BlockNumberOrHash{ | ||
BlockHash: &blockHash, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
bnh := BlockNumberOrHash{} | ||
err := bnh.UnmarshalJSON([]byte(tt.rawRequest)) | ||
|
||
if tt.shouldFail { | ||
assert.Error(t, err) | ||
} else { | ||
assert.NoError(t, err) | ||
if tt.expectedBnh.BlockNumber != nil { | ||
assert.Equal(t, *bnh.BlockNumber, *tt.expectedBnh.BlockNumber) | ||
} | ||
if tt.expectedBnh.BlockHash != nil { | ||
assert.Equal(t, bnh.BlockHash.String(), tt.expectedBnh.BlockHash.String()) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.