Skip to content

Commit

Permalink
Merge dcb56eb into 4c9f635
Browse files Browse the repository at this point in the history
  • Loading branch information
PierrickGT committed Oct 5, 2021
2 parents 4c9f635 + dcb56eb commit 6903be6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions contracts/Ticket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ contract Ticket is ControlledToken, ITicket {
uint224 balance = uint224(_balanceOf(msg.sender));
address currentDelegate = delegates[msg.sender];

require(currentDelegate != to, "Ticket/delegate-already-set");

if (currentDelegate != address(0)) {
_decreaseUserTwab(msg.sender, currentDelegate, balance);
} else {
Expand Down
3 changes: 2 additions & 1 deletion contracts/interfaces/ITicket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ interface ITicket {
* @dev Transfers (including mints) trigger the storage of a TWAB in delegatee(s) account, instead of the
targetted sender and/or recipient address(s).
* @dev "to" reset the delegatee use zero address (0x000.000)
* @param to Receipient of delegated TWAB
* @dev Current delegate address should be different from the new delegate address `to`.
* @param to Receipient of delegated TWAB.
*/
function delegate(address to) external;

Expand Down
13 changes: 7 additions & 6 deletions test/Ticket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -855,17 +855,18 @@ describe('Ticket', () => {
expect(await ticket.getBalanceAt(wallet2.address, timestamp)).to.equal(toWei('100'));
});

it('should not decrease user balance if address zero is mistakenly passed', async () => {
it('should revert if delegate address has already been set to passed address', async () => {
await ticket.mint(wallet1.address, toWei('100'));
await ticket.delegate(wallet2.address);

await expect(ticket.delegate(AddressZero))
.to.emit(ticket, 'Delegated')
.withArgs(wallet1.address, AddressZero);
await expect(ticket.delegate(wallet2.address)).to.be.revertedWith(
'Ticket/delegate-already-set',
);

const timestamp = (await provider.getBlock('latest')).timestamp;

expect(await ticket.delegateOf(wallet1.address)).to.equal(AddressZero);
expect(await ticket.getBalanceAt(wallet1.address, timestamp)).to.equal(toWei('100'));
expect(await ticket.delegateOf(wallet1.address)).to.equal(wallet2.address);
expect(await ticket.getBalanceAt(wallet2.address, timestamp)).to.equal(toWei('100'));
});

it('should clear old delegates if any', async () => {
Expand Down

0 comments on commit 6903be6

Please sign in to comment.