Skip to content

Commit

Permalink
Revert "chore: integrate launchTestNode into current test suites (#…
Browse files Browse the repository at this point in the history
…2579)"

This reverts commit 538d8b6.
  • Loading branch information
nedsalk committed Jul 19, 2024
1 parent 4f62528 commit 9dac477
Show file tree
Hide file tree
Showing 66 changed files with 2,873 additions and 3,394 deletions.
5 changes: 0 additions & 5 deletions .changeset/pretty-hornets-walk.md

This file was deleted.

69 changes: 24 additions & 45 deletions apps/demo-typegen/src/demo.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// #region Testing-in-ts-ts
import { ContractFactory, toHex, Address, Wallet } from 'fuels';
import { launchTestNode, safeExec } from 'fuels/test-utils';
import { ContractFactory, Provider, toHex, Wallet, FUEL_NETWORK_URL, Address } from 'fuels';
import { generateTestWallet, safeExec } from 'fuels/test-utils';

import storageSlots from '../contract/out/release/demo-contract-storage_slots.json';

Expand All @@ -10,17 +10,19 @@ import type { PredicateAbiInputs } from './predicate-types';
import { PredicateAbi__factory } from './predicate-types';
import { ScriptAbi__factory } from './script-types';

let baseAssetId: string;

/**
* @group node
* @group browser
*/
describe('ExampleContract', () => {
beforeAll(async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
baseAssetId = provider.getBaseAssetId();
});
it('with imported storage slots', async () => {
using launched = await launchTestNode();

const {
wallets: [wallet],
} = launched;
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);

// #region typegen-demo-contract-storage-slots
// #context import storageSlots from './contract/out/debug/demo-contract-storage_slots.json';
Expand All @@ -34,11 +36,8 @@ describe('ExampleContract', () => {
expect(contract.id).toBeTruthy();
});
it('should return the input', async () => {
using launched = await launchTestNode();

const {
wallets: [wallet],
} = launched;
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);

// Deploy
const factory = new ContractFactory(bytecode, DemoContractAbi__factory.abi, wallet);
Expand All @@ -65,11 +64,8 @@ describe('ExampleContract', () => {
});

it('deployContract method', async () => {
using launched = await launchTestNode();

const {
wallets: [wallet],
} = launched;
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);

// #region typegen-demo-contract-factory-deploy
// #context import { DemoContractAbi__factory } from './types';
Expand All @@ -92,13 +88,8 @@ describe('ExampleContract', () => {
// #endregion Testing-in-ts-ts

it('should throw when simulating via contract factory with wallet with no resources', async () => {
using launched = await launchTestNode();

const {
provider,
wallets: [fundedWallet],
} = launched;

const provider = await Provider.create(FUEL_NETWORK_URL);
const fundedWallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);
const unfundedWallet = Wallet.generate({ provider });

const factory = new ContractFactory(bytecode, DemoContractAbi__factory.abi, fundedWallet);
Expand All @@ -112,12 +103,8 @@ it('should throw when simulating via contract factory with wallet with no resour
});

it('should not throw when dry running via contract factory with wallet with no resources', async () => {
using launched = await launchTestNode();

const {
provider,
wallets: [fundedWallet],
} = launched;
const provider = await Provider.create(FUEL_NETWORK_URL);
const fundedWallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);
const unfundedWallet = Wallet.generate({ provider });

const factory = new ContractFactory(bytecode, DemoContractAbi__factory.abi, fundedWallet);
Expand All @@ -129,11 +116,8 @@ it('should not throw when dry running via contract factory with wallet with no r
});

test('Example script', async () => {
using launched = await launchTestNode();

const {
wallets: [wallet],
} = launched;
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);

// #region typegen-demo-script
// #context import { ScriptAbi__factory } from './types';
Expand All @@ -151,23 +135,18 @@ test('Example predicate', async () => {
// #context import { PredicateAbi__factory } from './types';

// In this exchange, we are first transferring some coins to the predicate
using launched = await launchTestNode();

const {
provider,
wallets: [wallet],
} = launched;

const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);
const receiver = Wallet.fromAddress(Address.fromRandom(), provider);

const predicateData: PredicateAbiInputs = [];
const predicate = PredicateAbi__factory.createInstance(provider, predicateData);

const tx = await wallet.transfer(predicate.address, 200_000, provider.getBaseAssetId());
const tx = await wallet.transfer(predicate.address, 150_000, baseAssetId);
const { isStatusSuccess } = await tx.wait();

// Then we are transferring some coins from the predicate to a random address (receiver)
const tx2 = await predicate.transfer(receiver.address, 50_000, provider.getBaseAssetId());
const tx2 = await predicate.transfer(receiver.address, 50_000, baseAssetId);
await tx2.wait();

expect((await receiver.getBalance()).toNumber()).toEqual(50_000);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "return-script"
Expand Down
Loading

0 comments on commit 9dac477

Please sign in to comment.