TestUtils
Overview
Namespace containing TestUtils utilities
Functions
authzDeepResolveMany
Creates a deep test authorization resolver with nested resolution for complex testing scenarios.
Import
You can import the entire package and access the function:
_10import * as sdk from "@onflow/sdk"_10_10sdk.TestUtils.authzDeepResolveMany(opts, depth)
Or import the namespace directly:
_10import { TestUtils } from "@onflow/sdk"_10_10TestUtils.authzDeepResolveMany(opts, depth)
Parameters
opts
(optional)
- Type:
_10interface IAuthzResolveMany {_10 tempId?: string_10 authorizations: any[]_10 proposer?: any_10 payer?: any_10}
- Description: Configuration including authorizations array and optional proposer/payer
depth
(optional)
- Type:
number
- Description: The depth of nesting for the resolver (default: 1)
Returns
_10(account: InteractionAccount) => InteractionAccount
authzFn
Creates a test authorization function for testing transactions.
Import
You can import the entire package and access the function:
_10import * as sdk from "@onflow/sdk"_10_10sdk.TestUtils.authzFn(opts)
Or import the namespace directly:
_10import { TestUtils } from "@onflow/sdk"_10_10TestUtils.authzFn(opts)
Parameters
opts
(optional)
- Type:
_10interface IAuthzOpts {_10 signingFunction?: (signable: any) => any_10}
- Description: Optional configuration including custom signing function
Returns
_10(account: Partial<InteractionAccount>) => Partial<InteractionAccount>
authzResolve
Creates a test authorization resolver that can be used for testing account resolution.
Import
You can import the entire package and access the function:
_10import * as sdk from "@onflow/sdk"_10_10sdk.TestUtils.authzResolve(opts)
Or import the namespace directly:
_10import { TestUtils } from "@onflow/sdk"_10_10TestUtils.authzResolve(opts)
Parameters
opts
(optional)
- Type:
_10interface IAuthzResolveOpts {_10 tempId?: string_10}
- Description: Optional configuration including temporary ID
Returns
_10(account: InteractionAccount) => { tempId: string; resolve: (account: Partial<InteractionAccount>) => Partial<InteractionAccount>; kind: InteractionResolverKind.ACCOUNT; addr: string; keyId: string | number; sequenceNum: number; signature: string; signingFunction: any; role: { proposer: boolean; authorizer: boolean; payer: boolean; param?: boolean; }; authorization: any; }
authzResolveMany
Creates a test authorization resolver that handles multiple accounts with different roles.
Import
You can import the entire package and access the function:
_10import * as sdk from "@onflow/sdk"_10_10sdk.TestUtils.authzResolveMany(opts)
Or import the namespace directly:
_10import { TestUtils } from "@onflow/sdk"_10_10TestUtils.authzResolveMany(opts)
Parameters
opts
(optional)
- Type:
_10interface IAuthzResolveMany {_10 tempId?: string_10 authorizations: any[]_10 proposer?: any_10 payer?: any_10}
- Description: Configuration including authorizations array and optional proposer/payer
Returns
_10(account: InteractionAccount) => InteractionAccount
idof
Generates a unique identifier for an account based on its address and key ID.
Import
You can import the entire package and access the function:
_10import * as sdk from "@onflow/sdk"_10_10sdk.TestUtils.idof(acct)
Or import the namespace directly:
_10import { TestUtils } from "@onflow/sdk"_10_10TestUtils.idof(acct)
Parameters
acct
- Type:
InteractionAccount
- Description: The account object
Returns
string
run
Runs a set of functions on an interaction
This is a utility function for testing that builds and resolves an interaction with the provided builder functions. It automatically adds a reference block and then resolves the interaction for testing purposes.
Import
You can import the entire package and access the function:
_10import * as sdk from "@onflow/sdk"_10_10sdk.TestUtils.run(fns)
Or import the namespace directly:
_10import { TestUtils } from "@onflow/sdk"_10_10TestUtils.run(fns)
Usage
_28import { run } from "@onflow/sdk"_28import * as fcl from "@onflow/fcl";_28_28// Test a simple script interaction_28const result = await run([_28 fcl.script`_28 access(all) fun main(): Int {_28 return 42_28 }_28 `_28]);_28_28console.log(result.cadence); // The Cadence script_28console.log(result.tag); // "SCRIPT"_28_28// Test a transaction with arguments_28const txResult = await run([_28 fcl.transaction`_28 transaction(amount: UFix64) {_28 prepare(account: AuthAccount) {_28 log(amount)_28 }_28 }_28 `,_28 fcl.args([fcl.arg("10.0", fcl.t.UFix64)])_28]);_28_28console.log(txResult.message.arguments); // The resolved arguments
Parameters
fns
(optional)
- Type:
_10((ix: Interaction) => Interaction | Promise<Interaction>)[]
- Description: An array of functions to run on the interaction
Returns
sig
Generates a test signature string for an account.
Import
You can import the entire package and access the function:
_10import * as sdk from "@onflow/sdk"_10_10sdk.TestUtils.sig(opts)
Or import the namespace directly:
_10import { TestUtils } from "@onflow/sdk"_10_10TestUtils.sig(opts)
Parameters
opts
- Type:
Partial<InteractionAccount>
- Description: Partial account object containing address and keyId
Returns
string