Skip to content

Commit

Permalink
fix()
Browse files Browse the repository at this point in the history
  • Loading branch information
immortal-tofu committed Nov 29, 2023
1 parent d3a9b1a commit 07a67bd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"task:allJoin": "hardhat task:allJoin",
"task:takeCard": "hardhat task:takeCard",
"task:accounts": "hardhat task:accounts",
"fhevm:start": "docker run -i -p 8545:8545 --rm --name fhevm ghcr.io/zama-ai/evmos-dev-node:v0.1.10",
"fhevm:start": "docker run -i -p 8545:8545 -p 8546:8546 --rm --name fhevm ghcr.io/zama-ai/evmos-dev-node:v0.1.10",
"fhevm:stop": "docker rm -f fhevm",
"fhevm:restart": "fhevm:stop && fhevm:start",
"fhevm:faucet": "npm run fhevm:faucet:alice && sleep 5 && npm run fhevm:faucet:bob && sleep 5 && npm run fhevm:faucet:carol && sleep 5 && npm run fhevm:faucet:dave",
Expand Down
50 changes: 34 additions & 16 deletions tasks/cipherbomb.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { task } from "hardhat/config";
import type { TaskArguments } from "hardhat/types";
import { task } from 'hardhat/config';
import type { TaskArguments } from 'hardhat/types';

import { Signers, getSigners } from "../test/signers";
import { Signers, getSigners } from '../test/signers';

task("task:join")
.addParam("address", "Address of the game")
.addParam("account", "Specify which account [alice, bob, carol, dave]")
task('task:join')
.addParam('address', 'Address of the game')
.addParam('account', 'Specify which account [alice, bob, carol, dave]')
.setAction(async function (taskArguments: TaskArguments, hre) {
const { ethers } = hre;
const signers = await getSigners(ethers);
const cipherbomb = await ethers.getContractAt(
"CipherBomb",
'CipherBomb',
taskArguments.address,
signers[taskArguments.account as keyof Signers],
);
Expand All @@ -21,19 +21,20 @@ task("task:join")
console.log(`${taskArguments.account} joined!`);
});

task("task:allJoin")
.addParam("address", "Address of the game")
task('task:allJoin')
.addParam('address', 'Address of the game')
.setAction(async function (taskArguments: TaskArguments, hre) {
const { ethers } = hre;
const signers = await getSigners(ethers);

await ["alice", "bob", "carol"].reduce(async (previous, account) => {
await ['alice', 'bob', 'carol'].reduce(async (previous, account) => {
await previous;
const cipherbomb = await ethers.getContractAt(
"CipherBomb",
'CipherBomb',
taskArguments.address,
signers[account as keyof Signers],
);
console.log(await cipherbomb.numberOfPlayers());
try {
const tx = await cipherbomb.join();
await cipherbomb.setName(account);
Expand All @@ -45,15 +46,15 @@ task("task:allJoin")
}, Promise.resolve());
});

task("task:takeCard")
.addParam("address", "Address of the game")
.addParam("account", "Specify which account [alice, bob, carol, dave]")
.addParam("from", "Specify which account from take a card")
task('task:takeCard')
.addParam('address', 'Address of the game')
.addParam('account', 'Specify which account [alice, bob, carol, dave]')
.addParam('from', 'Specify which account from take a card')
.setAction(async function (taskArguments: TaskArguments, hre) {
const { ethers } = hre;
const signers = await getSigners(ethers);
const cipherbomb = await ethers.getContractAt(
"CipherBomb",
'CipherBomb',
taskArguments.address,
signers[taskArguments.account as keyof Signers],
);
Expand All @@ -63,3 +64,20 @@ task("task:takeCard")

console.log(`${taskArguments.account} took a card from ${taskArguments.from}!`);
});

task('task:playerNameChanged')
.addParam('address', 'Address of the game')
.setAction(async function (taskArguments: TaskArguments, hre) {
const { ethers } = hre;
const signers = await getSigners(ethers);
const cipherbomb = await ethers.getContractAt(
'CipherBomb',
taskArguments.address,
signers[taskArguments.account as keyof Signers],
);
await new Promise(() => {
void cipherbomb.on(cipherbomb.filters.PlayerNameChanged, (address: string, name: string) =>
console.log('Change', address, name),
);
});
});
9 changes: 4 additions & 5 deletions test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { ContractMethodArgs, Typed } from "ethers";
import { ContractMethodArgs, Typed } from 'ethers';

// import { ethers } from "hardhat";
import { TypedContractMethod } from "../types/common";
import { TypedContractMethod } from '../types/common';

export const waitForBlock = (blockNumber: bigint, ethers: any) => {
return new Promise((resolve, reject) => {
const waitBlock = async (currentBlock: number) => {
// console.log(`Block ${currentBlock} reached! Waiting ${blockNumber}...`);
if (blockNumber <= BigInt(currentBlock)) {
// console.log(`Block ${currentBlock} reached!`);
await ethers.provider.off("block", waitBlock);
await ethers.provider.off('block', waitBlock);
resolve(blockNumber);
}
};
ethers.provider.on("block", waitBlock).catch((err: any) => {
ethers.provider.on('block', waitBlock).catch((err: any) => {
reject(err);
});
});
Expand All @@ -24,7 +24,6 @@ export const createTransaction = async <A extends [...{ [I in keyof A]-?: A[I] |
...params: A
) => {
const gasLimit = await method.estimateGas(...params);
console.log(gasLimit);
const updatedParams: ContractMethodArgs<A> = [
...params,
{ gasLimit: Math.min(10_000_000, Math.round(+gasLimit.toString() * 1.2)) },
Expand Down

0 comments on commit 07a67bd

Please sign in to comment.