Skip to content

Commit

Permalink
Merge branch 'integration-tests-signed' into oleh-bairak-qa-653-token…
Browse files Browse the repository at this point in the history
…sapi-accounts-api-automate-test-cases-for-contracts-api
  • Loading branch information
olehbairak authored Mar 20, 2024
2 parents 834384b + 1fd5261 commit 1c6e8ce
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/app/tests/e2e/features/copying.feature

Large diffs are not rendered by default.

5 changes: 5 additions & 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 Expand Up @@ -84,6 +85,10 @@ export enum BlockExplorer {
localNetwork = "/?network=local",
}

export enum Values {
txSumETH = "0.000009",
}

export enum Contracts {
greeterContractSepolia = "0x9c6D777A35D127f17eB28B75F80Bb7486118FbE0",
}
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");
});
});
});
});
96 changes: 96 additions & 0 deletions packages/integration-tests/tests/ui/withdraw.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { expect, test } from "@playwright/test";

import { BlockExplorer, Buffer, Path, Values, Wallets } from "../../src/constants";
import { Helper } from "../../src/helper";

import type { Locator } from "@playwright/test";

const helper = new Helper();
let url: string;
let withdrawTxHash: string;
let initiatorAddress: string;
let hash, initiatorAddressElement, toAddressElement, ethValue, erc20Value: Locator;

//@id1661
test("Check Withdraw ETH transaction on BE", async ({ page }) => {
withdrawTxHash = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.txEthWithdraw);
url = BlockExplorer.baseUrl + `/tx/${withdrawTxHash}` + BlockExplorer.localNetwork;
initiatorAddress = Wallets.richWalletAddress;

await page.goto(url);

hash = await page.locator(`//*[text()="Transaction Hash"]/..//..//*[text()="${withdrawTxHash}"]`).first();
initiatorAddressElement = await page.locator(`text=${initiatorAddress}`).first();
toAddressElement = await page
.locator(`//*[text()="To"]/..//..//..//*[text()="L1"]/..//*[text()="0x36615Cf349d...c049"]`)
.first();
ethValue = await page.locator(`text=${Values.txSumETH}`).first();

await expect(hash).toBeVisible();
await expect(ethValue).toBeVisible();
await expect(initiatorAddressElement).toBeVisible();
await expect(toAddressElement).toBeVisible();
});

//@id1686
test("Verify the ETH withdrawal to the other address", async ({ page }) => {
withdrawTxHash = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.txEthWithdrawOtherAddress);
url = BlockExplorer.baseUrl + `/tx/${withdrawTxHash}` + BlockExplorer.localNetwork;
initiatorAddress = Wallets.richWalletAddress;

await page.goto(url);

hash = await page.locator(`//*[text()="Transaction Hash"]/..//..//*[text()="${withdrawTxHash}"]`).first();
initiatorAddressElement = await page.locator(`text=${initiatorAddress}`).first();
toAddressElement = await page
.locator(`//*[text()="To"]/..//..//..//*[text()="L1"]/..//*[text()="0x586607935E1...8975"]`)
.first();
ethValue = await page.locator(`text=${Values.txSumETH}`).first();

await expect(hash).toBeVisible();
await expect(ethValue).toBeVisible();
await expect(initiatorAddressElement).toBeVisible();
await expect(toAddressElement).toBeVisible();
});

//@id1685
test("Check on BE Withdraw the custom ERC-20 via Portal", async ({ page }) => {
withdrawTxHash = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.txERC20Withdraw);
url = BlockExplorer.baseUrl + `/tx/${withdrawTxHash}` + BlockExplorer.localNetwork;
initiatorAddress = Wallets.richWalletAddress;

await page.goto(url);

hash = await page.locator(`//*[text()="Transaction Hash"]/..//..//*[text()="${withdrawTxHash}"]`).first();
initiatorAddressElement = await page.locator(`text=${initiatorAddress}`).first();
toAddressElement = await page
.locator(`//*[text()="To"]/..//..//..//*[text()="L1"]/..//*[text()="0x36615Cf349d...c049"]`)
.first();
erc20Value = await page.locator(`//*[text()="0x36615Cf349d...c049"]/..//..//*[text()="0.2"]`).first();

await expect(hash).toBeVisible();
await expect(erc20Value).toBeVisible();
await expect(initiatorAddressElement).toBeVisible();
await expect(toAddressElement).toBeVisible();
});

//@id1664
test("Check Withdraw transaction on BE for custom ERC-20 token to a different address", async ({ page }) => {
withdrawTxHash = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.txERC20WithdrawOtherAddress);
url = BlockExplorer.baseUrl + `/tx/${withdrawTxHash}` + BlockExplorer.localNetwork;
initiatorAddress = Wallets.richWalletAddress;

await page.goto(url);

hash = await page.locator(`//*[text()="Transaction Hash"]/..//..//*[text()="${withdrawTxHash}"]`).first();
initiatorAddressElement = await page.locator(`text=${initiatorAddress}`).first();
toAddressElement = await page
.locator(`//*[text()="To"]/..//..//..//*[text()="L1"]/..//*[text()="0x586607935E1...8975"]`)
.first();
erc20Value = await page.locator(`//*[text()="0x586607935E1...8975"]/..//..//*[text()="0.2"]`).first();

await expect(hash).toBeVisible();
await expect(erc20Value).toBeVisible();
await expect(initiatorAddressElement).toBeVisible();
await expect(toAddressElement).toBeVisible();
});

0 comments on commit 1c6e8ce

Please sign in to comment.