load_test_entropy.ts 3.3 KB

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