diff --git a/contracts/test/EVMCompatabilityTest.js b/contracts/test/EVMCompatabilityTest.js index 335d103c58..a5f37c9a11 100644 --- a/contracts/test/EVMCompatabilityTest.js +++ b/contracts/test/EVMCompatabilityTest.js @@ -3,7 +3,7 @@ const {isBigNumber} = require("hardhat/common"); const {uniq, shuffle} = require("lodash"); const { ethers, upgrades } = require('hardhat'); const { getImplementationAddress } = require('@openzeppelin/upgrades-core'); -const { deployEvmContract, setupSigners, fundAddress, getCosmosTx} = require("./lib") +const { deployEvmContract, setupSigners, fundAddress, getCosmosTx, getEvmTx} = require("./lib") const axios = require("axios"); function sleep(ms) { @@ -320,6 +320,9 @@ describe("EVM Test", function () { const cosmosTx = await getCosmosTx(ethers.provider, receipt.hash) expect(cosmosTx.length).to.be.equal(64) + const evmTx = await getEvmTx(ethers.provider, cosmosTx) + expect(evmTx).to.be.equal(receipt.hash) + await expect(txResponse) .to.emit(evmTester, 'StringSet') .withArgs(owner.address, "test"); diff --git a/contracts/test/lib.js b/contracts/test/lib.js index ddf6e546e8..4050db66f8 100644 --- a/contracts/test/lib.js +++ b/contracts/test/lib.js @@ -55,6 +55,10 @@ async function getCosmosTx(provider, evmTxHash) { return await provider.send("sei_getCosmosTx", [evmTxHash]) } +async function getEvmTx(provider, cosmosTxHash) { + return await provider.send("sei_getEvmTx", [cosmosTxHash]) +} + async function fundAddress(addr, amount="10000000000000000000") { const result = await evmSend(addr, adminKeyName, amount) await delay() @@ -469,6 +473,7 @@ module.exports = { evmSend, waitForReceipt, getCosmosTx, + getEvmTx, isDocker, testAPIEnabled, incrementPointerVersion, diff --git a/evmrpc/association.go b/evmrpc/association.go index 5d8af571e4..61aa942f24 100644 --- a/evmrpc/association.go +++ b/evmrpc/association.go @@ -160,3 +160,22 @@ func (t *AssociationAPI) GetCosmosTx(ctx context.Context, ethHash common.Hash) ( } return "", fmt.Errorf("transaction not found") } + +func (t *AssociationAPI) GetEvmTx(ctx context.Context, cosmosHash string) (result string, returnErr error) { + startTime := time.Now() + defer recordMetrics("sei_getEvmTx", t.connectionType, startTime, returnErr == nil) + hashBytes, err := hex.DecodeString(cosmosHash) + if err != nil { + return "", fmt.Errorf("failed to decode cosmosHash: %w", err) + } + + txResponse, err := t.tmClient.Tx(ctx, hashBytes, false) + if err != nil { + return "", err + } + if txResponse.TxResult.EvmTxInfo == nil { + return "", fmt.Errorf("transaction not found") + } + + return txResponse.TxResult.EvmTxInfo.TxHash, nil +} diff --git a/evmrpc/association_test.go b/evmrpc/association_test.go index 893ac8365b..4c50f746c3 100644 --- a/evmrpc/association_test.go +++ b/evmrpc/association_test.go @@ -31,21 +31,27 @@ func TestAssocation(t *testing.T) { } body := sendRequestGoodWithNamespace(t, "sei", "associate", txArgs) - require.Equal(t, body["result"], nil) + require.Equal(t, nil, body["result"]) } func TestGetSeiAddress(t *testing.T) { body := sendRequestGoodWithNamespace(t, "sei", "getSeiAddress", "0x1df809C639027b465B931BD63Ce71c8E5834D9d6") - require.Equal(t, body["result"], "sei1mf0llhmqane5w2y8uynmghmk2w4mh0xll9seym") + require.Equal(t, "sei1mf0llhmqane5w2y8uynmghmk2w4mh0xll9seym", body["result"]) } func TestGetEvmAddress(t *testing.T) { body := sendRequestGoodWithNamespace(t, "sei", "getEVMAddress", "sei1mf0llhmqane5w2y8uynmghmk2w4mh0xll9seym") - require.Equal(t, body["result"], "0x1df809C639027b465B931BD63Ce71c8E5834D9d6") + require.Equal(t, "0x1df809C639027b465B931BD63Ce71c8E5834D9d6", body["result"]) } func TestGetCosmosTx(t *testing.T) { body := sendRequestGoodWithNamespace(t, "sei", "getCosmosTx", "0xf02362077ac075a397344172496b28e913ce5294879d811bb0269b3be20a872e") fmt.Println(body) - require.Equal(t, body["result"], "690D39ADF56D4C811B766DFCD729A415C36C4BFFE80D63E305373B9518EBFB14") + require.Equal(t, "690D39ADF56D4C811B766DFCD729A415C36C4BFFE80D63E305373B9518EBFB14", body["result"]) +} + +func TestGetEvmTx(t *testing.T) { + body := sendRequestGoodWithNamespace(t, "sei", "getEvmTx", "690D39ADF56D4C811B766DFCD729A415C36C4BFFE80D63E305373B9518EBFB14") + fmt.Println(body) + require.Equal(t, "0xf02362077ac075a397344172496b28e913ce5294879d811bb0269b3be20a872e", body["result"]) } diff --git a/evmrpc/setup_test.go b/evmrpc/setup_test.go index cb297b999b..2921d75f6f 100644 --- a/evmrpc/setup_test.go +++ b/evmrpc/setup_test.go @@ -53,6 +53,9 @@ const DebugTraceMockHeight = 101 var DebugTraceHashHex = "0x1234567890123456789023456789012345678901234567890123456789000004" var DebugTraceBlockHash = "BE17E0261E539CB7E9A91E123A6D794E0163D656FCF9B8EAC07823F7ED28512B" +var TestCosmosTxHash = "690D39ADF56D4C811B766DFCD729A415C36C4BFFE80D63E305373B9518EBFB14" +var TestEvmTxHash = "0xf02362077ac075a397344172496b28e913ce5294879d811bb0269b3be20a872e" + var EncodingConfig = app.MakeEncodingConfig() var TxConfig = EncodingConfig.TxConfig var Encoder = TxConfig.TxEncoder() @@ -356,6 +359,10 @@ func (c *MockClient) BroadcastTx(context.Context, tmtypes.Tx) (*coretypes.Result return &coretypes.ResultBroadcastTx{Code: 0, Hash: []byte("0x123")}, nil } +func (c *MockClient) Tx(context.Context, bytes.HexBytes, bool) (*coretypes.ResultTx, error) { + return &coretypes.ResultTx{Hash: bytes.HexBytes(TestCosmosTxHash), Height: MockHeight, TxResult: abci.ExecTxResult{EvmTxInfo: &abci.EvmTxInfo{TxHash: TestEvmTxHash}}}, nil +} + func (c *MockClient) UnconfirmedTxs(ctx context.Context, page, perPage *int) (*coretypes.ResultUnconfirmedTxs, error) { tx, _ := Encoder(UnconfirmedTx) return &coretypes.ResultUnconfirmedTxs{