From fa620f1f5fe5c7eaeda6223ed8afc1b12b0711ef Mon Sep 17 00:00:00 2001 From: codchen Date: Thu, 19 Sep 2024 12:48:11 +0800 Subject: [PATCH] Fix events in 2-hop scenarios (#1857) * Fix events in 2-hop scenarios * integration test --- contracts/test/CW20toERC20PointerTest.js | 8 +++++++ x/evm/keeper/msg_server.go | 28 ++++++++++++------------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/contracts/test/CW20toERC20PointerTest.js b/contracts/test/CW20toERC20PointerTest.js index 0638aa38f..f1444fa5b 100644 --- a/contracts/test/CW20toERC20PointerTest.js +++ b/contracts/test/CW20toERC20PointerTest.js @@ -184,6 +184,14 @@ describe("CW20 to ERC20 Pointer", function () { const response = await wasmd.execute(pointer, transferBz, coinsBz); const receipt = await response.wait(); expect(receipt.status).to.equal(1); + + const filter = { + fromBlock: receipt["blockNumber"], + toBlock: 'latest', + topics: [ethers.id("Transfer(address,address,uint256)")] + }; + const logs = await ethers.provider.getLogs(filter); + expect(logs.length).to.equal(1); }); }); }); diff --git a/x/evm/keeper/msg_server.go b/x/evm/keeper/msg_server.go index 0402ff48a..76e9d329a 100644 --- a/x/evm/keeper/msg_server.go +++ b/x/evm/keeper/msg_server.go @@ -90,6 +90,20 @@ func (server msgServer) EVMTransaction(goCtx context.Context, msg *types.MsgEVMT return } extraSurplus := sdk.ZeroInt() + surplus, ferr := stateDB.Finalize() + if ferr != nil { + err = ferr + ctx.Logger().Error(fmt.Sprintf("failed to finalize EVM stateDB: %s", err)) + + telemetry.IncrCounterWithLabels( + []string{types.ModuleName, "errors", "stateDB_finalize"}, + 1, + []metrics.Label{ + telemetry.NewLabel("type", err.Error()), + }, + ) + return + } if isWasmdPrecompileCall { syntheticReceipt, err := server.GetTransientReceipt(ctx, ctx.TxSum()) if err == nil { @@ -132,20 +146,6 @@ func (server msgServer) EVMTransaction(goCtx context.Context, msg *types.MsgEVMT telemetry.IncrCounter(1, "receipt", "status", "success") } - surplus, ferr := stateDB.Finalize() - if ferr != nil { - err = ferr - ctx.Logger().Error(fmt.Sprintf("failed to finalize EVM stateDB: %s", err)) - - telemetry.IncrCounterWithLabels( - []string{types.ModuleName, "errors", "stateDB_finalize"}, - 1, - []metrics.Label{ - telemetry.NewLabel("type", err.Error()), - }, - ) - return - } surplus = surplus.Add(extraSurplus) bloom := ethtypes.Bloom{} bloom.SetBytes(receipt.LogsBloom)