Skip to content

Commit

Permalink
feat(contract_manager)Add option to test for all entropy contracts (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
m30m authored May 9, 2024
1 parent 1e1be9d commit 6e0bd05
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions contract_manager/scripts/latency_entropy_with_callback.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { toPrivateKey } from "../src";
import {
DefaultStore,
EvmEntropyContract,
PrivateKey,
toPrivateKey,
} from "../src";
import {
COMMON_DEPLOY_OPTIONS,
findEntropyContract,
Expand All @@ -12,26 +17,29 @@ const parser = yargs(hideBin(process.argv))
.usage(
"Requests a random number from an entropy contract and measures the\n" +
"latency between request submission and fulfillment by the Fortuna keeper service.\n" +
"Usage: $0 --chain-id <chain-id> --private-key <private-key>"
"Usage: $0 --private-key <private-key> --chain <chain-id> | --all-chains <testnet|mainnet>"
)
.options({
chain: {
type: "string",
demandOption: true,
desc: "test latency for the contract on this chain",
conflicts: "all-chains",
},
"all-chains": {
type: "string",
conflicts: "chain",
choices: ["testnet", "mainnet"],
desc: "test latency for all entropy contracts deployed either on mainnet or testnet",
},
"private-key": COMMON_DEPLOY_OPTIONS["private-key"],
});

async function main() {
const argv = await parser.argv;

const chain = findEvmChain(argv.chain);
const contract = findEntropyContract(chain);

async function testLatency(
contract: EvmEntropyContract,
privateKey: PrivateKey
) {
const provider = await contract.getDefaultProvider();
const userRandomNumber = contract.generateUserRandomNumber();
const privateKey = toPrivateKey(argv.privateKey);
const requestResponse = await contract.requestRandomness(
userRandomNumber,
provider,
Expand Down Expand Up @@ -84,4 +92,27 @@ async function main() {
}
}

async function main() {
const argv = await parser.argv;
if (!argv.chain && !argv["all-chains"]) {
throw new Error("Must specify either --chain or --all-chains");
}
const privateKey = toPrivateKey(argv.privateKey);
if (argv["all-chains"]) {
for (const contract of Object.values(DefaultStore.entropy_contracts)) {
if (
contract.getChain().isMainnet() ===
(argv["all-chains"] === "mainnet")
) {
console.log(`Testing latency for ${contract.getId()}...`);
await testLatency(contract, privateKey);
}
}
} else if (argv.chain) {
const chain = findEvmChain(argv.chain);
const contract = findEntropyContract(chain);
await testLatency(contract, privateKey);
}
}

main();

0 comments on commit 6e0bd05

Please sign in to comment.