Skip to content

Commit b11e4bd

Browse files
committed
feat: optimise run time for integration tests
1 parent 0ff4409 commit b11e4bd

File tree

7 files changed

+238
-205
lines changed

7 files changed

+238
-205
lines changed

packages/integration-tests/fork-tests/bridge_erc20.ts

Lines changed: 76 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
getBlock,
2121
FUEL_CALL_TX_PARAMS,
2222
hardhatSkipTime,
23+
fuels_parseEther,
2324
} from '@fuel-bridge/test-utils';
2425
import chai from 'chai';
2526
import { toBeHex, parseEther } from 'ethers';
@@ -32,8 +33,8 @@ import type {
3233
Provider,
3334
} from 'fuels';
3435

35-
import type { Containers } from '../docker-setup/docker';
3636
import { startContainers } from '../docker-setup/docker';
37+
import { fundWithdrawalTransactionWithBaseAssetResource } from '../utils/utils';
3738

3839
const { expect } = chai;
3940

@@ -52,8 +53,6 @@ describe('Bridging ERC20 tokens', async function () {
5253
let fuel_bridgeContractId: string;
5354
let fuel_testAssetId: string;
5455

55-
let containers: Containers;
56-
5756
// override the default test timeout from 2000ms
5857
this.timeout(DEFAULT_TIMEOUT_MS);
5958

@@ -66,7 +65,8 @@ describe('Bridging ERC20 tokens', async function () {
6665
fuelTokenSender: FuelWallet,
6766
ethereumTokenReceiverAddress: string,
6867
NUM_TOKENS: bigint,
69-
DECIMAL_DIFF: bigint
68+
DECIMAL_DIFF: bigint,
69+
useMessageCoin: boolean
7070
): Promise<MessageProof | null> {
7171
// withdraw tokens back to the base chain
7272
fuel_bridge.account = fuelTokenSender;
@@ -75,22 +75,19 @@ describe('Bridging ERC20 tokens', async function () {
7575
const fuelTokenSenderBalance = await fuelTokenSender.getBalance(
7676
fuel_testAssetId
7777
);
78-
const transactionRequest = await fuel_bridge.functions
79-
.withdraw(paddedAddress)
80-
.addContracts([fuel_bridge, fuel_bridgeImpl])
81-
.txParams({
82-
tip: 0,
83-
maxFee: 1,
84-
})
85-
.callParams({
86-
forward: {
87-
amount: new BN(NUM_TOKENS.toString()).div(
88-
new BN(DECIMAL_DIFF.toString())
89-
),
90-
assetId: fuel_testAssetId,
91-
},
92-
})
93-
.fundWithRequiredCoins();
78+
79+
const transactionRequest =
80+
await fundWithdrawalTransactionWithBaseAssetResource(
81+
env,
82+
fuel_bridge,
83+
fuelTokenSender,
84+
paddedAddress,
85+
NUM_TOKENS,
86+
9n,
87+
fuel_bridgeImpl,
88+
fuel_testAssetId,
89+
useMessageCoin
90+
);
9491

9592
const tx = await fuelTokenSender.sendTransaction(transactionRequest);
9693
const fWithdrawTxResult = await tx.waitForResult();
@@ -208,14 +205,9 @@ describe('Bridging ERC20 tokens', async function () {
208205

209206
before(async () => {
210207
// spinning up all docker containers
211-
containers = await startContainers(true, 8080, 8545, 4000);
212-
213-
env = await setupEnvironment({
214-
http_ethereum_client: 'http://127.0.0.1:8545',
215-
http_deployer: 'http://127.0.0.1:8080',
216-
http_fuel_client: 'http://127.0.0.1:4000/v1/graphql',
217-
});
208+
await startContainers();
218209

210+
env = await setupEnvironment({});
219211
eth_erc20GatewayAddress = (
220212
await env.eth.fuelERC20Gateway.getAddress()
221213
).toLowerCase();
@@ -309,6 +301,59 @@ describe('Bridging ERC20 tokens', async function () {
309301
);
310302
});
311303

304+
it('Bridge ETH to Fuel to be used as Message Coin during token withdrawal', async () => {
305+
// use the FuelMessagePortal to directly send ETH which should be immediately spendable
306+
const tx = await env.eth.fuelMessagePortal
307+
.connect(ethereumTokenSender)
308+
.depositETH(fuelTokenReceiverAddress, {
309+
value: parseEther('1'),
310+
});
311+
const receipt = await tx.wait();
312+
expect(receipt.status).to.equal(1);
313+
314+
// parse events from logs
315+
const filter = env.eth.fuelMessagePortal.filters.MessageSent(
316+
null, // Args set to null since there should be just 1 event for MessageSent
317+
null,
318+
null,
319+
null,
320+
null
321+
);
322+
323+
const [event, ...restOfEvents] =
324+
await env.eth.fuelMessagePortal.queryFilter(
325+
filter,
326+
receipt.blockNumber,
327+
receipt.blockNumber
328+
);
329+
expect(restOfEvents.length).to.be.eq(0); // Should be only 1 event
330+
331+
const fuelETHMessageNonce = new BN(event.args.nonce.toString());
332+
333+
fuelTokenMessageReceiver = fuelTokenReceiver.address;
334+
335+
// wait for message to appear in fuel client
336+
expect(
337+
await waitForMessage(
338+
env.fuel.provider,
339+
fuelTokenMessageReceiver,
340+
fuelETHMessageNonce,
341+
FUEL_MESSAGE_TIMEOUT_MS
342+
)
343+
).to.not.be.null;
344+
345+
// verify the incoming messages generated when base asset is minted on fuel
346+
const incomingMessagesonFuel = await env.fuel.signers[0].getMessages();
347+
348+
// eth as bridged once at the start
349+
expect(incomingMessagesonFuel.messages.length === 1).to.be.true;
350+
351+
// 1 eth was bridged
352+
expect(
353+
incomingMessagesonFuel.messages[0].amount.eq(fuels_parseEther('1'))
354+
).to.be.true;
355+
});
356+
312357
it('Bridge ERC20 via FuelERC20Gateway', async () => {
313358
// approve FuelERC20Gateway to spend the tokens
314359
await eth_testToken
@@ -468,7 +513,8 @@ describe('Bridging ERC20 tokens', async function () {
468513
fuelTokenSender,
469514
ethereumTokenReceiverAddress,
470515
NUM_TOKENS,
471-
DECIMAL_DIFF
516+
DECIMAL_DIFF,
517+
true
472518
);
473519
});
474520

@@ -586,7 +632,8 @@ describe('Bridging ERC20 tokens', async function () {
586632
fuelTokenSender,
587633
ethereumTokenReceiverAddress,
588634
NUM_TOKENS,
589-
DECIMAL_DIFF
635+
DECIMAL_DIFF,
636+
false
590637
);
591638

592639
// relay message
@@ -679,14 +726,4 @@ describe('Bridging ERC20 tokens', async function () {
679726
).to.be.true;
680727
});
681728
});
682-
683-
// stopping containers post the test
684-
after(async () => {
685-
await containers.postGresContainer.stop();
686-
await containers.l1_node.stop();
687-
688-
await containers.fuel_node.stop();
689-
690-
await containers.block_committer.stop();
691-
});
692729
});

packages/integration-tests/fork-tests/transfer_eth.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ import type {
2020
Provider,
2121
} from 'fuels';
2222

23-
import type { Containers } from '../docker-setup/docker';
24-
import { startContainers } from '../docker-setup/docker';
23+
import { stopEnvironment } from '../docker-setup/docker';
2524

2625
const { expect } = chai;
2726

@@ -33,8 +32,6 @@ describe('Transferring ETH', async function () {
3332

3433
let env: TestEnvironment;
3534

36-
let containers: Containers;
37-
3835
// override the default test timeout of 2000ms
3936
this.timeout(DEFAULT_TIMEOUT_MS);
4037

@@ -136,15 +133,7 @@ describe('Transferring ETH', async function () {
136133
}
137134

138135
before(async () => {
139-
// spinning up all docker containers
140-
containers = await startContainers(true, 9090, 7545, 3000);
141-
142-
env = await setupEnvironment({
143-
http_ethereum_client: 'http://127.0.0.1:7545',
144-
http_deployer: 'http://127.0.0.1:9090',
145-
http_fuel_client: 'http://127.0.0.1:3000/v1/graphql',
146-
});
147-
136+
env = await setupEnvironment({});
148137
BASE_ASSET_ID = env.fuel.provider.getBaseAssetId();
149138
});
150139

@@ -481,11 +470,6 @@ describe('Transferring ETH', async function () {
481470

482471
// stopping containers post the test
483472
after(async () => {
484-
await containers.postGresContainer.stop();
485-
await containers.l1_node.stop();
486-
487-
await containers.fuel_node.stop();
488-
489-
await containers.block_committer.stop();
473+
await stopEnvironment();
490474
});
491475
});

0 commit comments

Comments
 (0)