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

WIP: testing networks #3268

Closed
wants to merge 15 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('querying the chain', () => {
expect(balances).toBeDefined();
});

it('can getBlocks', async () => {
it.only('can getBlocks', async () => {
using launched = await launchTestNode();

const FUEL_NETWORK_URL = launched.provider.url;
Expand All @@ -152,16 +152,16 @@ describe('querying the chain', () => {

const provider = await Provider.create(FUEL_NETWORK_URL);

const blockToProduce = 3;
// const blockToProduce = 3;

// Force-producing some blocks to make sure that 10 blocks exist
await provider.produceBlocks(blockToProduce);
// // Force-producing some blocks to make sure that 10 blocks exist
// await provider.produceBlocks(blockToProduce);

const { blocks } = await provider.getBlocks({
last: blockToProduce,
last: 10,
});
// #endregion Provider-get-blocks
expect(blocks.length).toBe(blockToProduce);
expect(blocks.length).toBe(10);
});

it('can getMessageByNonce', async () => {
Expand Down
98 changes: 52 additions & 46 deletions packages/account/src/providers/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -925,59 +925,65 @@
});
});

it('can getBlocks', async () => {
it.only('can getBlocks', async () => {
using launched = await setupTestProviderAndWallets();
const blocksLenght = 5;

Check warning on line 930 in packages/account/src/providers/provider.test.ts

View workflow job for this annotation

GitHub Actions / Lint

'blocksLenght' is assigned a value but never used
const { provider } = launched;

// console.log(provider.url);
// Force-producing some blocks to make sure that blocksLenght blocks exist
await provider.produceBlocks(blocksLenght);
// await provider.produceBlocks(blocksLenght);
const { blocks } = await provider.getBlocks({
last: 5,
});
expect(blocks.length).toBe(blocksLenght);
blocks.forEach((block) => {
expect(block).toStrictEqual({
id: expect.any(String),
height: expect.any(BN),
time: expect.any(String),
header: {
applicationHash: expect.any(String),
daHeight: expect.any(BN),
eventInboxRoot: expect.any(String),
messageOutboxRoot: expect.any(String),
prevRoot: expect.any(String),
stateTransitionBytecodeVersion: expect.any(String),
transactionsCount: expect.any(String),
transactionsRoot: expect.any(String),
},
transactionIds: expect.any(Array<string>),
});
});
});

it('can getBlockWithTransactions', async () => {
last: 47,
});

console.log(blocks);

Check warning on line 940 in packages/account/src/providers/provider.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement
console.log(blocks.length);

Check warning on line 941 in packages/account/src/providers/provider.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement
// expect(blocks.length).toBe(blocksLenght);
// blocks.forEach((block) => {
// expect(block).toStrictEqual({
// id: expect.any(String),
// height: expect.any(BN),
// time: expect.any(String),
// header: {
// applicationHash: expect.any(String),
// daHeight: expect.any(BN),
// eventInboxRoot: expect.any(String),
// messageOutboxRoot: expect.any(String),
// prevRoot: expect.any(String),
// stateTransitionBytecodeVersion: expect.any(String),
// transactionsCount: expect.any(String),
// transactionsRoot: expect.any(String),
// },
// transactionIds: expect.any(Array<string>),
// });
// });
});

it.only('can getBlockWithTransactions', async () => {
using launched = await setupTestProviderAndWallets();
const { provider } = launched;
await provider.produceBlocks(1);
const block = await provider.getBlockWithTransactions('latest');
const { transactions } = await provider.getTransactions({ first: 100 });
expect(block).toStrictEqual({
id: expect.any(String),
height: expect.any(BN),
time: expect.any(String),
header: {
applicationHash: expect.any(String),
daHeight: expect.any(BN),
eventInboxRoot: expect.any(String),
messageOutboxRoot: expect.any(String),
prevRoot: expect.any(String),
stateTransitionBytecodeVersion: expect.any(String),
transactionsCount: expect.any(String),
transactionsRoot: expect.any(String),
},
transactionIds: expect.any(Array<string>),
transactions,
});
// await provider.produceBlocks(1);
// const block = await provider.getBlockWithTransactions('latest');
const { transactions } = await provider.getTransactions({ last: 164 });
console.log('length', transactions.length);

Check warning on line 969 in packages/account/src/providers/provider.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement
// expect(block).toStrictEqual({
// id: expect.any(String),
// height: expect.any(BN),
// time: expect.any(String),
// header: {
// applicationHash: expect.any(String),
// daHeight: expect.any(BN),
// eventInboxRoot: expect.any(String),
// messageOutboxRoot: expect.any(String),
// prevRoot: expect.any(String),
// stateTransitionBytecodeVersion: expect.any(String),
// transactionsCount: expect.any(String),
// transactionsRoot: expect.any(String),
// },
// transactionIds: expect.any(Array<string>),
// transactions,
// });
});

it('can getMessageProof with all data', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const BaseAssetId = defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.b
* @group node
*/
describe('setupTestProviderAndWallets', () => {
it('kills the node after going out of scope', async () => {
it.only('kills the node after going out of scope', async () => {
let url = '';
// eslint-disable-next-line no-lone-blocks
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { defaultSnapshotConfigs, type SnapshotConfigs } from '@fuel-ts/utils';
import { DEVNET_NETWORK_URL, TESTNET_NETWORK_URL } from '@internal/utils';

Check warning on line 2 in packages/account/src/test-utils/setup-test-provider-and-wallets.ts

View workflow job for this annotation

GitHub Actions / Lint

'DEVNET_NETWORK_URL' is defined but never used
import { mergeDeepRight } from 'ramda';

Check warning on line 3 in packages/account/src/test-utils/setup-test-provider-and-wallets.ts

View workflow job for this annotation

GitHub Actions / Lint

'mergeDeepRight' is defined but never used
import type { PartialDeep } from 'type-fest';

import type { ProviderOptions } from '../providers';
import { Provider } from '../providers';
import type { WalletUnlocked } from '../wallet';
import { Wallet, type WalletUnlocked } from '../wallet';

import type { LaunchNodeOptions } from './launchNode';
import { launchNode } from './launchNode';

Check warning on line 11 in packages/account/src/test-utils/setup-test-provider-and-wallets.ts

View workflow job for this annotation

GitHub Actions / Lint

'launchNode' is defined but never used
import { TestAssetId } from './test-asset-id';
import type { WalletsConfigOptions } from './wallet-config';
import { WalletsConfig } from './wallet-config';
Expand Down Expand Up @@ -51,13 +52,13 @@
*/
export async function setupTestProviderAndWallets({
walletsConfig: walletsConfigOptions = {},
providerOptions,

Check warning on line 55 in packages/account/src/test-utils/setup-test-provider-and-wallets.ts

View workflow job for this annotation

GitHub Actions / Lint

'providerOptions' is assigned a value but never used
nodeOptions = {},
launchNodeServerPort = process.env.LAUNCH_NODE_SERVER_PORT || undefined,

Check warning on line 57 in packages/account/src/test-utils/setup-test-provider-and-wallets.ts

View workflow job for this annotation

GitHub Actions / Lint

'launchNodeServerPort' is assigned a value but never used
}: Partial<LaunchCustomProviderAndGetWalletsOptions> = {}): Promise<SetupTestProviderAndWalletsReturn> {
// @ts-expect-error this is a polyfill (see https://devblogs.microsoft.com/typescript/announcing-typescript-5-2/#using-declarations-and-explicit-resource-management)
Symbol.dispose ??= Symbol('Symbol.dispose');
const walletsConfig = new WalletsConfig(

Check warning on line 61 in packages/account/src/test-utils/setup-test-provider-and-wallets.ts

View workflow job for this annotation

GitHub Actions / Lint

'walletsConfig' is assigned a value but never used
nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ??
defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
{
Expand All @@ -66,47 +67,22 @@
}
);

const launchNodeOptions: LaunchNodeOptions = {
loggingEnabled: false,
...nodeOptions,
snapshotConfig: mergeDeepRight(
defaultSnapshotConfigs,
walletsConfig.apply(nodeOptions?.snapshotConfig)
),
port: nodeOptions.port || '0',
};

let cleanup: () => void;
let url: string;
if (launchNodeServerPort) {
const serverUrl = `http://localhost:${launchNodeServerPort}`;
url = await (
await fetch(serverUrl, { method: 'POST', body: JSON.stringify(launchNodeOptions) })
).text();

cleanup = () => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
fetch(`${serverUrl}/cleanup/${url}`);
};
} else {
const settings = await launchNode(launchNodeOptions);
url = settings.url;
cleanup = settings.cleanup;
}
// @TODO change network + private key

let provider: Provider;
const provider = await Provider.create(TESTNET_NETWORK_URL);
const wallet = Wallet.fromPrivateKey('', provider);
petertonysmith94 marked this conversation as resolved.
Show resolved Hide resolved

try {
provider = await Provider.create(url, providerOptions);
} catch (err) {
cleanup();
throw err;
}
// console.log('Address', wallet.address.toB256());
// console.log('Base asset id', provider.getBaseAssetId());
// console.log(
// (await wallet.getBalances()).balances.map((b) => ({
// amount: b.amount.toString(),
// assetId: b.assetId,
// }))
// );

const wallets = walletsConfig.wallets;
wallets.forEach((wallet) => {
wallet.connect(provider);
});
const wallets = [wallet, wallet, wallet, wallet, wallet];
const cleanup = () => {};

return {
provider,
Expand Down
32 changes: 22 additions & 10 deletions packages/contract/src/test-utils/launch-test-node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { Account, WalletUnlocked } from '@fuel-ts/account';
import { Provider, Wallet } from '@fuel-ts/account';
import type { WalletUnlocked, Account } from '@fuel-ts/account';
import { DEVNET_NETWORK_URL, TESTNET_NETWORK_URL } from '@fuel-ts/account/configs';
import { setupTestProviderAndWallets } from '@fuel-ts/account/test-utils';
import type {
LaunchCustomProviderAndGetWalletsOptions,
Expand Down Expand Up @@ -129,15 +131,25 @@ export async function launchTestNode<const TFactories extends DeployContractConf
}: Partial<LaunchTestNodeOptions<TFactories>> = {}): Promise<LaunchTestNodeReturn<TFactories>> {
const snapshotConfig = getChainSnapshot(nodeOptions);
const args = getFuelCoreArgs(nodeOptions);
const { provider, wallets, cleanup } = await setupTestProviderAndWallets({
walletsConfig,
providerOptions,
nodeOptions: {
...nodeOptions,
snapshotConfig,
args,
},
});
// const { provider, wallets, cleanup } = await setupTestProviderAndWallets({
// walletsConfig,
// providerOptions,
// nodeOptions: {
// ...nodeOptions,
// snapshotConfig,
// args,
// },
// });

// @TODO change network + private key

const provider = await Provider.create(TESTNET_NETWORK_URL);
const wallet = Wallet.fromPrivateKey('', provider);

petertonysmith94 marked this conversation as resolved.
Show resolved Hide resolved
console.log('address', wallet.address.toB256());
console.log((await wallet.getBalances()).balances.map((b) => b.amount.toString()));
const wallets = [wallet, wallet, wallet, wallet, wallet, wallet, wallet, wallet];
const cleanup = () => {};

const contracts: TContracts<TFactories> = [] as TContracts<TFactories>;
const configs = contractsConfigs ?? [];
Expand Down
Loading
Loading