Skip to content

Commit

Permalink
Merge branch 'main' into deficake/319-upgrade-forc
Browse files Browse the repository at this point in the history
  • Loading branch information
DefiCake authored Oct 4, 2024
2 parents bf7c50b + 65387d2 commit e8d3b26
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-clocks-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@fuel-bridge/integration-tests': minor
---

add remaining token balance check for erc20 e2e tests
37 changes: 37 additions & 0 deletions packages/integration-tests/tests/bridge_erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ describe('Bridging ERC20 tokens', async function () {
let ethereumTokenReceiverAddress: string;
let ethereumTokenReceiverBalance: bigint;
let withdrawMessageProof: MessageProof;
let tokenBalanceBeforeWithdrawingOnFuel: BN;

before(async () => {
fuelTokenSender = env.fuel.signers[0];
Expand All @@ -388,6 +389,10 @@ describe('Bridging ERC20 tokens', async function () {
ethereumTokenReceiverBalance = await eth_testToken.balanceOf(
ethereumTokenReceiverAddress
);

tokenBalanceBeforeWithdrawingOnFuel = await fuelTokenSender.getBalance(
fuel_testAssetId
);
});

it('Bridge ERC20 via Fuel token contract', async () => {
Expand Down Expand Up @@ -430,6 +435,22 @@ describe('Bridging ERC20 tokens', async function () {
).to.be.true;
});

it('Check the remaining token balance on Fuel after the first withdrawal', async () => {
// fetch the remaining token balance
const currentTokenBalance = await fuelTokenSender.getBalance(
fuel_testAssetId
);

// currentTokenBalance has BN type by default hence the use of BN for conversion here
const expectedRemainingTokenBalanceOnFuel =
tokenBalanceBeforeWithdrawingOnFuel.sub(
new BN((NUM_TOKENS / DECIMAL_DIFF).toString())
);

expect(currentTokenBalance.eq(expectedRemainingTokenBalanceOnFuel)).to.be
.true;
});

it('Rate limit parameters are updated when current withdrawn amount is more than the new limit & set a new higher limit', async () => {
const deployer = await env.eth.deployer;
let newRateLimit = '5';
Expand Down Expand Up @@ -536,6 +557,22 @@ describe('Bridging ERC20 tokens', async function () {
expect(currentPeriodAmount === NUM_TOKENS).to.be.true;
});

it('Check the remaining token balance on Fuel after the second withdrawal', async () => {
// fetch the remaining token balance
const currentTokenBalance = await fuelTokenSender.getBalance(
fuel_testAssetId
);

// currentTokenBalance has BN type by default hence the use of BN for conversion here
const expectedRemainingTokenBalanceOnFuel =
tokenBalanceBeforeWithdrawingOnFuel.sub(
new BN(((NUM_TOKENS * 2n) / DECIMAL_DIFF).toString())
);

expect(currentTokenBalance.eq(expectedRemainingTokenBalanceOnFuel)).to.be
.true;
});

it('Rate limit parameters are updated when new limit is set after the initial duration', async () => {
const rateLimitDuration =
await env.eth.fuelERC20Gateway.rateLimitDuration(eth_testTokenAddress);
Expand Down
50 changes: 50 additions & 0 deletions packages/integration-tests/tests/bridge_mainnet_tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ describe('Bridge mainnet tokens', function () {
let ethereumTokenReceiverAddress: string;
let ethereumTokenReceiverBalance: bigint;
let withdrawMessageProof: MessageProof;
let tokenBalanceBeforeWithdrawingOnFuel: BN;

before(async () => {
fuelTokenSender = env.fuel.signers[0];
Expand All @@ -438,6 +439,9 @@ describe('Bridge mainnet tokens', function () {
ethereumTokenReceiverBalance = await token.balanceOf(
ethereumTokenReceiverAddress
);

tokenBalanceBeforeWithdrawingOnFuel =
await fuelTokenSender.getBalance(fuelAssetId);
});

it('Bridge ERC20 via Fuel token contract', async () => {
Expand Down Expand Up @@ -480,6 +484,29 @@ describe('Bridge mainnet tokens', function () {
).to.be.true;
});

it('Check the remaining token balance on Fuel after the first withdrawal', async () => {
// fetch the remaining token balance
const currentTokenBalance = await fuelTokenSender.getBalance(
fuelAssetId
);

// currentTokenBalance has BN type by default hence the use of BN for conversion here
const expectedRemainingTokenBalanceOnFuel =
tokenBalanceBeforeWithdrawingOnFuel.sub(
new BN(
(
NUM_TOKENS /
(index == tokenAddresses.length - 1
? DECIMAL_DIFF
: 10n ** (18n - decimals[index]))
).toString()
)
);

expect(currentTokenBalance.eq(expectedRemainingTokenBalanceOnFuel)).to
.be.true;
});

it('Rate limit parameters are updated when current withdrawn amount is more than the new limit', async () => {
const deployer = await env.eth.deployer;
const newRateLimit = '5';
Expand Down Expand Up @@ -580,6 +607,29 @@ describe('Bridge mainnet tokens', function () {
).to.be.true;
});

it('Check the remaining token balance on Fuel after the second withdrawal', async () => {
// fetch the remaining token balance
const currentTokenBalance = await fuelTokenSender.getBalance(
fuelAssetId
);

// currentTokenBalance has BN type by default hence the use of BN for conversion here
const expectedRemainingTokenBalanceOnFuel =
tokenBalanceBeforeWithdrawingOnFuel.sub(
new BN(
(
(NUM_TOKENS * 2n) /
(index == tokenAddresses.length - 1
? DECIMAL_DIFF
: 10n ** (18n - decimals[index]))
).toString()
)
);

expect(currentTokenBalance.eq(expectedRemainingTokenBalanceOnFuel)).to
.be.true;
});

it('Rate limit parameters are updated when new limit is set after the initial duration', async () => {
const deployer = await env.eth.deployer;
const newRateLimit = `40`;
Expand Down

0 comments on commit e8d3b26

Please sign in to comment.