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

Add account query tests #23

Merged
merged 1 commit into from
Oct 12, 2023
Merged
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
85 changes: 81 additions & 4 deletions tests/e2e/api/account.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { Aptos, AptosConfig, Network } from "../../../src";

// TODO
// add account getTransactions tests once sdk v2 supports faucet (which needs transaction operation support)
import { Account, Aptos, AptosConfig, Network } from "../../../src";
import { U64 } from "../../../src/bcs/serializable/move-primitives";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the exports this should all collapse! Hopefully everything will be easily accessible from one path.

import { SigningScheme } from "../../../src/types";

describe("account api", () => {
describe("throws when account address in invalid", () => {
Expand Down Expand Up @@ -79,6 +78,84 @@ describe("account api", () => {
expect(data).toHaveProperty("type");
expect(data.type).toBe("0x1::account::Account");
});

test("it fetches account transactions", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const senderAccount = Account.generate({ scheme: SigningScheme.Ed25519 });
await aptos.fundAccount({ accountAddress: senderAccount.accountAddress.toString(), amount: 1000000000 });
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const rawTxn = await aptos.generateTransaction({
sender: senderAccount.accountAddress.toString(),
data: {
function: "0x1::aptos_account::transfer",
type_arguments: [],
arguments: [bob.accountAddress, new U64(10)],
},
});
const authenticator = aptos.signTransaction({
signer: senderAccount,
transaction: rawTxn,
});
const response = await aptos.submitTransaction({
transaction: rawTxn,
senderAuthenticator: authenticator,
});
const txn = await aptos.waitForTransaction({ txnHash: response.hash });
const accountTransactions = await aptos.getAccountTransactions({
accountAddress: senderAccount.accountAddress.toString(),
});
expect(accountTransactions[0]).toStrictEqual(txn);
});
Comment on lines +82 to +109
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should put some of this stuff in a common place so that it can be a little more legible / add more white space


test("it fetches account transactions count", async () => {
const config = new AptosConfig({ network: Network.DEVNET });
const aptos = new Aptos(config);
const senderAccount = Account.generate({ scheme: SigningScheme.Ed25519 });
const response = await aptos.fundAccount({
accountAddress: senderAccount.accountAddress.toString(),
amount: 1000000000,
});

await aptos.waitForTransaction({ txnHash: response });
const accountTransactionsCount = await aptos.getAccountTransactionsCount({
accountAddress: senderAccount.accountAddress.toString(),
});
expect(accountTransactionsCount?.count).toBe(1);
});

test("it fetches account coins data", async () => {
const config = new AptosConfig({ network: Network.DEVNET });
const aptos = new Aptos(config);
const senderAccount = Account.generate({ scheme: SigningScheme.Ed25519 });
const response = await aptos.fundAccount({
accountAddress: senderAccount.accountAddress.toString(),
amount: 1000000000,
});

await aptos.waitForTransaction({ txnHash: response });
const accountCoinData = await aptos.getAccountCoinsData({
accountAddress: senderAccount.accountAddress.toString(),
});
expect(accountCoinData[0].amount).toBe(100000000);
expect(accountCoinData[0].asset_type).toBe("0x1::aptos_coin::AptosCoin");
});

test("it fetches account coins count", async () => {
const config = new AptosConfig({ network: Network.DEVNET });
const aptos = new Aptos(config);
const senderAccount = Account.generate({ scheme: SigningScheme.Ed25519 });
const response = await aptos.fundAccount({
accountAddress: senderAccount.accountAddress.toString(),
amount: 1000000000,
});

await aptos.waitForTransaction({ txnHash: response });
const accountCoinsCount = await aptos.getAccountCoinsCount({
accountAddress: senderAccount.accountAddress.toString(),
});
expect(accountCoinsCount?.count).toBe(1);
});
});

describe("fetch data with acount address as Uint8Array", () => {
Expand Down
Loading