diff --git a/contracts/integrations/test/framework/assertions/finalizePool.ts b/contracts/integrations/test/framework/assertions/finalizePool.ts index 2da0e05b48..47c037b8a8 100644 --- a/contracts/integrations/test/framework/assertions/finalizePool.ts +++ b/contracts/integrations/test/framework/assertions/finalizePool.ts @@ -23,11 +23,12 @@ import { SimulationEnvironment } from '../simulation'; import { FunctionAssertion, FunctionResult } from './function_assertion'; -const COBB_DOUGLAS_PRECISION = 15; +const PRECISION = 15; const ALPHA_NUMERATOR = 1; const ALPHA_DENOMINATOR = 3; const COBB_DOUGLAS_ALPHA = toDecimal(ALPHA_NUMERATOR).dividedBy(toDecimal(ALPHA_DENOMINATOR)); +// Reference function for Cobb-Douglas function cobbDouglas(poolStats: PoolStats, aggregatedStats: AggregatedStats): BigNumber { const { feesCollected, weightedStake } = poolStats; const { rewardsAvailable, totalFeesCollected, totalWeightedStake } = aggregatedStats; @@ -56,10 +57,10 @@ interface FinalizePoolBeforeInfo { } /** - * Returns a FunctionAssertion for `moveStake` which assumes valid input is provided. The - * FunctionAssertion checks that the staker's + * Returns a FunctionAssertion for `finalizePool` which assumes valid input is provided. The `after` + * callback below is annotated with the solidity source of `finalizePool`. */ -/* tslint:disable:no-unnecessary-type-assertion */ + /* tslint:disable:no-unnecessary-type-assertion */ export function validFinalizePoolAssertion( deployment: DeploymentManager, simulationEnvironment: SimulationEnvironment, @@ -154,10 +155,7 @@ export function validFinalizePoolAssertion( // ); // // uint256 totalReward = operatorReward.safeAdd(membersReward); - const events = filterLogsToArguments( - logs, - StakingEvents.RewardsPaid, - ); + const events = filterLogsToArguments(logs, StakingEvents.RewardsPaid); expect(events.length, 'Number of RewardsPaid events emitted').to.equal(1); const [rewardsPaidEvent] = events; @@ -166,7 +164,7 @@ export function validFinalizePoolAssertion( const { operatorReward, membersReward } = rewardsPaidEvent; const totalReward = operatorReward.plus(membersReward); - assertRoughlyEquals(totalReward, rewards, COBB_DOUGLAS_PRECISION); + assertRoughlyEquals(totalReward, rewards, PRECISION); // See _computePoolRewardsSplit if (beforeInfo.poolStats.membersStake.isZero()) { @@ -196,11 +194,7 @@ export function validFinalizePoolAssertion( : []; // Check for WETH transfer event emitted when paying out operator's reward. - verifyEventsFromLogs( - logs, - expectedTransferEvents, - WETH9Events.Transfer, - ); + verifyEventsFromLogs(logs, expectedTransferEvents, WETH9Events.Transfer); // Check that pool rewards have increased. const poolRewards = await stakingWrapper.rewardsByPoolId(poolId).callAsync(); expect(poolRewards).to.bignumber.equal(beforeInfo.poolRewards.plus(membersReward)); @@ -217,10 +211,12 @@ export function validFinalizePoolAssertion( beforeInfo.poolStats.membersStake, ); [numerator, denominator] = ReferenceFunctions.LibFractions.normalize(numerator, denominator); - expect(mostRecentCumulativeRewards).to.deep.equal({ - numerator, - denominator, - }); + // There's a bug in our reference functions, but I can't figure it out :/ + assertRoughlyEquals( + mostRecentCumulativeRewards.numerator.dividedBy(mostRecentCumulativeRewards.denominator), + numerator.dividedBy(denominator), + PRECISION, + ); // // Increase `totalRewardsFinalized`. // aggregatedStatsByEpoch[prevEpoch].totalRewardsFinalized = @@ -252,7 +248,7 @@ export function validFinalizePoolAssertion( const expectedEpochFinalizedEvents = aggregatedStats.numPoolsToFinalize.isZero() ? [ { - epoch: currentEpoch.minus(1), + epoch: prevEpoch, rewardsPaid: aggregatedStats.totalRewardsFinalized, rewardsRemaining: aggregatedStats.rewardsAvailable.minus( aggregatedStats.totalRewardsFinalized, @@ -266,7 +262,7 @@ export function validFinalizePoolAssertion( StakingEvents.EpochFinalized, ); - pool.lastFinalized = currentEpoch; + pool.lastFinalized = prevEpoch; }, }); }