Skip to content

Commit

Permalink
tweak test
Browse files Browse the repository at this point in the history
Signed-off-by: Naohiro Yoshida <[email protected]>
  • Loading branch information
Naohiro Yoshida committed Dec 2, 2024
1 parent af504ed commit 9fd6060
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
11 changes: 2 additions & 9 deletions e2e/contracts/scripts/recv.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
async function readContract(contractName) {
const fs = require("fs");
const path = require("path");

const filepath = path.join("addresses", contractName);
const address = fs.readFileSync(filepath, "utf-8");
return await hre.ethers.getContractAt(contractName, address);
}
const util = require("./util");

async function main() {
const accounts = await hre.ethers.getSigners();
const bob = accounts[1]

try {

const bank = await readContract("ICS20Bank");
const bank = await util.readContract("ICS20Bank");
const bobAmount = await bank.balanceOf(bob, `transfer/channel-0/simple_erc_20_token_for_test`)
console.log("received = ", bobAmount.toString())
if (parseInt(bobAmount.toString(), 10) !== 20) {
Expand Down
20 changes: 6 additions & 14 deletions e2e/contracts/scripts/send.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
async function readContract(contractName) {
const fs = require("fs");
const path = require("path");

const filepath = path.join("addresses", contractName);
const address = fs.readFileSync(filepath, "utf-8");
return await hre.ethers.getContractAt(contractName, address);
}
const util = require("./util");

async function main() {
const accounts = await hre.ethers.getSigners();
Expand All @@ -20,21 +13,20 @@ async function main() {

try {
// Mint
const bank = await readContract("ICS20Bank");
const bank = await util.readContract("ICS20Bank");
const mintResult = await bank.mint(alice, "simple_erc_20_token_for_test", mintAmount, {
from: alice
});
const mintReceipt = await mintResult.wait()
console.log("mint success block=", mintReceipt);
console.log("mint success", mintReceipt.hash);

// Send to counterparty chain
const transfer = await readContract("ICS20TransferBank");
console.log(transfer.interface)
const transfer = await util.readContract("ICS20TransferBank");
const transferResult = await transfer.sendTransfer("simple_erc_20_token_for_test", sendingAmount, bob, port, channel, timeoutHeight, {
from: alice,
});
const transferReceipt = await transferResult.wait()
console.log("send success block=", transferReceipt);
console.log("send success", transferReceipt.hash);

// Check reduced amount
const aliceAmount = await bank.balanceOf(alice, "simple_erc_20_token_for_test")
Expand All @@ -44,7 +36,7 @@ async function main() {
}

// Check escrow balance
const escrowAmount = await bank.balanceOf(transfer.address, "simple_erc_20_token_for_test")
const escrowAmount = await bank.balanceOf(transfer.target, "simple_erc_20_token_for_test")
console.log("escrow = ", escrowAmount.toString())
if (parseInt(escrowAmount.toString(), 10) !== sendingAmount) {
throw new Error("escrow amount error");
Expand Down
12 changes: 12 additions & 0 deletions e2e/contracts/scripts/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
async function readContract(contractName) {
const fs = require("fs");
const path = require("path");

const filepath = path.join("addresses", contractName);
const address = fs.readFileSync(filepath, "utf-8");
return await hre.ethers.getContractAt(contractName, address);
}

module.exports = {
readContract
};

0 comments on commit 9fd6060

Please sign in to comment.