From 11789790c0212affb6a97d6d02f358839031269b Mon Sep 17 00:00:00 2001 From: codchen Date: Fri, 31 May 2024 12:20:59 +0800 Subject: [PATCH] fix tests --- contracts/test/CW20toERC20PointerTest.js | 8 ++++---- contracts/test/ERC20toCW20PointerTest-backup.js | 5 +++-- contracts/test/ERC20toCW20PointerTest.js | 9 +++++---- contracts/test/lib.js | 12 ------------ x/evm/ante/preprocess.go | 6 ++++++ x/evm/state/balance.go | 2 -- 6 files changed, 18 insertions(+), 24 deletions(-) diff --git a/contracts/test/CW20toERC20PointerTest.js b/contracts/test/CW20toERC20PointerTest.js index d638755380..3591fd6e33 100644 --- a/contracts/test/CW20toERC20PointerTest.js +++ b/contracts/test/CW20toERC20PointerTest.js @@ -105,16 +105,16 @@ describe("CW20 to ERC20 Pointer", function () { expect(balanceAfter).to.equal((parseInt(balanceBefore) + 100).toString()); }); - it("transfer to unassociated address should fail", async function() { + it("transfer to unassociated address should succeed", async function() { const unassociatedSeiAddr = "sei1z7qugn2xy4ww0c9nsccftxw592n4xhxccmcf4q"; - const respBefore = await queryWasm(pointer, "balance", {address: accounts[1].seiAddress}); + const respBefore = await queryWasm(pointer, "balance", {address: admin.seiAddress}); const balanceBefore = respBefore.data.balance; await executeWasm(pointer, { transfer: { recipient: unassociatedSeiAddr, amount: "100" } }); - const respAfter = await queryWasm(pointer, "balance", {address: accounts[1].seiAddress}); + const respAfter = await queryWasm(pointer, "balance", {address: admin.seiAddress}); const balanceAfter = respAfter.data.balance; - expect(balanceAfter).to.equal(balanceBefore); + expect(balanceAfter).to.equal((parseInt(balanceBefore) - 100).toString()); }); it("transfer to contract address should succeed", async function() { diff --git a/contracts/test/ERC20toCW20PointerTest-backup.js b/contracts/test/ERC20toCW20PointerTest-backup.js index 1617cf148c..582a2cd518 100644 --- a/contracts/test/ERC20toCW20PointerTest-backup.js +++ b/contracts/test/ERC20toCW20PointerTest-backup.js @@ -99,9 +99,10 @@ describe("ERC20 to CW20 Pointer", function () { await expect(pointer.transfer(recipient.evmAddress, 20000000)).to.be.revertedWith("CosmWasm execute failed"); }); - it("transfer to unassociated address should fail", async function() { + it("transfer to unassociated address should succeed", async function() { const unassociatedRecipient = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; - await expect(pointer.transfer(unassociatedRecipient, 1)).to.be.revertedWithoutReason; + const tx = await pointer.transfer(unassociatedRecipient, 1); + await tx.wait(); }); it("transfer to contract address should succeed", async function() { diff --git a/contracts/test/ERC20toCW20PointerTest.js b/contracts/test/ERC20toCW20PointerTest.js index f8cc4ed66c..32f82f4b48 100644 --- a/contracts/test/ERC20toCW20PointerTest.js +++ b/contracts/test/ERC20toCW20PointerTest.js @@ -108,9 +108,10 @@ describe("ERC20 to CW20 Pointer", function () { await expect(pointer.transfer(recipient.evmAddress, balances.account0*10)).to.be.revertedWith("CosmWasm execute failed"); }); - it("transfer to unassociated address should fail", async function () { + it("transfer to unassociated address should succeed", async function () { const unassociatedRecipient = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; - await expect(pointer.transfer(unassociatedRecipient, 1)).to.be.revertedWithoutReason; + const tx = await pointer.transfer(unassociatedRecipient, 1); + await tx.wait(); }); it("transfer to contract address should succeed", async function () { @@ -263,7 +264,7 @@ describe("ERC20 to CW20 Pointer", function () { // verify new pointer testPointer(() => newPointer, { admin: 1000010, - account0: 1999989, + account0: 1999988, account1: 3000000 }); @@ -282,7 +283,7 @@ describe("ERC20 to CW20 Pointer", function () { // original pointer testPointer(() => pointer, { admin: 1000020, - account0: 1999978, + account0: 1999977, account1: 3000000 }); }) diff --git a/contracts/test/lib.js b/contracts/test/lib.js index ddf6e546e8..8850c6237d 100644 --- a/contracts/test/lib.js +++ b/contracts/test/lib.js @@ -97,7 +97,6 @@ async function importKey(name, keyfile) { } async function getNativeAccount(keyName) { - await associateKey(adminKeyName) const seiAddress = await getKeySeiAddress(keyName) await fundSeiAddress(seiAddress) await delay() @@ -109,7 +108,6 @@ async function getNativeAccount(keyName) { } async function getAdmin() { - await associateKey(adminKeyName) return await getNativeAccount(adminKeyName) } @@ -117,15 +115,6 @@ async function getKeySeiAddress(name) { return (await execute(`seid keys show ${name} -a`)).trim() } -async function associateKey(keyName) { - try { - await execute(`seid tx evm associate-address --from ${keyName} -b block`) - await delay() - }catch(e){ - console.log("skipping associate") - } -} - function getEventAttribute(response, type, attribute) { if(!response.logs || response.logs.length === 0) { throw new Error("logs not returned") @@ -463,7 +452,6 @@ module.exports = { proposeCW20toERC20Upgrade, importKey, getNativeAccount, - associateKey, delay, bankSend, evmSend, diff --git a/x/evm/ante/preprocess.go b/x/evm/ante/preprocess.go index b3f0088b82..7ed1180bbb 100644 --- a/x/evm/ante/preprocess.go +++ b/x/evm/ante/preprocess.go @@ -68,6 +68,12 @@ func (p *EVMPreprocessDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate if !p.accountKeeper.HasAccount(ctx, seiAddr) { p.accountKeeper.SetAccount(ctx, p.accountKeeper.NewAccountWithAddress(ctx, seiAddr)) } + if acc := p.accountKeeper.GetAccount(ctx, seiAddr); acc.GetPubKey() == nil { + if err := acc.SetPubKey(derived.PubKey); err != nil { + return ctx, err + } + p.accountKeeper.SetAccount(ctx, acc) + } if p.evmKeeper.EthReplayConfig.Enabled { p.evmKeeper.PrepareReplayedAddr(ctx, evmAddr) } diff --git a/x/evm/state/balance.go b/x/evm/state/balance.go index 5942788ef2..6a8706b716 100644 --- a/x/evm/state/balance.go +++ b/x/evm/state/balance.go @@ -11,7 +11,6 @@ import ( func (s *DBImpl) SubBalance(evmAddr common.Address, amt *big.Int, reason tracing.BalanceChangeReason) { s.k.PrepareReplayedAddr(s.ctx, evmAddr) - s.k.InitAccount(s.ctx, evmAddr) if amt.Sign() == 0 { return @@ -54,7 +53,6 @@ func (s *DBImpl) SubBalance(evmAddr common.Address, amt *big.Int, reason tracing func (s *DBImpl) AddBalance(evmAddr common.Address, amt *big.Int, reason tracing.BalanceChangeReason) { s.k.PrepareReplayedAddr(s.ctx, evmAddr) - s.k.InitAccount(s.ctx, evmAddr) if amt.Sign() == 0 { return