-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
test-utils.ts
35 lines (31 loc) · 1.14 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
import { randomBytes } from '@fuel-ts/keystore';
import type { Provider, CoinQuantityLike } from '@fuel-ts/providers';
import { coinQuantityfy, ScriptTransactionRequest } from '@fuel-ts/providers';
import Wallet from './wallet';
export const seedWallet = async (wallet: Wallet, quantities: CoinQuantityLike[]) => {
const genesisWallet = new Wallet(process.env.GENESIS_SECRET || randomBytes(32), wallet.provider);
// Connect to the same Provider as wallet
const coins = await genesisWallet.getCoinsToSpend(quantities);
// Create transaction
const request = new ScriptTransactionRequest({
gasLimit: 10000,
bytePrice: 1,
gasPrice: 1,
});
request.addCoins(coins);
quantities
.map(coinQuantityfy)
.forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
const response = await genesisWallet.sendTransaction(request);
await response.wait();
};
export const generateTestWallet = async (
provider: Provider,
quantities?: CoinQuantityLike[]
): Promise<Wallet> => {
const wallet = Wallet.generate({ provider });
if (quantities) {
await seedWallet(wallet, quantities);
}
return wallet;
};