Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

fix: Update the JSON-RPC to correct the return information. #1006

Merged
merged 6 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (rpc) [tharsis#990](https://github.com/tharsis/ethermint/pull/990) Calculate reward values from all `MsgEthereumTx` from a block in `eth_feeHistory`.
* (ante) [tharsis#991](https://github.com/tharsis/ethermint/pull/991) Set an upper bound to gasWanted to prevent DoS attack.
* (rpc) [tharsis#1006](https://github.com/tharsis/ethermint/pull/1006) Use `string` as the parameters type to correct ambiguous results.

## [v0.11.0] - 2022-03-06

Expand Down
4 changes: 2 additions & 2 deletions rpc/ethereum/namespaces/web3/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ func (a *PublicAPI) ClientVersion() string {
}

// Sha3 returns the keccak-256 hash of the passed-in input.
func (a *PublicAPI) Sha3(input hexutil.Bytes) hexutil.Bytes {
return crypto.Keccak256(input)
func (a *PublicAPI) Sha3(input string) hexutil.Bytes {
return crypto.Keccak256(hexutil.Bytes(input))
}
27 changes: 27 additions & 0 deletions tests/rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,33 @@ func callWithError(method string, params interface{}) (*Response, error) {
return rpcRes, nil
}

func TestWeb3_Sha3(t *testing.T) {
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
expectedRes1 := "0x23e7488ec9097f0126b0338926bfaeb5264b01cb162a0fd4a6d76e1081c2b24a"
rpcRes1 := call(t, "web3_sha3", []string{"0xabcd1234567890"})

res1 := hexutil.Bytes{}
err1 := res1.UnmarshalJSON(rpcRes1.Result)
require.NoError(t, err1)
require.Equal(t, expectedRes1, res1.String(), "expected: %s got: %s\n", expectedRes1, rpcRes1.Result)

expectedRes2 := "0x39bef1777deb3dfb14f64b9f81ced092c501fee72f90e93d03bb95ee89df9837"
rpcRes2 := call(t, "web3_sha3", []string{"0x"})

res2 := hexutil.Bytes{}
err2 := res2.UnmarshalJSON(rpcRes2.Result)
require.NoError(t, err2)
require.Equal(t, expectedRes2, res2.String(), "expected: %s got: %s\n", expectedRes2, rpcRes2.Result)

expectedRes3 := "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
rpcRes3 := call(t, "web3_sha3", []string{""})

res3 := hexutil.Bytes{}
err3 := res3.UnmarshalJSON(rpcRes3.Result)
require.NoError(t, err3)
require.Equal(t, expectedRes3, res3.String(), "expected: %s got: %s\n", expectedRes3, rpcRes3.Result)

}

func TestEth_protocolVersion(t *testing.T) {
expectedRes := hexutil.Uint(ethermint.ProtocolVersion)

Expand Down