From 5e3eeed10f7cd43d5c8be516e532981dc2852211 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Tue, 25 Jun 2019 23:27:47 -0700 Subject: [PATCH] more work on simulator --- contracts/staking/test/rewards_test.ts | 15 ++++++++------- contracts/staking/test/utils/Simulation.ts | 20 ++++++++++++++++++-- contracts/staking/test/utils/types.ts | 1 + 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/contracts/staking/test/rewards_test.ts b/contracts/staking/test/rewards_test.ts index fe404f79f5..51af08b64b 100644 --- a/contracts/staking/test/rewards_test.ts +++ b/contracts/staking/test/rewards_test.ts @@ -849,15 +849,17 @@ describe.only('Rewards', () => { new BigNumber('20.31028'), // 20.31028447343014834523983759032242063760612769662934308289 ], expectedPayoutByPoolOperator: [ - + new BigNumber('1.85514'), // 0.39 * 4.75677 + new BigNumber('9.60597'), // 0.59 * 16.28130 + new BigNumber('8.73342') // 0.43 * 20.31028 ], expectedMembersPayoutByPool: [ - new BigNumber('2.9016297'), // (1 - 0.39) * 4.75677 - new BigNumber('6.675333'), // (1 - 0.59) * 16.28130 - new BigNumber('11.5768596'), // (1 - 0.43) * 20.31028 + new BigNumber('2.90163'), // (1 - 0.39) * 4.75677 + new BigNumber('6.67533'), // (1 - 0.59) * 16.28130 + new BigNumber('11.57686'), // (1 - 0.43) * 20.31028 ], expectedPayoutByDelegator: [ - new BigNumber('11.5768596'), // (1 - 0.43) * 20.31028 + new BigNumber('11.57686'), // (1 - 0.43) * 20.31028 new BigNumber(0), new BigNumber(0), ], @@ -888,9 +890,8 @@ describe.only('Rewards', () => { ///// 7 CHECK PROFITS ///// // the expected payouts were computed by hand - + /* - /* ///// 10 CHECK DELEGATOR PAYOUT BY WITHDRAWING ///// { const poolPayoutById = await Promise.all([ diff --git a/contracts/staking/test/utils/Simulation.ts b/contracts/staking/test/utils/Simulation.ts index 6195e2c861..63fc9592a1 100644 --- a/contracts/staking/test/utils/Simulation.ts +++ b/contracts/staking/test/utils/Simulation.ts @@ -49,8 +49,12 @@ export class Simulation { } await this._setupDelegatorsAsync(this._p); await this._stakingWrapper.skipToNextEpochAsync(); - // everyone has been paid out. check balances. + // everyone has been paid out into the vault. check balances. await this._assertVaultBalancesAsync(this._p); + //await this._withdrawOperatorRewards(this._p); + //await this._withdrawDelegatorRewardsByUndelegating(this._p); + //OR + // await this._withdrawDelegatorRewardsWithoutUndelegating(this._p); } private async _setupPoolsAsync(p: SimulationParams): Promise { @@ -142,6 +146,8 @@ export class Simulation { private async _assertVaultBalancesAsync(p: SimulationParams): Promise { for (const i in _.range(p.numberOfPools)) { + // @TODO - we trim balances in here because payouts are accurate only to 5 decimal places. + // update once more accurate. // check pool balance in vault const poolId = this._poolIds[i]; const rewardVaultBalance = await this._stakingWrapper.rewardVaultBalanceOfAsync(poolId); @@ -149,7 +155,17 @@ export class Simulation { const expectedRewardBalance = p.expectedPayoutByPool[i]; expect(rewardVaultBalanceTrimmed, `expected balance in vault for pool with id ${poolId}`).to.be.bignumber.equal(expectedRewardBalance); // check operator's balance - const poolOperator = this._poolOperators[i]; + const poolOperatorVaultBalance = await this._stakingWrapper.getRewardBalanceOfOperatorAsync(poolId); + const poolOperatorVaultBalanceTrimmed = this._stakingWrapper.trimFloat(this._stakingWrapper.toFloatingPoint(poolOperatorVaultBalance, 18), 5); + const expectedPoolOperatorVaultBalance = p.expectedPayoutByPoolOperator[i]; + expect(poolOperatorVaultBalanceTrimmed, `operator balance in vault for pool with id ${poolId}`).to.be.bignumber.equal(expectedPoolOperatorVaultBalance); + // check balance of pool members + const membersVaultBalance = await this._stakingWrapper.getRewardBalanceOfPoolAsync(poolId); + const membersVaultBalanceTrimmed = this._stakingWrapper.trimFloat(this._stakingWrapper.toFloatingPoint(membersVaultBalance, 18), 5); + const expectedMembersVaultBalance = p.expectedMembersPayoutByPool[i]; + expect(membersVaultBalanceTrimmed, `members balance in vault for pool with id ${poolId}`).to.be.bignumber.equal(expectedMembersVaultBalance); + // compute balance of each member + } } } \ No newline at end of file diff --git a/contracts/staking/test/utils/types.ts b/contracts/staking/test/utils/types.ts index cc18bb3af3..cab8421fd1 100644 --- a/contracts/staking/test/utils/types.ts +++ b/contracts/staking/test/utils/types.ts @@ -42,6 +42,7 @@ export interface SimulationParams { expectedFeesByPool: BigNumber[], expectedPayoutByPool: BigNumber[], expectedPayoutByPoolOperator: BigNumber[], + expectedMembersPayoutByPool: BigNumber[], expectedPayoutByDelegator: BigNumber[], exchangeAddress: string, delegateInNextEpoch: Boolean,