-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
test-utils.ts
41 lines (37 loc) · 1.34 KB
/
test-utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import type { BytesLike } from '@ethersproject/bytes';
import type { Interface, JsonAbi } from '@fuel-ts/abi-coder';
import { NativeAssetId } from '@fuel-ts/constants';
import { Provider } from '@fuel-ts/providers';
import type { Wallet } from '@fuel-ts/wallet';
import { TestUtils } from '@fuel-ts/wallet';
import type Contract from '../contracts/contract';
import ContractFactory from '../contracts/contract-factory';
let contractInstance: Contract;
const deployContract = async (factory: ContractFactory) => {
if (contractInstance) return contractInstance;
contractInstance = await factory.deployContract();
return contractInstance;
};
let walletInstance: Wallet;
const createWallet = async () => {
if (walletInstance) return walletInstance;
const provider = new Provider('http://127.0.0.1:4000/graphql');
walletInstance = await TestUtils.generateTestWallet(provider, [
[5_000_000, NativeAssetId],
[5_000_000, '0x0101010101010101010101010101010101010101010101010101010101010101'],
]);
return walletInstance;
};
export const setup = async ({
contractBytecode,
abi,
}: {
contractBytecode: BytesLike;
abi: JsonAbi | Interface;
}) => {
// Create wallet
const wallet = await createWallet();
const factory = new ContractFactory(contractBytecode, abi, wallet);
const contract = await deployContract(factory);
return contract;
};