load_test_entropy.ts 2.5 KB

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