Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: covering tokens API endpoints #90

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 55 additions & 7 deletions packages/integration-tests/tests/api/tokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ describe("Tokens", () => {
.expect((res) =>
expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ l2Address: l2DepositedToken }))
)
.expect((res) => expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ l1Address: l1Token })))
.expect((res) => expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ symbol: "L1" })))
.expect((res) => expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ name: "L1 ERC20 token" })))
.expect((res) => expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ l1Address: l1Token })))
.expect((res) =>
expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ l2Address: l2DepositedToken }))
)
.expect((res) => expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ decimals: 18 })))
.expect((res) => expect(res.body.items[1]).toStrictEqual(expect.objectContaining({ l2Address: l2Token })))
.expect((res) => expect(res.body.items[1]).toStrictEqual(expect.objectContaining({ l1Address: null })))
.expect((res) => expect(res.body.items[1]).toStrictEqual(expect.objectContaining({ symbol: "L2" })))
.expect((res) => expect(res.body.items[1]).toStrictEqual(expect.objectContaining({ name: "L2 ERC20 token" })))
.expect((res) => expect(res.body.items[1]).toStrictEqual(expect.objectContaining({ decimals: 18 })))
.expect((res) => expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ name: "L1 ERC20 token" })))
.expect((res) => expect(typeof res.body.meta.totalItems).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.itemCount).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.itemsPerPage).toStrictEqual("number"))
Expand Down Expand Up @@ -124,6 +122,56 @@ describe("Tokens", () => {
expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ type: TransactionsType.transfer }))
);
});

//id1803
it("Verify the response via /tokens/{address}/transfers", async () => {
await setTimeout(localConfig.standardPause); //works unstable without timeout

l2Token = await helper.getStringFromFile(bufferFile + Buffer.customToken);
const emptyWallet = await helper.getStringFromFile(bufferFile + Buffer.emptyWalletAddress);
const paymaster = await helper.getStringFromFile(bufferFile + Buffer.paymaster);
txHash = await helper.getStringFromFile(bufferFile + Buffer.paymasterTx);
const apiRoute = `/tokens/${l2Token}/transfers?page=1&limit=10`;
const decapitalizedTokenAddress = l2Token.toLowerCase();

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ from: emptyWallet })))
.expect((res) => expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ to: paymaster })))
.expect((res) => expect(typeof res.body.items[0].blockNumber).toStrictEqual("number"))
.expect((res) =>
expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ transactionHash: txHash }))
)
.expect((res) => expect(typeof res.body.items[0].timestamp).toStrictEqual("string"))
.expect((res) => expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ amount: "1" })))
.expect((res) => expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ tokenAddress: l2Token })))
.expect((res) => expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ type: "transfer" })))
.expect((res) => expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ fields: null })))
.expect((res) => expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ isInternal: false })))
.expect((res) =>
expect(res.body.items[0].token).toStrictEqual(expect.objectContaining({ l2Address: l2Token }))
)
.expect((res) => expect(res.body.items[0].token).toStrictEqual(expect.objectContaining({ l1Address: null })))
.expect((res) =>
expect(res.body.items[0].token).toStrictEqual(expect.objectContaining({ symbol: "MyToken" }))
)
.expect((res) => expect(res.body.items[0].token).toStrictEqual(expect.objectContaining({ name: "MyToken" })))
.expect((res) => expect(res.body.items[0].token).toStrictEqual(expect.objectContaining({ decimals: 18 })))
.expect((res) => expect(typeof res.body.meta.currentPage).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.itemCount).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.itemsPerPage).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.totalItems).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.totalPages).toStrictEqual("number"))
.expect((res) =>
expect(res.body.links.first).toStrictEqual(`tokens/${decapitalizedTokenAddress}/transfers?limit=10`)
)
.expect((res) => expect(res.body.links.previous).toStrictEqual(""))
.expect((res) => expect(res.body.links.next).toStrictEqual(""))
.expect((res) =>
expect(res.body.links.last).toStrictEqual(`tokens/${decapitalizedTokenAddress}/transfers?page=1&limit=10`)
);
});
});
});
});
Loading