Skip to content

Commit

Permalink
Separate endpoint for associateTx (#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen authored and udpatil committed Mar 4, 2024
1 parent b807997 commit 03be332
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 41 deletions.
3 changes: 1 addition & 2 deletions contracts/test/EVMCompatabilityTester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
})
Expand Down
25 changes: 21 additions & 4 deletions evmrpc/association.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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) {
Expand Down
22 changes: 8 additions & 14 deletions evmrpc/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 0 additions & 21 deletions evmrpc/send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}

0 comments on commit 03be332

Please sign in to comment.