From b45802635818b6e55bde92d2d0cb907c4d7eaff5 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Fri, 6 Sep 2019 14:10:08 -0700 Subject: [PATCH] Readability improvements ... apparently I still cant spell catastrophe. --- .../staking/contracts/src/ReadOnlyProxy.sol | 9 ++++----- .../staking/contracts/src/StakingProxy.sol | 4 ++-- .../staking/contracts/src/libs/LibProxy.sol | 17 ++++++++++------- .../contracts/src/libs/LibStakingRichErrors.sol | 10 ++++------ ...{catastrophy_test.ts => catastrophe_test.ts} | 10 +++++----- 5 files changed, 25 insertions(+), 25 deletions(-) rename contracts/staking/test/{catastrophy_test.ts => catastrophe_test.ts} (91%) diff --git a/contracts/staking/contracts/src/ReadOnlyProxy.sol b/contracts/staking/contracts/src/ReadOnlyProxy.sol index 7421e57230..9351b04b65 100644 --- a/contracts/staking/contracts/src/ReadOnlyProxy.sol +++ b/contracts/staking/contracts/src/ReadOnlyProxy.sol @@ -18,7 +18,6 @@ pragma solidity ^0.5.9; -import "./immutable/MixinConstants.sol"; import "./immutable/MixinStorage.sol"; import "./libs/LibProxy.sol"; @@ -35,8 +34,8 @@ contract ReadOnlyProxy is { address(this).proxyCall( LibProxy.RevertRule.NEVER_REVERT, - this.revertDelegateCall.selector, - false // do not ignore this selector + this.revertDelegateCall.selector, // custom egress selector + false // do not ignore ingress selector ); } @@ -47,8 +46,8 @@ contract ReadOnlyProxy is { readOnlyProxyCallee.proxyCall( LibProxy.RevertRule.ALWAYS_REVERT, - bytes4(0), // no custom selector - true // ignore this selector + bytes4(0), // no custom egress selector + true // ignore ingress selector ); } } diff --git a/contracts/staking/contracts/src/StakingProxy.sol b/contracts/staking/contracts/src/StakingProxy.sol index d839ee021b..98e6282772 100644 --- a/contracts/staking/contracts/src/StakingProxy.sol +++ b/contracts/staking/contracts/src/StakingProxy.sol @@ -49,8 +49,8 @@ contract StakingProxy is { stakingContract.proxyCall( LibProxy.RevertRule.REVERT_ON_ERROR, - bytes4(0), // no custom selector - false // do not ignore this selector + bytes4(0), // no custom egress selector + false // do not ignore ingress selector ); } diff --git a/contracts/staking/contracts/src/libs/LibProxy.sol b/contracts/staking/contracts/src/libs/LibProxy.sol index e2dcfb4412..d3db45d549 100644 --- a/contracts/staking/contracts/src/libs/LibProxy.sol +++ b/contracts/staking/contracts/src/libs/LibProxy.sol @@ -30,13 +30,16 @@ library LibProxy { NEVER_REVERT } - /// @dev Executes a read-only call to the staking contract, via `revertDelegateCall`. - /// By routing through `revertDelegateCall` any state changes are reverted. + /// @dev Proxies incoming call to destination contract. + /// @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 proxyCall( address destination, RevertRule revertRule, - bytes4 customSelector, - bool ignoreSelector + bytes4 customEgressSelector, + bool ignoreIngressSelector ) internal { @@ -49,14 +52,14 @@ library LibProxy { assembly { // store selector of destination function let freeMemPtr := 0 - if gt(customSelector, 0) { - mstore(0x0, customSelector) + if gt(customEgressSelector, 0) { + mstore(0x0, customEgressSelector) freeMemPtr := add(freeMemPtr, 4) } // adjust the calldata offset, if we should ignore the selector let calldataOffset := 0 - if gt(ignoreSelector, 0) { + if gt(ignoreIngressSelector, 0) { calldataOffset := 4 } diff --git a/contracts/staking/contracts/src/libs/LibStakingRichErrors.sol b/contracts/staking/contracts/src/libs/LibStakingRichErrors.sol index 92e07f30f5..8b697fab5c 100644 --- a/contracts/staking/contracts/src/libs/LibStakingRichErrors.sol +++ b/contracts/staking/contracts/src/libs/LibStakingRichErrors.sol @@ -122,7 +122,7 @@ library LibStakingRichErrors { bytes4 internal constant INVALID_COBB_DOUGLAS_ALPHA_ERROR_SELECTOR = 0x8f8e73de; - // bytes4(keccak256("EthVaultNotSetError()")) + // bytes4(keccak256("EthVaultNotSetError()")) bytes4 internal constant ETH_VAULT_NOT_SET_ERROR_SELECTOR = 0xa067f596; @@ -135,8 +135,8 @@ library LibStakingRichErrors { 0xb7161acd; // bytes4(keccak256("ProxyDestinationCannotBeNil()")) - bytes4 internal constant PROXY_DESTINATION_CANNOT_BE_NIL = - 0x01ecebea; + bytes internal constant PROXY_DESTINATION_CANNOT_BE_NIL = + hex"01ecebea"; // solhint-disable func-name-mixedcase function MiscalculatedRewardsError( @@ -515,9 +515,7 @@ library LibStakingRichErrors { pure returns (bytes memory) { - return abi.encodeWithSelector( - PROXY_DESTINATION_CANNOT_BE_NIL - ); + return PROXY_DESTINATION_CANNOT_BE_NIL; } } diff --git a/contracts/staking/test/catastrophy_test.ts b/contracts/staking/test/catastrophe_test.ts similarity index 91% rename from contracts/staking/test/catastrophy_test.ts rename to contracts/staking/test/catastrophe_test.ts index 969f843b2f..ea0d90b60a 100644 --- a/contracts/staking/test/catastrophy_test.ts +++ b/contracts/staking/test/catastrophe_test.ts @@ -1,6 +1,6 @@ import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy'; import { DummyERC20TokenContract } from '@0x/contracts-erc20'; -import { blockchainTests, describe, expect, provider, web3Wrapper } from '@0x/contracts-test-utils'; +import { blockchainTests, describe, expect } from '@0x/contracts-test-utils'; import { BigNumber } from '@0x/utils'; import { LogWithDecodedArgs } from 'ethereum-types'; import * as _ from 'lodash'; @@ -10,7 +10,7 @@ import { StakingProxyReadOnlyModeSetEventArgs } from '../src'; import { StakingWrapper } from './utils/staking_wrapper'; // tslint:disable:no-unnecessary-type-assertion -blockchainTests.resets('Catastrophy Tests', () => { +blockchainTests.resets('Catastrophe Tests', env => { // constants const ZRX_TOKEN_DECIMALS = new BigNumber(18); const ZERO = new BigNumber(0); @@ -26,17 +26,17 @@ blockchainTests.resets('Catastrophy Tests', () => { // tests before(async () => { // create accounts - accounts = await web3Wrapper.getAvailableAddressesAsync(); + accounts = await env.web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; actors = accounts.slice(2, 5); // deploy erc20 proxy - erc20Wrapper = new ERC20Wrapper(provider, accounts, owner); + erc20Wrapper = new ERC20Wrapper(env.provider, accounts, owner); erc20ProxyContract = await erc20Wrapper.deployProxyAsync(); // deploy zrx token [zrxTokenContract] = await erc20Wrapper.deployDummyTokensAsync(1, ZRX_TOKEN_DECIMALS); await erc20Wrapper.setBalancesAndAllowancesAsync(); // deploy staking contracts - stakingWrapper = new StakingWrapper(provider, owner, erc20ProxyContract, zrxTokenContract, accounts); + stakingWrapper = new StakingWrapper(env.provider, owner, erc20ProxyContract, zrxTokenContract, accounts); await stakingWrapper.deployAndConfigureContractsAsync(); });