Skip to content

Commit

Permalink
fix: load test script
Browse files Browse the repository at this point in the history
  • Loading branch information
tHeMaskedMan981 committed Nov 18, 2024
1 parent 2717951 commit ea334d2
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 27 deletions.
73 changes: 58 additions & 15 deletions scripts/deploy/helpers/send-msg/outbound-load-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ const deployedAddressPath = path.join(

// batch outbound contract:
const helperContractAddress = {
11155112: "0xF76E77186Ae85Fa0D5fce51D03e59b964fe7717A",
11155111: "0x91C27Cad374246314E756f8Aa2f62F433d6F102C",
[ChainSlug.ARBITRUM_SEPOLIA]: "0x2c3E3Ff54d82cA96BBB2F4529bee114eB200e3F0",
[ChainSlug.OPTIMISM_SEPOLIA]: "0x4B882c8A1009c0a4fd80151FEb6d1a3656C49C9a",
[ChainSlug.ARBITRUM_SEPOLIA]: "0xd206accf23905ac3325d2614981f79657923dbfe",
[ChainSlug.OPTIMISM_SEPOLIA]: "0xa57d28c0fd64a3b82f3f9b5a2ce65c46d1483884",
[ChainSlug.ARBITRUM]: "0x19ff5eb35bbf1525b29ae96167b0c94ac5387ded",
};

const payload =
Expand All @@ -37,11 +36,11 @@ const WAIT_FOR_TX = true;
const totalIterations = 10;

// usage:
// npx ts-node scripts/deploy/helpers/send-msg/outbound-load-test.ts --chain arbitrum_sepolia --remoteChain optimism_sepolia --numOfRequests 10 --waitTime 6
// time npx ts-node scripts/deploy/helpers/send-msg/outbound-load-test.ts --chain arbitrum_sepolia --remoteChain optimism_sepolia --numOfRequests 10 --waitTimeSecs 4

export const main = async () => {
const amount = 100;
const msgGasLimit = "0";
const msgGasLimit = "100000";
let remoteChainSlug;

try {
Expand All @@ -68,8 +67,8 @@ export const main = async () => {
},
})
.option({
waitTime: {
description: "waitTime",
waitTimeSecs: {
description: "waitTimeSecs",
type: "number",
demandOption: false,
},
Expand Down Expand Up @@ -97,7 +96,7 @@ export const main = async () => {
const remoteChain = argv.remoteChain as HardhatChainName;
remoteChainSlug = hardhatChainNameToSlug[remoteChain];
const numOfRequests = argv.numOfRequests as number;
const waitTime = argv.waitTime as number;
const waitTimeSecs = argv.waitTimeSecs as number;

const config: any = JSON.parse(
fs.readFileSync(deployedAddressPath, "utf-8")
Expand All @@ -124,14 +123,15 @@ export const main = async () => {
counterAddress
);
await sendTx(
counterAddress,
signer,
helper,
remoteChainSlug,
amount,
msgGasLimit,
numOfRequests,
value,
waitTime,
waitTimeSecs,
chainSlug,
WAIT_FOR_TX
);
Expand All @@ -145,14 +145,15 @@ export const main = async () => {
};

const sendTx = async (
counterAddress: string,
signer,
helper,
remoteChainSlug,
amount,
msgGasLimit,
numOfRequests,
value,
waitTime,
waitTimeSecs,
chainSlug,
waitForConfirmation: boolean
) => {
Expand All @@ -163,14 +164,16 @@ const sendTx = async (
);

for (let index = 0; index < totalIterations; index++) {
console.log("========= starting iteration: ", index, " =========");
const start = Date.now();
const tx = await helper
.connect(signer)
.remoteAddOperationBatch(
counterAddress,
remoteChainSlug,
amount,
msgGasLimit,
numOfRequests,
payload,
{
value: BigNumber.from(value).mul(numOfRequests),
nonce: nonce + index,
Expand All @@ -182,7 +185,7 @@ const sendTx = async (
tx.hash
} was sent with ${amount} amount and ${msgGasLimit} gas limit to counter at ${remoteChainSlug}, value: ${
value * numOfRequests
}`
} in ${Date.now() - start} ms`
);
console.log(
`Track here: ${getAPIBaseURL(
Expand All @@ -194,8 +197,9 @@ const sendTx = async (
await tx.wait();
console.log(`remoteAddOperation-tx with hash: ${tx.hash} confirmed`);
}
if (waitTime && waitTime > 0) {
await sleep(waitTime);
if (waitTimeSecs && waitTimeSecs > 0) {
console.log("waiting for ", waitTimeSecs, " secs...");
await sleep(waitTimeSecs * 1000);
}
}
};
Expand All @@ -206,3 +210,42 @@ main()
console.error(error);
process.exit(1);
});

// Outbound load contract

// pragma solidity 0.8.19;

// interface ICounter {
// function remoteAddOperation(
// uint32 chainSlug_,
// uint256 amount_,
// uint256 minMsgGasLimit_,
// bytes32 executionParams_,
// bytes32 transmissionParams_
// ) external payable;
// }

// contract OutboundLoadTest {
// ICounter counter__;

// constructor() {}

// function remoteAddOperationBatch(
// address counter_,
// uint32 remoteChainSlug_,
// uint256 amount_,
// uint256 minMsgGasLimit_,
// uint256 totalMsgs
// ) external payable {
// counter__ = ICounter(counter_);
// for (uint256 i = 0; i < totalMsgs; i++) {
// counter__.remoteAddOperation{value: msg.value / totalMsgs}(
// remoteChainSlug_,
// amount_,
// minMsgGasLimit_,
// bytes32(0),
// bytes32(0)
// );
// }
// }
// }
32 changes: 20 additions & 12 deletions scripts/deploy/helpers/send-msg/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { config as dotenvConfig } from "dotenv";
import { ethers } from "ethers";
import { BigNumber, ethers } from "ethers";
import Counter from "../../../../out/Counter.sol/Counter.json";
import Socket from "../../../../out/Socket.sol/Socket.json";
import { ChainSlug } from "../../../../src";
Expand All @@ -13,11 +13,21 @@ import { mode, overrides } from "../../config/config";
const counterAddAmount = 100;

export const LoadTestHelperABI = [
{
inputs: [],
stateMutability: "nonpayable",
type: "constructor",
},
{
inputs: [
{
internalType: "address",
name: "counter_",
type: "address",
},
{
internalType: "uint32",
name: "chainSlug_",
name: "remoteChainSlug_",
type: "uint32",
},
{
Expand All @@ -27,19 +37,14 @@ export const LoadTestHelperABI = [
},
{
internalType: "uint256",
name: "msgGasLimit_",
name: "minMsgGasLimit_",
type: "uint256",
},
{
internalType: "uint256",
name: "totalMsgs_",
name: "totalMsgs",
type: "uint256",
},
{
internalType: "bytes",
name: "payload",
type: "bytes",
},
],
name: "remoteAddOperationBatch",
outputs: [],
Expand Down Expand Up @@ -82,7 +87,7 @@ export const getSocketFees = async (
plugAddress: string
) => {
const socket = await getSocketContract(chainSlug);
const value = await socket.getMinFees(
const value: BigNumber = await socket.getMinFees(
msgGasLimit,
payloadSize,
executionParams,
Expand Down Expand Up @@ -120,11 +125,14 @@ export const sendCounterBridgeMsg = async (
to
);

const feesUSDValue = formatEther(value.mul(BigNumber.from(3000)));
console.log(
`fees for path ${chainSlug}-${siblingSlug} is ${formatEther(value)} ETH`
`fees for path ${chainSlug}-${siblingSlug} is ${formatEther(
value
)} ETH, ${feesUSDValue} USD`
);

const { gasLimit, gasPrice, type } = overrides(chainSlug);
const { gasLimit, gasPrice, type } = await overrides(chainSlug);
// console.log({to, data, value, gasLimit});
let response = await relayTx({
to,
Expand Down

0 comments on commit ea334d2

Please sign in to comment.