Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
its-saeed committed Nov 3, 2023
1 parent c16a07f commit 36a8c4b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
40 changes: 36 additions & 4 deletions tests/EvmAcceptanceTests/tasks/InitSigners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,33 @@ import {join} from "path";
import clc from "cli-color";
import ora from "ora";
import {getAddressFromPrivateKey} from "@zilliqa-js/zilliqa";
import { getEthAddress } from "../helpers/SignersHelper";

task("init-signers", "A task to init signers")
.addParam("from", "Sender's private key")
.addParam(
"fromAddressType",
"It can be either `eth` or `zil`. If eth is selected, Eth address of private key will be used. Otherwise, the zil address will be used."
)
.addParam("count", "Number of signers to be generated")
.addParam("balance", "Balance of each newly generated signers")
.addFlag("append", "Append new signers to the end of the .signer-<network> file")
.setAction(async (taskArgs, hre) => {
const {from, count, balance, append} = taskArgs;
const {from, fromAddressType, count, balance, append} = taskArgs;

const spinner = ora();
spinner.start(`Creating ${count} accounts...`);

const accounts = await createAccountsEth(hre, from, hre.ethers.utils.parseEther(balance), count);

let accounts = [];
if (fromAddressType === "eth") {
accounts = await createAccountsEth(hre, from, hre.ethers.utils.parseEther(balance), count);
} else if (fromAddressType === "zil") {
accounts = await createAccountsZil(hre, from, hre.ethers.utils.parseEther(balance), count);
} else {
console.log(`--from-address-type should be either eth or zil. ${fromAddressType} is not supported`);
spinner.fail();
return;
}

spinner.succeed();

Expand Down Expand Up @@ -69,9 +83,27 @@ const createAccountsEth = async (
...accounts.map((signer) => getAddressFromPrivateKey(signer.privateKey).toLocaleLowerCase())
];

const value = amount.mul(addresses.length)

await hre.deployContractWithSigner("BatchTransferCtor", wallet, addresses, amount, {
value: amount.mul(addresses.length)
value
});

return accounts;
};

const createAccountsZil = async (
hre: HardhatRuntimeEnvironment,
privateKey: string,
amount: BigNumber,
count: number
) => {
await hre.run("transfer", {
from: privateKey,
to: getEthAddress(privateKey),
amount: ethers.utils.formatEther(amount.mul(count * 2)), // Add +amount for the source account itself
fromAddressType: "zil"
});

return createAccountsEth(hre, privateKey, amount, count);
};
2 changes: 0 additions & 2 deletions tests/EvmAcceptanceTests/tasks/RefundSigners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {
getEthAddress,
getEthSignersBalances,
getZilSignersBalances,
loadFromSignersFile,
loadSignersFromConfig
} from "../helpers/SignersHelper";

task("refund-signers", "A task to refund signers")
Expand Down
8 changes: 5 additions & 3 deletions tests/EvmAcceptanceTests/tasks/Setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ async function prepareToRunTestsSequentially(hre: HardhatRuntimeEnvironment) {
}

async function prepareToRunTests(hre: HardhatRuntimeEnvironment, needed_signers: number, needed_balance: number) {
const balanceInWei = hre.ethers.utils.parseEther(needed_balance.toString());
const ethBalances = await getEthSignersBalances(hre);
const zilBalances = await getZilSignersBalances(hre);
const signersAreEnough = ethBalances.length >= needed_signers;
const ethSignersHaveEnoughFund = ethBalances.every(([_, balance]) => balance.gt(needed_balance));
const zilSignersHaveEnoughFund = zilBalances.every(([_, balance]) => balance.gt(new BN(needed_balance)));
const ethSignersHaveEnoughFund = ethBalances.every(([_, balance]) => balance.gt(balanceInWei));
const zilSignersHaveEnoughFund = zilBalances.every(([_, balance]) => balance.gt(new BN(balanceInWei.toString())));

if (signersAreEnough && ethSignersHaveEnoughFund && zilSignersHaveEnoughFund) {
return;
Expand All @@ -108,7 +109,8 @@ async function prepareToRunTests(hre: HardhatRuntimeEnvironment, needed_signers:
from: sourceAccount.private_key,
count: (needed_signers - ethBalances.length).toString(),
balance: needed_balance.toString(),
append: false
append: false,
fromAddressType: sourceAccount.type as string
});
}
}

0 comments on commit 36a8c4b

Please sign in to comment.