Skip to content

Test Node Options

This reference describes all the options of the launchTestNode utility:

ts
import { launchTestNode } from 'fuels/test-utils';

using launched = await launchTestNode(/* options */);
See code in context

walletsConfig

Used to set the node's genesis block state (coins and messages).

  • count: number of wallets/addresses to generate on the genesis block.
  • assets: configure how many unique assets each wallet will own with the base asset included. Can be number or AssetId[].
    • The AssetId utility simplifies testing when different assets are necessary.
  • coinsPerAsset: number of coins (UTXOs) per asset id.
  • amountPerCoin: for each coin, the amount it'll contain.
  • messages: messages to assign to the wallets.

walletsConfig.assets

The AssetId utility integrates with walletsConfig and gives you an easy way to generate multiple random asset ids via the AssetId.random static method.

ts
import { AssetId, launchTestNode } from 'fuels/test-utils';

const assets = AssetId.random();

using launched = await launchTestNode({
  walletsConfig: {
    assets,
  },
});

const {
  wallets: [wallet],
} = launched;

const { coins } = await wallet.getCoins(assets[0].value);
See code in context

walletsConfig.messages

The TestMessage helper class is used to create messages for testing purposes. When passed via walletsConfig.messages, the recipient field of the message is overriden to be the wallet's address.

ts
import { TestMessage, launchTestNode } from 'fuels/test-utils';

const testMessage = new TestMessage({ amount: 1000 });

using launched = await launchTestNode({
  walletsConfig: {
    messages: [testMessage],
  },
});

const {
  wallets: [wallet],
} = launched;

const {
  messages: [message],
} = await wallet.getMessages();
// message.nonce === testMessage.nonce
See code in context

It can also be used standalone and passed into the initial state of the chain via the TestMessage.toChainMessage instance method.

ts
import { WalletUnlocked } from 'fuels';
import { TestMessage, launchTestNode } from 'fuels/test-utils';

const recipient = WalletUnlocked.generate();
const testMessage = new TestMessage({
  amount: 1000,
  recipient: recipient.address,
});

using launched = await launchTestNode({
  nodeOptions: {
    snapshotConfig: {
      stateConfig: {
        messages: [testMessage.toChainMessage()],
      },
    },
  },
});

const { provider } = launched;

recipient.provider = provider;

const {
  messages: [message],
} = await recipient.getMessages();
// message.nonce === testMessage.nonce
See code in context

contractsConfigs

Used to deploy contracts on the node the launchTestNode utility launches. It's an array of objects with the following properties:

  • deployer: contract deployer object compatible with factories outputted by pnpm fuels typegen. You can also pass in your custom object that satisfies the interface.
  • bytecode: the contract's bytecode.
  • walletIndex: the index of the wallets generated by walletsConfig that you want to deploy the contract with.
  • options: options for contract deployment that get passed to the ContractFactory.deployContract method.

nodeOptions

Options to modify the behavior of the node.

For example, you can specify your own base asset id of the chain like below:

ts
import { AssetId, launchTestNode } from 'fuels/test-utils';

const [baseAssetId] = AssetId.random();

using launched = await launchTestNode({
  nodeOptions: {
    snapshotConfig: {
      chainConfig: {
        consensus_parameters: {
          V1: {
            base_asset_id: baseAssetId.value,
          },
        },
      },
    },
  },
});
See code in context

Note: The API for these options is still not fully complete and better documentation will come in the future.

providerOptions

Provider options passed on Provider instantiation. More on them here.