Skip to content

Commit

Permalink
chore!: renamed AssetId to TestAssetId (#2905)
Browse files Browse the repository at this point in the history
* chore: renamed `AssetId` to `TestAssetId`

* chore: changeset

* chore: changeset

* chore: fixed incorrect import

* chore: fix doc-examples
  • Loading branch information
petertonysmith94 authored Aug 12, 2024
1 parent 29c556d commit 25efc03
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-eagles-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/account": patch
---

chore!: renamed `AssetId` to `TestAssetId`
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { WalletUnlocked } from 'fuels';
import { AssetId, TestMessage, launchTestNode } from 'fuels/test-utils';
import { TestAssetId, TestMessage, launchTestNode } from 'fuels/test-utils';
import { join } from 'path';

import { Counter, CounterFactory } from '../../../test/typegen/contracts';
Expand Down Expand Up @@ -72,11 +72,11 @@ describe('launching a test node', () => {

test('multiple contracts and wallets', async () => {
// #region advanced-example
// #import { launchTestNode, AssetId, TestMessage };
// #import { launchTestNode, TestAssetId, TestMessage };

// #context import { CounterFactory } from 'path/to/typegen/output';

const assets = AssetId.random(2);
const assets = TestAssetId.random(2);
const message = new TestMessage({ amount: 1000 });

using launched = await launchTestNode({
Expand Down Expand Up @@ -146,9 +146,9 @@ describe('launching a test node', () => {

test('customizing node options', async () => {
// #region custom-node-options
// #import { launchTestNode, AssetId };
// #import { launchTestNode, TestAssetId };

const [baseAssetId] = AssetId.random();
const [baseAssetId] = TestAssetId.random();

using launched = await launchTestNode({
nodeOptions: {
Expand All @@ -166,11 +166,11 @@ describe('launching a test node', () => {
// #endregion custom-node-options
});

test('using assetId', async () => {
test('using TestAssetId', async () => {
// #region asset-ids
// #import { launchTestNode, AssetId };
// #import { launchTestNode, TestAssetId };

const assets = AssetId.random();
const assets = TestAssetId.random();

using launched = await launchTestNode({
walletsConfig: {
Expand Down
6 changes: 3 additions & 3 deletions apps/docs/src/guide/testing/test-node-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ This reference describes all the options of the [`launchTestNode`](./launching-a
Used to set the node's genesis block state (coins and messages).

- `count`: number of wallets/addresses to generate on the genesis block.
- `assets`: configure how many unique assets each wallet will own with the base asset included. Can be `number` or `AssetId[]`.
- The `AssetId` utility simplifies testing when different assets are necessary.
- `assets`: configure how many unique assets each wallet will own with the base asset included. Can be `number` or `TestAssetId[]`.
- The `TestAssetId` utility simplifies testing when different assets are necessary.
- `coinsPerAsset`: number of coins (UTXOs) per asset id.
- `amountPerCoin`: for each coin, the amount it'll contain.
- `messages`: messages to assign to the wallets.

### `walletsConfig.assets`

The `AssetId` utility integrates with [`walletsConfig`](./test-node-options.md#walletsconfig) and gives you an easy way to generate multiple random asset ids via the `AssetId.random` static method.
The `TestAssetId` utility integrates with [`walletsConfig`](./test-node-options.md#walletsconfig) and gives you an easy way to generate multiple random asset ids via the `TestAssetId.random` static method.

<<< @/../../docs-snippets/src/guide/testing/launching-a-test-node.test.ts#asset-ids{ts:line-numbers}

Expand Down
2 changes: 1 addition & 1 deletion packages/account/src/test-util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ describe('test-utils.js', () => {
expect(testUtilsMod.setupTestProviderAndWallets).toBeTruthy();
expect(testUtilsMod.WalletsConfig).toBeTruthy();
expect(testUtilsMod.TestMessage).toBeTruthy();
expect(testUtilsMod.AssetId).toBeTruthy();
expect(testUtilsMod.TestAssetId).toBeTruthy();
});
});
2 changes: 1 addition & 1 deletion packages/account/src/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export * from './test-utils/launchNode';
export * from './test-utils/setup-test-provider-and-wallets';
export * from './test-utils/wallet-config';
export * from './test-utils/test-message';
export * from './test-utils/asset-id';
export * from './test-utils/test-asset-id';
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { Provider } from '../providers';
import { Signer } from '../signer';
import { WalletUnlocked } from '../wallet';

import { AssetId } from './asset-id';
import * as launchNodeMod from './launchNode';
import { setupTestProviderAndWallets } from './setup-test-provider-and-wallets';
import { TestAssetId } from './test-asset-id';
import type { ChainMessage } from './test-message';
import { TestMessage } from './test-message';

Expand Down Expand Up @@ -91,7 +91,7 @@ describe('setupTestProviderAndWallets', () => {
expect(sutCoin.blockCreated.toNumber()).toEqual(coin.tx_pointer_block_height);
});

it('default: two wallets, three assets (BaseAssetId, AssetId.A, AssetId.B), one coin, 10_000_000_000_ amount', async () => {
it('default: two wallets, three assets (BaseAssetId, TestAssetId.A, TestAssetId.B), one coin, 10_000_000_000_ amount', async () => {
using providerAndWallets = await setupTestProviderAndWallets();
const { wallets, provider } = providerAndWallets;

Expand Down Expand Up @@ -119,16 +119,16 @@ describe('setupTestProviderAndWallets', () => {
expect(baseAssetIdCoin.amount.toNumber()).toBe(10_000_000_000);

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const assetACoin = coins1.find((x) => x.assetId === AssetId.A.value)!;
const assetACoin = coins1.find((x) => x.assetId === TestAssetId.A.value)!;
expect(assetACoin.amount.toNumber()).toBe(10_000_000_000);

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const assetBCoin = coins1.find((x) => x.assetId === AssetId.B.value)!;
const assetBCoin = coins1.find((x) => x.assetId === TestAssetId.B.value)!;
expect(assetBCoin.amount.toNumber()).toBe(10_000_000_000);
});

it('can be given custom asset id and message', async () => {
const [assetId] = AssetId.random();
const [assetId] = TestAssetId.random();
const spendableMessage = new TestMessage();
const dataMessage = new TestMessage({
data: '0x2bca2aa612b304ece5b25988818dd7234e049913233eb918c11638af89d575be',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import type { ProviderOptions } from '../providers';
import { Provider } from '../providers';
import type { WalletUnlocked } from '../wallet';

import { AssetId } from './asset-id';
import type { LaunchNodeOptions } from './launchNode';
import { launchNode } from './launchNode';
import { TestAssetId } from './test-asset-id';
import type { WalletsConfigOptions } from './wallet-config';
import { WalletsConfig } from './wallet-config';

Expand All @@ -28,7 +28,7 @@ export interface LaunchCustomProviderAndGetWalletsOptions {

const defaultWalletConfigOptions: WalletsConfigOptions = {
count: 2,
assets: [AssetId.A, AssetId.B],
assets: [TestAssetId.A, TestAssetId.B],
coinsPerAsset: 1,
amountPerCoin: 10_000_000_000,
messages: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { randomBytes } from '@fuel-ts/crypto';
import { hexlify } from '@fuel-ts/utils';

export class AssetId {
public static A = new AssetId(
export class TestAssetId {
public static A = new TestAssetId(
'0x0101010101010101010101010101010101010101010101010101010101010101'
);

public static B = new AssetId(
public static B = new TestAssetId(
'0x0202020202020202020202020202020202020202020202020202020202020202'
);

Expand All @@ -15,7 +15,7 @@ export class AssetId {
public static random(count: number = 1) {
const assetIds = [];
for (let i = 0; i < count; i++) {
assetIds.push(new AssetId(hexlify(randomBytes(32))));
assetIds.push(new TestAssetId(hexlify(randomBytes(32))));
}
return assetIds;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/account/src/test-utils/wallet-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FuelError } from '@fuel-ts/errors';
import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils';
import { hexlify } from '@fuel-ts/utils';

import { AssetId } from './asset-id';
import { TestAssetId } from './test-asset-id';
import type { WalletsConfigOptions } from './wallet-config';
import { WalletsConfig } from './wallet-config';

Expand All @@ -13,7 +13,7 @@ import { WalletsConfig } from './wallet-config';
describe('WalletsConfig', () => {
const configOptions: WalletsConfigOptions = {
count: 2,
assets: [AssetId.A, AssetId.B],
assets: [TestAssetId.A, TestAssetId.B],
coinsPerAsset: 1,
amountPerCoin: 10_000_000_000,
messages: [],
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('WalletsConfig', () => {
});

it('allows custom assets to be provided', () => {
const [assetId] = AssetId.random();
const [assetId] = TestAssetId.random();
const baseAssetId = hexlify(randomBytes(32));
const {
stateConfig: { coins: allCoins },
Expand Down
10 changes: 5 additions & 5 deletions packages/account/src/test-utils/wallet-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { PartialDeep } from 'type-fest';

import { WalletUnlocked } from '../wallet';

import { AssetId } from './asset-id';
import { TestAssetId } from './test-asset-id';
import type { TestMessage } from './test-message';

export interface WalletsConfigOptions {
Expand All @@ -17,9 +17,9 @@ export interface WalletsConfigOptions {
/**
* If `number`, the number of unique asset ids each wallet will own with the base asset included.
*
* If `AssetId[]`, the asset ids the each wallet will own besides the base asset.
* If `TestAssetId[]`, the asset ids the each wallet will own besides the base asset.
*/
assets: number | AssetId[];
assets: number | TestAssetId[];

/**
* Number of coins (UTXOs) per asset id.
Expand Down Expand Up @@ -103,7 +103,7 @@ export class WalletsConfig {
private static createCoins(
wallets: WalletUnlocked[],
baseAssetId: string,
assets: number | AssetId[],
assets: number | TestAssetId[],
coinsPerAsset: number,
amountPerCoin: number
) {
Expand All @@ -113,7 +113,7 @@ export class WalletsConfig {
if (Array.isArray(assets)) {
assetIds = assetIds.concat(assets.map((a) => a.value));
} else {
assetIds = assetIds.concat(AssetId.random(assets - 1).map((a) => a.value));
assetIds = assetIds.concat(TestAssetId.random(assets - 1).map((a) => a.value));
}

wallets
Expand Down
10 changes: 5 additions & 5 deletions packages/fuel-gauge/src/doc-examples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
ZeroBytes32,
Predicate,
} from 'fuels';
import { AssetId, launchTestNode } from 'fuels/test-utils';
import { TestAssetId, launchTestNode } from 'fuels/test-utils';

import { PredicateTrue } from '../test/typegen';
import { CallTestContract } from '../test/typegen/contracts';
Expand Down Expand Up @@ -199,8 +199,8 @@ describe('Doc Examples', () => {
const submitted = await fundingWallet.batchTransfer([
{ amount: 100, destination: walletA.address, assetId: baseAssetId },
{ amount: 100, destination: walletB.address, assetId: baseAssetId },
{ amount: 100, destination: walletB.address, assetId: AssetId.B.value },
{ amount: 100, destination: walletB.address, assetId: AssetId.A.value },
{ amount: 100, destination: walletB.address, assetId: TestAssetId.B.value },
{ amount: 100, destination: walletB.address, assetId: TestAssetId.A.value },
]);

await submitted.waitForResult();
Expand All @@ -216,8 +216,8 @@ describe('Doc Examples', () => {
// validate balances
expect(walletABalances).toEqual([{ assetId: provider.getBaseAssetId(), amount: bn(100) }]);
expect(walletBBalances).toEqual([
{ assetId: AssetId.A.value, amount: bn(100) },
{ assetId: AssetId.B.value, amount: bn(100) },
{ assetId: TestAssetId.A.value, amount: bn(100) },
{ assetId: TestAssetId.B.value, amount: bn(100) },
{ assetId: provider.getBaseAssetId(), amount: bn(100) },
]);
expect(walletCBalances).toEqual([]);
Expand Down

0 comments on commit 25efc03

Please sign in to comment.