Skip to content

Commit

Permalink
Merge branch 'feature/drain' into feature/todos
Browse files Browse the repository at this point in the history
  • Loading branch information
zguesmi committed Jun 10, 2024
2 parents 884cc0b + 5a137b1 commit a8bde54
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 1 addition & 2 deletions contracts/VoucherHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,8 @@ contract VoucherHub is
* @param voucher address of the expired voucher to drain
*/
function drainVoucher(address voucher) external {
VoucherHubStorage storage $ = _getVoucherHubStorage();
require($._isVoucher[voucher], "VoucherHub: unknown voucher");
uint256 amount = balanceOf(voucher);
require(amount > 0, "VoucherHub: nothing to drain");
_burn(voucher, amount);
emit VoucherDrained(voucher, amount);
Voucher(voucher).drain(amount);
Expand Down
16 changes: 15 additions & 1 deletion test/VoucherHub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,21 @@ describe('VoucherHub', function () {
voucherHubWithVoucherManagerSigner.drainVoucher(
ethers.Wallet.createRandom().address,
),
).to.be.revertedWith('VoucherHub: unknown voucher');
).to.be.revertedWith('VoucherHub: nothing to drain');
});

it('Should not drain if balance is empty', async function () {
// Expire voucher
const expirationDate = await voucher.getExpiration();
await time.setNextBlockTimestamp(expirationDate + 100n); // after expiration
// Drain to empty the voucher from its balance.
await voucherHubWithVoucherManagerSigner
.drainVoucher(voucherAddress)
.then((tx) => tx.wait());
// Drain a second time when balance is empty.
await expect(
voucherHubWithVoucherManagerSigner.drainVoucher(voucherAddress),
).to.be.revertedWith('VoucherHub: nothing to drain');
});
});

Expand Down

0 comments on commit a8bde54

Please sign in to comment.