Skip to content

Commit bc02a46

Browse files
authored
feat: testcontainers integration (#386)
- closes #382
1 parent 7602794 commit bc02a46

20 files changed

+705
-176
lines changed

.changeset/clever-mails-agree.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@fuel-bridge/solidity-contracts': minor
3+
'@fuel-bridge/test-utils': minor
4+
---
5+
6+
testcontainer integration for all intergration tests

.github/workflows/upgrade-test-suite.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ jobs:
4343
working-directory: docker/envs
4444
- name: Run integration tests on a L1 fork after upgrading contracts
4545
run: |
46-
pnpm run test:fork
46+
pnpm run test:integration:fork

docker/Makefile

-15
This file was deleted.

docker/README.md

-61
This file was deleted.

docker/docker-compose.yml

-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ services:
8383
COMMITTER__APP__BUNDLE__FRAGMENT_ACCUMULATION_TIMEOUT: '10m'
8484
COMMITTER__APP__BUNDLE__NEW_BUNDLE_CHECK_INTERVAL: '3s'
8585
DEPLOYMENTS_HTTP: http://l1_chain:8081/deployments.local.json
86-
ports:
87-
# expose the service to the host for integration testing
88-
- ${COMMITTER_HTTP_PORT:-8888}:8888
8986
depends_on:
9087
db:
9188
condition: service_healthy

package.json

-6
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@
1212
"changeset:version": "changeset version",
1313
"build": "sh ./scripts/build.sh",
1414
"format": "sh ./scripts/format.sh",
15-
"node:build": "make -C ./docker build",
16-
"node:up": "make -C ./docker up",
17-
"node:stop": "make -C ./docker stop",
18-
"node:clean": "make -C ./docker clean",
19-
"node:logs": "make -C ./docker logs",
2015
"test": "sh ./scripts/test.sh",
21-
"test:fork": "sh ./scripts/test-fork.sh",
2216
"test:integration": "DEBUG=true pnpm --filter @fuel-bridge/integration-tests test",
2317
"test:integration:fork": "DEBUG=true pnpm --filter @fuel-bridge/integration-tests test-fork",
2418
"lint:check": "eslint . --ext .ts,.js",

packages/integration-tests/.env.example

+3
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ ETH_ERC721_TOKEN_ADDRESS=
2727
# (Optional) Fuel network specific variables
2828
FUEL_GAS_LIMIT=10000000
2929
FUEL_GAS_PRICE=1
30+
31+
# for fork test
32+
TENDERLY_RPC_URL=
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { config as dotEnvConfig } from 'dotenv';
2+
import * as path from 'path';
3+
import type {
4+
StartedTestContainer,
5+
StartedDockerComposeEnvironment,
6+
} from 'testcontainers';
7+
import { DockerComposeEnvironment } from 'testcontainers';
8+
9+
dotEnvConfig();
10+
11+
export type Containers = {
12+
postGresContainer: StartedTestContainer;
13+
l1_node: StartedTestContainer;
14+
fuel_node: StartedTestContainer;
15+
block_committer: StartedTestContainer;
16+
};
17+
18+
const PROJECT_ROOT = path.resolve(__dirname, '../../../');
19+
let environment: StartedDockerComposeEnvironment;
20+
21+
// responsible for starting all containers
22+
export async function startContainers() {
23+
// building images externally
24+
console.log('Setting up environment using docker compose...');
25+
environment = await new DockerComposeEnvironment(
26+
path.resolve(PROJECT_ROOT, 'docker'),
27+
'docker-compose.yml'
28+
)
29+
.withBuild()
30+
.up();
31+
32+
console.log('Environment setup done...');
33+
34+
const postGresContainer = environment.getContainer('db-1');
35+
36+
const l1_node: StartedTestContainer = environment.getContainer('l1_chain-1');
37+
const fuel_node: StartedTestContainer =
38+
environment.getContainer('fuel_core-1');
39+
const block_committer: StartedTestContainer = environment.getContainer(
40+
'fuel_block_commiter-1'
41+
);
42+
43+
return { postGresContainer, l1_node, fuel_node, block_committer };
44+
}
45+
46+
export async function stopEnvironment(): Promise<void> {
47+
console.log('Stopping environment...');
48+
if (environment) {
49+
await environment.down();
50+
}
51+
}

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

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import type {
3333
Provider,
3434
} from 'fuels';
3535

36+
import { startContainers, stopEnvironment } from '../docker-setup/docker';
3637
import { fundWithdrawalTransactionWithBaseAssetResource } from '../utils/utils';
3738

3839
const { expect } = chai;
@@ -203,6 +204,9 @@ describe('Bridging ERC20 tokens', async function () {
203204
}
204205

205206
before(async () => {
207+
// spinning up all docker containers
208+
await startContainers();
209+
206210
env = await setupEnvironment({});
207211
eth_erc20GatewayAddress = (
208212
await env.eth.fuelERC20Gateway.getAddress()
@@ -722,4 +726,9 @@ describe('Bridging ERC20 tokens', async function () {
722726
).to.be.true;
723727
});
724728
});
729+
730+
// stopping containers post the test
731+
after(async () => {
732+
await stopEnvironment();
733+
});
725734
});

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

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import type {
2020
Provider,
2121
} from 'fuels';
2222

23+
import { startContainers, stopEnvironment } from '../docker-setup/docker';
24+
2325
const { expect } = chai;
2426

2527
describe('Transferring ETH', async function () {
@@ -131,6 +133,9 @@ describe('Transferring ETH', async function () {
131133
}
132134

133135
before(async () => {
136+
// spinning up all docker containers
137+
await startContainers();
138+
134139
env = await setupEnvironment({});
135140
BASE_ASSET_ID = env.fuel.provider.getBaseAssetId();
136141
});
@@ -465,4 +470,9 @@ describe('Transferring ETH', async function () {
465470
expect(currentWithdrawnAmountAfterSettingLimit == 0n).to.be.true;
466471
});
467472
});
473+
474+
// stopping containers post the test
475+
after(async () => {
476+
await stopEnvironment();
477+
});
468478
});

packages/integration-tests/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
"fuels": "0.96.1",
2929
"mocha": "^10.0.0",
3030
"ts-node": "^10.9.1",
31-
"typescript": "^5.1.6"
31+
"typescript": "^5.1.6",
32+
"testcontainers": "^10.16.0",
33+
"@testcontainers/postgresql": "^10.16.0"
3234
}
3335
}

packages/integration-tests/tests/bridge_erc20.ts

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import type {
3737
MessageProof,
3838
} from 'fuels';
3939

40+
import { startContainers, stopEnvironment } from '../docker-setup/docker';
4041
import { fundWithdrawalTransactionWithBaseAssetResource } from '../utils/utils';
4142

4243
const { expect } = chai;
@@ -234,6 +235,9 @@ describe('Bridging ERC20 tokens', async function () {
234235
}
235236

236237
before(async () => {
238+
// spinning up all docker containers
239+
await startContainers();
240+
237241
env = await setupEnvironment({});
238242
eth_erc20GatewayAddress = (
239243
await env.eth.fuelERC20Gateway.getAddress()
@@ -876,4 +880,9 @@ describe('Bridging ERC20 tokens', async function () {
876880
).to.be.true;
877881
});
878882
});
883+
884+
// stopping containers post the test
885+
after(async () => {
886+
await stopEnvironment();
887+
});
879888
});

packages/integration-tests/tests/bridge_erc721.ts

+10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import type {
2727
MessageProof,
2828
} from 'fuels';
2929

30+
import { startContainers, stopEnvironment } from '../docker-setup/docker';
31+
3032
const { expect } = chai;
3133

3234
// TODO: develop new version of ERC721 gateway
@@ -48,6 +50,9 @@ describe.skip('Bridging ERC721 tokens', async function () {
4850
this.timeout(DEFAULT_TIMEOUT_MS);
4951

5052
before(async () => {
53+
// spinning up all docker containers
54+
await startContainers();
55+
5156
env = await setupEnvironment({});
5257
eth_testToken = await getOrDeployERC721Contract(env);
5358
eth_testTokenAddress = (await eth_testToken.getAddress()).toLowerCase();
@@ -263,4 +268,9 @@ describe.skip('Bridging ERC721 tokens', async function () {
263268
);
264269
});
265270
});
271+
272+
// stopping containers post the test
273+
after(async () => {
274+
await stopEnvironment();
275+
});
266276
});

packages/integration-tests/tests/bridge_mainnet_tokens.ts

+9
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import type {
4343
MessageProof,
4444
} from 'fuels';
4545

46+
import { startContainers, stopEnvironment } from '../docker-setup/docker';
4647
import { fundWithdrawalTransactionWithBaseAssetResource } from '../utils/utils';
4748

4849
const { expect } = chai;
@@ -160,6 +161,9 @@ describe('Bridge mainnet tokens', function () {
160161
}
161162

162163
before(async () => {
164+
// spinning up all docker containers
165+
await startContainers();
166+
163167
env = await setupEnvironment({});
164168
eth_erc20GatewayAddress = (
165169
await env.eth.fuelERC20Gateway.getAddress()
@@ -737,4 +741,9 @@ describe('Bridge mainnet tokens', function () {
737741
});
738742
});
739743
}
744+
745+
// stopping containers post the test
746+
after(async () => {
747+
await stopEnvironment();
748+
});
740749
});

packages/integration-tests/tests/bridge_proxy.ts

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { setupEnvironment, getOrDeployL2Bridge } from '@fuel-bridge/test-utils';
44
import chai from 'chai';
55
import type { Contract, FuelError } from 'fuels';
66

7+
import { startContainers, stopEnvironment } from '../docker-setup/docker';
8+
79
const { expect } = chai;
810

911
describe('Proxy', async function () {
@@ -16,6 +18,9 @@ describe('Proxy', async function () {
1618
let fuel_proxy: Proxy;
1719

1820
before(async () => {
21+
// spinning up all docker containers
22+
await startContainers();
23+
1924
env = await setupEnvironment({});
2025

2126
const { proxy, implementation } = await getOrDeployL2Bridge(
@@ -177,4 +182,9 @@ describe('Proxy', async function () {
177182
expect(message).contains('NotOwner');
178183
});
179184
});
185+
186+
// stopping containers post the test
187+
after(async () => {
188+
await stopEnvironment();
189+
});
180190
});

packages/integration-tests/tests/transfer_eth.ts

+10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import type {
2323
MessageProof,
2424
} from 'fuels';
2525

26+
import { startContainers, stopEnvironment } from '../docker-setup/docker';
27+
2628
const { expect } = chai;
2729

2830
describe('Transferring ETH', async function () {
@@ -93,6 +95,9 @@ describe('Transferring ETH', async function () {
9395
}
9496

9597
before(async () => {
98+
// spinning up all docker containers
99+
await startContainers();
100+
96101
env = await setupEnvironment({});
97102
BASE_ASSET_ID = env.fuel.provider.getBaseAssetId();
98103
});
@@ -523,4 +528,9 @@ describe('Transferring ETH', async function () {
523528
expect(currentWithdrawnAmountAfterSettingLimit == 0n).to.be.true;
524529
});
525530
});
531+
532+
// stopping containers post the test
533+
after(async () => {
534+
await stopEnvironment();
535+
});
526536
});

0 commit comments

Comments
 (0)