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 1 commit
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
Prev Previous commit
Next Next commit
test: migrate integration tests to ethers 6
  • Loading branch information
DefiCake committed Feb 16, 2024
commit 21140f9e933d8e6177243ea42e36efcd26b0e922
62 changes: 35 additions & 27 deletions packages/integration-tests/tests/bridge_erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 18,8 @@ import {
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 { Wallet } from 'ethers';
import { Address, BN } from 'fuels';
import type {
AbstractAddress,
Expand All @@ -31,15 32,16 @@ LOG_CONFIG.debug = false;

const { expect } = chai;

describe('Bridging ERC20 tokens', async function () {
describe.only('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 51,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,23 80,21 @@ 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);

await eth_testToken.mint(await env.eth.signers[1].getAddress(), 10_000);
});

describe('Bridge ERC20 to Fuel', async () => {
const NUM_TOKENS = 10_000_000_000;
let ethereumTokenSender: Signer;
const NUM_TOKENS = 10_000_000_000n;
let ethereumTokenSender: Wallet;
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,33 120,38 @@ 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)
.then((tx) => {
tx.wait();
});

// 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);

// parse events from logs
const event = env.eth.fuelMessagePortal.interface.parseLog(
result.logs[2]
const [event] = await env.eth.fuelMessagePortal.queryFilter(
env.eth.fuelMessagePortal.filters.MessageSent,
tx.blockNumber
);
fuelTokenMessageNonce = new BN(event.args.nonce.toHexString());

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 () {
Expand Down Expand Up @@ -171,18 180,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 ethereumTokenReceiver: Wallet;
let ethereumTokenReceiverAddress: string;
let ethereumTokenReceiverBalance: BigNumber;
let ethereumTokenReceiverBalance: bigint;
let withdrawMessageProof: MessageProof;

before(async () => {
Expand All @@ -202,7 211,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 259,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 286,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;
});
});
});
42 changes: 21 additions & 21 deletions packages/integration-tests/tests/bridge_erc721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 18,8 @@ import {
FUEL_CALL_TX_PARAMS,
} from '@fuel-bridge/test-utils';
import chai from 'chai';
import type { Wallet } from 'ethers';
import { BigNumber, utils } from 'ethers';
import { zeroPadValue } from 'ethers';
import type { Signer } from 'ethers';
import { Address, BN } from 'fuels';
import type {
AbstractAddress,
Expand All @@ -32,10 32,6 @@ LOG_CONFIG.debug = false;

const { expect } = chai;

const signerToHexTokenId = (signer: { address: string }) => {
return utils.hexZeroPad(BigNumber.from(signer.address).toHexString(), 32);
};

describe('Bridging ERC721 tokens', async function () {
// Timeout 6 minutes 40 seconds
const DEFAULT_TIMEOUT_MS: number = 400_000;
Expand All @@ -45,6 41,7 @@ describe('Bridging ERC721 tokens', async function () {
let eth_testToken: NFT;
let eth_testTokenAddress: string;
let eth_tokenId: string;
let eth_erc721GatewayAddress: string;
let fuel_testToken: Contract;
let fuel_testContractId: string;
let fuel_testAssetId: string;
Expand All @@ -55,7 52,10 @@ describe('Bridging ERC721 tokens', async function () {
before(async () => {
env = await setupEnvironment({});
eth_testToken = await getOrDeployERC721Contract(env);
eth_testTokenAddress = eth_testToken.address.toLowerCase();
eth_testTokenAddress = (await eth_testToken.getAddress()).toLowerCase();
eth_erc721GatewayAddress = (
await env.eth.fuelERC721Gateway.getAddress()
).toLowerCase();
fuel_testToken = await getOrDeployFuelTokenContract(
env,
eth_testToken,
Expand All @@ -80,26 80,26 @@ describe('Bridging ERC721 tokens', async function () {
eth_testTokenAddress
);
expect(fuel_to_eth_address(expectedGatewayContractId)).to.equal(
env.eth.fuelERC721Gateway.address.toLowerCase()
eth_erc721GatewayAddress
);

// mint tokens as starting balances
await eth_testToken.mint(
env.eth.deployer.address,
env.eth.deployer.address
await env.eth.deployer.getAddress(),
await env.eth.deployer.getAddress()
);
await eth_testToken.mint(
env.eth.signers[0].address,
env.eth.signers[0].address
await env.eth.signers[0].getAddress(),
await env.eth.signers[0].getAddress()
);
await eth_testToken.mint(
env.eth.signers[1].address,
env.eth.signers[1].address
await env.eth.signers[1].getAddress(),
await env.eth.signers[1].getAddress()
);
});

describe('Bridge ERC721 to Fuel', async () => {
let ethereumTokenSender: Wallet;
let ethereumTokenSender: Signer;
let fuelTokenReceiver: FuelWallet;
let fuelTokenReceiverAddress: string;
let fuelTokenMessageNonce: BN;
Expand All @@ -109,22 109,22 @@ describe('Bridging ERC721 tokens', async function () {
ethereumTokenSender = env.eth.signers[0];
fuelTokenReceiver = env.fuel.signers[0];
fuelTokenReceiverAddress = fuelTokenReceiver.address.toHexString();
eth_tokenId = signerToHexTokenId(ethereumTokenSender);
eth_tokenId = zeroPadValue(await ethereumTokenSender.getAddress(), 32);
fuel_testAssetId = getTokenId(fuel_testToken, eth_tokenId);
});

it('Bridge ERC721 via FuelERC721Gateway', async () => {
// approve FuelERC721Gateway to spend the tokens
await eth_testToken
.connect(ethereumTokenSender)
.approve(env.eth.fuelERC721Gateway.address, eth_tokenId);
.approve(env.eth.fuelERC721Gateway, eth_tokenId);

// use the FuelERC721Gateway to deposit test tokens and receive equivalent tokens on Fuel
const result = await env.eth.fuelERC721Gateway
.connect(ethereumTokenSender)
.deposit(
fuelTokenReceiverAddress,
eth_testToken.address,
eth_testToken.getAddress(),
fuel_testContractId,
eth_tokenId
)
Expand Down Expand Up @@ -155,7 155,7 @@ describe('Bridging ERC721 tokens', async function () {

// check that the tokenId now belongs to the gateway
expect(await eth_testToken.ownerOf(eth_tokenId)).to.be.equal(
env.eth.fuelERC721Gateway.address
eth_erc721GatewayAddress
);
});

Expand Down Expand Up @@ -189,14 189,14 @@ describe('Bridging ERC721 tokens', async function () {

describe('Bridge ERC721 from Fuel', async () => {
let fuelTokenSender: FuelWallet;
let ethereumTokenReceiver: Wallet;
let ethereumTokenReceiver: Signer;
let ethereumTokenReceiverAddress: string;
let withdrawMessageProof: MessageProof;

before(async () => {
fuelTokenSender = env.fuel.signers[0];
ethereumTokenReceiver = env.eth.signers[1];
ethereumTokenReceiverAddress = ethereumTokenReceiver.address;
ethereumTokenReceiverAddress = await ethereumTokenReceiver.getAddress();
});

it('Bridge ERC721 via Fuel token contract', async () => {
Expand Down
Loading