Skip to content

Commit

Permalink
Merge pull request #11 from datachainlab/add_test
Browse files Browse the repository at this point in the history
Add recv and ack test
  • Loading branch information
siburu authored Jul 19, 2023
2 parents db1c972 + eb12009 commit c143d97
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
1 change: 0 additions & 1 deletion e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ relayer:
./testrly tx update-clients ibc01 --home .testrly
./testrly tx connection ibc01 --home .testrly
./testrly tx channel ibc01 --home .testrly
nohup ./testrly service start ibc01 --home .testrly > testrly.log &

.PHONY:test
test:
Expand Down
6 changes: 6 additions & 0 deletions e2e/contracts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ deploy:
.PHONY:test
test:
npx truffle exec apps/send.js --network bsc_local2
sleep 60
../testrly tx relay ibc01 --home ../.testrly
npx truffle exec apps/recv.js --network bsc_local
../testrly query unrelayed-packets ibc01 --home ../.testrly | grep '{"src":null,"dst":null}'
../testrly tx relay-acknowledgements ibc01 --home ../.testrly
../testrly query unrelayed-acknowledgements ibc01 --home ../.testrly | grep '{"src":null,"dst":null}'
20 changes: 20 additions & 0 deletions e2e/contracts/apps/recv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const ICS20Bank = artifacts.require("ICS20Bank");

module.exports = async (callback) => {
const accounts = await web3.eth.getAccounts();
const bob = accounts[1]

try {

const bank = await ICS20Bank.deployed()
const bobAmount = await bank.balanceOf(bob, `transfer/channel-0/simple`)
console.log("received = ", bobAmount.toString())
if (parseInt(bobAmount.toString(), 10) !== 20) {
return callback("bob amount error");
}
callback()

}catch (e) {
callback(e);
}
};
29 changes: 15 additions & 14 deletions e2e/contracts/apps/send.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
const ICS20TransferBank = artifacts.require("ICS20TransferBank");
const ICS20Bank = artifacts.require("ICS20Bank");

const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))

module.exports = async (callback) => {
const accounts = await web3.eth.getAccounts();
const alice = accounts[0];
const bob = accounts[1];

const mintAmount = 100;
const sendAmount = 50;
const port = "transfer";
const channel = "channel-0";
const timeoutHeight = 0;
const mintAmount = 100;
const sendingAmount = 20

try {
// Mint
const bank = await ICS20Bank.deployed()
const initialAliceAmount = await bank.balanceOf(alice, "simple")
console.log("before = ", initialAliceAmount.toString())

const mintResult = await bank.mint(alice, "simple", mintAmount, {
from: alice
});
console.log("mint success", mintResult.tx);

// Send to counterparty chain
const transfer = await ICS20TransferBank.deployed()
const transferResult = await transfer.sendTransfer("simple", sendAmount, bob, port, channel, timeoutHeight, {
const transferResult = await transfer.sendTransfer("simple", sendingAmount, bob, port, channel, timeoutHeight, {
from: alice,
});
console.log("send success", transferResult.tx);

await sleep(10000)

// Check reduced amount
const aliceAmount = await bank.balanceOf(alice, "simple")
console.log("after = ", aliceAmount.toString())
if (parseInt(aliceAmount.toString(), 10) !== parseInt(initialAliceAmount.toString(), 10) + 50) {
callback("amount error");
} else {
callback()
if (parseInt(aliceAmount.toString(), 10) !== mintAmount - sendingAmount) {
return callback("alice amount error");
}

// Check escrow balance
const escrowAmount = await bank.balanceOf(transfer.address, "simple")
console.log("escrow = ", escrowAmount.toString())
if (parseInt(escrowAmount.toString(), 10) !== sendingAmount) {
return callback("escrow amount error");
}
// Wait for chain B receive the packet
callback()

}catch (e) {
callback(e);
Expand Down

0 comments on commit c143d97

Please sign in to comment.