load_test_entropy.ts 2.8 KB

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