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

Commit

Permalink
tests: eth_sendRawTx (#804)
Browse files Browse the repository at this point in the history
* tests: eth_sendRawTx

* update tests

* rm println
  • Loading branch information
fedekunze authored Dec 1, 2021
1 parent 3b0fa63 commit 705893c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
73 changes: 73 additions & 0 deletions tests/e2e/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/ethclient/gethclient"
"github.com/ethereum/go-ethereum/rpc"
Expand Down Expand Up @@ -164,6 +166,77 @@ func (s *IntegrationTestSuite) TestHeader() {
// s.Require().Equal(headerByHash, header)
}

func (s *IntegrationTestSuite) TestSendRawTransaction() {
testCases := []struct {
name string
data string
expEncodingErr bool
expError bool
}{
{
"rlp: expected input list for types.LegacyTx",
"0x85b7119c978b22ac5188a554916d5eb9000567b87b3b8a536222c3c2e6549b98",
true,
false,
},
{
"transaction type not supported",
"0x1238b01bfc01e946ffdf8ccb087a072298cf9f141899c5c586550cc910b8c5aa",
true,
false,
},
{
"rlp: element is larger than containing list",
"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
true,
false,
},
}

for _, tc := range testCases {
s.Run(tc.name, func() {
var data hexutil.Bytes

err := data.UnmarshalText([]byte(tc.data))
s.Require().NoError(err, data)

tx := new(ethtypes.Transaction)
err = tx.UnmarshalBinary(data)
if tc.expEncodingErr {
s.Require().Error(err)
s.Require().Equal(tc.name, err.Error())
return
}

s.Require().NoError(err)
s.Require().NotEmpty(tx)

hash := tx.Hash()

err = s.network.Validators[0].JSONRPCClient.SendTransaction(s.ctx, tx)
if tc.expError {
s.Require().Error(err)
return
}

s.Require().NoError(err)

err = s.network.WaitForNextBlock()
s.Require().NoError(err)

expTx, isPending, err := s.network.Validators[0].JSONRPCClient.TransactionByHash(s.ctx, hash)
if tc.expError {
s.Require().Error(err)
return
}

s.Require().NoError(err)
s.Require().False(isPending)
s.Require().Equal(tx, expTx)
})
}
}

func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}
3 changes: 1 addition & 2 deletions x/evm/types/compiled_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ func (s *CompiledContract) UnmarshalJSON(data []byte) error {

s.Bin = x.Bin
if err := json.Unmarshal([]byte(x.ABI), &s.ABI); err != nil {
fmt.Println("unmarshal abi fail", x.ABI, string(data))
return err
return fmt.Errorf("failed to unmarshal ABI: %w", err)
}

return nil
Expand Down

0 comments on commit 705893c

Please sign in to comment.