Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed May 30, 2024
1 parent faf45e1 commit 0dcbfb7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
9 changes: 6 additions & 3 deletions rpc/backend/call_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,12 @@ func (suite *BackendTestSuite) TestResend() {

func (suite *BackendTestSuite) TestSendRawTransaction() {
ethTx, bz := suite.buildEthereumTx()
rlpEncodedBz, _ := rlp.EncodeToBytes(ethTx.AsTransaction())
cosmosTx, _ := ethTx.BuildTx(suite.backend.clientCtx.TxConfig.NewTxBuilder(), "aphoton")
txBytes, _ := suite.backend.clientCtx.TxConfig.TxEncoder()(cosmosTx)
rlpEncodedBz, err := rlp.EncodeToBytes(ethTx.AsTransaction())
suite.Require().NoError(err)
cosmosTx, err := ethTx.BuildTx(suite.backend.clientCtx.TxConfig.NewTxBuilder(), "aphoton")
suite.Require().NoError(err)
txBytes, err := suite.backend.clientCtx.TxConfig.TxEncoder()(cosmosTx)
suite.Require().NoError(err)

testCases := []struct {
name string
Expand Down
16 changes: 11 additions & 5 deletions rpc/backend/sign_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func (suite *BackendTestSuite) TestSendTransaction() {
gas := hexutil.Uint64(1)
zeroGas := hexutil.Uint64(0)
toAddr := tests.GenerateAddress()
priv, _ := ethsecp256k1.GenerateKey()
priv, err := ethsecp256k1.GenerateKey()
suite.Require().NoError(err)
from := common.BytesToAddress(priv.PubKey().Address().Bytes())
nonce := hexutil.Uint64(1)
baseFee := sdk.NewInt(1)
Expand Down Expand Up @@ -104,9 +105,11 @@ func (suite *BackendTestSuite) TestSendTransaction() {
ethSigner := ethtypes.LatestSigner(suite.backend.ChainConfig())
msg := callArgsDefault.ToTransaction()
msg.Sign(ethSigner, suite.backend.clientCtx.Keyring)
tx, _ := msg.BuildTx(suite.backend.clientCtx.TxConfig.NewTxBuilder(), "aphoton")
tx, err := msg.BuildTx(suite.backend.clientCtx.TxConfig.NewTxBuilder(), "aphoton")
suite.Require().NoError(err)
txEncoder := suite.backend.clientCtx.TxConfig.TxEncoder()
txBytes, _ := txEncoder(tx)
txBytes, err := txEncoder(tx)
suite.Require().NoError(err)
RegisterBroadcastTxError(client, txBytes)
},
callArgsDefault,
Expand All @@ -129,9 +132,11 @@ func (suite *BackendTestSuite) TestSendTransaction() {
ethSigner := ethtypes.LatestSigner(suite.backend.ChainConfig())
msg := callArgsDefault.ToTransaction()
msg.Sign(ethSigner, suite.backend.clientCtx.Keyring)
tx, _ := msg.BuildTx(suite.backend.clientCtx.TxConfig.NewTxBuilder(), "aphoton")
tx, err := msg.BuildTx(suite.backend.clientCtx.TxConfig.NewTxBuilder(), "aphoton")
suite.Require().NoError(err)
txEncoder := suite.backend.clientCtx.TxConfig.TxEncoder()
txBytes, _ := txEncoder(tx)
txBytes, err := txEncoder(tx)
suite.Require().NoError(err)
RegisterBroadcastTx(client, txBytes)
},
callArgsDefault,
Expand Down Expand Up @@ -249,6 +254,7 @@ func (suite *BackendTestSuite) TestSignTypedData() {

if tc.expPass {
sigHash, _, err := apitypes.TypedDataAndHash(tc.inputTypedData)
suite.Require().NoError(err)
signature, _, err := suite.backend.clientCtx.Keyring.SignByAddress((sdk.AccAddress)(from.Bytes()), sigHash)
signature[goethcrypto.RecoveryIDOffset] += 27
suite.Require().NoError(err)
Expand Down
15 changes: 10 additions & 5 deletions rpc/backend/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func (suite *BackendTestSuite) TestTraceTransaction() {
txHash := msgEthereumTx.AsTransaction().Hash()
txHash2 := msgEthereumTx2.AsTransaction().Hash()

priv, _ := ethsecp256k1.GenerateKey()
priv, err := ethsecp256k1.GenerateKey()
suite.Require().NoError(err)
from := common.BytesToAddress(priv.PubKey().Address().Bytes())

queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
Expand All @@ -38,13 +39,17 @@ func (suite *BackendTestSuite) TestTraceTransaction() {

msgEthereumTx.From = from.String()
msgEthereumTx.Sign(ethSigner, suite.signer)
tx, _ := msgEthereumTx.BuildTx(suite.backend.clientCtx.TxConfig.NewTxBuilder(), "aphoton")
txBz, _ := txEncoder(tx)
tx, err := msgEthereumTx.BuildTx(suite.backend.clientCtx.TxConfig.NewTxBuilder(), "aphoton")
suite.Require().NoError(err)
txBz, err := txEncoder(tx)
suite.Require().NoError(err)

msgEthereumTx2.From = from.String()
msgEthereumTx2.Sign(ethSigner, suite.signer)
tx2, _ := msgEthereumTx2.BuildTx(suite.backend.clientCtx.TxConfig.NewTxBuilder(), "aphoton")
txBz2, _ := txEncoder(tx2)
tx2, err := msgEthereumTx2.BuildTx(suite.backend.clientCtx.TxConfig.NewTxBuilder(), "aphoton")
suite.Require().NoError(err)
txBz2, err := txEncoder(tx2)
suite.Require().NoError(err)

testCases := []struct {
name string
Expand Down
17 changes: 12 additions & 5 deletions rpc/backend/tx_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func (suite *BackendTestSuite) TestGetTransactionByHash() {
},
}

rpcTransaction, _ := rpctypes.NewRPCTransaction(msgEthereumTx.AsTransaction(), common.Hash{}, 0, 0, big.NewInt(1), suite.backend.chainID)
rpcTransaction, err := rpctypes.NewRPCTransaction(msgEthereumTx.AsTransaction(), common.Hash{}, 0, 0, big.NewInt(1), suite.backend.chainID)
suite.Require().NoError(err)

testCases := []struct {
name string
Expand Down Expand Up @@ -124,7 +125,8 @@ func (suite *BackendTestSuite) TestGetTransactionByHash() {

func (suite *BackendTestSuite) TestGetTransactionsByHashPending() {
msgEthereumTx, bz := suite.buildEthereumTx()
rpcTransaction, _ := rpctypes.NewRPCTransaction(msgEthereumTx.AsTransaction(), common.Hash{}, 0, 0, big.NewInt(1), suite.backend.chainID)
rpcTransaction, err := rpctypes.NewRPCTransaction(msgEthereumTx.AsTransaction(), common.Hash{}, 0, 0, big.NewInt(1), suite.backend.chainID)
suite.Require().NoError(err)

testCases := []struct {
name string
Expand Down Expand Up @@ -184,7 +186,8 @@ func (suite *BackendTestSuite) TestGetTransactionsByHashPending() {

func (suite *BackendTestSuite) TestGetTxByEthHash() {
msgEthereumTx, bz := suite.buildEthereumTx()
rpcTransaction, _ := rpctypes.NewRPCTransaction(msgEthereumTx.AsTransaction(), common.Hash{}, 0, 0, big.NewInt(1), suite.backend.chainID)
rpcTransaction, err := rpctypes.NewRPCTransaction(msgEthereumTx.AsTransaction(), common.Hash{}, 0, 0, big.NewInt(1), suite.backend.chainID)
suite.Require().NoError(err)

testCases := []struct {
name string
Expand Down Expand Up @@ -294,7 +297,7 @@ func (suite *BackendTestSuite) TestGetTransactionByBlockAndIndex() {
},
}

txFromMsg, _ := rpctypes.NewTransactionFromMsg(
txFromMsg, err := rpctypes.NewTransactionFromMsg(
msgEthTx,
common.BytesToHash(defaultBlock.Hash().Bytes()),
1,
Expand All @@ -303,6 +306,8 @@ func (suite *BackendTestSuite) TestGetTransactionByBlockAndIndex() {
suite.backend.chainID,
nil,
)
suite.Require().NoError(err)

testCases := []struct {
name string
registerMock func()
Expand Down Expand Up @@ -389,7 +394,7 @@ func (suite *BackendTestSuite) TestGetTransactionByBlockAndIndex() {
func (suite *BackendTestSuite) TestGetTransactionByBlockNumberAndIndex() {
msgEthTx, bz := suite.buildEthereumTx()
defaultBlock := types.MakeBlock(1, []types.Tx{bz}, nil, nil)
txFromMsg, _ := rpctypes.NewTransactionFromMsg(
txFromMsg, err := rpctypes.NewTransactionFromMsg(
msgEthTx,
common.BytesToHash(defaultBlock.Hash().Bytes()),
1,
Expand All @@ -398,6 +403,8 @@ func (suite *BackendTestSuite) TestGetTransactionByBlockNumberAndIndex() {
suite.backend.chainID,
nil,
)
suite.Require().NoError(err)

testCases := []struct {
name string
registerMock func()
Expand Down

0 comments on commit 0dcbfb7

Please sign in to comment.