Tests are passing and ran linter
This commit is contained in:
@@ -162,29 +162,37 @@ contract MixinCumulativeRewards is
|
|||||||
function _trySetMostRecentCumulativeRewardEpoch(bytes32 poolId, uint256 epoch)
|
function _trySetMostRecentCumulativeRewardEpoch(bytes32 poolId, uint256 epoch)
|
||||||
internal
|
internal
|
||||||
{
|
{
|
||||||
// load the current value, sanity check that we're not trying to go back in time
|
|
||||||
uint256 currentMostRecentEpoch = cumulativeRewardsByPoolLastStored[poolId];
|
|
||||||
assert(epoch >= currentMostRecentEpoch);
|
|
||||||
|
|
||||||
// check if we should do any work
|
// check if we should do any work
|
||||||
|
uint256 currentMostRecentEpoch = cumulativeRewardsByPoolLastStored[poolId];
|
||||||
if (epoch == currentMostRecentEpoch) {
|
if (epoch == currentMostRecentEpoch) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update state to reflect the most recent cumulative reward
|
// update state to reflect the most recent cumulative reward
|
||||||
_forceSetMostRecentCumulativeRewardEpoch(poolId, epoch);
|
_forceSetMostRecentCumulativeRewardEpoch(
|
||||||
|
poolId,
|
||||||
// unset the previous most recent reward, if it is no longer needed
|
currentMostRecentEpoch,
|
||||||
_tryUnsetCumulativeReward(poolId, currentMostRecentEpoch);
|
epoch
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @dev Forcefully sets the epoch of the most recent cumulative reward.
|
/// @dev Forcefully sets the epoch of the most recent cumulative reward.
|
||||||
/// @param poolId Unique Id of pool.
|
/// @param poolId Unique Id of pool.
|
||||||
/// @param epoch of the most recent cumulative reward.
|
/// @param currentMostRecentEpoch of the most recent cumulative reward.
|
||||||
function _forceSetMostRecentCumulativeRewardEpoch(bytes32 poolId, uint256 epoch)
|
/// @param newMostRecentEpoch of the new most recent cumulative reward.
|
||||||
|
function _forceSetMostRecentCumulativeRewardEpoch(
|
||||||
|
bytes32 poolId,
|
||||||
|
uint256 currentMostRecentEpoch,
|
||||||
|
uint256 newMostRecentEpoch
|
||||||
|
)
|
||||||
internal
|
internal
|
||||||
{
|
{
|
||||||
cumulativeRewardsByPoolLastStored[poolId] = epoch;
|
// sanity check that we're not trying to go back in time
|
||||||
|
assert(newMostRecentEpoch >= currentMostRecentEpoch);
|
||||||
|
cumulativeRewardsByPoolLastStored[poolId] = newMostRecentEpoch;
|
||||||
|
|
||||||
|
// unset the previous most recent reward, if it is no longer needed
|
||||||
|
_tryUnsetCumulativeReward(poolId, currentMostRecentEpoch);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @dev Adds a dependency on a cumulative reward for a given epoch.
|
/// @dev Adds a dependency on a cumulative reward for a given epoch.
|
||||||
@@ -209,8 +217,7 @@ contract MixinCumulativeRewards is
|
|||||||
} else {
|
} else {
|
||||||
_removeDependencyOnCumulativeReward(
|
_removeDependencyOnCumulativeReward(
|
||||||
poolId,
|
poolId,
|
||||||
epoch,
|
epoch
|
||||||
mostRecentCumulativeRewardInfo.cumulativeRewardEpoch
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -240,11 +247,9 @@ contract MixinCumulativeRewards is
|
|||||||
/// @dev Removes a dependency on a cumulative reward for a given epoch.
|
/// @dev Removes a dependency on a cumulative reward for a given epoch.
|
||||||
/// @param poolId Unique Id of pool.
|
/// @param poolId Unique Id of pool.
|
||||||
/// @param epoch to remove dependency from.
|
/// @param epoch to remove dependency from.
|
||||||
/// @param mostRecentCumulativeRewardEpoch Epoch of the most recent cumulative reward.
|
|
||||||
function _removeDependencyOnCumulativeReward(
|
function _removeDependencyOnCumulativeReward(
|
||||||
bytes32 poolId,
|
bytes32 poolId,
|
||||||
uint256 epoch,
|
uint256 epoch
|
||||||
uint256 mostRecentCumulativeRewardEpoch
|
|
||||||
)
|
)
|
||||||
internal
|
internal
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ contract MixinStakingPoolRewards is
|
|||||||
);
|
);
|
||||||
|
|
||||||
// store cumulative rewards and set most recent
|
// store cumulative rewards and set most recent
|
||||||
_trySetCumulativeReward(
|
_forceSetCumulativeReward(
|
||||||
poolId,
|
poolId,
|
||||||
epoch,
|
epoch,
|
||||||
IStructs.Fraction({
|
IStructs.Fraction({
|
||||||
|
|||||||
@@ -48,7 +48,11 @@ contract TestCumulativeRewardTracking is
|
|||||||
internal
|
internal
|
||||||
{
|
{
|
||||||
emit SetCumulativeReward(poolId, epoch);
|
emit SetCumulativeReward(poolId, epoch);
|
||||||
MixinCumulativeRewards._forceSetCumulativeReward(poolId, epoch, value);
|
MixinCumulativeRewards._forceSetCumulativeReward(
|
||||||
|
poolId,
|
||||||
|
epoch,
|
||||||
|
value
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _forceUnsetCumulativeReward(bytes32 poolId, uint256 epoch)
|
function _forceUnsetCumulativeReward(bytes32 poolId, uint256 epoch)
|
||||||
@@ -58,18 +62,26 @@ contract TestCumulativeRewardTracking is
|
|||||||
MixinCumulativeRewards._forceUnsetCumulativeReward(poolId, epoch);
|
MixinCumulativeRewards._forceUnsetCumulativeReward(poolId, epoch);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _forceSetMostRecentCumulativeRewardEpoch(bytes32 poolId, uint256 epoch)
|
function _forceSetMostRecentCumulativeRewardEpoch(
|
||||||
|
bytes32 poolId,
|
||||||
|
uint256 currentMostRecentEpoch,
|
||||||
|
uint256 newMostRecentEpoch
|
||||||
|
)
|
||||||
internal
|
internal
|
||||||
{
|
{
|
||||||
emit SetMostRecentCumulativeReward(poolId, epoch);
|
emit SetMostRecentCumulativeReward(poolId, newMostRecentEpoch);
|
||||||
MixinCumulativeRewards._forceSetMostRecentCumulativeRewardEpoch(poolId, epoch);
|
MixinCumulativeRewards._forceSetMostRecentCumulativeRewardEpoch(
|
||||||
|
poolId,
|
||||||
|
currentMostRecentEpoch,
|
||||||
|
newMostRecentEpoch
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _assertMixinParamsBeforeInit()
|
function _assertMixinParamsBeforeInit()
|
||||||
internal
|
internal
|
||||||
{}
|
{} // solhint-disable-line no-empty-blocks
|
||||||
|
|
||||||
function _assertMixinSchedulerBeforeInit()
|
function _assertMixinSchedulerBeforeInit()
|
||||||
internal
|
internal
|
||||||
{}
|
{} // solhint-disable-line no-empty-blocks
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,11 +35,7 @@ blockchainTests.resets('Cumulative Reward Tracking', env => {
|
|||||||
|
|
||||||
describe('Tracking Cumulative Rewards (CR)', () => {
|
describe('Tracking Cumulative Rewards (CR)', () => {
|
||||||
it('should set CR hen a pool is created is epoch 0', async () => {
|
it('should set CR hen a pool is created is epoch 0', async () => {
|
||||||
await simulation.runTestAsync(
|
await simulation.runTestAsync([], [TestAction.CreatePool], [{ event: 'SetCumulativeReward', epoch: 0 }]);
|
||||||
[],
|
|
||||||
[TestAction.CreatePool],
|
|
||||||
[{ event: 'SetCumulativeReward', epoch: 0 }],
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
it('should set CR and Most Recent CR when a pool is created in epoch >0', async () => {
|
it('should set CR and Most Recent CR when a pool is created in epoch >0', async () => {
|
||||||
await simulation.runTestAsync(
|
await simulation.runTestAsync(
|
||||||
|
|||||||
@@ -37,20 +37,20 @@ export class CumulativeRewardTrackingSimulation {
|
|||||||
private static _extractTestLogs(txReceiptLogs: DecodedLogArgs[]): TestLog[] {
|
private static _extractTestLogs(txReceiptLogs: DecodedLogArgs[]): TestLog[] {
|
||||||
const logs = [];
|
const logs = [];
|
||||||
for (const log of txReceiptLogs) {
|
for (const log of txReceiptLogs) {
|
||||||
if ((log as DecodedLogArgs).event === 'SetMostRecentCumulativeReward') {
|
if (log.event === 'SetMostRecentCumulativeReward') {
|
||||||
logs.push({
|
logs.push({
|
||||||
event: 'SetMostRecentCumulativeReward',
|
event: 'SetMostRecentCumulativeReward',
|
||||||
epoch: (log as DecodedLogArgs).args.epoch.toNumber(),
|
epoch: log.args.epoch.toNumber(),
|
||||||
});
|
});
|
||||||
} else if ((log as DecodedLogArgs).event === 'SetCumulativeReward') {
|
} else if (log.event === 'SetCumulativeReward') {
|
||||||
logs.push({
|
logs.push({
|
||||||
event: 'SetCumulativeReward',
|
event: 'SetCumulativeReward',
|
||||||
epoch: (log as DecodedLogArgs).args.epoch.toNumber(),
|
epoch: log.args.epoch.toNumber(),
|
||||||
});
|
});
|
||||||
} else if ((log as DecodedLogArgs).event === 'UnsetCumulativeReward') {
|
} else if (log.event === 'UnsetCumulativeReward') {
|
||||||
logs.push({
|
logs.push({
|
||||||
event: 'UnsetCumulativeReward',
|
event: 'UnsetCumulativeReward',
|
||||||
epoch: (log as DecodedLogArgs).args.epoch.toNumber(),
|
epoch: log.args.epoch.toNumber(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,6 +159,7 @@ export class CumulativeRewardTrackingSimulation {
|
|||||||
{ from: this._poolOperator },
|
{ from: this._poolOperator },
|
||||||
);
|
);
|
||||||
const createStakingPoolLog = txReceipt.logs[0];
|
const createStakingPoolLog = txReceipt.logs[0];
|
||||||
|
// tslint:disable-next-line no-unnecessary-type-assertion
|
||||||
this._poolId = (createStakingPoolLog as DecodedLogArgs).args.poolId;
|
this._poolId = (createStakingPoolLog as DecodedLogArgs).args.poolId;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user