Skip to content

Commit

Permalink
Remove amount from voucher drain
Browse files Browse the repository at this point in the history
  • Loading branch information
zguesmi committed Jun 10, 2024
1 parent fb17fbe commit e3b20cd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion contracts/VoucherHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ contract VoucherHub is
require(amount > 0, "VoucherHub: nothing to drain");
_burn(voucher, amount);
emit VoucherDrained(voucher, amount);
Voucher(voucher).drain(amount);
Voucher(voucher).drain();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/beacon/IVoucher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface IVoucher {
) external returns (bytes32);
function claim(bytes32 taskId) external;
function claimBoost(bytes32 dealId, uint256 taskIndex) external;
function drain(uint256 amount) external;
function drain() external;

function getVoucherHub() external view returns (address);
function getType() external view returns (uint256);
Expand Down
6 changes: 3 additions & 3 deletions contracts/beacon/Voucher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,14 @@ contract Voucher is Initializable, IVoucher {
/**
* Drain balance of voucher on PoCo if it is expired.
* Funds are sent to the VoucherHub contract.
* @param amount amount to be drained
*/
function drain(uint256 amount) external onlyVoucherHub onlyExpired {
function drain() external onlyVoucherHub onlyExpired {
VoucherStorage storage $ = _getVoucherStorage();
address voucherHub = $._voucherHub;
// Although transfer function in PoCo always returns true (or reverts),
// a return value check is added here in case its behavior changes.
if (!IERC20(IVoucherHub(voucherHub).getIexecPoco()).transfer(voucherHub, amount)) {
IERC20 iexecPoco = IERC20(IVoucherHub(voucherHub).getIexecPoco());
if (!iexecPoco.transfer(voucherHub, iexecPoco.balanceOf(address(this)))) {
revert("Voucher: drain failed");
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/beacon/Voucher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1062,23 +1062,23 @@ describe('Voucher', function () {
await time.setNextBlockTimestamp(expirationDate + 100n); // after expiration
// Drain
const voucherHubSigner = await ethers.getImpersonatedSigner(voucherHubAddress);
await expect(voucherAsAnyone.connect(voucherHubSigner).drain(voucherValue))
await expect(voucherAsAnyone.connect(voucherHubSigner).drain())
.to.emit(iexecPocoInstance, 'Transfer')
.withArgs(voucherAddress, voucherHubAddress, voucherValue);
expect(await iexecPocoInstance.balanceOf(voucherAddress)).to.equal(0);
});

it('Should not drain voucher if sender is not authorized', async function () {
await expect(voucherAsAnyone.drain(voucherValue)).to.be.revertedWith(
await expect(voucherAsAnyone.drain()).to.be.revertedWith(
'Voucher: sender is not VoucherHub',
);
});

it('Should not drain voucher if not expired', async function () {
const voucherHubSigner = await ethers.getImpersonatedSigner(voucherHubAddress);
await expect(
voucherAsAnyone.connect(voucherHubSigner).drain(voucherValue),
).to.be.revertedWith('Voucher: voucher is not expired');
await expect(voucherAsAnyone.connect(voucherHubSigner).drain()).to.be.revertedWith(
'Voucher: voucher is not expired',
);
});
});

Expand Down

0 comments on commit e3b20cd

Please sign in to comment.