Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update amountPerCoin prop in WalletConfig to accept BN #3594

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changeset/pink-mails-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

chore: update `amountPerCoin` prop in `WalletConfig` to accept BN
9 changes: 5 additions & 4 deletions packages/account/src/test-utils/wallet-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { randomBytes } from '@fuel-ts/crypto';
import { FuelError } from '@fuel-ts/errors';
import { bn, type BigNumberish } from '@fuel-ts/math';
import { defaultSnapshotConfigs, hexlify, type SnapshotConfigs } from '@fuel-ts/utils';
import type { PartialDeep } from 'type-fest';

Expand Down Expand Up @@ -29,7 +30,7 @@ export interface WalletsConfigOptions {
/**
* For each coin, the amount it'll contain.
*/
amountPerCoin: number;
amountPerCoin: BigNumberish;

/**
* Messages that are supposed to be on the wallet.
Expand Down Expand Up @@ -105,7 +106,7 @@ export class WalletsConfig {
baseAssetId: string,
assets: number | TestAssetId[],
coinsPerAsset: number,
amountPerCoin: number
amountPerCoin: BigNumberish
) {
const coins: SnapshotConfigs['stateConfig']['coins'] = [];

Expand All @@ -122,7 +123,7 @@ export class WalletsConfig {
assetIds.forEach((assetId) => {
for (let index = 0; index < coinsPerAsset; index++) {
coins.push({
amount: amountPerCoin,
amount: bn(amountPerCoin),
asset_id: assetId,
owner: walletAddress,
tx_pointer_block_height: 0,
Expand Down Expand Up @@ -167,7 +168,7 @@ export class WalletsConfig {
'Number of coins per asset must be greater than zero.'
);
}
if (amountPerCoin < 0) {
if (bn(amountPerCoin).lt(0)) {
throw new FuelError(
FuelError.CODES.INVALID_INPUT_PARAMETERS,
'Amount per coin must be greater than or equal to zero.'
Expand Down
6 changes: 3 additions & 3 deletions packages/fuel-gauge/src/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ describe('Contract', () => {
using launched = await launchTestNode({
contractsConfigs,
walletsConfig: {
amountPerCoin: 2 ** 62,
amountPerCoin: bn(2).pow(62),
},
});
const {
Expand All @@ -713,7 +713,7 @@ describe('Contract', () => {
const initialBalance = new BN(
await contract.getBalance(await provider.getBaseAssetId())
).toNumber();
const amountToContract = bn(2).pow(62); // Very big number
const amountToContract = bn(2).pow(61); // Very big number
arboleya marked this conversation as resolved.
Show resolved Hide resolved

const tx = await wallet.transferToContract(
contract.id,
Expand All @@ -733,7 +733,7 @@ describe('Contract', () => {
using launched = await launchTestNode({
contractsConfigs,
walletsConfig: {
amountPerCoin: 2 ** 62,
amountPerCoin: bn(2).pow(62),
},
});
const {
Expand Down
Loading