From 03be3328584dc116f2bbe6278b8f129ba57bf9f8 Mon Sep 17 00:00:00 2001 From: codchen Date: Wed, 24 Jan 2024 00:26:50 +0800 Subject: [PATCH] Separate endpoint for associateTx (#1272) --- contracts/test/EVMCompatabilityTester.js | 3 +-- evmrpc/association.go | 25 ++++++++++++++++++++---- evmrpc/send.go | 22 ++++++++------------- evmrpc/send_test.go | 21 -------------------- 4 files changed, 30 insertions(+), 41 deletions(-) diff --git a/contracts/test/EVMCompatabilityTester.js b/contracts/test/EVMCompatabilityTester.js index 8a5fe52bdb..76b560f53a 100644 --- a/contracts/test/EVMCompatabilityTester.js +++ b/contracts/test/EVMCompatabilityTester.js @@ -308,8 +308,7 @@ describe("EVM Test", function () { await expect(evmTester.revertIfFalse(false)).to.be.reverted; }); - // TODO: fix this test the re-enable, it's breaking on CI - it.skip("Should not revert when true is passed to revertIfFalse", async function () { + it("Should not revert when true is passed to revertIfFalse", async function () { await evmTester.revertIfFalse(true) }); }) diff --git a/evmrpc/association.go b/evmrpc/association.go index 27d970aa10..e1ff0dbf89 100644 --- a/evmrpc/association.go +++ b/evmrpc/association.go @@ -3,13 +3,16 @@ package evmrpc import ( "context" "encoding/hex" + "errors" "fmt" "strings" "time" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/ethereum/go-ethereum/common" "github.com/sei-protocol/sei-chain/x/evm/keeper" + "github.com/sei-protocol/sei-chain/x/evm/types" "github.com/sei-protocol/sei-chain/x/evm/types/ethtx" rpcclient "github.com/tendermint/tendermint/rpc/client" ) @@ -54,15 +57,29 @@ func (t *AssociationAPI) Associate(ctx context.Context, req *AssociateRequest) ( S: sBytes, } - data, err := associateTx.Marshal() + msg, err := types.NewMsgEVMTransaction(&associateTx) if err != nil { return err } - _, err = t.sendAPI.SendRawTransaction(ctx, data) - if err != nil { + txBuilder := t.sendAPI.txConfig.NewTxBuilder() + if err = txBuilder.SetMsgs(msg); err != nil { return err } - return nil + txbz, encodeErr := t.sendAPI.txConfig.TxEncoder()(txBuilder.GetTx()) + if encodeErr != nil { + return encodeErr + } + + res, broadcastError := t.tmClient.BroadcastTx(ctx, txbz) + if broadcastError != nil { + err = broadcastError + } else if res == nil { + err = errors.New("missing broadcast response") + } else if res.Code != 0 { + err = sdkerrors.ABCIError(sdkerrors.RootCodespace, res.Code, "") + } + + return err } func (t *AssociationAPI) GetSeiAddress(_ context.Context, ethAddress common.Address) (result string, returnErr error) { diff --git a/evmrpc/send.go b/evmrpc/send.go index bdb77825f1..a22c8e6da7 100644 --- a/evmrpc/send.go +++ b/evmrpc/send.go @@ -55,20 +55,14 @@ func (s *SendAPI) SendRawTransaction(ctx context.Context, input hexutil.Bytes) ( s.slowMu.Lock() defer s.slowMu.Unlock() } - var txData ethtx.TxData - associateTx := ethtx.AssociateTx{} - if associateTx.Unmarshal(input) == nil { - txData = &associateTx - } else { - tx := new(ethtypes.Transaction) - if err = tx.UnmarshalBinary(input); err != nil { - return - } - hash = tx.Hash() - txData, err = ethtx.NewTxDataFromTx(tx) - if err != nil { - return - } + tx := new(ethtypes.Transaction) + if err = tx.UnmarshalBinary(input); err != nil { + return + } + hash = tx.Hash() + txData, err := ethtx.NewTxDataFromTx(tx) + if err != nil { + return } msg, err := types.NewMsgEVMTransaction(txData) if err != nil { diff --git a/evmrpc/send_test.go b/evmrpc/send_test.go index 25ca5db1fe..d7fddc3d04 100644 --- a/evmrpc/send_test.go +++ b/evmrpc/send_test.go @@ -10,8 +10,6 @@ import ( "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" - testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper" - "github.com/sei-protocol/sei-chain/x/evm/types/ethtx" "github.com/stretchr/testify/require" ) @@ -65,22 +63,3 @@ func TestSendRawTransaction(t *testing.T) { errMap = resObj["error"].(map[string]interface{}) require.Equal(t, ": invalid sequence", errMap["message"].(string)) } - -func TestSendAssociateTransaction(t *testing.T) { - privKey := testkeeper.MockPrivateKey() - testPrivHex := hex.EncodeToString(privKey.Bytes()) - key, _ := crypto.HexToECDSA(testPrivHex) - emptyHash := common.Hash{} - sig, err := crypto.Sign(emptyHash[:], key) - require.Nil(t, err) - R, S, _, _ := ethtx.DecodeSignature(sig) - V := big.NewInt(int64(sig[64])) - txData := ethtx.AssociateTx{V: V.Bytes(), R: R.Bytes(), S: S.Bytes()} - bz, err := txData.Marshal() - require.Nil(t, err) - payload := "0x" + hex.EncodeToString(bz) - - resObj := sendRequestGood(t, "sendRawTransaction", payload) - result := resObj["result"].(string) - require.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000000", result) -}