Skip to content

Commit

Permalink
hardhat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed Jul 1, 2024
1 parent b551d45 commit a1a975a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
3 changes: 0 additions & 3 deletions contracts/src/CW20ERC20Pointer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ contract CW20ERC20Pointer is ERC20 {
string memory req = _curlyBrace(_formatPayload("increase_allowance", _curlyBrace(_join(spenderAddr, amt, ","))));
_execute(bytes(req));
}
emit Approval(msg.sender, spender, amount);
return true;
}

Expand All @@ -83,7 +82,6 @@ contract CW20ERC20Pointer is ERC20 {
string memory amt = _formatPayload("amount", _doubleQuotes(Strings.toString(amount)));
string memory req = _curlyBrace(_formatPayload("transfer", _curlyBrace(_join(recipient, amt, ","))));
_execute(bytes(req));
emit Transfer(msg.sender, to, amount);
return true;
}

Expand All @@ -94,7 +92,6 @@ contract CW20ERC20Pointer is ERC20 {
string memory amt = _formatPayload("amount", _doubleQuotes(Strings.toString(amount)));
string memory req = _curlyBrace(_formatPayload("transfer_from", _curlyBrace(_join(_join(sender, recipient, ","), amt, ","))));
_execute(bytes(req));
emit Transfer(from, to, amount);
return true;
}

Expand Down
22 changes: 22 additions & 0 deletions contracts/test/ERC20toCW20PointerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,23 @@ describe("ERC20 to CW20 Pointer", function () {
expect(await pointer.balanceOf(sender.evmAddress)).to.equal(balances.account0);
expect(await pointer.balanceOf(recipient.evmAddress)).to.equal(balances.account1);

const blockNumber = await ethers.provider.getBlockNumber();
const tx = await pointer.transfer(recipient.evmAddress, 1);
await tx.wait();

expect(await pointer.balanceOf(sender.evmAddress)).to.equal(balances.account0-1);
expect(await pointer.balanceOf(recipient.evmAddress)).to.equal(balances.account1+1);

// check logs
const filter = {
fromBlock: blockNumber,
toBlock: 'latest',
address: await pointer.getAddress(),
topics: [ethers.id("Transfer(address,address,uint256)")]
};
const logs = await ethers.provider.getLogs(filter);
expect(logs.length).to.equal(1);

const cleanupTx = await pointer.connect(recipient.signer).transfer(sender.evmAddress, 1);
await cleanupTx.wait();
});
Expand All @@ -124,10 +135,21 @@ describe("ERC20 to CW20 Pointer", function () {
it("should approve", async function () {
const owner = accounts[0].evmAddress;
const spender = accounts[1].evmAddress;
const blockNumber = await ethers.provider.getBlockNumber();
const tx = await pointer.approve(spender, 1000000);
await tx.wait();
const allowance = await pointer.allowance(owner, spender);
expect(Number(allowance)).to.equal(1000000);

// check logs
const filter = {
fromBlock: blockNumber,
toBlock: 'latest',
address: await pointer.getAddress(),
topics: [ethers.id("Approval(address,address,uint256)")]
};
const logs = await ethers.provider.getLogs(filter);
expect(logs.length).to.equal(1);
});

it("should lower approval", async function () {
Expand Down
2 changes: 1 addition & 1 deletion x/evm/artifacts/README
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The source files are under contracts/src. The artifacts should be updated whenever the source files change. To update run the following (with NativeSeiTokensERC20 as an example):
- `solc --overwrite @openzeppelin=contracts/lib/openzeppelin-contracts --bin -o x/evm/artifacts/cw721 contracts/src/CW721ERC721Pointer.sol`
- `solc --overwrite @openzeppelin=contracts/lib/openzeppelin-contracts --bin -o x/evm/artifacts/cw20 contracts/src/CW721ERC721Pointer.sol`
- `solc --overwrite @openzeppelin=contracts/lib/openzeppelin-contracts --abi -o x/evm/artifacts/cw721 contracts/src/CW721ERC721Pointer.sol`
- (clean up any artifact that is not CW721ERC721Pointer.bin/abi)
- `abigen --abi=x/evm/artifacts/cw721/CW721ERC721Pointer.abi --pkg=cw721 --out=x/evm/artifacts/cw721/cw721.go`
2 changes: 1 addition & 1 deletion x/evm/artifacts/cw20/CW20ERC20Pointer.bin

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion x/evm/artifacts/cw20/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/sei-protocol/sei-chain/x/evm/config"
)

const currentVersion uint16 = 1
const currentVersion uint16 = 2

var versionOverride uint16

Expand Down

0 comments on commit a1a975a

Please sign in to comment.