Skip to content

Commit

Permalink
chore: pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Aug 14, 2024
1 parent 0f8f2cc commit 8939ed9
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 252 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ In order to run tests locally, you can run the following commands:
pnpm pretest

# run all tests in a node environment
pnpm test:node
pnpm test

# you may also run tests in a browser environment
pnpm test:browser
Expand Down Expand Up @@ -232,7 +232,7 @@ Manually edit the `internal/fuel-core/VERSION` file, add the right version, and

```sh
pnpm install # will download new binaries
pnpm test:node
pnpm test
```

If all tests pass, that's it.
Expand Down
3 changes: 0 additions & 3 deletions internal/check-imports/src/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
hexlify,
createConfig,
} from 'fuels';
import { generateTestWallet, seedTestWallet } from 'fuels/test-utils';

const { log } = console;

Expand Down Expand Up @@ -168,8 +167,6 @@ log(WalletManager);
* wallet
*/
log(Wallet);
log(generateTestWallet);
log(seedTestWallet);
log(FUEL_NETWORK_URL);

/**
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
"knip:fix": "knip --fix",
"depsync:lint": "syncpack list-mismatches",
"depsync:fix": "syncpack fix-mismatches",
"test": "vitest --run --coverage --config vitest.node.config.mts $(scripts/tests-find.sh --node)",
"test:node": "vitest --run --coverage --config vitest.node.config.mts $(scripts/tests-find.sh --node)",
"test:browser": "vitest --run --coverage --config vitest.browser.config.mts $(scripts/tests-find.sh --browser)",
"test:all": "run-p test:node test:browser",
"test:filter": "vitest --run --coverage false --config vitest.node.config.mts",
"test:coverage-merge": "tsx ./scripts/tests-coverage-merge.ts",
"test:coverage-diff": "tsx ./scripts/tests-coverage-diff.ts",
"test:watch": "vitest --watch --config vitest.node.config.mts $(scripts/tests-find.sh --node)",
"test:validate": "./scripts/tests-validate.sh",
"test:browser": "vitest --run --coverage --config vitest.browser.config.mts $(scripts/tests-find.sh --browser)",
"test:browser:filter": "vitest --run --coverage false --config vitest.browser.config.mts",
"test:e2e": "vitest --run --config vitest.node.config.mts $(scripts/tests-find.sh --e2e)",
"test:integration": "vitest --run --config vitest.node.config.mts $(scripts/tests-find.sh --integration)",
Expand Down
38 changes: 9 additions & 29 deletions packages/account/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ This module contains the class to manage a private key and signing for a standar

## Table of contents

- [Documentation](#documentation)
- [Usage](#usage)
- [Installation](#installation)
- [Full SDK Installation](#full-sdk-installation)
- [Contributing](#contributing)
- [Changelog](#changelog)
- [License](#license)
- [`@fuel-ts/account`](#fuel-tsaccount)
- [Table of contents](#table-of-contents)
- [Documentation](#documentation)
- [Usage](#usage)
- [Installation](#installation)
- [Full SDK Installation](#full-sdk-installation)
- [Contributing](#contributing)
- [Changelog](#changelog)
- [License](#license)

## Documentation

Expand All @@ -38,28 +40,6 @@ pnpm add fuels
npm add fuels
```

## Test Utilities

These test utilities are exported to assist in testing apps using Fuels.

```ts
import { bn } from "@fuel-ts/math";
import {
seedTestWallet,
generateTestWallet,
} from "@fuel-ts/account/test-utils";

const provider = await Provider.create("http://127.0.0.1:4000/v1/graphql");

// seeding
const wallet = Wallet.fromPrivateKey("0x...", provider);
const baseAssetId = provider.getBaseAssetId();
seedTestWallet(wallet, [{ assetId: baseAssetId, amount: bn(100_000) }]);

// generating
const wallet = await generateTestWallet(provider, [[1_000, baseAssetId]]);
```

## Contributing

In order to contribute to `@fuel-ts/account`, please see the main [fuels-ts](https://github.com/FuelLabs/fuels-ts) monorepo.
Expand Down
3 changes: 2 additions & 1 deletion packages/account/src/account.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { Address } from '@fuel-ts/address';
import { ErrorCode, FuelError } from '@fuel-ts/errors';
import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils';
Expand Down Expand Up @@ -345,7 +346,7 @@ describe('Account', () => {
const { balances: receiverBalances } = await receiver.getBalances();

expect(isStatusSuccess).toBeTruthy();
expect(receiverBalances).toEqual([{ assetId: provider.getBaseAssetId(), amount: bn(1) }]);
expect(receiverBalances).toEqual([{ assetId: TestAssetId.A.value, amount: bn(1) }]);
});

it('can transfer to multiple destinations', async () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/account/src/test-util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import * as testUtilsMod from './test-utils';
*/
describe('test-utils.js', () => {
test('should export all test utilities', () => {
expect(testUtilsMod.generateTestWallet).toBeTruthy();
expect(testUtilsMod.seedTestWallet).toBeTruthy();
expect(testUtilsMod.launchNode).toBeTruthy();
expect(testUtilsMod.setupTestProviderAndWallets).toBeTruthy();
expect(testUtilsMod.WalletsConfig).toBeTruthy();
Expand Down
2 changes: 0 additions & 2 deletions packages/account/src/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export * from './test-utils/generateTestWallet';
export * from './test-utils/seedTestWallet';
export * from './test-utils/launchNode';
export * from './test-utils/setup-test-provider-and-wallets';
export * from './test-utils/wallet-config';
Expand Down
16 changes: 0 additions & 16 deletions packages/account/src/test-utils/generateTestWallet.ts

This file was deleted.

47 changes: 0 additions & 47 deletions packages/account/src/test-utils/launchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import os from 'os';
import path from 'path';
import { getPortPromise } from 'portfinder';

import type { ProviderOptions } from '../providers';
import { Provider } from '../providers';
import { Signer } from '../signer';
import type { WalletUnlocked } from '../wallet';

import { generateTestWallet } from './generateTestWallet';

const getFlagValueFromArgs = (args: string[], flag: string) => {
const flagIndex = args.indexOf(flag);
Expand Down Expand Up @@ -303,45 +298,3 @@ export const launchNode = async ({

child.on('error', reject);
});

const generateWallets = async (count: number, provider: Provider) => {
const baseAssetId = provider.getBaseAssetId();
const wallets: WalletUnlocked[] = [];
for (let i = 0; i < count; i += 1) {
const wallet = await generateTestWallet(provider, [[100_000, baseAssetId]]);
wallets.push(wallet);
}
return wallets;
};

export type LaunchNodeAndGetWalletsResult = Promise<{
wallets: WalletUnlocked[];
stop: () => void;
provider: Provider;
}>;

/**
* Launches a fuel-core node and returns a provider, 10 wallets, and a cleanup function to stop the node.
* @param launchNodeOptions - options to launch the fuel-core node with.
* @param walletCount - the number of wallets to generate. (optional, defaults to 10)
* */
export const launchNodeAndGetWallets = async ({
launchNodeOptions,
providerOptions,
walletCount = 10,
}: {
launchNodeOptions?: Partial<LaunchNodeOptions>;
providerOptions?: Partial<ProviderOptions>;
walletCount?: number;
} = {}): LaunchNodeAndGetWalletsResult => {
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});

const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`, providerOptions);
const wallets = await generateWallets(walletCount, provider);

const cleanup = () => {
closeNode();
};

return { wallets, stop: cleanup, provider };
};
109 changes: 0 additions & 109 deletions packages/account/src/test-utils/launchNodeAndGetWallets.test.ts

This file was deleted.

40 changes: 0 additions & 40 deletions packages/account/src/test-utils/seedTestWallet.ts

This file was deleted.

0 comments on commit 8939ed9

Please sign in to comment.