From b0792736490f6628b3cb185fac2b00c2452d4129 Mon Sep 17 00:00:00 2001 From: BkChoy Date: Mon, 25 Nov 2024 05:56:28 -0500 Subject: [PATCH] added test for forceWithdraw --- .../core/priorityPool/withdrawal-pool.test.ts | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/test/core/priorityPool/withdrawal-pool.test.ts b/test/core/priorityPool/withdrawal-pool.test.ts index 4c9b56ea..71fbf96f 100644 --- a/test/core/priorityPool/withdrawal-pool.test.ts +++ b/test/core/priorityPool/withdrawal-pool.test.ts @@ -225,6 +225,61 @@ describe('WithdrawalPool', () => { ) }) + it('forceWithdraw should work correctly', async () => { + const { signers, accounts, withdrawalPool, token } = await loadFixture(deployFixture) + + await withdrawalPool.queueWithdrawal(accounts[0], toEther(1000)) + await withdrawalPool.queueWithdrawal(accounts[1], toEther(250)) + await withdrawalPool.queueWithdrawal(accounts[0], toEther(500)) + await withdrawalPool.deposit(toEther(1200)) + + await expect(withdrawalPool.forceWithdraw([1, 3], [1, 1])).to.be.revertedWithCustomError( + withdrawalPool, + 'InvalidWithdrawalId()' + ) + + await withdrawalPool.deposit(toEther(550)) + + await expect(withdrawalPool.forceWithdraw([1], [2])).to.be.revertedWithCustomError( + withdrawalPool, + 'InvalidWithdrawalId()' + ) + + let startingBalance1 = await token.balanceOf(accounts[1]) + let startingBalance0 = await token.balanceOf(accounts[0]) + + await withdrawalPool.forceWithdraw([2, 1, 3], [2, 1, 2]) + assert.equal(fromEther((await token.balanceOf(accounts[1])) - startingBalance1), 250) + assert.deepEqual( + (await withdrawalPool.getWithdrawalIdsByOwner(accounts[1])).map((id) => Number(id)), + [] + ) + assert.deepEqual( + (await withdrawalPool.getWithdrawals([2])).map((d: any) => [ + fromEther(d[0]), + fromEther(d[1]), + ]), + [[0, 0]] + ) + + assert.equal(fromEther((await token.balanceOf(accounts[0])) - startingBalance0), 1500) + assert.deepEqual( + (await withdrawalPool.getWithdrawalIdsByOwner(accounts[1])).map((id) => Number(id)), + [] + ) + assert.deepEqual( + (await withdrawalPool.getWithdrawals([1, 2, 3])).map((d: any) => [ + fromEther(d[0]), + fromEther(d[1]), + ]), + [ + [0, 0], + [0, 0], + [0, 0], + ] + ) + }) + it('getWithdrawalIdsByOwner should work correctly', async () => { const { signers, accounts, withdrawalPool } = await loadFixture(deployFixture)