Skip to content

Commit d1825c9

Browse files
authored
chore: update amountPerCoin prop in WalletConfig to accept BN (#3594)
1 parent e5251e2 commit d1825c9

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

.changeset/pink-mails-dream.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@fuel-ts/account": patch
3+
"@fuel-ts/utils": patch
4+
---
5+
6+
chore: update `amountPerCoin` prop in `WalletConfig` to accept BN

packages/account/src/test-utils/wallet-config.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { randomBytes } from '@fuel-ts/crypto';
22
import { FuelError } from '@fuel-ts/errors';
3+
import { bn, type BigNumberish } from '@fuel-ts/math';
34
import { defaultSnapshotConfigs, hexlify, type SnapshotConfigs } from '@fuel-ts/utils';
45
import type { PartialDeep } from 'type-fest';
56

@@ -29,7 +30,7 @@ export interface WalletsConfigOptions {
2930
/**
3031
* For each coin, the amount it'll contain.
3132
*/
32-
amountPerCoin: number;
33+
amountPerCoin: BigNumberish;
3334

3435
/**
3536
* Messages that are supposed to be on the wallet.
@@ -105,7 +106,7 @@ export class WalletsConfig {
105106
baseAssetId: string,
106107
assets: number | TestAssetId[],
107108
coinsPerAsset: number,
108-
amountPerCoin: number
109+
amountPerCoin: BigNumberish
109110
) {
110111
const coins: SnapshotConfigs['stateConfig']['coins'] = [];
111112

@@ -122,7 +123,7 @@ export class WalletsConfig {
122123
assetIds.forEach((assetId) => {
123124
for (let index = 0; index < coinsPerAsset; index++) {
124125
coins.push({
125-
amount: amountPerCoin,
126+
amount: bn(amountPerCoin).toString(),
126127
asset_id: assetId,
127128
owner: walletAddress,
128129
tx_pointer_block_height: 0,
@@ -167,7 +168,7 @@ export class WalletsConfig {
167168
'Number of coins per asset must be greater than zero.'
168169
);
169170
}
170-
if (amountPerCoin < 0) {
171+
if (bn(amountPerCoin).lt(0)) {
171172
throw new FuelError(
172173
FuelError.CODES.INVALID_INPUT_PARAMETERS,
173174
'Amount per coin must be greater than or equal to zero.'

packages/fuel-gauge/src/contract.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ describe('Contract', () => {
701701
using launched = await launchTestNode({
702702
contractsConfigs,
703703
walletsConfig: {
704-
amountPerCoin: 2 ** 62,
704+
amountPerCoin: bn(2).pow(62),
705705
},
706706
});
707707
const {
@@ -713,7 +713,7 @@ describe('Contract', () => {
713713
const initialBalance = new BN(
714714
await contract.getBalance(await provider.getBaseAssetId())
715715
).toNumber();
716-
const amountToContract = bn(2).pow(62); // Very big number
716+
const amountToContract = bn(2).pow(61); // Very big number
717717

718718
const tx = await wallet.transferToContract(
719719
contract.id,
@@ -733,7 +733,7 @@ describe('Contract', () => {
733733
using launched = await launchTestNode({
734734
contractsConfigs,
735735
walletsConfig: {
736-
amountPerCoin: 2 ** 62,
736+
amountPerCoin: bn(2).pow(62),
737737
},
738738
});
739739
const {

packages/utils/src/utils/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import type { BN } from '@fuel-ts/math';
1+
import type { BigNumberish, BN } from '@fuel-ts/math';
22

33
interface Coin {
44
tx_id: string;
55
output_index: number;
66
tx_pointer_block_height: number;
77
tx_pointer_tx_idx: number;
88
owner: string;
9-
amount: number | BN;
9+
amount: BigNumberish;
1010
asset_id: string;
1111
}
1212

0 commit comments

Comments
 (0)