Skip to content

Commit

Permalink
Merge pull request #191 from matter-labs/QA-690-Create-automation-tes…
Browse files Browse the repository at this point in the history
…t-for-Accounts-tc1854

test: create autotest for Accounts tc1854
  • Loading branch information
amelnytskyi authored Mar 20, 2024
2 parents f4442b2 + cc0f288 commit 1fd5261
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/integration-tests/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum Buffer {
paymasterTx = "paymasterTx.txt",
addressMultiTransferETH = "multiTransferETH.txt",
txMultiTransferETH = "txMultiTransferETH.txt",
txMultiTransferCall = "txMultiTransferCall.txt",
txMultiTransferCustomTokenI = "txMultiTransferCustomTokenI.txt",
txMultiTransferCustomTokenII = "txMultiTransferCustomTokenII.txt",
addressMultiCallMiddle = "multiCallMiddle.txt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default async function callMultiTransferETH(hre: HardhatRuntimeEnvironmen
const ethTransfer = await makeTransfer(etherAddress, ethers.utils.parseEther("0.101"));
const customToken1Transfer = await makeTransfer(customTokenI, ethers.utils.parseUnits("1", 18));
const customToken2Transfer = await makeTransfer(customTokenII, ethers.utils.parseUnits("1", 18));
const multiTransferResult = await makeMultiTransfer();

async function makeTransfer(token: string, amount: ethers.BigNumber) {
const transfer = await wallet.transfer({
Expand All @@ -47,22 +48,27 @@ export default async function callMultiTransferETH(hre: HardhatRuntimeEnvironmen
});

// await commitment
const transferReceipt = await transfer.wait(1);
const transferReceipt = await transfer.waitFinalize();
console.log(`Tx transfer hash for ${token}: ${transferReceipt.transactionHash}`);

return transferReceipt.transactionHash;
}

//call the deployed contract.
const transferFromContract = await attachedContract.multiTransfer(
[richWalletAddress, mainWalletAddress, secondaryWalletAddress],
[etherAddress, customTokenI, customTokenII],
[ethAmount, customTokenIAmount, customTokenIIAmount]
);
if (transferFromContract) {
console.log(`Contract transfer to us!`);
} else {
console.error(`Contract said something unexpected: ${transferFromContract}`);
async function makeMultiTransfer() {
const transferFromContract = await attachedContract.multiTransfer(
[richWalletAddress, mainWalletAddress, secondaryWalletAddress],
[etherAddress, customTokenI, customTokenII],
[ethAmount, customTokenIAmount, customTokenIIAmount]
);
if (transferFromContract) {
console.log(`Contract transfer to us!`);
const transferReceipt = await transferFromContract.waitFinalize();
console.log(`Contract transfer transaction hash: ${transferReceipt.transactionHash}`);
return transferReceipt.transactionHash;
} else {
console.error(`Contract said something unexpected: ${transferFromContract}`);
}
}

// Show the contract balance
Expand Down Expand Up @@ -90,6 +96,7 @@ export default async function callMultiTransferETH(hre: HardhatRuntimeEnvironmen
)}" Custom token II`
);

await helper.writeFile(Path.absolutePathToBufferFiles, Buffer.txMultiTransferCall, multiTransferResult);
await helper.writeFile(Path.absolutePathToBufferFiles, Buffer.txMultiTransferETH, ethTransfer);
await helper.writeFile(Path.absolutePathToBufferFiles, Buffer.txMultiTransferCustomTokenI, customToken1Transfer);
await helper.writeFile(Path.absolutePathToBufferFiles, Buffer.txMultiTransferCustomTokenII, customToken2Transfer);
Expand Down
34 changes: 33 additions & 1 deletion packages/integration-tests/tests/api/accounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Helper } from "../../src/helper";
import { Playbook } from "../../src/playbook/playbook";

describe("API module: Account", () => {
jest.setTimeout(localConfig.standardTimeout);
jest.setTimeout(localConfig.extendedTimeout);

const helper = new Helper();
let apiRoute: string;
Expand Down Expand Up @@ -258,5 +258,37 @@ describe("API module: Account", () => {
expect(typeof response.body.result[0].blockReward).toStrictEqual("string");
});
});

//id1854
it("Verify /api?module=account&action=txlistinternal&txhash=", async () => {
await helper.runRetriableTestAction(async () => {
const blocks = await request(environment.blockExplorerAPI).get("/blocks");
const blockNumber = blocks.body.items[0].number;
const txHash = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.txMultiTransferCall);
apiRoute = `/api?module=account&action=txlistinternal&page=1&offset=10&sort=desc&endblock=${blockNumber}&startblock=0&txhash=${txHash}`;
response = await helper.performBlockExplorerApiGetRequest(apiRoute);

expect(response.status).toBe(200);
expect(response.body).toStrictEqual(expect.objectContaining({ status: "1" }));
expect(response.body).toStrictEqual(expect.objectContaining({ message: "OK" }));
expect(response.body.result[0]).toStrictEqual(expect.objectContaining({ hash: txHash }));
expect(response.body.result[0]).toStrictEqual(expect.objectContaining({ to: Wallets.richWalletAddress }));
expect(response.body.result[0]).toStrictEqual(expect.objectContaining({ type: "call" }));
expect(typeof response.body.result[0].blockNumber).toStrictEqual("string");
expect(typeof response.body.result[0].timeStamp).toStrictEqual("string");
expect(typeof response.body.result[0].from).toStrictEqual("string");
expect(typeof response.body.result[0].value).toStrictEqual("string");
expect(typeof response.body.result[0].gas).toStrictEqual("string");
expect(typeof response.body.result[0].input).toStrictEqual("string");
expect(typeof response.body.result[0].contractAddress).toBeTruthy();
expect(typeof response.body.result[0].gasUsed).toStrictEqual("string");
expect(typeof response.body.result[0].fee).toStrictEqual("string");
expect(typeof response.body.result[0].l1BatchNumber).toStrictEqual("string");
expect(typeof response.body.result[0].traceId).toBeTruthy();
expect(typeof response.body.result[0].transactionType).toStrictEqual("string");
expect(typeof response.body.result[0].isError).toStrictEqual("string");
expect(typeof response.body.result[0].errCode).toStrictEqual("string");
});
});
});
});

0 comments on commit 1fd5261

Please sign in to comment.