mirror of
https://github.com/vacp2p/linea-monorepo.git
synced 2026-01-09 04:08:01 -05:00
postman test script from concurrent to serial tx (#954)
This commit is contained in:
@@ -40,7 +40,7 @@ import { config } from "dotenv";
|
|||||||
import yargs from "yargs";
|
import yargs from "yargs";
|
||||||
import { hideBin } from "yargs/helpers";
|
import { hideBin } from "yargs/helpers";
|
||||||
import { sanitizePrivKey } from "./cli";
|
import { sanitizePrivKey } from "./cli";
|
||||||
import { ContractTransactionReceipt, Wallet, JsonRpcProvider } from "ethers";
|
import { Wallet, JsonRpcProvider, ContractTransactionResponse } from "ethers";
|
||||||
import { LineaRollup, LineaRollup__factory } from "@consensys/linea-sdk";
|
import { LineaRollup, LineaRollup__factory } from "@consensys/linea-sdk";
|
||||||
import { SendMessageArgs } from "./types";
|
import { SendMessageArgs } from "./types";
|
||||||
import { encodeSendMessage } from "./helpers";
|
import { encodeSendMessage } from "./helpers";
|
||||||
@@ -134,7 +134,7 @@ const sendMessage = async (
|
|||||||
messageNonce: bigint,
|
messageNonce: bigint,
|
||||||
senderNonce: number,
|
senderNonce: number,
|
||||||
logString: string,
|
logString: string,
|
||||||
): Promise<ContractTransactionReceipt | null> => {
|
): Promise<ContractTransactionResponse> => {
|
||||||
const lineaRollup = LineaRollup__factory.connect(L1_MESSAGE_SERVICE_ADDRESS[deploymentEnv], sender) as LineaRollup;
|
const lineaRollup = LineaRollup__factory.connect(L1_MESSAGE_SERVICE_ADDRESS[deploymentEnv], sender) as LineaRollup;
|
||||||
const tx = await lineaRollup.sendMessage(args.to, args.fee, args.calldata, { value: args.fee, nonce: senderNonce });
|
const tx = await lineaRollup.sendMessage(args.to, args.fee, args.calldata, { value: args.fee, nonce: senderNonce });
|
||||||
const messageHash = encodeSendMessage(
|
const messageHash = encodeSendMessage(
|
||||||
@@ -147,21 +147,22 @@ const sendMessage = async (
|
|||||||
);
|
);
|
||||||
|
|
||||||
console.log(`Sent message with messageHash=${messageHash}. ${logString}`);
|
console.log(`Sent message with messageHash=${messageHash}. ${logString}`);
|
||||||
return await tx.wait();
|
return tx;
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendMessages = async (deploymentEnv: DeploymentEnv, sender: Wallet, testScenarios: TestScenario[]) => {
|
const sendMessages = async (deploymentEnv: DeploymentEnv, sender: Wallet, testScenarios: TestScenario[]) => {
|
||||||
const nextSenderNonce = await sender.getNonce();
|
const nextSenderNonce = await sender.getNonce();
|
||||||
const nextMessageCounter = await getMessageCounter(deploymentEnv, sender);
|
const nextMessageCounter = await getMessageCounter(deploymentEnv, sender);
|
||||||
|
|
||||||
const sendMessagePromises: Promise<ContractTransactionReceipt | null>[] = testScenarios.map((s, i) => {
|
// If we send concurrently, we have high risk of sending nonces out of order
|
||||||
|
for (let i = 0; i < testScenarios.length; i++) {
|
||||||
|
const s = testScenarios[i];
|
||||||
const functionArgs: SendMessageArgs = {
|
const functionArgs: SendMessageArgs = {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
to: sender.address,
|
to: sender.address,
|
||||||
fee: s.fee,
|
fee: s.fee,
|
||||||
calldata: s.calldata,
|
calldata: s.calldata,
|
||||||
};
|
};
|
||||||
return sendMessage(
|
await sendMessage(
|
||||||
deploymentEnv,
|
deploymentEnv,
|
||||||
sender,
|
sender,
|
||||||
functionArgs,
|
functionArgs,
|
||||||
@@ -169,8 +170,7 @@ const sendMessages = async (deploymentEnv: DeploymentEnv, sender: Wallet, testSc
|
|||||||
nextSenderNonce + i,
|
nextSenderNonce + i,
|
||||||
s.logString,
|
s.logString,
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
await Promise.all(sendMessagePromises);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getMessageCounter = async (deploymentEnv: DeploymentEnv, signer: Wallet) => {
|
const getMessageCounter = async (deploymentEnv: DeploymentEnv, signer: Wallet) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user