|
| 1 | +import yargs from "yargs"; |
| 2 | +import { hideBin } from "yargs/helpers"; |
| 3 | +import { |
| 4 | + DefaultStore, |
| 5 | + EvmEntropyContract, |
| 6 | + PrivateKey, |
| 7 | + toPrivateKey, |
| 8 | +} from "../src"; |
| 9 | +import { |
| 10 | + COMMON_DEPLOY_OPTIONS, |
| 11 | + findEntropyContract, |
| 12 | + findEvmChain, |
| 13 | +} from "./common"; |
| 14 | +import Web3 from "web3"; |
| 15 | + |
| 16 | +const parser = yargs(hideBin(process.argv)) |
| 17 | + .usage( |
| 18 | + "Load tests the entropy contract using the EntropyTester contract with many requests in a single transaction\n" + |
| 19 | + "it does not monitor whether the callbacks are actually submitted or not.\n" + |
| 20 | + "Usage: $0 --private-key <private-key> --chain <chain-id> --tester-address <tester-address>" |
| 21 | + ) |
| 22 | + .options({ |
| 23 | + chain: { |
| 24 | + type: "string", |
| 25 | + demandOption: true, |
| 26 | + desc: "test latency for the contract on this chain", |
| 27 | + }, |
| 28 | + "tester-address": { |
| 29 | + type: "string", |
| 30 | + demandOption: true, |
| 31 | + desc: "Tester contract address", |
| 32 | + }, |
| 33 | + "success-count": { |
| 34 | + type: "number", |
| 35 | + default: 100, |
| 36 | + desc: "How many successful requests to make", |
| 37 | + }, |
| 38 | + "revert-count": { |
| 39 | + type: "number", |
| 40 | + default: 0, |
| 41 | + desc: "How many requests to make where the callback should revert", |
| 42 | + }, |
| 43 | + "private-key": COMMON_DEPLOY_OPTIONS["private-key"], |
| 44 | + }); |
| 45 | + |
| 46 | +const ABI = [ |
| 47 | + { |
| 48 | + inputs: [ |
| 49 | + { |
| 50 | + internalType: "address", |
| 51 | + name: "provider", |
| 52 | + type: "address", |
| 53 | + }, |
| 54 | + { |
| 55 | + internalType: "uint64", |
| 56 | + name: "success", |
| 57 | + type: "uint64", |
| 58 | + }, |
| 59 | + { |
| 60 | + internalType: "uint64", |
| 61 | + name: "fail", |
| 62 | + type: "uint64", |
| 63 | + }, |
| 64 | + ], |
| 65 | + name: "batchRequests", |
| 66 | + outputs: [], |
| 67 | + stateMutability: "nonpayable", |
| 68 | + type: "function", |
| 69 | + }, |
| 70 | +] as any; |
| 71 | + |
| 72 | +async function main() { |
| 73 | + const argv = await parser.argv; |
| 74 | + const privateKey = toPrivateKey(argv.privateKey); |
| 75 | + const chain = findEvmChain(argv.chain); |
| 76 | + const contract = findEntropyContract(chain); |
| 77 | + const provider = await contract.getDefaultProvider(); |
| 78 | + const fee = await contract.getFee(provider); |
| 79 | + const web3 = new Web3(contract.chain.getRpcUrl()); |
| 80 | + const testerContract = new web3.eth.Contract(ABI, argv.testerAddress); |
| 81 | + const { address } = web3.eth.accounts.wallet.add(privateKey); |
| 82 | + const transactionObject = testerContract.methods.batchRequests( |
| 83 | + provider, |
| 84 | + argv.successCount, |
| 85 | + argv.revertCount |
| 86 | + ); |
| 87 | + const totalCount = argv.successCount + argv.revertCount; |
| 88 | + const result = await contract.chain.estiamteAndSendTransaction( |
| 89 | + transactionObject, |
| 90 | + { |
| 91 | + from: address, |
| 92 | + value: (fee * totalCount).toString(), |
| 93 | + } |
| 94 | + ); |
| 95 | + console.log("Submitted transaction ", result.transactionHash); |
| 96 | +} |
| 97 | + |
| 98 | +main(); |
0 commit comments