diff --git a/CHANGELOG.md b/CHANGELOG.md index 2640eafce..b2c5c5a10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ All notable changes to the Aptos TypeScript SDK will be captured in this file. T - Handle `Unauthorized` server error - Add function to create object address locally - Add function to create token object address locally +- Add signers to entry function ABI for future signature count checking +- [`Breaking`] Add type-safe view functions with ABI support # 1.10.0 (2024-03-11) diff --git a/examples/typescript-esm/multisig_v2.ts b/examples/typescript-esm/multisig_v2.ts index 89b1b80d2..17d3148a0 100644 --- a/examples/typescript-esm/multisig_v2.ts +++ b/examples/typescript-esm/multisig_v2.ts @@ -21,7 +21,6 @@ import { Account, Aptos, AptosConfig, - InputViewRequestData, Network, NetworkToNetworkName, MoveString, @@ -30,6 +29,7 @@ import { TransactionPayloadMultiSig, MultiSig, AccountAddress, + InputViewFunctionData, } from "@aptos-labs/ts-sdk"; // Default to devnet, but allow for overriding @@ -90,7 +90,7 @@ const settingUpMultiSigAccount = async () => { // =========================================================================================== // Get the next multisig account address. This will be the same as the account address of the multisig account we'll // be creating. - const payload: InputViewRequestData = { + const payload: InputViewFunctionData = { function: "0x1::multisig_account::get_next_multisig_account_address", functionArguments: [owner1.accountAddress.toString()], }; diff --git a/examples/typescript/swap.ts b/examples/typescript/swap.ts index b254f5d75..01e5acd0c 100644 --- a/examples/typescript/swap.ts +++ b/examples/typescript/swap.ts @@ -19,9 +19,9 @@ import { Aptos, AptosConfig, Ed25519PrivateKey, + InputViewFunctionData, Network, NetworkToNetworkName, - InputViewRequestData, } from "@aptos-labs/ts-sdk"; import { createInterface } from "readline"; // Default to devnet, but allow for overriding @@ -38,7 +38,7 @@ const getOptimalLpAmount = async ( token1Addr: AccountAddress, token2Addr: AccountAddress, ): Promise => { - const payload: InputViewRequestData = { + const payload: InputViewFunctionData = { function: `${swap.toString()}::router::optimal_liquidity_amounts`, functionArguments: [token1Addr, token2Addr, false, "200000", "300000", "200", "300"], }; diff --git a/examples/typescript/your_fungible_asset.ts b/examples/typescript/your_fungible_asset.ts index e87907def..c876e6c8f 100644 --- a/examples/typescript/your_fungible_asset.ts +++ b/examples/typescript/your_fungible_asset.ts @@ -7,7 +7,7 @@ import { AnyNumber, Aptos, AptosConfig, - InputViewRequestData, + InputViewFunctionData, Network, NetworkToNetworkName, } from "@aptos-labs/ts-sdk"; @@ -127,7 +127,7 @@ const getFaBalance = async (owner: Account, assetType: string): Promise /** Return the address of the managed fungible asset that's created when this module is deployed */ async function getMetadata(admin: Account): Promise { - const payload: InputViewRequestData = { + const payload: InputViewFunctionData = { function: `${admin.accountAddress}::fa_coin::get_metadata`, functionArguments: [], }; diff --git a/src/api/general.ts b/src/api/general.ts index 7ae447f54..9e7f7ae1e 100644 --- a/src/api/general.ts +++ b/src/api/general.ts @@ -11,8 +11,8 @@ import { getProcessorStatus, getTableItem, queryIndexer, - view, } from "../internal/general"; +import { view } from "../internal/view"; import { AnyNumber, Block, @@ -23,9 +23,9 @@ import { LedgerVersionArg, MoveValue, TableItemRequest, - InputViewRequestData, } from "../types"; import { ProcessorType } from "../utils/const"; +import { InputViewFunctionData } from "../transactions"; /** * A class to query all `General` Aptos related queries @@ -137,7 +137,7 @@ export class General { * @returns an array of Move values */ async view>(args: { - payload: InputViewRequestData; + payload: InputViewFunctionData; options?: LedgerVersionArg; }): Promise { return view({ aptosConfig: this.config, ...args }); diff --git a/src/client/get.ts b/src/client/get.ts index db244b155..cf0869dfd 100644 --- a/src/client/get.ts +++ b/src/client/get.ts @@ -59,8 +59,8 @@ export async function get( method: "GET", originMethod, path, - contentType: contentType?.valueOf(), - acceptType: acceptType?.valueOf(), + contentType, + acceptType, params, overrides: { ...aptosConfig.clientConfig, diff --git a/src/client/post.ts b/src/client/post.ts index a04434e86..0e99e46da 100644 --- a/src/client/post.ts +++ b/src/client/post.ts @@ -67,8 +67,8 @@ export async function post( originMethod, path, body, - contentType: contentType?.valueOf(), - acceptType: acceptType?.valueOf(), + contentType, + acceptType, params, overrides, }, diff --git a/src/internal/ans.ts b/src/internal/ans.ts index 17300232c..5361fa5f7 100644 --- a/src/internal/ans.ts +++ b/src/internal/ans.ts @@ -11,12 +11,13 @@ import { AptosConfig } from "../api/aptosConfig"; import { Account, AccountAddress, AccountAddressInput } from "../core"; import { InputGenerateTransactionOptions, SimpleTransaction } from "../transactions/types"; -import { GetANSNameResponse, MoveAddressType, MoveValue, OrderByArg, PaginationArgs, WhereArg } from "../types"; +import { GetANSNameResponse, MoveAddressType, OrderByArg, PaginationArgs, WhereArg } from "../types"; import { GetNamesQuery } from "../types/generated/operations"; import { GetNames } from "../types/generated/queries"; import { CurrentAptosNamesBoolExp } from "../types/generated/types"; import { Network } from "../utils/apiEndpoints"; -import { queryIndexer, view } from "./general"; +import { queryIndexer } from "./general"; +import { view } from "./view"; import { generateTransaction } from "./transactionSubmission"; export const VALIDATION_RULES_DESCRIPTION = [ @@ -85,12 +86,6 @@ function getRouterAddress(aptosConfig: AptosConfig): string { return address; } -const Some = (value: T): MoveValue => ({ vec: [value] }); -const None = (): MoveValue => ({ vec: [] }); -// != here is intentional, we want to check for null and undefined -// eslint-disable-next-line eqeqeq -const Option = (value: T | undefined | null): MoveValue => (value != undefined ? Some(value) : None()); - const unwrapOption = (option: any): T | undefined => { if (!!option && typeof option === "object" && "vec" in option && Array.isArray(option.vec)) { return option.vec[0]; @@ -108,7 +103,7 @@ export async function getOwnerAddress(args: { aptosConfig: AptosConfig; name: st aptosConfig, payload: { function: `${routerAddress}::router::get_owner_addr`, - functionArguments: [domainName, Option(subdomainName)], + functionArguments: [domainName, subdomainName], }, }); @@ -219,7 +214,7 @@ export async function getExpiration(args: { aptosConfig: AptosConfig; name: stri aptosConfig, payload: { function: `${routerAddress}::router::get_expiration`, - functionArguments: [domainName, Option(subdomainName)], + functionArguments: [domainName, subdomainName], }, }); @@ -303,7 +298,7 @@ export async function getTargetAddress(args: { aptosConfig, payload: { function: `${routerAddress}::router::get_target_addr`, - functionArguments: [domainName, Option(subdomainName)], + functionArguments: [domainName, subdomainName], }, }); @@ -570,6 +565,6 @@ export async function renewDomain(args: { function sanitizeANSName(name: GetANSNameResponse[0]): GetANSNameResponse[0] { return { ...name, - expiration_timestamp: new Date(name.expiration_timestamp).valueOf(), + expiration_timestamp: new Date(name.expiration_timestamp).getTime(), }; } diff --git a/src/internal/general.ts b/src/internal/general.ts index 4ea17c1aa..673c4a377 100644 --- a/src/internal/general.ts +++ b/src/internal/general.ts @@ -18,10 +18,7 @@ import { GraphqlQuery, LedgerInfo, LedgerVersionArg, - MoveValue, TableItemRequest, - ViewRequest, - InputViewRequestData, } from "../types"; import { GetChainTopUserTransactionsQuery, GetProcessorStatusQuery } from "../types/generated/operations"; import { GetChainTopUserTransactions, GetProcessorStatus } from "../types/generated/queries"; @@ -84,27 +81,6 @@ export async function getTableItem(args: { return response.data as T; } -export async function view = Array>(args: { - aptosConfig: AptosConfig; - payload: InputViewRequestData; - options?: LedgerVersionArg; -}): Promise { - const { aptosConfig, payload, options } = args; - const { data } = await postAptosFullNode({ - aptosConfig, - originMethod: "view", - path: "view", - params: { ledger_version: options?.ledgerVersion }, - body: { - function: payload.function, - type_arguments: payload.typeArguments ?? [], - arguments: payload.functionArguments ?? [], - }, - }); - - return data as T; -} - export async function getChainTopUserTransactions(args: { aptosConfig: AptosConfig; limit: number; @@ -168,7 +144,7 @@ export async function getProcessorStatus(args: { const { aptosConfig, processorType } = args; const whereCondition: { processor: { _eq: string } } = { - processor: { _eq: processorType.valueOf() }, + processor: { _eq: processorType }, }; const graphqlQuery = { diff --git a/src/internal/transactionSubmission.ts b/src/internal/transactionSubmission.ts index 007e40f94..2ba817485 100644 --- a/src/internal/transactionSubmission.ts +++ b/src/internal/transactionSubmission.ts @@ -20,7 +20,6 @@ import { generateSignedTransaction, sign, generateSigningMessage, - generateTransactionPayloadWithABI, } from "../transactions/transactionBuilder/transactionBuilder"; import { InputGenerateTransactionData, @@ -111,20 +110,14 @@ export async function buildTransactionPayload( // TODO: Add ABI checking later payload = await generateTransactionPayload(data); } else if ("multisigAddress" in data) { - if (data.abi) { - payload = generateTransactionPayloadWithABI({ abi: data.abi, ...data }); - } else { - generateTransactionPayloadData = { - aptosConfig, - multisigAddress: data.multisigAddress, - function: data.function, - functionArguments: data.functionArguments, - typeArguments: data.typeArguments, - }; - payload = await generateTransactionPayload(generateTransactionPayloadData); - } - } else if (data.abi) { - payload = generateTransactionPayloadWithABI({ abi: data.abi, ...data }); + generateTransactionPayloadData = { + aptosConfig, + multisigAddress: data.multisigAddress, + function: data.function, + functionArguments: data.functionArguments, + typeArguments: data.typeArguments, + }; + payload = await generateTransactionPayload(generateTransactionPayloadData); } else { generateTransactionPayloadData = { aptosConfig, @@ -365,9 +358,9 @@ export async function rotateAuthKey(args: { data: { function: "0x1::account::rotate_authentication_key", functionArguments: [ - new U8(fromAccount.signingScheme.valueOf()), // from scheme + new U8(fromAccount.signingScheme), // from scheme MoveVector.U8(fromAccount.publicKey.toUint8Array()), - new U8(newAccount.signingScheme.valueOf()), // to scheme + new U8(newAccount.signingScheme), // to scheme MoveVector.U8(newAccount.publicKey.toUint8Array()), MoveVector.U8(proofSignedByCurrentPrivateKey.toUint8Array()), MoveVector.U8(proofSignedByNewPrivateKey.toUint8Array()), diff --git a/src/internal/view.ts b/src/internal/view.ts new file mode 100644 index 000000000..d73964d3f --- /dev/null +++ b/src/internal/view.ts @@ -0,0 +1,35 @@ +// Copyright © Aptos Foundation +// SPDX-License-Identifier: Apache-2.0 + +import { LedgerVersionArg, MimeType, MoveValue } from "../types"; +import { AptosConfig } from "../api/aptosConfig"; +import { generateViewFunctionPayload, InputViewFunctionData } from "../transactions"; +import { Serializer } from "../bcs"; +import { postAptosFullNode } from "../client"; + +export async function view = Array>(args: { + aptosConfig: AptosConfig; + payload: InputViewFunctionData; + options?: LedgerVersionArg; +}): Promise { + const { aptosConfig, payload, options } = args; + const viewFunctionPayload = await generateViewFunctionPayload({ + ...payload, + aptosConfig, + }); + + const serializer = new Serializer(); + viewFunctionPayload.serialize(serializer); + const bytes = serializer.toUint8Array(); + + const { data } = await postAptosFullNode({ + aptosConfig, + path: "view", + originMethod: "view", + contentType: MimeType.BCS_VIEW_FUNCTION, + params: { ledger_version: options?.ledgerVersion }, + body: bytes, + }); + + return data as T; +} diff --git a/src/transactions/transactionBuilder/remoteAbi.ts b/src/transactions/transactionBuilder/remoteAbi.ts index cb590b23c..cee854e29 100644 --- a/src/transactions/transactionBuilder/remoteAbi.ts +++ b/src/transactions/transactionBuilder/remoteAbi.ts @@ -4,7 +4,13 @@ import { parseTypeTag } from "../typeTag/parser"; import { TypeTag, TypeTagStruct } from "../typeTag"; import { AptosConfig } from "../../api/aptosConfig"; -import { EntryFunctionArgumentTypes, SimpleEntryFunctionArgumentTypes, EntryFunctionABI } from "../types"; +import { + EntryFunctionArgumentTypes, + SimpleEntryFunctionArgumentTypes, + EntryFunctionABI, + ViewFunctionABI, + FunctionABI, +} from "../types"; import { Bool, MoveOption, MoveString, MoveVector, U128, U16, U256, U32, U64, U8 } from "../../bcs"; import { AccountAddress } from "../../core"; import { getModule } from "../../internal/account"; @@ -27,6 +33,7 @@ import { isString, throwTypeMismatch, } from "./helpers"; +import { MoveFunction } from "../../types"; const TEXT_ENCODER = new TextEncoder(); @@ -45,6 +52,29 @@ export function standardizeTypeTags(typeArguments?: Array): Ar ); } +/** + * Fetches a function ABI from the on-chain module ABI. It doesn't validate whether it's a view or entry function. + * @param moduleAddress + * @param moduleName + * @param functionName + * @param aptosConfig + */ +export async function fetchFunctionAbi( + moduleAddress: string, + moduleName: string, + functionName: string, + aptosConfig: AptosConfig, +): Promise { + // This fetch from the API is currently cached + const module = await getModule({ aptosConfig, accountAddress: moduleAddress, moduleName }); + + if (module.abi) { + return module.abi.exposed_functions.find((func) => func.name === functionName); + } + + return undefined; +} + /** * Fetches the ABI for an entry function from the module * @@ -59,10 +89,7 @@ export async function fetchEntryFunctionAbi( functionName: string, aptosConfig: AptosConfig, ): Promise { - // This fetch from the API is currently cached - const module = await getModule({ aptosConfig, accountAddress: moduleAddress, moduleName }); - - const functionAbi = module.abi?.exposed_functions.find((func) => func.name === functionName); + const functionAbi = await fetchFunctionAbi(moduleAddress, moduleName, functionName, aptosConfig); // If there's no ABI, then the function is invalid if (!functionAbi) { @@ -75,15 +102,61 @@ export async function fetchEntryFunctionAbi( } // Remove the signer arguments - const first = findFirstNonSignerArg(functionAbi); + const numSigners = findFirstNonSignerArg(functionAbi); const params: TypeTag[] = []; - for (let i = first; i < functionAbi.params.length; i += 1) { + for (let i = numSigners; i < functionAbi.params.length; i += 1) { params.push(parseTypeTag(functionAbi.params[i], { allowGenerics: true })); } + return { + signers: numSigners, + typeParameters: functionAbi.generic_type_params, + parameters: params, + }; +} + +/** + * Fetches the ABI for a view function from the module + * + * @param moduleAddress + * @param moduleName + * @param functionName + * @param aptosConfig + */ +export async function fetchViewFunctionAbi( + moduleAddress: string, + moduleName: string, + functionName: string, + aptosConfig: AptosConfig, +): Promise { + const functionAbi = await fetchFunctionAbi(moduleAddress, moduleName, functionName, aptosConfig); + + // If there's no ABI, then the function is invalid + if (!functionAbi) { + throw new Error(`Could not find view function ABI for '${moduleAddress}::${moduleName}::${functionName}'`); + } + + // Non-view functions can't be used + if (!functionAbi.is_view) { + throw new Error(`'${moduleAddress}::${moduleName}::${functionName}' is not an view function`); + } + + // Type tag parameters for the function + const params: TypeTag[] = []; + for (let i = 0; i < functionAbi.params.length; i += 1) { + params.push(parseTypeTag(functionAbi.params[i], { allowGenerics: true })); + } + + // The return types of the view function + const returnTypes: TypeTag[] = []; + for (let i = 0; i < functionAbi.return.length; i += 1) { + returnTypes.push(parseTypeTag(functionAbi.return[i], { allowGenerics: true })); + } + return { typeParameters: functionAbi.generic_type_params, parameters: params, + returnTypes, }; } @@ -96,7 +169,7 @@ export async function fetchEntryFunctionAbi( */ export function convertArgument( functionName: string, - functionAbi: EntryFunctionABI, + functionAbi: FunctionABI, arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes, position: number, genericTypeParams: Array, diff --git a/src/transactions/transactionBuilder/transactionBuilder.ts b/src/transactions/transactionBuilder/transactionBuilder.ts index 5cec0b60f..c614f79aa 100644 --- a/src/transactions/transactionBuilder/transactionBuilder.ts +++ b/src/transactions/transactionBuilder/transactionBuilder.ts @@ -69,8 +69,11 @@ import { InputGenerateTransactionPayloadDataWithABI, InputEntryFunctionDataWithABI, InputMultiSigDataWithABI, + InputViewFunctionDataWithRemoteABI, + InputViewFunctionDataWithABI, + FunctionABI, } from "../types"; -import { convertArgument, fetchEntryFunctionAbi, standardizeTypeTags } from "./remoteAbi"; +import { convertArgument, fetchEntryFunctionAbi, fetchViewFunctionAbi, standardizeTypeTags } from "./remoteAbi"; import { memoizeAsync } from "../../utils/memoize"; import { AnyNumber } from "../../types"; import { getFunctionParts, isScriptDataInput } from "./helpers"; @@ -105,15 +108,17 @@ export async function generateTransactionPayload( if (isScriptDataInput(args)) { return generateTransactionPayloadScript(args); } - const { moduleAddress, moduleName, functionName } = getFunctionParts(args.function); - // We fetch the entry function ABI, and then pretend that we already had the ABI - const functionAbi = await memoizeAsync( - async () => fetchEntryFunctionAbi(moduleAddress, moduleName, functionName, args.aptosConfig), - `entry-function-${args.aptosConfig.network}-${moduleAddress}-${moduleName}-${functionName}`, - 1000 * 60 * 5, // 5 minutes - )(); + const functionAbi = await fetchAbi({ + key: "entry-function", + moduleAddress, + moduleName, + functionName, + aptosConfig: args.aptosConfig, + abi: args.abi, + fetch: fetchEntryFunctionAbi, + }); // Fill in the ABI return generateTransactionPayloadWithABI({ abi: functionAbi, ...args }); @@ -170,6 +175,53 @@ export function generateTransactionPayloadWithABI( return new TransactionPayloadEntryFunction(entryFunctionPayload); } +export async function generateViewFunctionPayload(args: InputViewFunctionDataWithRemoteABI): Promise { + const { moduleAddress, moduleName, functionName } = getFunctionParts(args.function); + + const functionAbi = await fetchAbi({ + key: "view-function", + moduleAddress, + moduleName, + functionName, + aptosConfig: args.aptosConfig, + abi: args.abi, + fetch: fetchViewFunctionAbi, + }); + + // Fill in the ABI + return generateViewFunctionPayloadWithABI({ abi: functionAbi, ...args }); +} + +export function generateViewFunctionPayloadWithABI(args: InputViewFunctionDataWithABI): EntryFunction { + const functionAbi = args.abi; + const { moduleAddress, moduleName, functionName } = getFunctionParts(args.function); + + // Ensure that all type arguments are typed properly + const typeArguments = standardizeTypeTags(args.typeArguments); + + // Check the type argument count against the ABI + if (typeArguments.length !== functionAbi.typeParameters.length) { + throw new Error( + `Type argument count mismatch, expected ${functionAbi.typeParameters.length}, received ${typeArguments.length}`, + ); + } + + // Check all BCS types, and convert any non-BCS types + const functionArguments: Array = + args?.functionArguments?.map((arg, i) => convertArgument(args.function, functionAbi, arg, i, typeArguments)) ?? []; + + // Check that all arguments are accounted for + if (functionArguments.length !== functionAbi.parameters.length) { + throw new Error( + // eslint-disable-next-line max-len + `Too few arguments for '${moduleAddress}::${moduleName}::${functionName}', expected ${functionAbi.parameters.length} but got ${functionArguments.length}`, + ); + } + + // Generate entry function payload + return EntryFunction.build(`${moduleAddress}::${moduleName}`, functionName, typeArguments, functionArguments); +} + function generateTransactionPayloadScript(args: InputScriptData) { return new TransactionPayloadScript( new Script(Hex.fromHexInput(args.bytecode).toUint8Array(), args.typeArguments ?? [], args.functionArguments), @@ -570,3 +622,42 @@ export function generateSigningMessage(transaction: AnyRawTransaction): Uint8Arr return mergedArray; } + +/** + * Fetches and caches ABIs with allowing for pass-through on provided ABIs + * @param key + * @param moduleAddress + * @param moduleName + * @param functionName + * @param aptosConfig + * @param abi + * @param fetch + */ +async function fetchAbi({ + key, + moduleAddress, + moduleName, + functionName, + aptosConfig, + abi, + fetch, +}: { + key: string; + moduleAddress: string; + moduleName: string; + functionName: string; + aptosConfig: AptosConfig; + abi?: T; + fetch: (moduleAddress: string, moduleName: string, functionName: string, aptosConfig: AptosConfig) => Promise; +}): Promise { + if (abi) { + return abi; + } + + // We fetch the entry function ABI, and then pretend that we already had the ABI + return memoizeAsync( + async () => fetch(moduleAddress, moduleName, functionName, aptosConfig), + `${key}-${aptosConfig.network}-${moduleAddress}-${moduleName}-${functionName}`, + 1000 * 60 * 5, // 5 minutes + )(); +} diff --git a/src/transactions/types.ts b/src/transactions/types.ts index d668da6d7..589dac105 100644 --- a/src/transactions/types.ts +++ b/src/transactions/types.ts @@ -146,14 +146,50 @@ export type InputScriptData = { functionArguments: Array; }; +/** + * The data needed to generate a View Function payload + */ +export type InputViewFunctionData = { + function: MoveFunctionId; + typeArguments?: Array; + functionArguments?: Array; + abi?: ViewFunctionABI; +}; + +/** + * Data needed to generate a view function payload and fetch the remote ABI + */ +export type InputViewFunctionDataWithRemoteABI = InputViewFunctionData & { aptosConfig: AptosConfig }; + +/** + * Data needed to generate a view function, with an already fetched ABI + */ +export type InputViewFunctionDataWithABI = InputViewFunctionData & { abi: ViewFunctionABI }; + +/** + * Data need for a generic function ABI, both view and entry + */ +export type FunctionABI = { + typeParameters: Array; + parameters: Array; +}; + /** * Interface of an Entry function's ABI. * * This is used to provide type checking and simple input conversion on ABI based transaction submission. */ -export type EntryFunctionABI = { - typeParameters: Array; - parameters: Array; +export type EntryFunctionABI = FunctionABI & { + signers?: number; +}; + +/** + * Interface of an View function's ABI. + * + * This is used to provide type checking and simple input conversion on ABI based transaction submission. + */ +export type ViewFunctionABI = FunctionABI & { + returnTypes: Array; }; /** diff --git a/src/types/index.ts b/src/types/index.ts index f2ac134f7..4360faf1b 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -19,6 +19,7 @@ export enum MimeType { * BCS representation, used for transaction submission in BCS input */ BCS_SIGNED_TRANSACTION = "application/x.aptos.signed_transaction+bcs", + BCS_VIEW_FUNCTION = "application/x.aptos.view_function+bcs", } /** @@ -1022,34 +1023,8 @@ export type Block = { transactions?: Array; }; -/** - * The data needed to generate a View Request payload - */ -export type InputViewRequestData = { - function: MoveFunctionId; - typeArguments?: Array; - functionArguments?: Array; -}; - // REQUEST TYPES -/** - * View request for the Move view function API - * - * `type MoveFunctionId = ${string}::${string}::${string}`; - */ -export type ViewRequest = { - function: MoveFunctionId; - /** - * Type arguments of the function - */ - typeArguments: Array; - /** - * Arguments of the function - */ - functionArguments: Array; -}; - /** * Table Item request for the GetTableItem API */ diff --git a/tests/e2e/ans/ans.test.ts b/tests/e2e/ans/ans.test.ts index 7bdc361dc..4c227c4a4 100644 --- a/tests/e2e/ans/ans.test.ts +++ b/tests/e2e/ans/ans.test.ts @@ -478,7 +478,7 @@ describe("ANS", () => { ); // Change the expiration date of the name to be tomorrow - const newExpirationDate = Math.floor(new Date(Date.now() + 1 * 24 * 60 * 60 * 1000).valueOf() / 1000); + const newExpirationDate = Math.floor(new Date(Date.now() + 24 * 60 * 60 * 1000).getTime() / 1000); await changeExpirationDate(1, newExpirationDate, name); await signAndSubmit(alice, await aptos.renewDomain({ name, sender: alice })); diff --git a/tests/e2e/api/general.test.ts b/tests/e2e/api/general.test.ts index fb4f6d5a8..f8ffe629a 100644 --- a/tests/e2e/api/general.test.ts +++ b/tests/e2e/api/general.test.ts @@ -1,7 +1,7 @@ // Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 -import { AptosConfig, Aptos, Network, GraphqlQuery, InputViewRequestData, ProcessorType } from "../../../src"; +import { AptosConfig, Aptos, Network, GraphqlQuery, ProcessorType, InputViewFunctionData } from "../../../src"; describe("general api", () => { test("it fetches ledger info", async () => { @@ -101,7 +101,7 @@ describe("general api", () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const payload: InputViewRequestData = { + const payload: InputViewFunctionData = { function: "0x1::chain_id::get", }; @@ -114,7 +114,7 @@ describe("general api", () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const payload: InputViewRequestData = { + const payload: InputViewFunctionData = { function: "0x1::chain_id::get", }; @@ -127,7 +127,7 @@ describe("general api", () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const payload: InputViewRequestData = { + const payload: InputViewFunctionData = { function: "0x1::account::exists_at", functionArguments: ["0x1"], }; @@ -136,7 +136,7 @@ describe("general api", () => { expect(exists).toBe(true); - const payload2: InputViewRequestData = { + const payload2: InputViewFunctionData = { function: "0x1::account::exists_at", functionArguments: ["0x12345"], }; @@ -150,7 +150,7 @@ describe("general api", () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const payload: InputViewRequestData = { + const payload: InputViewFunctionData = { function: "0x1::account::get_sequence_number", functionArguments: ["0x1"], }; @@ -159,7 +159,7 @@ describe("general api", () => { expect(BigInt(sequenceNumber)).toEqual(BigInt(0)); - const payload2: InputViewRequestData = { + const payload2: InputViewFunctionData = { function: "0x1::account::get_authentication_key", functionArguments: ["0x1"], }; @@ -173,7 +173,7 @@ describe("general api", () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const payload: InputViewRequestData = { + const payload: InputViewFunctionData = { function: "0x1::coin::symbol", typeArguments: ["0x1::aptos_coin::AptosCoin"], }; @@ -181,7 +181,7 @@ describe("general api", () => { const symbol = (await aptos.view<[string]>({ payload }))[0]; expect(symbol).toEqual("APT"); - const payload2: InputViewRequestData = { + const payload2: InputViewFunctionData = { function: "0x1::coin::is_account_registered", typeArguments: ["0x1::aptos_coin::AptosCoin"], functionArguments: ["0x1"], @@ -190,10 +190,9 @@ describe("general api", () => { const isRegistered = (await aptos.view<[boolean]>({ payload: payload2 }))[0]; expect(isRegistered).toEqual(false); - const payload3: InputViewRequestData = { + const payload3: InputViewFunctionData = { function: "0x1::coin::supply", typeArguments: ["0x1::aptos_coin::AptosCoin"], - functionArguments: [], }; const supply = (await aptos.view<[{ vec: [string] }]>({ payload: payload3 }))[0].vec[0]; @@ -204,7 +203,7 @@ describe("general api", () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const payload: InputViewRequestData = { + const payload: InputViewFunctionData = { function: "0x1::account::get_sequence_number", functionArguments: ["0x123456"], }; diff --git a/tests/e2e/client/post.test.ts b/tests/e2e/client/post.test.ts index 31cb3ef7f..a3cd1a53e 100644 --- a/tests/e2e/client/post.test.ts +++ b/tests/e2e/client/post.test.ts @@ -3,10 +3,10 @@ import { GraphqlQuery, postAptosIndexer, postAptosFullNode, - ViewRequest, U8, postAptosFaucet, Account, + InputViewFunctionData, } from "../../../src"; import { GetChainTopUserTransactionsQuery } from "../../../src/types/generated/operations"; import { GetChainTopUserTransactions } from "../../../src/types/generated/queries"; @@ -54,7 +54,7 @@ describe("post request", () => { describe("fullnode", () => { test("it sets correct headers on post request", async () => { try { - await postAptosFullNode({ + await postAptosFullNode({ aptosConfig, originMethod: "testPostFullnodeQuery", path: "view",