From d30210d617d99df036d2b1458bb9dfd23573d081 Mon Sep 17 00:00:00 2001 From: maayan Date: Mon, 27 Nov 2023 17:05:08 -0500 Subject: [PATCH] add your_coin example --- examples/typescript/package.json | 1 + .../publish_package_from_filepath.ts | 14 +- examples/typescript/tsconfig.json | 6 +- examples/typescript/utils.ts | 25 ++- examples/typescript/yourCoin/index.ts | 142 ++++++++++++++++++ .../typescript/yourCoin/moonCoin/Move.toml | 11 ++ .../yourCoin/moonCoin/moonCoin.json | 16 ++ .../yourCoin/moonCoin/scripts/register.move | 5 + .../yourCoin/moonCoin/sources/MoonCoin.move | 13 ++ src/api/account.ts | 54 ++++++- src/internal/account.ts | 22 +++ tests/e2e/api/account.test.ts | 87 +++-------- 12 files changed, 311 insertions(+), 85 deletions(-) create mode 100644 examples/typescript/yourCoin/index.ts create mode 100644 examples/typescript/yourCoin/moonCoin/Move.toml create mode 100644 examples/typescript/yourCoin/moonCoin/moonCoin.json create mode 100644 examples/typescript/yourCoin/moonCoin/scripts/register.move create mode 100644 examples/typescript/yourCoin/moonCoin/sources/MoonCoin.move diff --git a/examples/typescript/package.json b/examples/typescript/package.json index 968db9dc4..5f2ee00a4 100644 --- a/examples/typescript/package.json +++ b/examples/typescript/package.json @@ -13,6 +13,7 @@ "swap": "ts-node swap.ts", "publish_package_from_filepath": "ts-node publish_package_from_filepath.ts", "external_signing": "ts-node external_signing.ts", + "your_coin": "ts-node yourCoin/index.ts", "test": "run-s simple_transfer mint_nft multi_agent_transfer simple_sponsored_transaction transfer_coin custom_client publish_package_from_filepath external_signing" }, "keywords": [], diff --git a/examples/typescript/publish_package_from_filepath.ts b/examples/typescript/publish_package_from_filepath.ts index cb5a7bd2b..ca018bdfd 100644 --- a/examples/typescript/publish_package_from_filepath.ts +++ b/examples/typescript/publish_package_from_filepath.ts @@ -11,10 +11,8 @@ /* eslint-disable max-len */ import assert from "assert"; -import fs from "fs"; -import path from "path"; import { Account, Aptos, AptosConfig, Hex, Network, NetworkToNetworkName } from "@aptos-labs/ts-sdk"; -import { compilePackage } from "./utils"; +import { compilePackage, getPackageBytesToPublish } from "./utils"; const APTOS_NETWORK: Network = NetworkToNetworkName[process.env.APTOS_NETWORK] || Network.DEVNET; @@ -34,15 +32,7 @@ async function main() { console.log("\n=== Compiling the package locally ==="); compilePackage("facoin", "facoin/facoin.json", [{ name: "FACoin", address: alice.accountAddress }]); - // current working directory - the root folder of this repo - const cwd = process.cwd(); - // target directory - current working directory + facoin/facoin.json (facoin.json is generated with the prevoius cli command) - const modulePath = path.join(cwd, "facoin/facoin.json"); - - const jsonData = JSON.parse(fs.readFileSync(modulePath, "utf8")); - - const metadataBytes = jsonData.args[0].value; - const byteCode = jsonData.args[1].value; + const { metadataBytes, byteCode } = getPackageBytesToPublish("facoin/facoin.json"); console.log("\n===Publishing FAcoin package==="); const transaction = await aptos.publishPackageTransaction({ diff --git a/examples/typescript/tsconfig.json b/examples/typescript/tsconfig.json index b6381f2d6..ddda7744e 100644 --- a/examples/typescript/tsconfig.json +++ b/examples/typescript/tsconfig.json @@ -13,11 +13,7 @@ "target": "es2020", "pretty": true }, - "include": [ - "src", - "*.ts" - ], "paths": { - "@aptos/*": "../..", + "@aptos/*": "../.." } } diff --git a/examples/typescript/utils.ts b/examples/typescript/utils.ts index 37ee5ddad..ea6a931ab 100644 --- a/examples/typescript/utils.ts +++ b/examples/typescript/utils.ts @@ -1,8 +1,11 @@ import { execSync } from "child_process"; +import path from "path"; +import fs from "fs"; import { AccountAddress } from "@aptos-labs/ts-sdk"; /* eslint-disable no-console */ /* eslint-disable max-len */ + /** * A convenience function to compile a package locally with the CLI * @param packageDir @@ -21,7 +24,7 @@ export function compilePackage( console.log("aptos is not installed. Please install it from the instructions on aptos.dev"); } - const addressArg = namedAddresses.map(({ name, address }) => `${name}=${address}`).join(" "); + const addressArg = namedAddresses.map(({ name, address }) => `${name}=${address.toString()}`).join(" "); // Assume-yes automatically overwrites the previous compiled version, only do this if you are sure you want to overwrite the previous version. const compileCommand = `aptos move build-publish-payload --json-output-file ${outputFile} --package-dir ${packageDir} --named-addresses ${addressArg} --assume-yes`; @@ -29,3 +32,23 @@ export function compilePackage( console.log(compileCommand); execSync(compileCommand); } + +/** + * A convenience function to get the compiled package metadataBytes and byteCode + * @param packageDir + * @param outputFile + * @param namedAddresses + */ +export function getPackageBytesToPublish(filePath: string) { + // current working directory - the root folder of this repo + const cwd = process.cwd(); + // target directory - current working directory + facoin/facoin.json (facoin.json is generated with the prevoius cli command) + const modulePath = path.join(cwd, filePath); + + const jsonData = JSON.parse(fs.readFileSync(modulePath, "utf8")); + + const metadataBytes = jsonData.args[0].value; + const byteCode = jsonData.args[1].value; + + return { metadataBytes, byteCode }; +} diff --git a/examples/typescript/yourCoin/index.ts b/examples/typescript/yourCoin/index.ts new file mode 100644 index 000000000..5f50d9f6e --- /dev/null +++ b/examples/typescript/yourCoin/index.ts @@ -0,0 +1,142 @@ +/* eslint-disable no-console */ +/* eslint-disable max-len */ + +import { Account, AccountAddress, Aptos, AptosConfig, Network, NetworkToNetworkName } from "@aptos-labs/ts-sdk"; +import { compilePackage, getPackageBytesToPublish } from "../utils"; + +/** + * This example demonstrate how one can publish a new custom coin to chain. + * It uses the MoonCoin.move module that can be found in this folder + * + * Before running this example, we should compile the package locally: + * 1. Acquire the Aptos CLI, see https://aptos.dev/cli-tools/aptos-cli/use-cli/install-aptos-cli + * 2. cd `~/aptos-ts-sdk/examples/typescript` + * 3. Run `pnpm run your_coin` + */ + +const MOON_COINS_TO_MINT = 100; +const MOON_COINS_TO_TRANSFER = 100; + +// Setup the client +const APTOS_NETWORK: Network = NetworkToNetworkName[process.env.APTOS_NETWORK] || Network.DEVNET; +const config = new AptosConfig({ network: APTOS_NETWORK }); +const aptos = new Aptos(config); + +/** Register the receiver account to receive transfers for the new coin. */ +async function registerCoin(receiver: Account, coinTypeAddress: AccountAddress): Promise { + const transaction = await aptos.build.transaction({ + sender: receiver.accountAddress, + data: { + function: "0x1::managed_coin::register", + typeArguments: [`${coinTypeAddress.toString()}::moon_coin::MoonCoin`], + functionArguments: [], + }, + }); + + const senderAuthenticator = aptos.sign.transaction({ signer: receiver, transaction }); + const pendingTxn = await aptos.submit.transaction({ transaction, senderAuthenticator }); + + return pendingTxn.hash; +} + +/** Transfer the newly created coin to a specified receiver address */ +async function transferCoin( + sender: Account, + receiverAddress: AccountAddress, + amount: number | bigint, +): Promise { + const transaction = await aptos.build.transaction({ + sender: sender.accountAddress, + data: { + function: "0x1::aptos_account::transfer_coins", + typeArguments: [`${sender.accountAddress.toString()}::moon_coin::MoonCoin`], + functionArguments: [receiverAddress, amount], + }, + }); + + const senderAuthenticator = aptos.sign.transaction({ signer: sender, transaction }); + const pendingTxn = await aptos.submit.transaction({ transaction, senderAuthenticator }); + + return pendingTxn.hash; +} + +/** Mints amount of the newly created coin to a specified receiver address */ +async function mintCoin(minter: Account, receiverAddress: AccountAddress, amount: number): Promise { + const transaction = await aptos.build.transaction({ + sender: minter.accountAddress, + data: { + function: "0x1::managed_coin::mint", + typeArguments: [`${minter.accountAddress.toString()}::moon_coin::MoonCoin`], + functionArguments: [receiverAddress, amount], + }, + }); + + const senderAuthenticator = aptos.sign.transaction({ signer: minter, transaction }); + const pendingTxn = await aptos.submit.transaction({ transaction, senderAuthenticator }); + + return pendingTxn.hash; +} + +/** Returns the balance of the newly created coin for an account */ +const getBalance = async (accountAddress: AccountAddress, coinTypeAddress: AccountAddress) => { + const amount = await aptos.getAccountCoinAmount({ + accountAddress, + coinType: `${coinTypeAddress.toString()}::moon_coin::MoonCoin`, + }); + + return amount; +}; + +async function main() { + // Create two accounts, Alice and Bob + const alice = Account.generate(); + const bob = Account.generate(); + + console.log("\n=== Addresses ==="); + console.log(`Alice: ${alice.accountAddress.toString()}`); + console.log(`Bob: ${bob.accountAddress.toString()}`); + + // Fund alice account + await aptos.fundAccount({ accountAddress: alice.accountAddress, amount: 100_000_000 }); + + // Please ensure you have the aptos CLI installed + console.log("\n=== Compiling MoonCoin package locally ==="); + compilePackage("yourCoin/moonCoin", "yourCoin/moonCoin/moonCoin.json", [ + { name: "MoonCoin", address: alice.accountAddress }, + ]); + + const { metadataBytes, byteCode } = getPackageBytesToPublish("yourCoin/moonCoin/moonCoin.json"); + + console.log(`\n=== Publishing MoonCoin package to ${aptos.config.network} network ===`); + + // Publish MoonCoin package to chain + const transaction = await aptos.publishPackageTransaction({ + account: alice.accountAddress, + metadataBytes, + moduleBytecode: byteCode, + }); + + const pendingTransaction = await aptos.signAndSubmitTransaction({ + signer: alice, + transaction, + }); + + console.log(`Publish package transaction hash: ${pendingTransaction.hash}`); + await aptos.waitForTransaction({ transactionHash: pendingTransaction.hash }); + + console.log(`Bob's initial MoonCoin balance: ${await getBalance(bob.accountAddress, alice.accountAddress)}.`); + + console.log(`Alice mints herself ${MOON_COINS_TO_MINT} MoonCoin.`); + const registerCoinTransactionHash = await registerCoin(alice, alice.accountAddress); + await aptos.waitForTransaction({ transactionHash: registerCoinTransactionHash }); + + const mintCoinTransactionHash = await mintCoin(alice, alice.accountAddress, MOON_COINS_TO_MINT); + await aptos.waitForTransaction({ transactionHash: mintCoinTransactionHash }); + + console.log(`Alice transfers ${MOON_COINS_TO_TRANSFER} MoonCoin to Bob.`); + const transferCoinTransactionHash = await transferCoin(alice, bob.accountAddress, MOON_COINS_TO_TRANSFER); + await aptos.waitForTransaction({ transactionHash: transferCoinTransactionHash }); + console.log(`Bob's updated MoonCoin balance: ${await getBalance(bob.accountAddress, alice.accountAddress)}.`); +} + +main(); diff --git a/examples/typescript/yourCoin/moonCoin/Move.toml b/examples/typescript/yourCoin/moonCoin/Move.toml new file mode 100644 index 000000000..2002cb815 --- /dev/null +++ b/examples/typescript/yourCoin/moonCoin/Move.toml @@ -0,0 +1,11 @@ +[package] +name = "MoonCoin" +version = "0.0.0" + +[addresses] +MoonCoin = "_" + +[dependencies.AptosFramework] +git = "https://github.com/aptos-labs/aptos-core.git" +rev = "mainnet" +subdir = "aptos-move/framework/aptos-framework" diff --git a/examples/typescript/yourCoin/moonCoin/moonCoin.json b/examples/typescript/yourCoin/moonCoin/moonCoin.json new file mode 100644 index 000000000..bbd86108c --- /dev/null +++ b/examples/typescript/yourCoin/moonCoin/moonCoin.json @@ -0,0 +1,16 @@ +{ + "function_id": "0x1::code::publish_package_txn", + "type_args": [], + "args": [ + { + "type": "hex", + "value": "0x084d6f6f6e436f696e0100000000000000004032344143313145423932453634313844304231433438373434313939313043444631453544454532383836333335383231353241353435444145423932454533aa011f8b08000000000002ff3d8db10ec2300c44777f05ca4ec28cc48090d8f882aa426962daa8c48ee2b4fc3e89689117dfdd3bbb4bd6cd76c41ec8463c5c0eeac14c370ea460c52c81a999275d470174d6fb8c22283dec60cb9f2df398903c920b28fa9a0acb3dd7a31fce730f63280d9c4a497236a6ca6919b4e3686c238f6f3bc8b63acea82ba020e3da4ad10622ac5a96c187dcac1f197945f3da9f6cf5bf56f005ed2121f8de00000001096d6f6f6e5f636f696eac011f8b08000000000002ff654e4b0ac23010dde7144317d2826b1751dcb8d61ea1c4765a82c944f241b0e4ee26412bd559bd79f33ea3cd1014c2d9183a19499ceb84ba3e419819a471de86de2f0298232bfc18082449dfe992503ba4012d878d9313a16ddef63ce2ee8deb462b343e8cbda50e4162c2a1d4709e53a450f289874fcbb15ecce58792bd5d71d72a8b21ababbf4bdb5e7ec8dd7a1d8572f8a59a7d819145f602f36168b21101000000000300000000000000000000000000000000000000000000000000000000000000010e4170746f734672616d65776f726b00000000000000000000000000000000000000000000000000000000000000010b4170746f735374646c696200000000000000000000000000000000000000000000000000000000000000010a4d6f76655374646c696200" + }, + { + "type": "hex", + "value": [ + "0xa11ceb0b060000000a01000402040403080b04130205151007254308684006a801150abd01050cc2011200000101000200000003000100010503010100010201060c0001080005060c0a020a020201096d6f6f6e5f636f696e0c6d616e616765645f636f696e084d6f6f6e436f696e0b696e69745f6d6f64756c650b64756d6d795f6669656c640a696e697469616c697a659c8916ead086418de2a9a041f507c0636c67107a196378cdbfe371f1724c452100000000000000000000000000000000000000000000000000000000000000010a020a094d6f6f6e20436f696e0a0205044d4f4f4e00020104010000000001070b000700070131060938000200" + ] + } + ] +} \ No newline at end of file diff --git a/examples/typescript/yourCoin/moonCoin/scripts/register.move b/examples/typescript/yourCoin/moonCoin/scripts/register.move new file mode 100644 index 000000000..21c627410 --- /dev/null +++ b/examples/typescript/yourCoin/moonCoin/scripts/register.move @@ -0,0 +1,5 @@ +script { + fun register(account: &signer) { + aptos_framework::managed_coin::register(account) + } +} diff --git a/examples/typescript/yourCoin/moonCoin/sources/MoonCoin.move b/examples/typescript/yourCoin/moonCoin/sources/MoonCoin.move new file mode 100644 index 000000000..458faa348 --- /dev/null +++ b/examples/typescript/yourCoin/moonCoin/sources/MoonCoin.move @@ -0,0 +1,13 @@ +module MoonCoin::moon_coin { + struct MoonCoin {} + + fun init_module(sender: &signer) { + aptos_framework::managed_coin::initialize( + sender, + b"Moon Coin", + b"MOON", + 6, + false, + ); + } +} diff --git a/src/api/account.ts b/src/api/account.ts index 2c4b651d2..d092c50ad 100644 --- a/src/api/account.ts +++ b/src/api/account.ts @@ -21,6 +21,7 @@ import { } from "../types"; import { deriveAccountFromPrivateKey, + getAccountCoinAmount, getAccountCoinsCount, getAccountCoinsData, getAccountCollectionsWithOwnedTokens, @@ -40,6 +41,7 @@ import { import { ProcessorType } from "../utils/const"; import { AptosConfig } from "./aptosConfig"; import { waitForIndexerOnVersion } from "./utils"; +import { CurrentFungibleAssetBalancesBoolExp } from "../types/generated/types"; /** * A class to query all `Account` related queries on Aptos. @@ -356,9 +358,10 @@ export class Account { * * @param args.accountAddress The account address we want to get the coins data for * @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying - * @param args.options.pagination.offset The number coin to start returning results from - * @param args.options.pagination.limit The number of results to return - * @param args.options.orderBy The order to sort the coins by + * @param args.options.pagination.offset optional. The number coin to start returning results from + * @param args.options.pagination.limit optional. The number of results to return + * @param args.options.orderBy optional. The order to sort the coins by + * @param args.options.where optional. Filter the results by * @returns Array with the coins data */ async getAccountCoinsData(args: { @@ -367,6 +370,7 @@ export class Account { options?: { pagination?: PaginationArgs; orderBy?: OrderBy; + where?: CurrentFungibleAssetBalancesBoolExp; }; }): Promise { await waitForIndexerOnVersion({ @@ -399,14 +403,54 @@ export class Account { return getAccountCoinsCount({ aptosConfig: this.config, ...args }); } + /** + * Queries the acount's APT amount + * + * @param args.accountAddress The account address we want to get the total count for + * @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying + * @returns Current amount of account's APT + */ + async getAccountAPTAmount(args: { + accountAddress: AccountAddressInput; + minimumLedgerVersion?: AnyNumber; + }): Promise { + await waitForIndexerOnVersion({ + config: this.config, + minimumLedgerVersion: args.minimumLedgerVersion, + processorTypes: [ProcessorType.ACCOUNT_TRANSACTION_PROCESSOR], + }); + return getAccountCoinAmount({ aptosConfig: this.config, coinType: "0x1::aptos_coin::AptosCoin", ...args }); + } + + /** + * Queries the acount's coin amount by the coin type + * + * @param args.accountAddress The account address we want to get the total count for + * @param args.coinType The coin type to query + * @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying + * @returns Current amount of account's coin + */ + async getAccountCoinAmount(args: { + accountAddress: AccountAddressInput; + coinType: MoveStructId; + minimumLedgerVersion?: AnyNumber; + }): Promise { + await waitForIndexerOnVersion({ + config: this.config, + minimumLedgerVersion: args.minimumLedgerVersion, + processorTypes: [ProcessorType.ACCOUNT_TRANSACTION_PROCESSOR], + }); + return getAccountCoinAmount({ aptosConfig: this.config, ...args }); + } + /** * Queries an account's owned objects * * @param args.accountAddress The account address we want to get the objects for * @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying - * @param args.options.pagination.offset The number coin to start returning results from + * @param args.options.pagination.offset The starting position to start returning results from * @param args.options.pagination.limit The number of results to return - * @param args.options.orderBy The order to sort the coins by + * @param args.options.orderBy The order to sort the objects by * @returns Objects array with the object data */ async getAccountOwnedObjects(args: { diff --git a/src/internal/account.ts b/src/internal/account.ts index ebdb437ee..15e38d25a 100644 --- a/src/internal/account.ts +++ b/src/internal/account.ts @@ -54,6 +54,7 @@ import { import { memoizeAsync } from "../utils/memoize"; import { Secp256k1PrivateKey, AuthenticationKey, Ed25519PrivateKey } from "../core"; import { AnyPublicKey } from "../core/crypto/anyPublicKey"; +import { CurrentFungibleAssetBalancesBoolExp } from "../types/generated/types"; export async function getInfo(args: { aptosConfig: AptosConfig; @@ -414,18 +415,39 @@ export async function getAccountTransactionsCount(args: { return data.account_transactions_aggregate.aggregate ? data.account_transactions_aggregate.aggregate.count : 0; } +export async function getAccountCoinAmount(args: { + aptosConfig: AptosConfig; + accountAddress: AccountAddressInput; + coinType: MoveStructId; +}): Promise { + const { aptosConfig, accountAddress, coinType } = args; + const address = AccountAddress.from(accountAddress).toStringLong(); + + const data = await getAccountCoinsData({ + aptosConfig, + accountAddress: address, + options: { + where: { asset_type: { _eq: coinType } }, + }, + }); + + return data[0] ? data[0].amount : 0; +} + export async function getAccountCoinsData(args: { aptosConfig: AptosConfig; accountAddress: AccountAddressInput; options?: { pagination?: PaginationArgs; orderBy?: OrderBy; + where?: CurrentFungibleAssetBalancesBoolExp; }; }): Promise { const { aptosConfig, accountAddress, options } = args; const address = AccountAddress.from(accountAddress).toStringLong(); const whereCondition: { owner_address: { _eq: string } } = { + ...options?.where, owner_address: { _eq: address }, }; diff --git a/tests/e2e/api/account.test.ts b/tests/e2e/api/account.test.ts index b123c7110..cde313275 100644 --- a/tests/e2e/api/account.test.ts +++ b/tests/e2e/api/account.test.ts @@ -27,7 +27,7 @@ describe("account api", () => { }); }); - describe("fetch data with account address as string", () => { + describe("fetch data", () => { test("it fetches account data", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); @@ -198,6 +198,30 @@ describe("account api", () => { expect(accountCoinsCount).toBe(1); }); + test("it fetches account's coin amount", async () => { + const config = new AptosConfig({ network: Network.LOCAL }); + const aptos = new Aptos(config); + const senderAccount = Account.generate(); + const fundTxn = await aptos.fundAccount({ + accountAddress: senderAccount.accountAddress, + amount: FUND_AMOUNT, + }); + + await aptos.waitForTransaction({ transactionHash: fundTxn.hash }); + // custom coin type + const accountCoinsAmount = await aptos.getAccountCoinAmount({ + accountAddress: senderAccount.accountAddress, + coinType: "my::coin::type", + }); + expect(accountCoinsAmount).toBe(0); + // APT Aptos coin + const accountAPTAmount = await aptos.getAccountCoinAmount({ + accountAddress: senderAccount.accountAddress, + coinType: "0x1::aptos_coin::AptosCoin", + }); + expect(accountAPTAmount).toBe(100000000); + }); + test("lookupOriginalAccountAddress - Look up account address before key rotation", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); @@ -242,67 +266,6 @@ describe("account api", () => { }); }); - describe("fetch data with account address as Uint8Array", () => { - test("it fetches account data", async () => { - const config = new AptosConfig({ network: Network.LOCAL }); - const aptos = new Aptos(config); - const data = await aptos.getAccountInfo({ - accountAddress: new Uint8Array([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - ]), - }); - expect(data).toHaveProperty("sequence_number"); - expect(data.sequence_number).toBe("0"); - expect(data).toHaveProperty("authentication_key"); - expect(data.authentication_key).toBe("0x0000000000000000000000000000000000000000000000000000000000000001"); - }); - - test("it fetches account modules", async () => { - const config = new AptosConfig({ network: Network.LOCAL }); - const aptos = new Aptos(config); - const data = await aptos.getAccountModules({ - accountAddress: new Uint8Array([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - ]), - }); - expect(data.length).toBeGreaterThan(0); - }); - - test("it fetches an account module", async () => { - const config = new AptosConfig({ network: Network.LOCAL }); - const aptos = new Aptos(config); - const data = await aptos.getAccountModule({ - accountAddress: new Uint8Array([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - ]), - moduleName: "coin", - }); - expect(data).toHaveProperty("bytecode"); - }); - - test("it fetches account resources", async () => { - const config = new AptosConfig({ network: Network.LOCAL }); - const aptos = new Aptos(config); - const data = await aptos.getAccountResources({ - accountAddress: new Uint8Array([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - ]), - }); - expect(data.length).toBeGreaterThan(0); - }); - - test("it fetches an account resource with partial information", async () => { - const config = new AptosConfig({ network: Network.LOCAL }); - const aptos = new Aptos(config); - const data = await aptos.getAccountResource<{ authentication_key: string }>({ - accountAddress: "0x1", - resourceType: "0x1::account::Account", - }); - expect(data).toHaveProperty("authentication_key"); - expect(data.authentication_key).toBe("0x0000000000000000000000000000000000000000000000000000000000000001"); - }); - }); - describe("Key Rotation", () => { test("it should rotate ed25519 to ed25519 auth key correctly", async () => { const config = new AptosConfig({ network: Network.LOCAL });