Skip to content

Commit

Permalink
feat: testcontainers integration (#386)
Browse files Browse the repository at this point in the history
- closes #382
  • Loading branch information
viraj124 authored Feb 14, 2025
1 parent 7602794 commit bc02a46
Show file tree
Hide file tree
Showing 20 changed files with 705 additions and 176 deletions.
6 changes: 6 additions & 0 deletions .changeset/clever-mails-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@fuel-bridge/solidity-contracts': minor
'@fuel-bridge/test-utils': minor
---

testcontainer integration for all intergration tests
2 changes: 1 addition & 1 deletion .github/workflows/upgrade-test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ jobs:
working-directory: docker/envs
- name: Run integration tests on a L1 fork after upgrading contracts
run: |
pnpm run test:fork
pnpm run test:integration:fork
15 changes: 0 additions & 15 deletions docker/Makefile

This file was deleted.

61 changes: 0 additions & 61 deletions docker/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ services:
COMMITTER__APP__BUNDLE__FRAGMENT_ACCUMULATION_TIMEOUT: '10m'
COMMITTER__APP__BUNDLE__NEW_BUNDLE_CHECK_INTERVAL: '3s'
DEPLOYMENTS_HTTP: http://l1_chain:8081/deployments.local.json
ports:
# expose the service to the host for integration testing
- ${COMMITTER_HTTP_PORT:-8888}:8888
depends_on:
db:
condition: service_healthy
Expand Down
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@
"changeset:version": "changeset version",
"build": "sh ./scripts/build.sh",
"format": "sh ./scripts/format.sh",
"node:build": "make -C ./docker build",
"node:up": "make -C ./docker up",
"node:stop": "make -C ./docker stop",
"node:clean": "make -C ./docker clean",
"node:logs": "make -C ./docker logs",
"test": "sh ./scripts/test.sh",
"test:fork": "sh ./scripts/test-fork.sh",
"test:integration": "DEBUG=true pnpm --filter @fuel-bridge/integration-tests test",
"test:integration:fork": "DEBUG=true pnpm --filter @fuel-bridge/integration-tests test-fork",
"lint:check": "eslint . --ext .ts,.js",
Expand Down
3 changes: 3 additions & 0 deletions packages/integration-tests/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ ETH_ERC721_TOKEN_ADDRESS=
# (Optional) Fuel network specific variables
FUEL_GAS_LIMIT=10000000
FUEL_GAS_PRICE=1

# for fork test
TENDERLY_RPC_URL=
51 changes: 51 additions & 0 deletions packages/integration-tests/docker-setup/docker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { config as dotEnvConfig } from 'dotenv';
import * as path from 'path';
import type {
StartedTestContainer,
StartedDockerComposeEnvironment,
} from 'testcontainers';
import { DockerComposeEnvironment } from 'testcontainers';

dotEnvConfig();

export type Containers = {
postGresContainer: StartedTestContainer;
l1_node: StartedTestContainer;
fuel_node: StartedTestContainer;
block_committer: StartedTestContainer;
};

const PROJECT_ROOT = path.resolve(__dirname, '../../../');
let environment: StartedDockerComposeEnvironment;

// responsible for starting all containers
export async function startContainers() {
// building images externally
console.log('Setting up environment using docker compose...');
environment = await new DockerComposeEnvironment(
path.resolve(PROJECT_ROOT, 'docker'),
'docker-compose.yml'
)
.withBuild()
.up();

console.log('Environment setup done...');

const postGresContainer = environment.getContainer('db-1');

const l1_node: StartedTestContainer = environment.getContainer('l1_chain-1');
const fuel_node: StartedTestContainer =
environment.getContainer('fuel_core-1');
const block_committer: StartedTestContainer = environment.getContainer(
'fuel_block_commiter-1'
);

return { postGresContainer, l1_node, fuel_node, block_committer };
}

export async function stopEnvironment(): Promise<void> {
console.log('Stopping environment...');
if (environment) {
await environment.down();
}
}
9 changes: 9 additions & 0 deletions packages/integration-tests/fork-tests/bridge_erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type {
Provider,
} from 'fuels';

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

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

before(async () => {
// spinning up all docker containers
await startContainers();

env = await setupEnvironment({});
eth_erc20GatewayAddress = (
await env.eth.fuelERC20Gateway.getAddress()
Expand Down Expand Up @@ -722,4 +726,9 @@ describe('Bridging ERC20 tokens', async function () {
).to.be.true;
});
});

// stopping containers post the test
after(async () => {
await stopEnvironment();
});
});
10 changes: 10 additions & 0 deletions packages/integration-tests/fork-tests/transfer_eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import type {
Provider,
} from 'fuels';

import { startContainers, stopEnvironment } from '../docker-setup/docker';

const { expect } = chai;

describe('Transferring ETH', async function () {
Expand Down Expand Up @@ -131,6 +133,9 @@ describe('Transferring ETH', async function () {
}

before(async () => {
// spinning up all docker containers
await startContainers();

env = await setupEnvironment({});
BASE_ASSET_ID = env.fuel.provider.getBaseAssetId();
});
Expand Down Expand Up @@ -465,4 +470,9 @@ describe('Transferring ETH', async function () {
expect(currentWithdrawnAmountAfterSettingLimit == 0n).to.be.true;
});
});

// stopping containers post the test
after(async () => {
await stopEnvironment();
});
});
4 changes: 3 additions & 1 deletion packages/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"fuels": "0.96.1",
"mocha": "^10.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
"typescript": "^5.1.6",
"testcontainers": "^10.16.0",
"@testcontainers/postgresql": "^10.16.0"
}
}
9 changes: 9 additions & 0 deletions packages/integration-tests/tests/bridge_erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type {
MessageProof,
} from 'fuels';

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

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

before(async () => {
// spinning up all docker containers
await startContainers();

env = await setupEnvironment({});
eth_erc20GatewayAddress = (
await env.eth.fuelERC20Gateway.getAddress()
Expand Down Expand Up @@ -876,4 +880,9 @@ describe('Bridging ERC20 tokens', async function () {
).to.be.true;
});
});

// stopping containers post the test
after(async () => {
await stopEnvironment();
});
});
10 changes: 10 additions & 0 deletions packages/integration-tests/tests/bridge_erc721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import type {
MessageProof,
} from 'fuels';

import { startContainers, stopEnvironment } from '../docker-setup/docker';

const { expect } = chai;

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

before(async () => {
// spinning up all docker containers
await startContainers();

env = await setupEnvironment({});
eth_testToken = await getOrDeployERC721Contract(env);
eth_testTokenAddress = (await eth_testToken.getAddress()).toLowerCase();
Expand Down Expand Up @@ -263,4 +268,9 @@ describe.skip('Bridging ERC721 tokens', async function () {
);
});
});

// stopping containers post the test
after(async () => {
await stopEnvironment();
});
});
9 changes: 9 additions & 0 deletions packages/integration-tests/tests/bridge_mainnet_tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import type {
MessageProof,
} from 'fuels';

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

const { expect } = chai;
Expand Down Expand Up @@ -160,6 +161,9 @@ describe('Bridge mainnet tokens', function () {
}

before(async () => {
// spinning up all docker containers
await startContainers();

env = await setupEnvironment({});
eth_erc20GatewayAddress = (
await env.eth.fuelERC20Gateway.getAddress()
Expand Down Expand Up @@ -737,4 +741,9 @@ describe('Bridge mainnet tokens', function () {
});
});
}

// stopping containers post the test
after(async () => {
await stopEnvironment();
});
});
10 changes: 10 additions & 0 deletions packages/integration-tests/tests/bridge_proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { setupEnvironment, getOrDeployL2Bridge } from '@fuel-bridge/test-utils';
import chai from 'chai';
import type { Contract, FuelError } from 'fuels';

import { startContainers, stopEnvironment } from '../docker-setup/docker';

const { expect } = chai;

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

before(async () => {
// spinning up all docker containers
await startContainers();

env = await setupEnvironment({});

const { proxy, implementation } = await getOrDeployL2Bridge(
Expand Down Expand Up @@ -177,4 +182,9 @@ describe('Proxy', async function () {
expect(message).contains('NotOwner');
});
});

// stopping containers post the test
after(async () => {
await stopEnvironment();
});
});
10 changes: 10 additions & 0 deletions packages/integration-tests/tests/transfer_eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import type {
MessageProof,
} from 'fuels';

import { startContainers, stopEnvironment } from '../docker-setup/docker';

const { expect } = chai;

describe('Transferring ETH', async function () {
Expand Down Expand Up @@ -93,6 +95,9 @@ describe('Transferring ETH', async function () {
}

before(async () => {
// spinning up all docker containers
await startContainers();

env = await setupEnvironment({});
BASE_ASSET_ID = env.fuel.provider.getBaseAssetId();
});
Expand Down Expand Up @@ -523,4 +528,9 @@ describe('Transferring ETH', async function () {
expect(currentWithdrawnAmountAfterSettingLimit == 0n).to.be.true;
});
});

// stopping containers post the test
after(async () => {
await stopEnvironment();
});
});
Loading

0 comments on commit bc02a46

Please sign in to comment.