diff --git a/.changeset/wise-clocks-crash.md b/.changeset/wise-clocks-crash.md new file mode 100644 index 00000000..f17eef87 --- /dev/null +++ b/.changeset/wise-clocks-crash.md @@ -0,0 +1,5 @@ +--- +'@fuel-bridge/integration-tests': minor +--- + +add remaining token balance check for erc20 e2e tests diff --git a/packages/integration-tests/tests/bridge_erc20.ts b/packages/integration-tests/tests/bridge_erc20.ts index 0f68ec69..c82850a0 100644 --- a/packages/integration-tests/tests/bridge_erc20.ts +++ b/packages/integration-tests/tests/bridge_erc20.ts @@ -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]; @@ -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 () => { @@ -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'; @@ -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); diff --git a/packages/integration-tests/tests/bridge_mainnet_tokens.ts b/packages/integration-tests/tests/bridge_mainnet_tokens.ts index 39cb5319..4c569bb1 100644 --- a/packages/integration-tests/tests/bridge_mainnet_tokens.ts +++ b/packages/integration-tests/tests/bridge_mainnet_tokens.ts @@ -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]; @@ -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 () => { @@ -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'; @@ -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`;