Skip to main content

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:


_10
import * as sdk from "@onflow/sdk"
_10
_10
sdk.TestUtils.authzDeepResolveMany(opts, depth)

Or import the namespace directly:


_10
import { TestUtils } from "@onflow/sdk"
_10
_10
TestUtils.authzDeepResolveMany(opts, depth)

Parameters

opts (optional)
  • Type:

_10
interface 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:


_10
import * as sdk from "@onflow/sdk"
_10
_10
sdk.TestUtils.authzFn(opts)

Or import the namespace directly:


_10
import { TestUtils } from "@onflow/sdk"
_10
_10
TestUtils.authzFn(opts)

Parameters

opts (optional)
  • Type:

_10
interface 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:


_10
import * as sdk from "@onflow/sdk"
_10
_10
sdk.TestUtils.authzResolve(opts)

Or import the namespace directly:


_10
import { TestUtils } from "@onflow/sdk"
_10
_10
TestUtils.authzResolve(opts)

Parameters

opts (optional)
  • Type:

_10
interface 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:


_10
import * as sdk from "@onflow/sdk"
_10
_10
sdk.TestUtils.authzResolveMany(opts)

Or import the namespace directly:


_10
import { TestUtils } from "@onflow/sdk"
_10
_10
TestUtils.authzResolveMany(opts)

Parameters

opts (optional)
  • Type:

_10
interface 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:


_10
import * as sdk from "@onflow/sdk"
_10
_10
sdk.TestUtils.idof(acct)

Or import the namespace directly:


_10
import { TestUtils } from "@onflow/sdk"
_10
_10
TestUtils.idof(acct)

Parameters

acct

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:


_10
import * as sdk from "@onflow/sdk"
_10
_10
sdk.TestUtils.run(fns)

Or import the namespace directly:


_10
import { TestUtils } from "@onflow/sdk"
_10
_10
TestUtils.run(fns)

Usage


_28
import { run } from "@onflow/sdk"
_28
import * as fcl from "@onflow/fcl";
_28
_28
// Test a simple script interaction
_28
const result = await run([
_28
fcl.script`
_28
access(all) fun main(): Int {
_28
return 42
_28
}
_28
`
_28
]);
_28
_28
console.log(result.cadence); // The Cadence script
_28
console.log(result.tag); // "SCRIPT"
_28
_28
// Test a transaction with arguments
_28
const 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
_28
console.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

Promise<Interaction>

sig

Generates a test signature string for an account.

Import

You can import the entire package and access the function:


_10
import * as sdk from "@onflow/sdk"
_10
_10
sdk.TestUtils.sig(opts)

Or import the namespace directly:


_10
import { TestUtils } from "@onflow/sdk"
_10
_10
TestUtils.sig(opts)

Parameters

opts
  • Type: Partial<InteractionAccount>
  • Description: Partial account object containing address and keyId

Returns

string