Skip to content

Commit 9fd6060

Browse files
author
Naohiro Yoshida
committed
tweak test
Signed-off-by: Naohiro Yoshida <naohiro.yoshida@datachain.jp>
1 parent af504ed commit 9fd6060

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

e2e/contracts/scripts/recv.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
async function readContract(contractName) {
2-
const fs = require("fs");
3-
const path = require("path");
4-
5-
const filepath = path.join("addresses", contractName);
6-
const address = fs.readFileSync(filepath, "utf-8");
7-
return await hre.ethers.getContractAt(contractName, address);
8-
}
1+
const util = require("./util");
92

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

147
try {
158

16-
const bank = await readContract("ICS20Bank");
9+
const bank = await util.readContract("ICS20Bank");
1710
const bobAmount = await bank.balanceOf(bob, `transfer/channel-0/simple_erc_20_token_for_test`)
1811
console.log("received = ", bobAmount.toString())
1912
if (parseInt(bobAmount.toString(), 10) !== 20) {

e2e/contracts/scripts/send.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
async function readContract(contractName) {
2-
const fs = require("fs");
3-
const path = require("path");
4-
5-
const filepath = path.join("addresses", contractName);
6-
const address = fs.readFileSync(filepath, "utf-8");
7-
return await hre.ethers.getContractAt(contractName, address);
8-
}
1+
const util = require("./util");
92

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

2114
try {
2215
// Mint
23-
const bank = await readContract("ICS20Bank");
16+
const bank = await util.readContract("ICS20Bank");
2417
const mintResult = await bank.mint(alice, "simple_erc_20_token_for_test", mintAmount, {
2518
from: alice
2619
});
2720
const mintReceipt = await mintResult.wait()
28-
console.log("mint success block=", mintReceipt);
21+
console.log("mint success", mintReceipt.hash);
2922

3023
// Send to counterparty chain
31-
const transfer = await readContract("ICS20TransferBank");
32-
console.log(transfer.interface)
24+
const transfer = await util.readContract("ICS20TransferBank");
3325
const transferResult = await transfer.sendTransfer("simple_erc_20_token_for_test", sendingAmount, bob, port, channel, timeoutHeight, {
3426
from: alice,
3527
});
3628
const transferReceipt = await transferResult.wait()
37-
console.log("send success block=", transferReceipt);
29+
console.log("send success", transferReceipt.hash);
3830

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

4638
// Check escrow balance
47-
const escrowAmount = await bank.balanceOf(transfer.address, "simple_erc_20_token_for_test")
39+
const escrowAmount = await bank.balanceOf(transfer.target, "simple_erc_20_token_for_test")
4840
console.log("escrow = ", escrowAmount.toString())
4941
if (parseInt(escrowAmount.toString(), 10) !== sendingAmount) {
5042
throw new Error("escrow amount error");

e2e/contracts/scripts/util.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
async function readContract(contractName) {
2+
const fs = require("fs");
3+
const path = require("path");
4+
5+
const filepath = path.join("addresses", contractName);
6+
const address = fs.readFileSync(filepath, "utf-8");
7+
return await hre.ethers.getContractAt(contractName, address);
8+
}
9+
10+
module.exports = {
11+
readContract
12+
};

0 commit comments

Comments
 (0)