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

Add pnpm audit to CI #126

Merged
merged 38 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift click to select a range
1c3d3d8
ci: add pnpm audit and update vunerabilities
luizstacio Dec 14, 2023
a4d9352
chore: apply audit --fix
DefiCake Feb 9, 2024
55ac568
chore: audit only high and critical security vulnerabilities
DefiCake Feb 9, 2024
2aba639
chore: update dependencies, issue with toolbox
DefiCake Feb 9, 2024
531da9d
chore: remove overrides, move packages at solidity-contracts to devDe…
DefiCake Feb 9, 2024
9489a54
chore: bump hardhat chai matchers
DefiCake Feb 9, 2024
f646b03
test: fix ecdsa tests with ethers v6
DefiCake Feb 9, 2024
8086667
test: refactor harness and erc20Gateway tests
DefiCake Feb 12, 2024
2f675e2
test: enable erc20gateway v2 tests
DefiCake Feb 13, 2024
b612ef1
test: refactor erc20gateway v3 tests
DefiCake Feb 13, 2024
2494e1e
test: refactor erc721gateway tests
DefiCake Feb 13, 2024
7acf65a
test: refactor erc721GatewayV2 test
DefiCake Feb 13, 2024
9a258cc
test: refactor FuelChainState tests
DefiCake Feb 13, 2024
eed2799
test: refactor messagesIncoming.ts
DefiCake Feb 13, 2024
97e052e
test: refactor messagesIncomingV2
DefiCake Feb 13, 2024
d2b9e27
test: refactor messagesOutgoingV2
DefiCake Feb 13, 2024
a558202
test: refactor messagesOutgoingV2
DefiCake Feb 13, 2024
7bd9bb0
test: refactor upgrade.ts
DefiCake Feb 13, 2024
4ce6c3b
chore: add wip, refactor test utils
DefiCake Feb 13, 2024
e59b871
chore: add wip, test utils refactor
DefiCake Feb 14, 2024
4a48a04
chore: upgrade to latest hardhat version
DefiCake Feb 14, 2024
956d913
fix: remove test flakiness on queryFilter, use block number intead of…
DefiCake Feb 14, 2024
545d198
chore: refactor integration test 's hardhat
DefiCake Feb 14, 2024
042c53d
chore: disable code minification
DefiCake Feb 14, 2024
2f856c3
chore: fix hardhat_mine to increase time and normalise typings
DefiCake Feb 15, 2024
6f49dae
chore: delete unused dependencies, update ethers
DefiCake Feb 15, 2024
c6297d0
chore: update pnpm lockfile
DefiCake Feb 15, 2024
21140f9
test: migrate integration tests to ethers 6
DefiCake Feb 15, 2024
9389483
refactor: use DEBUG env directly instead of inside an object
DefiCake Feb 16, 2024
2892d3e
chore: update hardhat
DefiCake Feb 16, 2024
a8bf1ad
chore: rearrange private key usage to avoid signer collision with blo…
DefiCake Feb 16, 2024
7542737
test: update tests to use latest dependencies
DefiCake Feb 16, 2024
721f471
refactor: remove unused code
DefiCake Feb 16, 2024
caae327
chore: update pnpm-lock.yaml
DefiCake Feb 16, 2024
adaa505
chore: update broken pnpm-lock after rebase
DefiCake Feb 16, 2024
1b37e93
chore: add changeset
DefiCake Feb 16, 2024
5cc1328
test: fix transfer_eth test
DefiCake Feb 19, 2024
6f14bd4
refactor: cache .getAddress() where possible
DefiCake Feb 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/calm-spiders-love.md
Original file line number Diff line number Diff line change
@@ -0,0 1,8 @@
---
'@fuel-bridge/message-predicates': minor
'@fuel-bridge/solidity-contracts': minor
'@fuel-bridge/fungible-token': minor
'@fuel-bridge/test-utils': minor
---

Add pnpm audit to CI and migrate dependencies to safe versions
12 changes: 11 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 13,16 @@ concurrency:
cancel-in-progress: true

jobs:
audit-deps:
name: Audit Dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: FuelLabs/github-actions/setups/node@master
- run: pnpm audit --prod --audit-level high

check-packages-changed:
needs: audit-deps
name: Check if packages have change
runs-on: ubuntu-latest
outputs:
Expand All @@ -29,7 38,7 @@ jobs:

changesets:
name: Changeset Checks
needs: check-packages-changed
needs: [audit-deps, check-packages-changed]
if: ${{ github.head_ref != 'changeset-release/main' && needs.check-packages-changed.outputs.changed == 'true' }}
runs-on: ubuntu-latest
steps:
Expand All @@ -42,6 51,7 @@ jobs:

validate:
runs-on: buildjet-4vcpu-ubuntu-2204
needs: audit-deps
steps:
- uses: actions/checkout@v3
- uses: FuelLabs/github-actions/setups/node@master
Expand Down
14 changes: 9 additions & 5 deletions docker/l1-chain/hardhat/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 1,13 @@
import type { HardhatUserConfig } from 'hardhat/types';
import '@nomiclabs/hardhat-etherscan';
import '@nomicfoundation/hardhat-ethers';
import '@nomicfoundation/hardhat-network-helpers';
import '@nomicfoundation/hardhat-verify';
import '@nomicfoundation/hardhat-chai-matchers';
import '@typechain/hardhat';
import '@openzeppelin/hardhat-upgrades';
import 'hardhat-typechain';
import 'hardhat-deploy';
import 'solidity-coverage';

const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY || '';
const LOCALHOST_HTTP = process.env.LOCALHOST_HTTP || '';

const config: HardhatUserConfig = {
Expand All @@ -26,8 30,8 @@ const config: HardhatUserConfig = {
url: LOCALHOST_HTTP,
},
},
etherscan: {
apiKey: ETHERSCAN_API_KEY,
typechain: {
outDir: 'typechain',
},
};

Expand Down
12 changes: 0 additions & 12 deletions docker/l1-chain/hardhat/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/esbuild-bin-loader/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 4,6 @@ export default {
dts: true,
treeshake: true,
format: ['cjs', 'esm'],
minify: true,
minify: false,
entry: ['./src/index.ts'],
};
2 changes: 1 addition & 1 deletion packages/fungible-token/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 7,6 @@ export default {
treeshake: true,
esbuildPlugins: [esbuildBinLoader],
format: ['cjs', 'esm'],
minify: true,
minify: false,
entry: ['./exports/index.ts'],
};
5 changes: 1 addition & 4 deletions packages/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 14,6 @@
"transfer": "pnpm ts-node scripts/transfer.ts"
},
"devDependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/providers": "^5.7.0",
"@fuel-bridge/fungible-token": "workspace:*",
"@fuel-bridge/message-predicates": "workspace:*",
"@fuel-bridge/solidity-contracts": "workspace:*",
Expand All @@ -26,7 23,7 @@
"chai": "^4.3.6",
"dotenv": "^16.0.3",
"ethereum-waffle": "^4.0.2",
"ethers": "^5.7.2",
"ethers": "6.11.0",
"fuels": "0.73.0",
"mocha": "^10.0.0",
"ts-node": "^10.9.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/integration-tests/scripts/bridgeERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 70,7 @@ const TOKEN_AMOUNT = '10';
// approve fuel erc20 gateway to spend the tokens
console.log('Approving Tokens for gateway...');
const eApproveTx = await ethTestToken.approve(
gatewayContract.address,
await gatewayContract.getAddress(),
ethers_parseToken(TOKEN_AMOUNT, 18)
);
const eApproveTxResult = await eApproveTx.wait();
Expand All @@ -83,7 83,7 @@ const TOKEN_AMOUNT = '10';
console.log(`Sending ${TOKEN_AMOUNT} Tokens from Ethereum...`);
const eDepositTx = await gatewayContract.deposit(
fuelAcctAddr,
ethTestToken.address,
await ethTestToken.getAddress(),
fuelTestToken.id.toHexString(),
ethers_parseToken(TOKEN_AMOUNT, 18)
);
Expand Down
2 changes: 1 addition & 1 deletion packages/integration-tests/scripts/bridgeETH.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 12,7 @@ import {
getBlock,
FUEL_CALL_TX_PARAMS,
} from '@fuel-bridge/test-utils';
import { parseEther } from 'ethers/lib/utils';
import { parseEther } from 'ethers';
import {
Address,
BN,
Expand Down
67 changes: 38 additions & 29 deletions packages/integration-tests/tests/bridge_erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 10,15 @@ import {
FUEL_TX_PARAMS,
getMessageOutReceipt,
fuel_to_eth_address,
LOG_CONFIG,
waitForBlockCommit,
waitForBlockFinalization,
getTokenId,
getBlock,
FUEL_CALL_TX_PARAMS,
} from '@fuel-bridge/test-utils';
import chai from 'chai';
import type { BigNumber, Signer } from 'ethers';
import { toBeHex } from 'ethers';
import type { Signer } from 'ethers';
import { Address, BN } from 'fuels';
import type {
AbstractAddress,
Expand All @@ -27,19 27,18 @@ import type {
MessageProof,
} from 'fuels';

LOG_CONFIG.debug = false;

const { expect } = chai;

describe('Bridging ERC20 tokens', async function () {
// Timeout 6 minutes
const DEFAULT_TIMEOUT_MS: number = 400_000;
const FUEL_MESSAGE_TIMEOUT_MS: number = 30_000;
const DECIMAL_DIFF = 1_000_000_000;
const DECIMAL_DIFF = 1_000_000_000n;

let env: TestEnvironment;
let eth_testToken: Token;
let eth_testTokenAddress: string;
let eth_erc20GatewayAddress: string;
let fuel_testToken: Contract;
let fuel_testContractId: string;
let fuel_testAssetId: string;
Expand All @@ -49,8 48,11 @@ describe('Bridging ERC20 tokens', async function () {

before(async () => {
env = await setupEnvironment({});
eth_erc20GatewayAddress = (
await env.eth.fuelERC20Gateway.getAddress()
).toLowerCase();
eth_testToken = await getOrDeployECR20Contract(env);
eth_testTokenAddress = eth_testToken.address.toLowerCase();
eth_testTokenAddress = (await eth_testToken.getAddress()).toLowerCase();
fuel_testToken = await getOrDeployFuelTokenContract(
env,
eth_testToken,
Expand All @@ -75,11 77,12 @@ describe('Bridging ERC20 tokens', async function () {
eth_testTokenAddress
);
expect(fuel_to_eth_address(expectedGatewayContractId)).to.equal(
env.eth.fuelERC20Gateway.address.toLowerCase()
eth_erc20GatewayAddress
);
expect(await eth_testToken.decimals()).to.equal(18);
expect(await eth_testToken.decimals()).to.equal(18n);

// mint tokens as starting balances

await eth_testToken.mint(await env.eth.deployer.getAddress(), 10_000);

await eth_testToken.mint(await env.eth.signers[0].getAddress(), 10_000);
Expand All @@ -88,10 91,10 @@ describe('Bridging ERC20 tokens', async function () {
});

describe('Bridge ERC20 to Fuel', async () => {
const NUM_TOKENS = 10_000_000_000;
const NUM_TOKENS = 10_000_000_000n;
let ethereumTokenSender: Signer;
let ethereumTokenSenderAddress: string;
let ethereumTokenSenderBalance: BigNumber;
let ethereumTokenSenderBalance: bigint;
let fuelTokenReceiver: FuelWallet;
let fuelTokenReceiverAddress: string;
let fuelTokenReceiverBalance: BN;
Expand All @@ -102,6 105,7 @@ describe('Bridging ERC20 tokens', async function () {
ethereumTokenSender = env.eth.signers[0];
ethereumTokenSenderAddress = await ethereumTokenSender.getAddress();
await eth_testToken.mint(ethereumTokenSenderAddress, NUM_TOKENS);

ethereumTokenSenderBalance = await eth_testToken.balanceOf(
ethereumTokenSenderAddress
);
Expand All @@ -116,38 120,44 @@ describe('Bridging ERC20 tokens', async function () {
// approve FuelERC20Gateway to spend the tokens
await eth_testToken
.connect(ethereumTokenSender)
.approve(env.eth.fuelERC20Gateway.address, NUM_TOKENS);
.approve(eth_erc20GatewayAddress, NUM_TOKENS);

// use the FuelERC20Gateway to deposit test tokens and receive equivalent tokens on Fuel
const tx = await env.eth.fuelERC20Gateway
.connect(ethereumTokenSender)
.deposit(
fuelTokenReceiverAddress,
eth_testToken.address,
eth_testTokenAddress,
fuel_testContractId,
NUM_TOKENS
);
const result = await tx.wait();
expect(result.status).to.equal(1);
const receipt = await tx.wait();
expect(receipt.status).to.equal(1);

// parse events from logs
const event = env.eth.fuelMessagePortal.interface.parseLog(
result.logs[2]
);
fuelTokenMessageNonce = new BN(event.args.nonce.toHexString());
const [event, ...restOfEvents] =
await env.eth.fuelMessagePortal.queryFilter(
env.eth.fuelMessagePortal.filters.MessageSent,
receipt.blockNumber,
receipt.blockNumber
);
expect(restOfEvents.length).to.be.eq(0); // Should be only 1 event

fuelTokenMessageNonce = new BN(event.args.nonce.toString());
fuelTokenMessageReceiver = Address.fromB256(event.args.recipient);

// check that the sender balance has decreased by the expected amount
const newSenderBalance = await eth_testToken.balanceOf(
ethereumTokenSenderAddress
);
expect(newSenderBalance.eq(ethereumTokenSenderBalance.sub(NUM_TOKENS))).to
.be.true;
expect(newSenderBalance === ethereumTokenSenderBalance - NUM_TOKENS).to.be
.true;
});

it('Relay message from Ethereum on Fuel', async function () {
it('Relay message from Ethereum on Fuel', async () => {
// override the default test timeout from 2000ms
this.timeout(FUEL_MESSAGE_TIMEOUT_MS);

// relay the message ourselves
const message = await waitForMessage(
env.fuel.provider,
Expand All @@ -171,18 181,18 @@ describe('Bridging ERC20 tokens', async function () {

expect(
newReceiverBalance.eq(
fuelTokenReceiverBalance.add(NUM_TOKENS / DECIMAL_DIFF)
fuelTokenReceiverBalance.add(toBeHex(NUM_TOKENS / DECIMAL_DIFF))
)
).to.be.true;
});
});

describe('Bridge ERC20 from Fuel', async () => {
const NUM_TOKENS = 10_000_000_000;
const NUM_TOKENS = 10_000_000_000n;
let fuelTokenSender: FuelWallet;
let ethereumTokenReceiver: Signer;
let ethereumTokenReceiverAddress: string;
let ethereumTokenReceiverBalance: BigNumber;
let ethereumTokenReceiverBalance: bigint;
let withdrawMessageProof: MessageProof;

before(async () => {
Expand All @@ -202,7 212,7 @@ describe('Bridging ERC20 tokens', async function () {
const fuelTokenSenderBalance = await fuelTokenSender.getBalance(
fuel_testAssetId
);
const scope = await fuel_testToken.functions
const scope = fuel_testToken.functions
.withdraw(paddedAddress)
.txParams(FUEL_CALL_TX_PARAMS)
.callParams({
Expand Down Expand Up @@ -250,7 260,7 @@ describe('Bridging ERC20 tokens', async function () {
);
expect(
newSenderBalance.eq(
fuelTokenSenderBalance.sub(NUM_TOKENS / DECIMAL_DIFF)
fuelTokenSenderBalance.sub(toBeHex(NUM_TOKENS / DECIMAL_DIFF))
)
).to.be.true;
});
Expand All @@ -277,9 287,8 @@ describe('Bridging ERC20 tokens', async function () {
const newReceiverBalance = await eth_testToken.balanceOf(
ethereumTokenReceiverAddress
);
expect(
newReceiverBalance.eq(ethereumTokenReceiverBalance.add(NUM_TOKENS))
).to.be.true;
expect(newReceiverBalance === ethereumTokenReceiverBalance NUM_TOKENS)
.to.be.true;
});
});
});
Loading
Loading