Update OnlyCallableByPoolOperatorOrMakerError params and address PR feedback
This commit is contained in:
@@ -75,9 +75,9 @@ library LibStakingRichErrors {
|
||||
bytes4 internal constant INSUFFICIENT_BALANCE_ERROR_SELECTOR =
|
||||
0x84c8b7c9;
|
||||
|
||||
// bytes4(keccak256("OnlyCallableByPoolOperatorOrMakerError(address,address)"))
|
||||
// bytes4(keccak256("OnlyCallableByPoolOperatorOrMakerError(address,bytes32)"))
|
||||
bytes4 internal constant ONLY_CALLABLE_BY_POOL_OPERATOR_OR_MAKER_ERROR_SELECTOR =
|
||||
0x471c3580;
|
||||
0x7677eb13;
|
||||
|
||||
// bytes4(keccak256("MakerPoolAssignmentError(uint8,address,bytes32)"))
|
||||
bytes4 internal constant MAKER_POOL_ASSIGNMENT_ERROR_SELECTOR =
|
||||
@@ -215,7 +215,7 @@ library LibStakingRichErrors {
|
||||
|
||||
function OnlyCallableByPoolOperatorOrMakerError(
|
||||
address senderAddress,
|
||||
address operator
|
||||
bytes32 poolId
|
||||
)
|
||||
internal
|
||||
pure
|
||||
@@ -224,7 +224,7 @@ library LibStakingRichErrors {
|
||||
return abi.encodeWithSelector(
|
||||
ONLY_CALLABLE_BY_POOL_OPERATOR_OR_MAKER_ERROR_SELECTOR,
|
||||
senderAddress,
|
||||
operator
|
||||
poolId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ contract MixinStakingPool is
|
||||
LibRichErrors.rrevert(LibStakingRichErrors.MakerPoolAssignmentError(
|
||||
LibStakingRichErrors.MakerPoolAssignmentErrorCodes.MakerAddressAlreadyRegistered,
|
||||
makerAddress,
|
||||
getStakingPoolIdOfMaker(makerAddress)
|
||||
poolJoinStatus.poolId
|
||||
));
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ contract MixinStakingPool is
|
||||
LibRichErrors.rrevert(LibStakingRichErrors.MakerPoolAssignmentError(
|
||||
LibStakingRichErrors.MakerPoolAssignmentErrorCodes.MakerAddressAlreadyRegistered,
|
||||
makerAddress,
|
||||
getStakingPoolIdOfMaker(makerAddress)
|
||||
poolJoinStatus.poolId
|
||||
));
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ contract MixinStakingPool is
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.OnlyCallableByPoolOperatorOrMakerError(
|
||||
msg.sender,
|
||||
operator
|
||||
poolId
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ contract MixinStakingPoolRewards is
|
||||
}
|
||||
|
||||
if (membersReward > 0) {
|
||||
// Increment the balance of the pool
|
||||
// Increase the balance of the pool
|
||||
_increasePoolRewards(poolId, membersReward);
|
||||
|
||||
// Fetch the last epoch at which we stored an entry for this pool;
|
||||
@@ -292,7 +292,7 @@ contract MixinStakingPoolRewards is
|
||||
return;
|
||||
}
|
||||
|
||||
// Decrement the balance of the pool
|
||||
// Decrease the balance of the pool
|
||||
_decreasePoolRewards(poolId, balance);
|
||||
|
||||
// Withdraw the member's WETH balance
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import { chaiSetup, constants, getCodesizeFromArtifact } from '@0x/contracts-test-utils';
|
||||
import * as chai from 'chai';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
import { constants, expect, getCodesizeFromArtifact } from '@0x/contracts-test-utils';
|
||||
|
||||
import { artifacts } from '../src';
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@ blockchainTests('Staking Pool Management', env => {
|
||||
before(async () => {
|
||||
// create accounts
|
||||
accounts = await env.getAccountAddressesAsync();
|
||||
owner = accounts[0];
|
||||
users = accounts.slice(2);
|
||||
[owner, ...users] = accounts;
|
||||
// set up ERC20Wrapper
|
||||
erc20Wrapper = new ERC20Wrapper(env.provider, accounts, owner);
|
||||
// deploy staking contracts
|
||||
@@ -139,7 +138,7 @@ blockchainTests('Staking Pool Management', env => {
|
||||
await maker.addMakerToStakingPoolAsync(
|
||||
poolId,
|
||||
makerAddress,
|
||||
new StakingRevertErrors.OnlyCallableByPoolOperatorOrMakerError(makerAddress, operatorAddress),
|
||||
new StakingRevertErrors.OnlyCallableByPoolOperatorOrMakerError(makerAddress, poolId),
|
||||
);
|
||||
});
|
||||
it('should fail to add a maker to a pool if not called by operator/registered maker', async () => {
|
||||
@@ -159,7 +158,7 @@ blockchainTests('Staking Pool Management', env => {
|
||||
await maker2.addMakerToStakingPoolAsync(
|
||||
poolId,
|
||||
maker1Address,
|
||||
new StakingRevertErrors.OnlyCallableByPoolOperatorOrMakerError(maker2Address, operatorAddress),
|
||||
new StakingRevertErrors.OnlyCallableByPoolOperatorOrMakerError(maker2Address, poolId),
|
||||
);
|
||||
});
|
||||
it('Maker should successfully remove themselves from a pool', async () => {
|
||||
@@ -248,7 +247,7 @@ blockchainTests('Staking Pool Management', env => {
|
||||
await maker2.removeMakerFromStakingPoolAsync(
|
||||
poolId,
|
||||
maker1Address,
|
||||
new StakingRevertErrors.OnlyCallableByPoolOperatorOrMakerError(maker2Address, operatorAddress),
|
||||
new StakingRevertErrors.OnlyCallableByPoolOperatorOrMakerError(maker2Address, poolId),
|
||||
);
|
||||
});
|
||||
it('Should fail if maker already assigned to another pool tries to join', async () => {
|
||||
@@ -363,30 +362,6 @@ blockchainTests('Staking Pool Management', env => {
|
||||
// remove non-existent maker from pool
|
||||
await poolOperator.removeMakerFromStakingPoolAsync(poolId, makerAddress, revertError);
|
||||
});
|
||||
it('Should fail to add a maker when called by someone other than the pool operator', async () => {
|
||||
// test parameters
|
||||
const operatorAddress = users[0];
|
||||
const operatorShare = (39 / 100) * PPM_DENOMINATOR;
|
||||
const poolOperator = new PoolOperatorActor(operatorAddress, stakingApiWrapper);
|
||||
const makerAddress = users[1];
|
||||
const maker = new MakerActor(makerAddress, stakingApiWrapper);
|
||||
const notOperatorAddress = users[2];
|
||||
// create pool
|
||||
const poolId = await poolOperator.createStakingPoolAsync(operatorShare, true);
|
||||
expect(poolId).to.be.equal(stakingConstants.INITIAL_POOL_ID);
|
||||
// add maker to pool
|
||||
await maker.joinStakingPoolAsMakerAsync(poolId);
|
||||
const revertError = new StakingRevertErrors.OnlyCallableByPoolOperatorOrMakerError(
|
||||
notOperatorAddress,
|
||||
operatorAddress,
|
||||
);
|
||||
const tx = stakingApiWrapper.stakingContract.addMakerToStakingPool.awaitTransactionSuccessAsync(
|
||||
poolId,
|
||||
makerAddress,
|
||||
{ from: notOperatorAddress },
|
||||
);
|
||||
await expect(tx).to.revertWith(revertError);
|
||||
});
|
||||
it('Should fail to remove a maker when called by someone other than the pool operator or maker', async () => {
|
||||
// test parameters
|
||||
const operatorAddress = users[0];
|
||||
@@ -404,7 +379,7 @@ blockchainTests('Staking Pool Management', env => {
|
||||
// try to remove the maker address from an address other than the operator
|
||||
const revertError = new StakingRevertErrors.OnlyCallableByPoolOperatorOrMakerError(
|
||||
neitherOperatorNorMakerAddress,
|
||||
operatorAddress,
|
||||
poolId,
|
||||
);
|
||||
const tx = stakingApiWrapper.stakingContract.removeMakerFromStakingPool.awaitTransactionSuccessAsync(
|
||||
poolId,
|
||||
@@ -530,7 +505,7 @@ blockchainTests('Staking Pool Management', env => {
|
||||
await maker.decreaseStakingPoolOperatorShareAsync(
|
||||
poolId,
|
||||
operatorShare - 1,
|
||||
new StakingRevertErrors.OnlyCallableByPoolOperatorOrMakerError(makerAddress, operatorAddress),
|
||||
new StakingRevertErrors.OnlyCallableByPoolOperatorOrMakerError(makerAddress, poolId),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -78,11 +78,11 @@ export class InsufficientBalanceError extends RevertError {
|
||||
}
|
||||
|
||||
export class OnlyCallableByPoolOperatorOrMakerError extends RevertError {
|
||||
constructor(senderAddress?: string, poolOperatorAddress?: string) {
|
||||
constructor(senderAddress?: string, poolId?: string) {
|
||||
super(
|
||||
'OnlyCallableByPoolOperatorOrMakerError',
|
||||
'OnlyCallableByPoolOperatorOrMakerError(address senderAddress, address poolOperatorAddress)',
|
||||
{ senderAddress, poolOperatorAddress },
|
||||
'OnlyCallableByPoolOperatorOrMakerError(address senderAddress, bytes32 poolId)',
|
||||
{ senderAddress, poolId },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user