-
Notifications
You must be signed in to change notification settings - Fork 44
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
import { SigningScheme } from "../../../src/types"; | ||
|
||
describe("account api", () => { | ||
describe("throws when account address in invalid", () => { | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", () => { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.