Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen authored and stevenlanders committed May 31, 2024
1 parent 31c7586 commit 1178979
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 24 deletions.
8 changes: 4 additions & 4 deletions contracts/test/CW20toERC20PointerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 3 additions & 2 deletions contracts/test/ERC20toCW20PointerTest-backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
9 changes: 5 additions & 4 deletions contracts/test/ERC20toCW20PointerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -263,7 +264,7 @@ describe("ERC20 to CW20 Pointer", function () {
// verify new pointer
testPointer(() => newPointer, {
admin: 1000010,
account0: 1999989,
account0: 1999988,
account1: 3000000
});

Expand All @@ -282,7 +283,7 @@ describe("ERC20 to CW20 Pointer", function () {
// original pointer
testPointer(() => pointer, {
admin: 1000020,
account0: 1999978,
account0: 1999977,
account1: 3000000
});
})
Expand Down
12 changes: 0 additions & 12 deletions contracts/test/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -109,23 +108,13 @@ async function getNativeAccount(keyName) {
}

async function getAdmin() {
await associateKey(adminKeyName)
return await getNativeAccount(adminKeyName)
}

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")
Expand Down Expand Up @@ -463,7 +452,6 @@ module.exports = {
proposeCW20toERC20Upgrade,
importKey,
getNativeAccount,
associateKey,
delay,
bankSend,
evmSend,
Expand Down
6 changes: 6 additions & 0 deletions x/evm/ante/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 78 in x/evm/ante/preprocess.go

View check run for this annotation

Codecov / codecov/patch

x/evm/ante/preprocess.go#L78

Added line #L78 was not covered by tests
}
Expand Down
2 changes: 0 additions & 2 deletions x/evm/state/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1178979

Please sign in to comment.