From 01bc2ec17037c88bf774b1091279676de2d7d83f Mon Sep 17 00:00:00 2001 From: WilliamXieCrypto <87299790+WilliamXieCrypto@users.noreply.github.com> Date: Mon, 21 Mar 2022 19:40:24 +0800 Subject: [PATCH] fix: Update the JSON-RPC to correct the return information. (#1006) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Update the JSON-RPC to correct the return information. * Update CHANGELOG.md * update: move the tests to integration_test.go * refactor the tests and use table tests instead Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> --- CHANGELOG.md | 1 + rpc/ethereum/namespaces/web3/api.go | 4 ++-- tests/e2e/integration_test.go | 36 +++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c027e2f2..44e328d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. * (ante) [tharsis#1004](https://github.com/tharsis/ethermint/pull/1004) make MaxTxGasWanted configurable. ## [v0.11.0] - 2022-03-06 diff --git a/rpc/ethereum/namespaces/web3/api.go b/rpc/ethereum/namespaces/web3/api.go index 54af350d..04fbee76 100644 --- a/rpc/ethereum/namespaces/web3/api.go +++ b/rpc/ethereum/namespaces/web3/api.go @@ -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)) } diff --git a/tests/e2e/integration_test.go b/tests/e2e/integration_test.go index 3c09b860..ace2ad24 100644 --- a/tests/e2e/integration_test.go +++ b/tests/e2e/integration_test.go @@ -46,6 +46,7 @@ type IntegrationTestSuite struct { gethClient *gethclient.Client ethSigner ethtypes.Signer + rpcClient *rpc.Client } func (s *IntegrationTestSuite) SetupSuite() { @@ -74,6 +75,7 @@ func (s *IntegrationTestSuite) SetupSuite() { rpcClient, err := rpc.DialContext(s.ctx, address) s.Require().NoError(err) + s.rpcClient = rpcClient s.gethClient = gethclient.New(rpcClient) s.Require().NotNil(s.gethClient) chainId, err := ethermint.ParseChainID(s.cfg.ChainID) @@ -685,3 +687,37 @@ func (s *IntegrationTestSuite) waitForTransaction() { func TestIntegrationTestSuite(t *testing.T) { suite.Run(t, new(IntegrationTestSuite)) } + +func (s *IntegrationTestSuite) TestWeb3Sha3() { + testCases := []struct { + name string + arg string + expected string + }{ + { + "normal input", + "0xabcd1234567890", + "0x23e7488ec9097f0126b0338926bfaeb5264b01cb162a0fd4a6d76e1081c2b24a", + }, + { + "0x case", + "0x", + "0x39bef1777deb3dfb14f64b9f81ced092c501fee72f90e93d03bb95ee89df9837", + }, + { + "empty string case", + "", + "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", + }, + } + + for _, tc := range testCases { + s.Run(tc.name, func() { + var result string + + err := s.rpcClient.Call(&result, "web3_sha3", tc.arg) + s.Require().NoError(err) + s.Require().Equal(tc.expected, result) + }) + } +}