From c3df7a39a5316155b720c36c9078caa121c7c297 Mon Sep 17 00:00:00 2001 From: RetricSu Date: Thu, 19 May 2022 11:53:13 +0800 Subject: [PATCH 1/3] chore: wait confirm for tx --- contracts/hardhat.config.js | 3 +++ contracts/test/Calc.js | 3 ++- contracts/test/HeadTail.js | 9 ++++++--- contracts/test/SisyhusGamble.js | 19 +++++++++++++------ contracts/test/Token.js | 8 +++++--- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/contracts/hardhat.config.js b/contracts/hardhat.config.js index ac9809c4..807ea36c 100644 --- a/contracts/hardhat.config.js +++ b/contracts/hardhat.config.js @@ -46,6 +46,9 @@ module.exports = { hardfork: "berlin" } }, + mocha: { + timeout: 1800000 // 30 minutes + }, solidity: { compilers: [ { // for polyjuice contracts diff --git a/contracts/test/Calc.js b/contracts/test/Calc.js index 833839c3..e362e147 100644 --- a/contracts/test/Calc.js +++ b/contracts/test/Calc.js @@ -8,7 +8,8 @@ describe("Calc contract", function () { await contract.deployed() //Set data - await contract.store(256); + const i = await contract.store(256); + await i.wait(); //Read data const number = await contract.retrieve(); diff --git a/contracts/test/HeadTail.js b/contracts/test/HeadTail.js index 9e4b8ff7..ceaba0db 100644 --- a/contracts/test/HeadTail.js +++ b/contracts/test/HeadTail.js @@ -99,9 +99,10 @@ describe('HeadTail', () => { expect(await contract.userOneAddress()).to.be.equal(userOne.address); - await contract.connect(userTwo).depositUserTwo(true, { + const tx = await contract.connect(userTwo).depositUserTwo(true, { value: BET_VALUE }); + await tx.wait(); expect(await contract.userTwoAddress()).to.be.equal(userTwo.address); }); @@ -125,15 +126,17 @@ describe('HeadTail', () => { expect(await contract.userOneAddress()).to.be.equal(userOne.address); - await contract.connect(userTwo).depositUserTwo(true, { + const tx = await contract.connect(userTwo).depositUserTwo(true, { gasPrice: 0, value: BET_VALUE }); + await tx.wait(); - await contract.revealUserOneChoice(userOneChoice, userOneChoiceSecret, { + const tx1 = await contract.revealUserOneChoice(userOneChoice, userOneChoiceSecret, { gasPrice: 0, gasLimit: 10000000 }); + await tx1.wait(); expect(await getBalanceAsString(userOne.address)).to.be.equal( startingUserOneBalance.sub(BET_VALUE).toString(), diff --git a/contracts/test/SisyhusGamble.js b/contracts/test/SisyhusGamble.js index b5db7666..99349c6e 100644 --- a/contracts/test/SisyhusGamble.js +++ b/contracts/test/SisyhusGamble.js @@ -26,13 +26,15 @@ describe("SisyphusGamble", function () { expect(balanceOfSender).equals(10000); console.log("Start a new sisyphus gamble"); - await erc20.approve(sisyphusGambleVenues.address, 1); - await sisyphusGambleVenues.newSisyphusGamble(erc20.address, + const tx = await erc20.approve(sisyphusGambleVenues.address, 1); + tx.wait(); + const tx1 = await sisyphusGambleVenues.newSisyphusGamble(erc20.address, 1, // startingPrize 1, // minGamble 1, // weight 2, // gamblingBlocks ); + await tx1.wait(); expect(await erc20.balanceOf(sender.address)).to.equal(balanceOfSender - 1); console.log(` Getting Sisyphus Gamble Venues...`); let gameList = await sisyphusGambleVenues.getSisyphusGambleVenues(); @@ -42,12 +44,17 @@ describe("SisyphusGamble", function () { console.log("SisyphusGambling..."); let gambleContract = await ethers.getContractAt("SisyphusGamble", sisyphusGambleAddress); - await erc20.approve(sisyphusGambleAddress, 3); - await gambleContract.gamble(1); + const tx2 = await erc20.approve(sisyphusGambleAddress, 3); + await tx2.wait(); + const tx3 = await gambleContract.gamble(1); + await tx3.wait(); + expect(await gambleContract.totalPrize()).eq(2); - await gambleContract.gamble(1); + const tx4 = await gambleContract.gamble(1); + await tx4.wait(); expect(await gambleContract.totalPrize()).eq(3); - await gambleContract.gamble(1); + const tx5 = await gambleContract.gamble(1); + await tx5.wait(); expect(await gambleContract.totalPrize()).eq(4); console.log(">> Claim Prize"); diff --git a/contracts/test/Token.js b/contracts/test/Token.js index 28316ce2..a20eb73a 100644 --- a/contracts/test/Token.js +++ b/contracts/test/Token.js @@ -61,7 +61,8 @@ describe("Token contract", function () { describe("Transactions", function () { it("Should transfer tokens between accounts", async function () { // Transfer 50 tokens from owner to addr1 - await hardhatToken.transfer(addr1.address, 50); + const tx = await hardhatToken.transfer(addr1.address, 50); + await tx.wait(); const addr1Balance = await hardhatToken.balanceOf(addr1.address); expect(addr1Balance).to.equal(50); }); @@ -70,8 +71,9 @@ describe("Token contract", function () { const initialOwnerBalance = await hardhatToken.balanceOf(owner.address); // Transfer 100 tokens from owner to addr1. - await hardhatToken.transfer(addr1.address, 100); - + const tx = await hardhatToken.transfer(addr1.address, 100); + await tx.wait(); + // Check balances. const finalOwnerBalance = await hardhatToken.balanceOf(owner.address); expect(finalOwnerBalance).to.equal(initialOwnerBalance.sub(100)); From 5253f4dbed02f916c7ce9a7082090f51d46ceaf7 Mon Sep 17 00:00:00 2001 From: RetricSu Date: Thu, 19 May 2022 14:04:54 +0800 Subject: [PATCH 2/3] chore: add missing await --- contracts/test/SisyhusGamble.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/test/SisyhusGamble.js b/contracts/test/SisyhusGamble.js index 99349c6e..103a516d 100644 --- a/contracts/test/SisyhusGamble.js +++ b/contracts/test/SisyhusGamble.js @@ -27,7 +27,7 @@ describe("SisyphusGamble", function () { console.log("Start a new sisyphus gamble"); const tx = await erc20.approve(sisyphusGambleVenues.address, 1); - tx.wait(); + await tx.wait(); const tx1 = await sisyphusGambleVenues.newSisyphusGamble(erc20.address, 1, // startingPrize 1, // minGamble From 797d386ccc99705ea5ee0372221716ad9b8b7c83 Mon Sep 17 00:00:00 2001 From: RetricSu Date: Mon, 23 May 2022 12:24:04 +0800 Subject: [PATCH 3/3] chore(sisyphusGambleVenues): tune gamblingBlocks from 2 to 4 --- contracts/test/SisyhusGamble.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/test/SisyhusGamble.js b/contracts/test/SisyhusGamble.js index 103a516d..1748c604 100644 --- a/contracts/test/SisyhusGamble.js +++ b/contracts/test/SisyhusGamble.js @@ -32,7 +32,7 @@ describe("SisyphusGamble", function () { 1, // startingPrize 1, // minGamble 1, // weight - 2, // gamblingBlocks + 4, // gamblingBlocks ); await tx1.wait(); expect(await erc20.balanceOf(sender.address)).to.equal(balanceOfSender - 1);