Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
asselstine committed Oct 6, 2021
1 parent 2a9d203 commit ff7e8b8
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 57 deletions.
4 changes: 2 additions & 2 deletions contracts/DrawBeacon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ contract DrawBeacon is IDrawBeacon, Ownable {
}

/// @inheritdoc IDrawBeacon
function calculateNextBeaconPeriodStartTime(uint256 _currentTime)
function calculateNextBeaconPeriodStartTime(uint256 __currentTime)
external
view
override
Expand All @@ -201,7 +201,7 @@ contract DrawBeacon is IDrawBeacon, Ownable {
_calculateNextBeaconPeriodStartTime(
beaconPeriodStartedAt,
beaconPeriodSeconds,
uint64(_currentTime)
uint64(__currentTime)
);
}

Expand Down
10 changes: 4 additions & 6 deletions contracts/DrawCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,10 @@ contract DrawCalculator is IDrawCalculator, Ownable {
// generate timestamps with draw cutoff offsets included
for (uint32 i = 0; i < _draws.length; i++) {
unchecked {
_timestampsWithStartCutoffTimes[i] = (
_draws[i].timestamp - _prizeDistributions[i].startTimestampOffset
);
_timestampsWithEndCutoffTimes[i] = (
_draws[i].timestamp - _prizeDistributions[i].endTimestampOffset
);
_timestampsWithStartCutoffTimes[i] =
_draws[i].timestamp - _prizeDistributions[i].startTimestampOffset;
_timestampsWithEndCutoffTimes[i] =
_draws[i].timestamp - _prizeDistributions[i].endTimestampOffset;
}
}

Expand Down
4 changes: 1 addition & 3 deletions contracts/libraries/OverflowSafeComparatorLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

pragma solidity 0.8.6;

import "hardhat/console.sol";

/// @title OverflowSafeComparatorLib library to share comparator functions between contracts
/// @dev Code taken from Uniswap V3 Oracle.sol: https://github.com/Uniswap/v3-core/blob/3e88af408132fc957e3e406f65a0ce2b1ca06c3d/contracts/libraries/Oracle.sol
/// @author PoolTogether Inc.
Expand Down Expand Up @@ -38,7 +36,7 @@ library OverflowSafeComparatorLib {
uint32 _a,
uint32 _b,
uint32 _timestamp
) internal view returns (bool) {
) internal pure returns (bool) {

// No need to adjust if there hasn't been an overflow
if (_a <= _timestamp && _b <= _timestamp) return _a <= _b;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract OverflowSafeComparatorLibHarness {
uint32 _a,
uint32 _b,
uint32 _timestamp
) external view returns (bool) {
) external pure returns (bool) {
return _a.lte(_b, _timestamp);
}

Expand Down
96 changes: 51 additions & 45 deletions test/Ticket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async function printTwabs(
debugLog(`Twab ${index} { amount: ${twab.amount}, timestamp: ${twab.timestamp}}`);
});

return twabs
return twabs;
}

describe('Ticket', () => {
Expand All @@ -84,10 +84,10 @@ describe('Ticket', () => {
);

// delegate for each of the users
await ticket.delegate(wallet1.address)
await ticket.connect(wallet2).delegate(wallet2.address)
await ticket.connect(wallet3).delegate(wallet3.address)
await ticket.connect(wallet4).delegate(wallet4.address)
await ticket.delegate(wallet1.address);
await ticket.connect(wallet2).delegate(wallet2.address);
await ticket.connect(wallet3).delegate(wallet3.address);
await ticket.connect(wallet4).delegate(wallet4.address);
});

describe('constructor()', () => {
Expand All @@ -102,7 +102,7 @@ describe('Ticket', () => {
expect(await ticket.name()).to.equal(ticketName);
expect(await ticket.symbol()).to.equal(ticketSymbol);
expect(await ticket.decimals()).to.equal(ticketDecimals);
expect(await ticket.controller()).to.equal(wallet1.address)
expect(await ticket.controller()).to.equal(wallet1.address);
});

it('should fail if token decimal is not greater than 0', async () => {
Expand Down Expand Up @@ -345,13 +345,13 @@ describe('Ticket', () => {
const twabs = await printTwabs(ticket, wallet1, debug);

const matchingTwabs = twabs.reduce((all: any, twab: any) => {
debug(`TWAB timestamp ${twab.timestamp}, timestamp: ${timestamp}`)
debug(twab)
debug(`TWAB timestamp ${twab.timestamp}, timestamp: ${timestamp}`);
debug(twab);
if (twab.timestamp.toString() == timestamp.toString()) {
all.push(twab)
all.push(twab);
}
return all
}, [])
return all;
}, []);

expect(matchingTwabs.length).to.equal(1);
expect(await ticket.totalSupply()).to.equal(mintAmount.mul(2));
Expand Down Expand Up @@ -865,9 +865,7 @@ describe('Ticket', () => {
await ticket.mint(wallet1.address, toWei('100'));
await ticket.delegate(wallet2.address);

await expect(
ticket.delegate(wallet2.address)
).to.not.emit(ticket, 'Delegated')
await expect(ticket.delegate(wallet2.address)).to.not.emit(ticket, 'Delegated');
});

it('should allow the delegate to be reset by passing zero', async () => {
Expand Down Expand Up @@ -942,54 +940,62 @@ describe('Ticket', () => {
it('should allow somone to delegate with a signature', async () => {
// @ts-ignore
const { user, delegate, nonce, deadline, v, r, s } = await delegateSignature({
ticket, userWallet: wallet1, delegate: wallet2.address
})
ticket,
userWallet: wallet1,
delegate: wallet2.address,
});

await ticket.connect(wallet3).delegateWithSignature(user, delegate, deadline, v, r, s)
await ticket.connect(wallet3).delegateWithSignature(user, delegate, deadline, v, r, s);

expect(await ticket.delegateOf(wallet1.address)).to.equal(wallet2.address)
})
})
expect(await ticket.delegateOf(wallet1.address)).to.equal(wallet2.address);
});
});

describe('controllerDelegateFor', () => {
it('should allow the controller to delegate for a user', async () => {
await ticket.controllerDelegateFor(wallet2.address, wallet3.address)
await ticket.controllerDelegateFor(wallet2.address, wallet3.address);

expect(await ticket.delegateOf(wallet2.address)).to.equal(wallet3.address)
})
expect(await ticket.delegateOf(wallet2.address)).to.equal(wallet3.address);
});

it('should not allow anyone else to delegate', async () => {
await expect(
ticket.connect(wallet2).controllerDelegateFor(wallet1.address, wallet3.address)
).to.be.revertedWith('ControlledToken/only-controller')

})
})
ticket.connect(wallet2).controllerDelegateFor(wallet1.address, wallet3.address),
).to.be.revertedWith('ControlledToken/only-controller');
});
});

context('when the timestamp overflows', () => {

let overflowMintTimestamp: number
let overflowMintTimestamp: number;

beforeEach(async () => {
await ticket.mint(wallet1.address, toWei('100'))
const timestamp = (await ethers.provider.getBlock('latest')).timestamp
const timeUntilOverflow = (2**32 - timestamp)
await increaseTime(timeUntilOverflow)
await ticket.mint(wallet1.address, toWei('100'))
overflowMintTimestamp = (await ethers.provider.getBlock('latest')).timestamp
await increaseTime(100)
})
await ticket.mint(wallet1.address, toWei('100'));
const timestamp = (await ethers.provider.getBlock('latest')).timestamp;
const timeUntilOverflow = 2 ** 32 - timestamp;
await increaseTime(timeUntilOverflow);
await ticket.mint(wallet1.address, toWei('100'));
overflowMintTimestamp = (await ethers.provider.getBlock('latest')).timestamp;
await increaseTime(100);
});

describe('getAverageBalanceBetween()', () => {
it('should function across overflow boundary', async () => {
expect(await ticket.getAverageBalanceBetween(wallet1.address, overflowMintTimestamp-100, overflowMintTimestamp+100)).to.equal(toWei('150'))
})
})
expect(
await ticket.getAverageBalanceBetween(
wallet1.address,
overflowMintTimestamp - 100,
overflowMintTimestamp + 100,
),
).to.equal(toWei('150'));
});
});

describe('getBalanceAt', () => {
it('should function across overflow boundary', async () => {
expect(await ticket.getBalanceAt(wallet1.address, overflowMintTimestamp)).to.equal(toWei('200'))
})
})
})
expect(await ticket.getBalanceAt(wallet1.address, overflowMintTimestamp)).to.equal(
toWei('200'),
);
});
});
});
});

0 comments on commit ff7e8b8

Please sign in to comment.