@0x:contracts-staking
Fixed style issues in staking RichErrors
This commit is contained in:
@@ -45,7 +45,7 @@ library LibProxy {
|
||||
{
|
||||
if (destination == address(0)) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.ProxyDestinationCannotBeNil()
|
||||
LibStakingRichErrors.ProxyDestinationCannotBeNilError()
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -127,9 +127,9 @@ library LibStakingRichErrors {
|
||||
bytes4 internal constant INVALID_STAKE_STATUS_ERROR_SELECTOR =
|
||||
0xb7161acd;
|
||||
|
||||
// bytes4(keccak256("ProxyDestinationCannotBeNil()"))
|
||||
bytes internal constant PROXY_DESTINATION_CANNOT_BE_NIL =
|
||||
hex"01ecebea";
|
||||
// bytes4(keccak256("ProxyDestinationCannotBeNilError()"))
|
||||
bytes internal constant PROXY_DESTINATION_CANNOT_BE_NIL_ERROR =
|
||||
hex"6eff8285";
|
||||
|
||||
// bytes4(keccak256("InitializationError(uint8)"))
|
||||
bytes4 internal constant INITIALIZATION_ERROR_SELECTOR =
|
||||
@@ -440,12 +440,12 @@ library LibStakingRichErrors {
|
||||
);
|
||||
}
|
||||
|
||||
function ProxyDestinationCannotBeNil()
|
||||
function ProxyDestinationCannotBeNilError()
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return PROXY_DESTINATION_CANNOT_BE_NIL;
|
||||
return PROXY_DESTINATION_CANNOT_BE_NIL_ERROR;
|
||||
}
|
||||
|
||||
function InvalidWethAssetDataError()
|
||||
|
57
contracts/staking/contracts/test/TestLibProxy.sol
Normal file
57
contracts/staking/contracts/test/TestLibProxy.sol
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
/**********************************************
|
||||
|
||||
THIS IS AN EXTREMELY DANGEROUS CONTRACT!
|
||||
|
||||
IT IS ONLY INTENDED FOR TESTING AND SHOULD
|
||||
NEVER BE USED IN PRODUCTION!
|
||||
|
||||
**********************************************/
|
||||
|
||||
pragma solidity ^0.5.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "../src/libs/LibProxy.sol";
|
||||
|
||||
|
||||
contract TestLibProxy {
|
||||
|
||||
using LibProxy for address;
|
||||
|
||||
/// @dev Exposes the `proxyCall()` library function from LibProxy.
|
||||
/// @param destination Address to call.
|
||||
/// @param revertRule Describes scenarios in which this function reverts.
|
||||
/// @param customEgressSelector Custom selector used to call destination contract.
|
||||
/// @param ignoreIngressSelector Ignore the selector used to call into this contract.
|
||||
function externalProxyCall(
|
||||
address destination,
|
||||
LibProxy.RevertRule revertRule,
|
||||
bytes4 customEgressSelector,
|
||||
bool ignoreIngressSelector
|
||||
)
|
||||
external
|
||||
{
|
||||
destination.proxyCall(
|
||||
revertRule,
|
||||
customEgressSelector,
|
||||
ignoreIngressSelector
|
||||
);
|
||||
}
|
||||
}
|
@@ -37,7 +37,7 @@
|
||||
},
|
||||
"config": {
|
||||
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.",
|
||||
"abis": "./generated-artifacts/@(EthVault|IEthVault|IStaking|IStakingEvents|IStakingPoolRewardVault|IStakingProxy|IStorageInit|IStructs|IVaultCore|IZrxVault|LibFixedMath|LibFixedMathRichErrors|LibProxy|LibSafeDowncast|LibStakingRichErrors|MixinConstants|MixinDeploymentConstants|MixinEthVault|MixinExchangeFees|MixinExchangeManager|MixinParams|MixinScheduler|MixinStake|MixinStakeBalances|MixinStakeStorage|MixinStakingPool|MixinStakingPoolRewardVault|MixinStakingPoolRewards|MixinStorage|MixinVaultCore|MixinZrxVault|ReadOnlyProxy|Staking|StakingPoolRewardVault|StakingProxy|TestCobbDouglas|TestInitTarget|TestLibFixedMath|TestProtocolFees|TestProtocolFeesERC20Proxy|TestStaking|TestStakingProxy|TestStorageLayout|ZrxVault).json"
|
||||
"abis": "./generated-artifacts/@(EthVault|IEthVault|IStaking|IStakingEvents|IStakingPoolRewardVault|IStakingProxy|IStorageInit|IStructs|IVaultCore|IZrxVault|LibFixedMath|LibFixedMathRichErrors|LibProxy|LibSafeDowncast|LibStakingRichErrors|MixinConstants|MixinDeploymentConstants|MixinEthVault|MixinExchangeFees|MixinExchangeManager|MixinParams|MixinScheduler|MixinStake|MixinStakeBalances|MixinStakeStorage|MixinStakingPool|MixinStakingPoolRewardVault|MixinStakingPoolRewards|MixinStorage|MixinVaultCore|MixinZrxVault|ReadOnlyProxy|Staking|StakingPoolRewardVault|StakingProxy|TestCobbDouglas|TestInitTarget|TestLibFixedMath|TestLibProxy|TestProtocolFees|TestProtocolFeesERC20Proxy|TestStaking|TestStakingProxy|TestStorageLayout|ZrxVault).json"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@@ -43,6 +43,7 @@ import * as StakingProxy from '../generated-artifacts/StakingProxy.json';
|
||||
import * as TestCobbDouglas from '../generated-artifacts/TestCobbDouglas.json';
|
||||
import * as TestInitTarget from '../generated-artifacts/TestInitTarget.json';
|
||||
import * as TestLibFixedMath from '../generated-artifacts/TestLibFixedMath.json';
|
||||
import * as TestLibProxy from '../generated-artifacts/TestLibProxy.json';
|
||||
import * as TestProtocolFees from '../generated-artifacts/TestProtocolFees.json';
|
||||
import * as TestProtocolFeesERC20Proxy from '../generated-artifacts/TestProtocolFeesERC20Proxy.json';
|
||||
import * as TestStaking from '../generated-artifacts/TestStaking.json';
|
||||
@@ -89,6 +90,7 @@ export const artifacts = {
|
||||
TestCobbDouglas: TestCobbDouglas as ContractArtifact,
|
||||
TestInitTarget: TestInitTarget as ContractArtifact,
|
||||
TestLibFixedMath: TestLibFixedMath as ContractArtifact,
|
||||
TestLibProxy: TestLibProxy as ContractArtifact,
|
||||
TestProtocolFees: TestProtocolFees as ContractArtifact,
|
||||
TestProtocolFeesERC20Proxy: TestProtocolFeesERC20Proxy as ContractArtifact,
|
||||
TestStaking: TestStaking as ContractArtifact,
|
||||
|
@@ -41,6 +41,7 @@ export * from '../generated-wrappers/staking_proxy';
|
||||
export * from '../generated-wrappers/test_cobb_douglas';
|
||||
export * from '../generated-wrappers/test_init_target';
|
||||
export * from '../generated-wrappers/test_lib_fixed_math';
|
||||
export * from '../generated-wrappers/test_lib_proxy';
|
||||
export * from '../generated-wrappers/test_protocol_fees';
|
||||
export * from '../generated-wrappers/test_protocol_fees_erc20_proxy';
|
||||
export * from '../generated-wrappers/test_staking';
|
||||
|
40
contracts/staking/test/unit_tests/lib_proxy.ts
Normal file
40
contracts/staking/test/unit_tests/lib_proxy.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { blockchainTests, constants, expect } from '@0x/contracts-test-utils';
|
||||
import { StakingRevertErrors } from '@0x/order-utils';
|
||||
|
||||
import { artifacts, TestLibProxyContract } from '../../src';
|
||||
|
||||
enum RevertRule {
|
||||
RevertOnError,
|
||||
AlwaysRevert,
|
||||
NeverRevert,
|
||||
}
|
||||
|
||||
blockchainTests.resets('LibProxy', env => {
|
||||
let proxy: TestLibProxyContract;
|
||||
|
||||
before(async () => {
|
||||
proxy = await TestLibProxyContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TestLibProxy,
|
||||
env.provider,
|
||||
env.txDefaults,
|
||||
artifacts,
|
||||
);
|
||||
});
|
||||
|
||||
describe('proxyCall', () => {
|
||||
it('should revert when the destination is address zero and the revert rule is `AlwaysRevert`', async () => {
|
||||
const expectedError = new StakingRevertErrors.ProxyDestinationCannotBeNilError();
|
||||
const tx = proxy.externalProxyCall.awaitTransactionSuccessAsync(
|
||||
constants.NULL_ADDRESS,
|
||||
RevertRule.AlwaysRevert,
|
||||
);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
describe('REVERT_ON_ERROR', () => {});
|
||||
|
||||
describe('ALWAYS_REVERT', () => {});
|
||||
|
||||
describe('NEVER_REVERT', () => {});
|
||||
});
|
||||
});
|
@@ -41,6 +41,7 @@
|
||||
"generated-artifacts/TestCobbDouglas.json",
|
||||
"generated-artifacts/TestInitTarget.json",
|
||||
"generated-artifacts/TestLibFixedMath.json",
|
||||
"generated-artifacts/TestLibProxy.json",
|
||||
"generated-artifacts/TestProtocolFees.json",
|
||||
"generated-artifacts/TestProtocolFeesERC20Proxy.json",
|
||||
"generated-artifacts/TestStaking.json",
|
||||
|
Reference in New Issue
Block a user