remove staking RevertReasons from TS types, ExchangeAlreadyRegisteredError -> ExchangeAddressAlreadyRegisteredError

This commit is contained in:
Michael Zhu 2019-08-26 11:21:16 -07:00
parent 0d5e037081
commit 2c15b3f9bd
8 changed files with 95 additions and 141 deletions

View File

@ -55,7 +55,7 @@ contract MixinExchangeManager is
onlyOwner
{
if (validExchanges[addr]) {
LibRichErrors.rrevert(LibStakingRichErrors.ExchangeAlreadyRegisteredError(
LibRichErrors.rrevert(LibStakingRichErrors.ExchangeAddressAlreadyRegisteredError(
addr
));
}

View File

@ -30,9 +30,9 @@ library LibStakingRichErrors {
bytes4 internal constant ONLY_CALLABLE_BY_EXCHANGE_ERROR_SELECTOR =
0xb56d2df0;
// bytes4(keccak256("ExchangeAlreadyRegisteredError(address)"))
bytes4 internal constant EXCHANGE_ALREADY_REGISTERED_ERROR_SELECTOR =
0x5ef5b57d;
// bytes4(keccak256("ExchangeAddressAlreadyRegisteredError(address)"))
bytes4 internal constant EXCHANGE_ADDRESS_ALREADY_REGISTERED_ERROR_SELECTOR =
0xc87a78b7;
// bytes4(keccak256("ExchangeAddressNotRegisteredError(address)"))
bytes4 internal constant EXCHANGE_ADDRESS_NOT_REGISTERED_ERROR_SELECTOR =
@ -118,6 +118,8 @@ library LibStakingRichErrors {
bytes4 internal constant POOL_ALREADY_EXISTS_ERROR_SELECTOR =
0x2a5e4dcf;
// solhint-disable func-name-mixedcase
function MiscalculatedRewardsError(
uint256 totalRewardsPaid,
uint256 initialContractBalance
@ -146,7 +148,7 @@ library LibStakingRichErrors {
);
}
function ExchangeAlreadyRegisteredError(
function ExchangeAddressAlreadyRegisteredError(
address exchangeAddress
)
internal
@ -154,7 +156,7 @@ library LibStakingRichErrors {
returns (bytes memory)
{
return abi.encodeWithSelector(
EXCHANGE_ALREADY_REGISTERED_ERROR_SELECTOR,
EXCHANGE_ADDRESS_ALREADY_REGISTERED_ERROR_SELECTOR,
exchangeAddress
);
}

View File

@ -75,10 +75,7 @@ export class StakerActor extends BaseActor {
expectedStakerBalances.deactivatedStakeBalance = initStakerBalances.deactivatedStakeBalance.plus(amount);
await this.assertBalancesAsync(expectedStakerBalances);
}
public async burnDeactivatedStakeAndWithdrawZrxAsync(
amount: BigNumber,
revertError?: RevertError,
): Promise<void> {
public async burnDeactivatedStakeAndWithdrawZrxAsync(amount: BigNumber, revertError?: RevertError): Promise<void> {
// query init balances
const initZrxBalanceOfVault = await this._stakingWrapper.getZrxTokenBalanceOfZrxVaultAsync();
const initStakerBalances = await this.getBalancesAsync();

View File

@ -47,7 +47,7 @@ blockchainTests.only('Exchange Integrations', env => {
const isValidAddressValid = await stakingWrapper.isValidExchangeAddressAsync(exchange);
expect(isValidAddressValid).to.be.true();
// 3 try adding valid address again
let revertError = new StakingRevertErrors.ExchangeAlreadyRegisteredError(exchange);
let revertError = new StakingRevertErrors.ExchangeAddressAlreadyRegisteredError(exchange);
let tx = stakingWrapper.addExchangeAddressAsync(exchange);
await expect(tx).to.revertWith(revertError);
// 4 remove valid address

View File

@ -113,12 +113,7 @@ blockchainTests.only('Staking Pool Management', env => {
await poolOperator.addMakerToStakingPoolAsync(poolId, makerAddress, makerApproval.signature);
const revertError = new StakingRevertErrors.MakerAddressAlreadyRegisteredError(makerAddress);
// add same maker to pool again
await poolOperator.addMakerToStakingPoolAsync(
poolId,
makerAddress,
makerApproval.signature,
revertError,
);
await poolOperator.addMakerToStakingPoolAsync(poolId, makerAddress, makerApproval.signature, revertError);
});
it('Should fail to remove a maker that does not exist', async () => {
// test parameters
@ -135,11 +130,7 @@ blockchainTests.only('Staking Pool Management', env => {
poolId,
);
// remove non-existent maker from pool
await poolOperator.removeMakerFromStakingPoolAsync(
poolId,
makerAddress,
revertError,
);
await poolOperator.removeMakerFromStakingPoolAsync(poolId, makerAddress, revertError);
});
it('Should fail to add a maker who signed with the wrong private key', async () => {
// test parameters
@ -161,12 +152,7 @@ blockchainTests.only('Staking Pool Management', env => {
makerAddress,
makerApproval.signature,
);
await poolOperator.addMakerToStakingPoolAsync(
poolId,
makerAddress,
makerApproval.signature,
revertError,
);
await poolOperator.addMakerToStakingPoolAsync(poolId, makerAddress, makerApproval.signature, revertError);
});
it('Should fail to add a maker who signed with the wrong staking contract address', async () => {
// test parameters
@ -187,12 +173,7 @@ blockchainTests.only('Staking Pool Management', env => {
makerAddress,
makerApproval.signature,
);
await poolOperator.addMakerToStakingPoolAsync(
poolId,
makerAddress,
makerApproval.signature,
revertError,
);
await poolOperator.addMakerToStakingPoolAsync(poolId, makerAddress, makerApproval.signature, revertError);
});
it('Should fail to add a maker who signed with the wrong chain id', async () => {
// test parameters
@ -220,12 +201,7 @@ blockchainTests.only('Staking Pool Management', env => {
makerAddress,
makerApproval.signature,
);
await poolOperator.addMakerToStakingPoolAsync(
poolId,
makerAddress,
makerApproval.signature,
revertError,
);
await poolOperator.addMakerToStakingPoolAsync(poolId, makerAddress, makerApproval.signature, revertError);
});
it('Should fail to add a maker when called by someone other than the pool operator', async () => {
// test parameters

View File

@ -8,11 +8,7 @@ const MAX_UINT256 = new BigNumber(2).pow(256).minus(1);
export function safeAdd(a: BigNumber, b: BigNumber): BigNumber {
const r = a.plus(b);
if (r.isGreaterThan(MAX_UINT256)) {
throw new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.AdditionOverflow,
a,
b,
);
throw new SafeMathRevertErrors.Uint256BinopError(SafeMathRevertErrors.BinopErrorCodes.AdditionOverflow, a, b);
}
return r;
}
@ -52,11 +48,7 @@ export function safeMul(a: BigNumber, b: BigNumber): BigNumber {
*/
export function safeDiv(a: BigNumber, b: BigNumber): BigNumber {
if (b.isEqualTo(0)) {
throw new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.DivisionByZero,
a,
b,
);
throw new SafeMathRevertErrors.Uint256BinopError(SafeMathRevertErrors.BinopErrorCodes.DivisionByZero, a, b);
}
return a.dividedToIntegerBy(b);
}

View File

@ -18,11 +18,13 @@ export class OnlyCallableByExchangeError extends RevertError {
}
}
export class ExchangeAlreadyRegisteredError extends RevertError {
export class ExchangeAddressAlreadyRegisteredError extends RevertError {
constructor(exchangeAddress?: string) {
super('ExchangeAlreadyRegisteredError', 'ExchangeAlreadyRegisteredError(address exchangeAddress)', {
exchangeAddress,
});
super(
'ExchangeAddressAlreadyRegisteredError',
'ExchangeAddressAlreadyRegisteredError(address exchangeAddress)',
{ exchangeAddress },
);
}
}
@ -196,7 +198,7 @@ export class PoolAlreadyExistsError extends RevertError {
const types = [
MiscalculatedRewardsError,
OnlyCallableByExchangeError,
ExchangeAlreadyRegisteredError,
ExchangeAddressAlreadyRegisteredError,
ExchangeAddressNotRegisteredError,
SignatureLengthGreaterThan0RequiredError,
SignatureUnsupportedError,

View File

@ -341,21 +341,6 @@ export enum RevertReason {
TargetNotEven = 'TARGET_NOT_EVEN',
UnexpectedStaticCallResult = 'UNEXPECTED_STATIC_CALL_RESULT',
TransfersSuccessful = 'TRANSFERS_SUCCESSFUL',
// Staking
OnlyCallableByPoolOperator = 'ONLY_CALLABLE_BY_POOL_OPERATOR',
OnlyCallableByPoolOperatorOrMaker = 'ONLY_CALLABLE_BY_POOL_OPERATOR_OR_MAKER',
MakerAddressAlreadyRegistered = 'MAKER_ADDRESS_ALREADY_REGISTERED',
MakerAddressNotRegistered = 'MAKER_ADDRESS_NOT_REGISTERED',
OnlyCallableByExchange = 'ONLY_CALLABLE_BY_EXCHANGE',
ExchangeAddressAlreadyRegistered = 'EXCHANGE_ADDRESS_ALREADY_REGISTERED',
ExchangeAddressNotRegistered = 'EXCHANGE_ADDRESS_NOT_REGISTERED',
PoolAlreadyExists = 'POOL_ALREADY_EXISTS',
PoolBalanceIsZero = 'POOL_BALANCE_IS_ZERO',
InvalidOwner = 'INVALID_OWNER',
AmountExceedsBalanceOfPool = 'AMOUNT_EXCEEDS_BALANCE_OF_POOL',
OnlyCallableByStakingContract = 'ONLY_CALLABLE_BY_STAKING_CONTRACT',
InvalidMakerSignature = 'INVALID_MAKER_SIGNATURE',
InsufficientBalance = 'INSUFFICIENT_BALANCE',
}
export enum StatusCodes {