Also, it seems to me that you’re not using the launchTestNode
utility as intended, especially because you’re not returning a cleanup
function anywhere, which means that you’re going to be having fuel-core
nodes staying on even after tests are finished. I did a bit of a refactor based on my understanding of the code as well and the defaults as well besides adding a cleanup
field in the return.
Two things to note:
- cleanup is returned
- contracts are directly deployed via the
contractsConfigs
field
export async function setup(): Promise<
{
wallet1: WalletUnlocked;
wallet2: WalletUnlocked;
wallet3: WalletUnlocked;
wallet4: WalletUnlocked;
provider: Provider;
feeSplitterContract: PropsFeeSplitterContract;
cleanup: () => void;
}
> {
const message = new TestMessage({ amount: 1000 });
const launched = await launchTestNode({
walletsConfig: {
count: 4, // Number of wallets to create
messages: [message], // Initial messages
},
contractsConfigs: [
{ factory: PropsFeeSplitterContractFactory },
{ factory: PropsRegistryContractFactory }
]
});
// Destructure the launched object to get wallets and contracts
const {
contracts: [feeSplitterContract, propsRegistryContract],
wallets: [wallet1, wallet2, wallet3, wallet4],
provider,
cleanup
} = launched;
console.log("PROVIDER: ", provider);
const addressIdentityInput = { Address: wallet1.address.toB56() };
// Initialize the Fee Splitter Contract
const { waitForResult: waitForFeeSplitterConstructorResult } =
await feeSplitterContract.functions
.constructor(addressIdentityInput)
.call();
await waitForFeeSplitterConstructorResult();
// Log hash of deployed fee splitter contract
const feeSplitterContractId = feeSplitterContract.id;
// console.log(
// "Props Fee Splitter Contract deployed at:",
// feeSplitterContractId.toB256()
// );
// Initialize the Props Registry Contract
const { waitForResult: waitForPropsRegistryConstructorResult } =
await propsRegistryContract.functions
.constructor(addressIdentityInput)
.call();
await waitForPropsRegistryConstructorResult();
// Log hash of deployed registry contract
const registryContractId = propsRegistryContract.id;
// console.log(
// "Props Registry Contract deployed at:",
// registryContractId.toB256()
// );
return { wallet1, wallet2, wallet3, wallet4, provider, feeSplitterContract, cleanup };
}
And then you have to call cleanup
at the end of each test:
const { cleanup, ...rest } = await setup();
// do stuff in test
// done with node?
cleanup();
If you want to make it using
-compatible, you can do this to the return:
const returnObj = { wallet1, wallet2, wallet3, wallet4, provider, feeSplitterContract, cleanup };
return Object.assign(returnObj, {[Symbol.disposable]: cleanup});
and then you can write your tests like this:
using launched = await setup();
// do testing
// when launched variable goes out of scope,
// the cleanup function will be called automagically