From 9e2914c8936dc4d9d258283abc7495fde2204025 Mon Sep 17 00:00:00 2001 From: crStiv Date: Mon, 3 Feb 2025 16:38:35 +0100 Subject: [PATCH] Update test-coin.ts --- packages/account/src/test-utils/test-coin.ts | 48 +++++++++++++++----- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/packages/account/src/test-utils/test-coin.ts b/packages/account/src/test-utils/test-coin.ts index 47846b1e456..6b16254cf14 100644 --- a/packages/account/src/test-utils/test-coin.ts +++ b/packages/account/src/test-utils/test-coin.ts @@ -1,25 +1,51 @@ import { Coin } from '@fuel-ts/account'; -import { bn } from '@fuel-ts/math'; +import { bn, type BN } from '@fuel-ts/math'; import { getRandomB256 } from '@fuel-ts/crypto'; +interface TestCoinSpecs { + id: string; + owner: string; + amount: BN; + type: number; +} + export class TestCoin { + public readonly id: string; + public readonly owner: string; + public readonly amount: BN; + public readonly type: number; + + /** + * A helper class to create coins for testing purposes. + */ + constructor({ + id = getRandomB256(), + owner = getRandomB256(), + amount = bn(1000000), + type = 0, + }: Partial = {}) { + this.id = id; + this.owner = owner; + this.amount = amount; + this.type = type; + } + /** - * Creates a single test coin with given parameters + * Creates a chain-compatible coin object */ - static create(params: Partial = {}): Coin { + toCoin(): Coin { return { - id: params.id || getRandomB256(), - owner: params.owner || getRandomB256(), - amount: params.amount || bn(1000000), - type: params.type || 0, - ...params + id: this.id, + owner: this.owner, + amount: this.amount, + type: this.type, }; } /** - * Generates an array of test coins with the same base parameters + * Creates multiple test coins with the same base parameters */ - static many(params: Partial = {}, count = 1): Coin[] { - return Array.from({ length: count }, () => TestCoin.create(params)); + static many(params: Partial = {}, count = 1): Coin[] { + return Array.from({ length: count }, () => new TestCoin(params).toCoin()); } }