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
8 changes: 8 additions & 0 deletions .changeset/strange-glasses-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@internal/fuel-core": patch
"@fuel-ts/versions": patch
"@fuel-ts/account": patch
"fuels": patch
---

chore: update `fuel-core` to `0.38.0`
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
DEVNET_WALLET_PVT_KEY=
TESTNET_WALLET_PVT_KEY=
PUBLISHED_NPM_TAG=
PUBLISHED_NPM_TAG=


TESTING_NETWORK_URL=
TESTING_NETWORK_PVT_KEY=
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('Resubmitting Failed Transactions', () => {
}
}
// #endregion resubmitting-failed-transactions-3
}).rejects.toThrow('Transaction is not inserted. UTXO does not exist: 0x');
}).rejects.toThrowError(/Transaction input validation failed: UTXO \(id: .*\) does not exist/);

await expect(
(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion internal/fuel-core/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.37.1
0.38.0
100 changes: 53 additions & 47 deletions packages/account/src/providers/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@

const version = await provider.getVersion();

expect(version).toEqual('0.37.1');
expect(version).toEqual(versions.FUEL_CORE);
});

it('can call()', async () => {
Expand Down 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
1 change: 1 addition & 0 deletions packages/account/src/test-utils/launchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export const launchNode = async ({
['--ip', ipToUse],
['--port', portToUse],
useInMemoryDb ? ['--db-type', 'in-memory'] : ['--db-path', tempDir],
['--tx-ttl-check-interval', '1s'],
['--min-gas-price', minGasPrice],
poaInstant ? ['--poa-instant', 'true'] : [],
['--native-executor-version', nativeExecutorVersion],
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

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

'TESTNET_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,9 +52,9 @@
*/
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');
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;
}

let provider: Provider;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const provider = await Provider.create(process.env.TESTING_NETWORK_URL!);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const wallet = Wallet.fromPrivateKey(process.env.TESTING_NETWORK_PVT_KEY!, provider);

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
34 changes: 24 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,27 @@ 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

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const provider = await Provider.create(process.env.TESTING_NETWORK_URL!);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const wallet = Wallet.fromPrivateKey(process.env.TESTING_NETWORK_PVT_KEY!, provider);

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