Skip to content

Commit

Permalink
fix(TWABDelegator): remove _requireContract
Browse files Browse the repository at this point in the history
  • Loading branch information
PierrickGT committed Mar 15, 2022
1 parent f0e4948 commit 0da337d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 23 deletions.
11 changes: 0 additions & 11 deletions contracts/TWABDelegator.sol
Expand Up @@ -301,8 +301,6 @@ contract TWABDelegator is ERC20, LowLevelDelegator, PermitAndMulticall {
_requireAmountGtZero(_amount);

Delegation _delegation = Delegation(_computeAddress(_delegator, _slot));
_requireContract(address(_delegation));

IERC20(ticket).safeTransferFrom(msg.sender, address(_delegation), _amount);

emit DelegationFunded(_delegator, _slot, _amount, msg.sender);
Expand All @@ -329,7 +327,6 @@ contract TWABDelegator is ERC20, LowLevelDelegator, PermitAndMulticall {
_requireAmountGtZero(_amount);

Delegation _delegation = Delegation(_computeAddress(_delegator, _slot));
_requireContract(address(_delegation));

_burn(_delegator, _amount);

Expand Down Expand Up @@ -629,14 +626,6 @@ contract TWABDelegator is ERC20, LowLevelDelegator, PermitAndMulticall {
require(block.timestamp >= _delegation.lockUntil(), "TWABDelegator/delegation-locked");
}

/**
* @notice Require to verify that `_address` is a contract.
* @param _address Address to check
*/
function _requireContract(address _address) internal view {
require(_address.isContract(), "TWABDelegator/not-a-contract");
}

/**
* @notice Require to verify that a `_lockDuration` does not exceed the maximum lock duration.
* @param _lockDuration Lock duration to check
Expand Down
57 changes: 45 additions & 12 deletions test/TWABDelegator.test.ts
Expand Up @@ -456,6 +456,29 @@ describe('Test Set Name', () => {
expect(await ticket.delegateOf(delegationAddress)).to.eq(firstDelegatee.address);
});

it('should fund an inexistent delegation and then create it', async () => {
await twabDelegator.connect(stranger).fundDelegation(owner.address, 1, amount);

const transaction = await twabDelegator.createDelegation(
owner.address,
1,
firstDelegatee.address,
MAX_EXPIRY,
);

delegationAddress = await getDelegationAddress(transaction);

const firstDelegateeAccountDetails = await ticket.getAccountDetails(firstDelegatee.address);
expect(firstDelegateeAccountDetails.balance).to.eq(amount);

expect(await twabDelegator.balanceOf(owner.address)).to.eq(Zero);
expect(await twabDelegator.balanceOf(stranger.address)).to.eq(Zero);

expect(await ticket.balanceOf(twabDelegator.address)).to.eq(Zero);
expect(await ticket.balanceOf(delegationAddress)).to.eq(amount);
expect(await ticket.delegateOf(delegationAddress)).to.eq(firstDelegatee.address);
});

it('should fail to transfer tickets to a delegation if delegator passed is address zero', async () => {
await expect(
twabDelegator.connect(stranger).fundDelegation(AddressZero, 0, amount),
Expand All @@ -467,12 +490,6 @@ describe('Test Set Name', () => {
twabDelegator.connect(stranger).fundDelegation(owner.address, 0, Zero),
).to.be.revertedWith('TWABDelegator/amount-gt-zero');
});

it('should fail to fund an inexistent delegation', async () => {
await expect(
twabDelegator.connect(stranger).fundDelegation(owner.address, 1, amount),
).to.be.revertedWith('TWABDelegator/not-a-contract');
});
});

describe('fundDelegationFromStake()', () => {
Expand Down Expand Up @@ -537,6 +554,28 @@ describe('Test Set Name', () => {
expect(await ticket.delegateOf(delegationAddress)).to.eq(firstDelegatee.address);
});

it('should transfer tickets to an inexistent delegation and then create it', async () => {
await twabDelegator.fundDelegationFromStake(owner.address, 1, amount);

const transaction = await twabDelegator.createDelegation(
owner.address,
1,
firstDelegatee.address,
MAX_EXPIRY,
);

delegationAddress = await getDelegationAddress(transaction);

const firstDelegateeAccountDetails = await ticket.getAccountDetails(firstDelegatee.address);
expect(firstDelegateeAccountDetails.balance).to.eq(amount);

expect(await twabDelegator.balanceOf(owner.address)).to.eq(Zero);

expect(await ticket.balanceOf(twabDelegator.address)).to.eq(Zero);
expect(await ticket.balanceOf(delegationAddress)).to.eq(amount);
expect(await ticket.delegateOf(delegationAddress)).to.eq(firstDelegatee.address);
});

it('should fail to transfer tickets to a delegation if delegator passed is not a delegator', async () => {
await expect(
twabDelegator.fundDelegationFromStake(stranger.address, 0, amount),
Expand All @@ -554,12 +593,6 @@ describe('Test Set Name', () => {
twabDelegator.fundDelegationFromStake(owner.address, 0, amount.mul(2)),
).to.be.revertedWith('ERC20: burn amount exceeds balance');
});

it('should fail to transfer tickets to an inexistent delegation', async () => {
await expect(
twabDelegator.fundDelegationFromStake(owner.address, 1, amount),
).to.be.revertedWith('TWABDelegator/not-a-contract');
});
});

describe('withdrawDelegationToStake()', () => {
Expand Down

0 comments on commit 0da337d

Please sign in to comment.