From e9b1d1003c23957243d808a2924db4be914e2129 Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Tue, 18 Jul 2023 13:36:18 +0900 Subject: [PATCH 1/9] add recv/ack test Signed-off-by: Naohiro Yoshida --- e2e/contracts/Makefile | 2 ++ e2e/contracts/apps/ack.js | 21 +++++++++++++++++++++ e2e/contracts/apps/recv.js | 26 ++++++++++++++++++++++++++ e2e/contracts/apps/send.js | 15 +++------------ 4 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 e2e/contracts/apps/ack.js create mode 100644 e2e/contracts/apps/recv.js diff --git a/e2e/contracts/Makefile b/e2e/contracts/Makefile index 06ed839..956ced7 100644 --- a/e2e/contracts/Makefile +++ b/e2e/contracts/Makefile @@ -7,3 +7,5 @@ deploy: .PHONY:test test: npx truffle exec apps/send.js --network bsc_local2 + npx truffle exec apps/recv.js --network bsc_local + npx truffle exec apps/ack.js --network bsc_local2 diff --git a/e2e/contracts/apps/ack.js b/e2e/contracts/apps/ack.js new file mode 100644 index 0000000..c668d5f --- /dev/null +++ b/e2e/contracts/apps/ack.js @@ -0,0 +1,21 @@ +const ICS20Bank = artifacts.require("ICS20Bank"); + +module.exports = async (callback) => { + const accounts = await web3.eth.getAccounts(); + const alice = accounts[0]; + + try { + + const bank = await ICS20Bank.deployed() + const aliceAmount = await bank.balanceOf(alice, "simple") + console.log("after = ", aliceAmount.toString()) + if (parseInt(aliceAmount.toString(), 10) !== 80) { + callback("amount error"); + } else { + callback() + } + + }catch (e) { + callback(e); + } +}; diff --git a/e2e/contracts/apps/recv.js b/e2e/contracts/apps/recv.js new file mode 100644 index 0000000..054b1ed --- /dev/null +++ b/e2e/contracts/apps/recv.js @@ -0,0 +1,26 @@ +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 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) { + callback("amount error"); + } else { + callback() + } + + // Wait for chain A receive the acknowledgement + await sleep(10000) + + }catch (e) { + callback(e); + } +}; diff --git a/e2e/contracts/apps/send.js b/e2e/contracts/apps/send.js index fa9cebb..5d99eca 100644 --- a/e2e/contracts/apps/send.js +++ b/e2e/contracts/apps/send.js @@ -8,8 +8,6 @@ module.exports = async (callback) => { const alice = accounts[0]; const bob = accounts[1]; - const mintAmount = 100; - const sendAmount = 50; const port = "transfer"; const channel = "channel-0"; const timeoutHeight = 0; @@ -20,28 +18,21 @@ module.exports = async (callback) => { const initialAliceAmount = await bank.balanceOf(alice, "simple") console.log("before = ", initialAliceAmount.toString()) - const mintResult = await bank.mint(alice, "simple", mintAmount, { + const mintResult = await bank.mint(alice, "simple", 100, { 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", 20, bob, port, channel, timeoutHeight, { from: alice, }); console.log("send success", transferResult.tx); + // Wait for chain B receive the packet await sleep(10000) - 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() - } - }catch (e) { callback(e); } From 99922d9441d759dedc3ea2c87375e880ed48d86b Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Tue, 18 Jul 2023 14:03:39 +0900 Subject: [PATCH 2/9] change test Signed-off-by: Naohiro Yoshida --- e2e/contracts/apps/recv.js | 4 ++-- e2e/contracts/apps/send.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/e2e/contracts/apps/recv.js b/e2e/contracts/apps/recv.js index 054b1ed..342bf10 100644 --- a/e2e/contracts/apps/recv.js +++ b/e2e/contracts/apps/recv.js @@ -14,11 +14,11 @@ module.exports = async (callback) => { if (parseInt(bobAmount.toString(), 10) !== 20) { callback("amount error"); } else { + // Wait for chain A receive the acknowledgement + await sleep(10000) callback() } - // Wait for chain A receive the acknowledgement - await sleep(10000) }catch (e) { callback(e); diff --git a/e2e/contracts/apps/send.js b/e2e/contracts/apps/send.js index 5d99eca..7e4c528 100644 --- a/e2e/contracts/apps/send.js +++ b/e2e/contracts/apps/send.js @@ -32,6 +32,7 @@ module.exports = async (callback) => { // Wait for chain B receive the packet await sleep(10000) + callback() }catch (e) { callback(e); From 61652c304d10262abfb1f7256e3d893ec9345fdc Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Tue, 18 Jul 2023 14:25:02 +0900 Subject: [PATCH 3/9] change wait time Signed-off-by: Naohiro Yoshida --- e2e/contracts/apps/recv.js | 2 +- e2e/contracts/apps/send.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/contracts/apps/recv.js b/e2e/contracts/apps/recv.js index 342bf10..1b6b528 100644 --- a/e2e/contracts/apps/recv.js +++ b/e2e/contracts/apps/recv.js @@ -15,7 +15,7 @@ module.exports = async (callback) => { callback("amount error"); } else { // Wait for chain A receive the acknowledgement - await sleep(10000) + await sleep(50000) callback() } diff --git a/e2e/contracts/apps/send.js b/e2e/contracts/apps/send.js index 7e4c528..3e5b596 100644 --- a/e2e/contracts/apps/send.js +++ b/e2e/contracts/apps/send.js @@ -31,7 +31,7 @@ module.exports = async (callback) => { console.log("send success", transferResult.tx); // Wait for chain B receive the packet - await sleep(10000) + await sleep(50000) callback() }catch (e) { From d53a818ca47748bfd40dc654b241656c591de8b0 Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Tue, 18 Jul 2023 15:38:08 +0900 Subject: [PATCH 4/9] check escrow balance Signed-off-by: Naohiro Yoshida --- e2e/contracts/apps/ack.js | 18 ++++++++---------- e2e/contracts/apps/recv.js | 10 ++++------ e2e/contracts/apps/send.js | 24 ++++++++++++++++++------ 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/e2e/contracts/apps/ack.js b/e2e/contracts/apps/ack.js index c668d5f..c2050ec 100644 --- a/e2e/contracts/apps/ack.js +++ b/e2e/contracts/apps/ack.js @@ -1,19 +1,17 @@ const ICS20Bank = artifacts.require("ICS20Bank"); +const ICS20TransferBank = artifacts.require("ICS20TransferBank"); -module.exports = async (callback) => { - const accounts = await web3.eth.getAccounts(); - const alice = accounts[0]; +module.exports = async (callback) => { try { - + const escrow = await ICS20TransferBank.deployed() const bank = await ICS20Bank.deployed() - const aliceAmount = await bank.balanceOf(alice, "simple") - console.log("after = ", aliceAmount.toString()) - if (parseInt(aliceAmount.toString(), 10) !== 80) { - callback("amount error"); - } else { - callback() + const escrowAmount = await bank.balanceOf(escrow.address, "simple") + console.log("escrow = ", escrowAmount.toString()) + if (parseInt(escrowAmount.toString(), 10) !== 0) { + return callback("escrow amount error"); } + callback() }catch (e) { callback(e); diff --git a/e2e/contracts/apps/recv.js b/e2e/contracts/apps/recv.js index 1b6b528..9e828cd 100644 --- a/e2e/contracts/apps/recv.js +++ b/e2e/contracts/apps/recv.js @@ -12,13 +12,11 @@ module.exports = async (callback) => { const bobAmount = await bank.balanceOf(bob, `transfer/channel-0/simple`) console.log("received = ", bobAmount.toString()) if (parseInt(bobAmount.toString(), 10) !== 20) { - callback("amount error"); - } else { - // Wait for chain A receive the acknowledgement - await sleep(50000) - callback() + return callback("bob amount error"); } - + // Wait for chain A receive the acknowledgement + await sleep(30000) + callback() }catch (e) { callback(e); diff --git a/e2e/contracts/apps/send.js b/e2e/contracts/apps/send.js index 3e5b596..ef3ce12 100644 --- a/e2e/contracts/apps/send.js +++ b/e2e/contracts/apps/send.js @@ -11,27 +11,39 @@ module.exports = async (callback) => { 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", 100, { + 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", 20, bob, port, channel, timeoutHeight, { + const transferResult = await transfer.sendTransfer("simple", sendingAmount, bob, port, channel, timeoutHeight, { from: alice, }); console.log("send success", transferResult.tx); + // Check reduced amount + const aliceAmount = await bank.balanceOf(alice, "simple") + console.log("after = ", aliceAmount.toString()) + 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 - await sleep(50000) + await sleep(30000) callback() }catch (e) { From ef4850579c895caba09b6e54e2e6e3092626ec2f Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Tue, 18 Jul 2023 16:02:07 +0900 Subject: [PATCH 5/9] change test Signed-off-by: Naohiro Yoshida --- e2e/contracts/Makefile | 2 ++ e2e/contracts/apps/ack.js | 1 - e2e/contracts/apps/recv.js | 4 ---- e2e/contracts/apps/send.js | 3 --- 4 files changed, 2 insertions(+), 8 deletions(-) diff --git a/e2e/contracts/Makefile b/e2e/contracts/Makefile index 956ced7..d7262df 100644 --- a/e2e/contracts/Makefile +++ b/e2e/contracts/Makefile @@ -7,5 +7,7 @@ deploy: .PHONY:test test: npx truffle exec apps/send.js --network bsc_local2 + sleep 30 npx truffle exec apps/recv.js --network bsc_local + sleep 30 npx truffle exec apps/ack.js --network bsc_local2 diff --git a/e2e/contracts/apps/ack.js b/e2e/contracts/apps/ack.js index c2050ec..427ede5 100644 --- a/e2e/contracts/apps/ack.js +++ b/e2e/contracts/apps/ack.js @@ -1,7 +1,6 @@ const ICS20Bank = artifacts.require("ICS20Bank"); const ICS20TransferBank = artifacts.require("ICS20TransferBank"); - module.exports = async (callback) => { try { const escrow = await ICS20TransferBank.deployed() diff --git a/e2e/contracts/apps/recv.js b/e2e/contracts/apps/recv.js index 9e828cd..bbb2050 100644 --- a/e2e/contracts/apps/recv.js +++ b/e2e/contracts/apps/recv.js @@ -1,7 +1,5 @@ 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 bob = accounts[1] @@ -14,8 +12,6 @@ module.exports = async (callback) => { if (parseInt(bobAmount.toString(), 10) !== 20) { return callback("bob amount error"); } - // Wait for chain A receive the acknowledgement - await sleep(30000) callback() }catch (e) { diff --git a/e2e/contracts/apps/send.js b/e2e/contracts/apps/send.js index ef3ce12..80c350b 100644 --- a/e2e/contracts/apps/send.js +++ b/e2e/contracts/apps/send.js @@ -1,8 +1,6 @@ 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]; @@ -43,7 +41,6 @@ module.exports = async (callback) => { return callback("escrow amount error"); } // Wait for chain B receive the packet - await sleep(30000) callback() }catch (e) { From 2dac07429abb386f6fb2d9fe7d1c2f3f18ebe306 Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Tue, 18 Jul 2023 16:21:18 +0900 Subject: [PATCH 6/9] fix ack Signed-off-by: Naohiro Yoshida --- e2e/contracts/Makefile | 6 +++--- e2e/contracts/apps/ack.js | 18 ------------------ 2 files changed, 3 insertions(+), 21 deletions(-) delete mode 100644 e2e/contracts/apps/ack.js diff --git a/e2e/contracts/Makefile b/e2e/contracts/Makefile index d7262df..5b9f40a 100644 --- a/e2e/contracts/Makefile +++ b/e2e/contracts/Makefile @@ -7,7 +7,7 @@ deploy: .PHONY:test test: npx truffle exec apps/send.js --network bsc_local2 - sleep 30 + sleep 60 npx truffle exec apps/recv.js --network bsc_local - sleep 30 - npx truffle exec apps/ack.js --network bsc_local2 + sleep 60 + ../testrly query unrelayed-acknowledgements ibc01 --home .testrly | grep '{"src":null,"dst":null}' diff --git a/e2e/contracts/apps/ack.js b/e2e/contracts/apps/ack.js deleted file mode 100644 index 427ede5..0000000 --- a/e2e/contracts/apps/ack.js +++ /dev/null @@ -1,18 +0,0 @@ -const ICS20Bank = artifacts.require("ICS20Bank"); -const ICS20TransferBank = artifacts.require("ICS20TransferBank"); - -module.exports = async (callback) => { - try { - const escrow = await ICS20TransferBank.deployed() - const bank = await ICS20Bank.deployed() - const escrowAmount = await bank.balanceOf(escrow.address, "simple") - console.log("escrow = ", escrowAmount.toString()) - if (parseInt(escrowAmount.toString(), 10) !== 0) { - return callback("escrow amount error"); - } - callback() - - }catch (e) { - callback(e); - } -}; From 55c16bcc77fee68e9018ecf698c628fb7b60d9b4 Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Tue, 18 Jul 2023 16:22:57 +0900 Subject: [PATCH 7/9] change path Signed-off-by: Naohiro Yoshida --- e2e/contracts/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/contracts/Makefile b/e2e/contracts/Makefile index 5b9f40a..f4001ab 100644 --- a/e2e/contracts/Makefile +++ b/e2e/contracts/Makefile @@ -10,4 +10,4 @@ test: sleep 60 npx truffle exec apps/recv.js --network bsc_local sleep 60 - ../testrly query unrelayed-acknowledgements ibc01 --home .testrly | grep '{"src":null,"dst":null}' + ../testrly query unrelayed-acknowledgements ibc01 --home ../.testrly | grep '{"src":null,"dst":null}' From 120cfbddb8dd393c27d9af92fa222fd3260baab9 Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Wed, 19 Jul 2023 11:27:39 +0900 Subject: [PATCH 8/9] use explicit command for test Signed-off-by: Naohiro Yoshida --- e2e/Makefile | 1 - e2e/contracts/Makefile | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/Makefile b/e2e/Makefile index 489e370..33aaf36 100644 --- a/e2e/Makefile +++ b/e2e/Makefile @@ -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: diff --git a/e2e/contracts/Makefile b/e2e/contracts/Makefile index f4001ab..1bd591a 100644 --- a/e2e/contracts/Makefile +++ b/e2e/contracts/Makefile @@ -7,7 +7,8 @@ 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 - sleep 60 + ../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}' From eb120093ca701031135805f8444e990aabefdc75 Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Wed, 19 Jul 2023 11:47:30 +0900 Subject: [PATCH 9/9] wait Signed-off-by: Naohiro Yoshida --- e2e/contracts/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/e2e/contracts/Makefile b/e2e/contracts/Makefile index 1bd591a..35119e8 100644 --- a/e2e/contracts/Makefile +++ b/e2e/contracts/Makefile @@ -7,6 +7,7 @@ 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}'