You'll often want to create one or more test wallets when testing your contracts. Here's how to do it.
// #import { Wallet, WalletLocked, WalletUnlocked };
// use the `generate` helper to make an Unlocked Wallet
const myWallet: WalletUnlocked = Wallet.generate({
provider,
});
// or use an Address to create a wallet
const someWallet: WalletLocked = Wallet.fromAddress(myWallet.address, provider);
If you need multiple test wallets, they can be set up as follows:
// #import { Provider, bn, FUEL_NETWORK_URL, generateTestWallet };
const provider = await Provider.create(FUEL_NETWORK_URL);
const assetIdA = '0x0101010101010101010101010101010101010101010101010101010101010101';
const assetIdB = '0x0202020202020202020202020202020202020202020202020202020202020202';
// single asset
const walletA = await generateTestWallet(provider, [[42, BaseAssetId]]);
// multiple assets
const walletB = await generateTestWallet(provider, [
// [Amount, AssetId]
[100, assetIdA],
[200, assetIdB],
[30, BaseAssetId],
]);
// this wallet has no assets
const walletC = await generateTestWallet(provider);
// retrieve balances of wallets
const walletABalances = await walletA.getBalances();
const walletBBalances = await walletB.getBalances();
const walletCBalances = await walletC.getBalances();
// validate balances
expect(walletABalances).toEqual([{ assetId: BaseAssetId, amount: bn(42) }]);
expect(walletBBalances).toEqual([
{ assetId: BaseAssetId, amount: bn(30) },
{ assetId: assetIdA, amount: bn(100) },
{ assetId: assetIdB, amount: bn(200) },
]);
expect(walletCBalances).toEqual([]);