Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Fix 100% operator share #2333

Merged
merged 4 commits into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ contract MixinStakingPool is
poolId,
newOperatorShare
));
} else if (newOperatorShare >= currentOperatorShare) {
// new share must be less than the current share
} else if (newOperatorShare > currentOperatorShare) {
// new share must be less than or equal to the current share
LibRichErrors.rrevert(LibStakingRichErrors.OperatorShareError(
LibStakingRichErrors.OperatorShareErrorCodes.CanOnlyDecreaseOperatorShare,
poolId,
Expand Down
9 changes: 2 additions & 7 deletions contracts/staking/test/pools_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ blockchainTests('Staking Pool Management', env => {
// decrease operator share
await poolOperator.decreaseStakingPoolOperatorShareAsync(poolId, increasedOperatorShare, revertError);
});
it('Should fail if operator calls decreaseStakingPoolOperatorShare but newOperatorShare == oldOperatorShare', async () => {
it('Should be successful if operator calls decreaseStakingPoolOperatorShare and newOperatorShare == oldOperatorShare', async () => {
// test parameters
const operatorAddress = users[0];
const operatorShare = (39 / 100) * PPM_DENOMINATOR;
Expand All @@ -184,13 +184,8 @@ blockchainTests('Staking Pool Management', env => {
const poolId = await poolOperator.createStakingPoolAsync(operatorShare, false);
expect(poolId).to.be.equal(stakingConstants.INITIAL_POOL_ID);

const revertError = new StakingRevertErrors.OperatorShareError(
StakingRevertErrors.OperatorShareErrorCodes.CanOnlyDecreaseOperatorShare,
poolId,
operatorShare,
);
// decrease operator share
await poolOperator.decreaseStakingPoolOperatorShareAsync(poolId, operatorShare, revertError);
await poolOperator.decreaseStakingPoolOperatorShareAsync(poolId, operatorShare);
});
it('should fail to decrease operator share if not called by operator', async () => {
// test parameters
Expand Down
29 changes: 15 additions & 14 deletions contracts/staking/test/unit_tests/staking_pool_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ blockchainTests.resets('MixinStakingPool unit tests', env => {
expect(pool.operator).to.eq(operator);
expect(pool.operatorShare).to.bignumber.eq(operatorShare);
});
it('records pool details when operator share is 100%', async () => {
const operatorShare = constants.PPM_100_PERCENT;
await testContract.createStakingPool.awaitTransactionSuccessAsync(operatorShare, false, { from: operator });
const pool = await testContract.getStakingPool.callAsync(nextPoolId);
expect(pool.operator).to.eq(operator);
expect(pool.operatorShare).to.bignumber.eq(operatorShare);
});
it('returns the next pool ID', async () => {
const poolId = await testContract.createStakingPool.callAsync(randomOperatorShare(), false, {
from: operator,
Expand Down Expand Up @@ -239,20 +246,6 @@ blockchainTests.resets('MixinStakingPool unit tests', env => {
const expectedError = new StakingRevertErrors.OnlyCallableByPoolOperatorError(maker, poolId);
return expect(tx).to.revertWith(expectedError);
});
it('fails if operator share is equal to current', async () => {
const { poolId, operatorShare } = await createPoolAsync();
const tx = testContract.decreaseStakingPoolOperatorShare.awaitTransactionSuccessAsync(
poolId,
operatorShare,
{ from: operator },
);
const expectedError = new StakingRevertErrors.OperatorShareError(
StakingRevertErrors.OperatorShareErrorCodes.CanOnlyDecreaseOperatorShare,
poolId,
operatorShare,
);
return expect(tx).to.revertWith(expectedError);
});
it('fails if operator share is greater than current', async () => {
const { poolId, operatorShare } = await createPoolAsync();
const tx = testContract.decreaseStakingPoolOperatorShare.awaitTransactionSuccessAsync(
Expand Down Expand Up @@ -291,6 +284,14 @@ blockchainTests.resets('MixinStakingPool unit tests', env => {
const pool = await testContract.getStakingPool.callAsync(poolId);
expect(pool.operatorShare).to.bignumber.eq(operatorShare - 1);
});
it('does not modify operator share if equal to current', async () => {
const { poolId, operatorShare } = await createPoolAsync();
await testContract.decreaseStakingPoolOperatorShare.awaitTransactionSuccessAsync(poolId, operatorShare, {
from: operator,
});
const pool = await testContract.getStakingPool.callAsync(poolId);
expect(pool.operatorShare).to.bignumber.eq(operatorShare);
});
it('does not modify operator', async () => {
const { poolId, operatorShare } = await createPoolAsync();
await testContract.decreaseStakingPoolOperatorShare.awaitTransactionSuccessAsync(
Expand Down