Remove Time.Delay *At functions (#4606)
Co-authored-by: Francisco Giordano <fg@frang.io>
This commit is contained in:
@ -54,8 +54,8 @@ library Time {
|
|||||||
* 0xAAAAAAAAAAAABBBBBBBBCCCCCCCC
|
* 0xAAAAAAAAAAAABBBBBBBBCCCCCCCC
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* NOTE: The {get} and {update} function operate using timestamps. Block number based delays should use the
|
* NOTE: The {get} and {withUpdate} functions operate using timestamps. Block number based delays are not currently
|
||||||
* {getAt} and {withUpdateAt} variants of these functions.
|
* supported.
|
||||||
*/
|
*/
|
||||||
type Delay is uint112;
|
type Delay is uint112;
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ library Time {
|
|||||||
* @dev Get the value at a given timepoint plus the pending value and effect timepoint if there is a scheduled
|
* @dev Get the value at a given timepoint plus the pending value and effect timepoint if there is a scheduled
|
||||||
* change after this timepoint. If the effect timepoint is 0, then the pending value should not be considered.
|
* change after this timepoint. If the effect timepoint is 0, then the pending value should not be considered.
|
||||||
*/
|
*/
|
||||||
function getFullAt(Delay self, uint48 timepoint) internal pure returns (uint32, uint32, uint48) {
|
function _getFullAt(Delay self, uint48 timepoint) private pure returns (uint32, uint32, uint48) {
|
||||||
(uint32 valueBefore, uint32 valueAfter, uint48 effect) = self.unpack();
|
(uint32 valueBefore, uint32 valueAfter, uint48 effect) = self.unpack();
|
||||||
return effect <= timepoint ? (valueAfter, 0, 0) : (valueBefore, valueAfter, effect);
|
return effect <= timepoint ? (valueAfter, 0, 0) : (valueBefore, valueAfter, effect);
|
||||||
}
|
}
|
||||||
@ -80,22 +80,15 @@ library Time {
|
|||||||
* effect timepoint is 0, then the pending value should not be considered.
|
* effect timepoint is 0, then the pending value should not be considered.
|
||||||
*/
|
*/
|
||||||
function getFull(Delay self) internal view returns (uint32, uint32, uint48) {
|
function getFull(Delay self) internal view returns (uint32, uint32, uint48) {
|
||||||
return self.getFullAt(timestamp());
|
return _getFullAt(self, timestamp());
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Get the value the Delay will be at a given timepoint.
|
|
||||||
*/
|
|
||||||
function getAt(Delay self, uint48 timepoint) internal pure returns (uint32) {
|
|
||||||
(uint32 delay, , ) = getFullAt(self, timepoint);
|
|
||||||
return delay;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Get the current value.
|
* @dev Get the current value.
|
||||||
*/
|
*/
|
||||||
function get(Delay self) internal view returns (uint32) {
|
function get(Delay self) internal view returns (uint32) {
|
||||||
return self.getAt(timestamp());
|
(uint32 delay, , ) = self.getFull();
|
||||||
|
return delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -87,27 +87,6 @@ contract('Time', function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getAt & getFullAt', async function () {
|
|
||||||
const valueBefore = 24194n;
|
|
||||||
const valueAfter = 4214143n;
|
|
||||||
|
|
||||||
for (const timepoint of [...SOME_VALUES, MAX_UINT48])
|
|
||||||
for (const effect of effectSamplesForTimepoint(timepoint)) {
|
|
||||||
const isPast = effect <= timepoint;
|
|
||||||
|
|
||||||
const delay = packDelay({ valueBefore, valueAfter, effect });
|
|
||||||
|
|
||||||
expect(await this.mock.$getAt(delay, timepoint)).to.be.bignumber.equal(
|
|
||||||
String(isPast ? valueAfter : valueBefore),
|
|
||||||
);
|
|
||||||
|
|
||||||
const getFullAt = await this.mock.$getFullAt(delay, timepoint);
|
|
||||||
expect(getFullAt[0]).to.be.bignumber.equal(String(isPast ? valueAfter : valueBefore));
|
|
||||||
expect(getFullAt[1]).to.be.bignumber.equal(String(isPast ? 0n : valueAfter));
|
|
||||||
expect(getFullAt[2]).to.be.bignumber.equal(String(isPast ? 0n : effect));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('get & getFull', async function () {
|
it('get & getFull', async function () {
|
||||||
const timepoint = await clock.timestamp().then(BigInt);
|
const timepoint = await clock.timestamp().then(BigInt);
|
||||||
const valueBefore = 24194n;
|
const valueBefore = 24194n;
|
||||||
|
|||||||
Reference in New Issue
Block a user