Remove tests related to read-only mode

This commit is contained in:
Amir Bandeali
2019-10-27 11:10:15 -07:00
parent 58e9c70203
commit 33a0c22021
8 changed files with 2 additions and 203 deletions

View File

@@ -1,109 +0,0 @@
import { ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { blockchainTests, describe, expect } from '@0x/contracts-test-utils';
import { BigNumber } from '@0x/utils';
import { LogWithDecodedArgs } from 'ethereum-types';
import * as _ from 'lodash';
import { StakingProxyReadOnlyModeSetEventArgs } from '../src';
import { deployAndConfigureContractsAsync, StakingApiWrapper } from './utils/api_wrapper';
import { toBaseUnitAmount } from './utils/number_utils';
import { StakeStatus } from './utils/types';
// tslint:disable:no-unnecessary-type-assertion
blockchainTests.resets('Catastrophe Tests', env => {
// constants
const ZERO = new BigNumber(0);
// tokens & addresses
let accounts: string[];
let owner: string;
let actors: string[];
// wrappers
let stakingApiWrapper: StakingApiWrapper;
let erc20Wrapper: ERC20Wrapper;
// tests
before(async () => {
// create accounts
accounts = await env.web3Wrapper.getAvailableAddressesAsync();
owner = accounts[0];
actors = accounts.slice(2, 5);
// set up ERC20Wrapper
erc20Wrapper = new ERC20Wrapper(env.provider, accounts, owner);
// deploy staking contracts
stakingApiWrapper = await deployAndConfigureContractsAsync(env, owner, erc20Wrapper);
});
describe('Read-Only Mode', () => {
it('should be able to change state by default', async () => {
// stake some zrx and assert the balance
const amountToStake = toBaseUnitAmount(10);
await stakingApiWrapper.stakingContract.stake.awaitTransactionSuccessAsync(amountToStake, {
from: actors[0],
});
const undelegatedStakeBalance = await stakingApiWrapper.stakingContract.getOwnerStakeByStatus.callAsync(
actors[0],
StakeStatus.Undelegated,
);
expect(undelegatedStakeBalance.currentEpochBalance).to.be.bignumber.equal(amountToStake);
});
it('should not change state when in read-only mode', async () => {
// set to read-only mode
await stakingApiWrapper.stakingProxyContract.setReadOnlyMode.awaitTransactionSuccessAsync(true);
// try to stake
const amountToStake = toBaseUnitAmount(10);
await stakingApiWrapper.stakingContract.stake.awaitTransactionSuccessAsync(amountToStake, {
from: actors[0],
});
const undelegatedStakeBalance = await stakingApiWrapper.stakingContract.getOwnerStakeByStatus.callAsync(
actors[0],
StakeStatus.Undelegated,
);
expect(undelegatedStakeBalance.currentEpochBalance).to.be.bignumber.equal(ZERO);
});
it('should read values correctly when in read-only mode', async () => {
// stake some zrx
const amountToStake = toBaseUnitAmount(10);
await stakingApiWrapper.stakingContract.stake.awaitTransactionSuccessAsync(amountToStake, {
from: actors[0],
});
// set to read-only mode
await stakingApiWrapper.stakingProxyContract.setReadOnlyMode.awaitTransactionSuccessAsync(true);
// read stake balance in read-only mode
const undelegatedStakeBalanceReadOnly = await stakingApiWrapper.stakingContract.getOwnerStakeByStatus.callAsync(
actors[0],
StakeStatus.Undelegated,
);
expect(undelegatedStakeBalanceReadOnly.currentEpochBalance).to.be.bignumber.equal(amountToStake);
});
it('should exit read-only mode', async () => {
// set to read-only mode
await stakingApiWrapper.stakingProxyContract.setReadOnlyMode.awaitTransactionSuccessAsync(true);
await stakingApiWrapper.stakingProxyContract.setReadOnlyMode.awaitTransactionSuccessAsync(false);
// try to stake
const amountToStake = toBaseUnitAmount(10);
await stakingApiWrapper.stakingContract.stake.awaitTransactionSuccessAsync(amountToStake, {
from: actors[0],
});
const undelegatedStakeBalance = await stakingApiWrapper.stakingContract.getOwnerStakeByStatus.callAsync(
actors[0],
StakeStatus.Undelegated,
);
expect(undelegatedStakeBalance.currentEpochBalance).to.be.bignumber.equal(amountToStake);
});
it('should emit event and store correct configuration when setting read-only mode', async () => {
// set to read-only mode
const txReceipt = await stakingApiWrapper.stakingProxyContract.setReadOnlyMode.awaitTransactionSuccessAsync(
true,
);
expect(txReceipt.logs.length).to.be.equal(1);
const trueLog = txReceipt.logs[0] as LogWithDecodedArgs<StakingProxyReadOnlyModeSetEventArgs>;
expect(trueLog.args.readOnlyMode).to.be.true();
const timestamp = await env.web3Wrapper.getBlockTimestampAsync(txReceipt.blockNumber);
expect(trueLog.args.timestamp).to.bignumber.equal(timestamp);
const readOnlyState = await stakingApiWrapper.stakingProxyContract.readOnlyState.callAsync();
expect(readOnlyState[0]).to.be.true();
expect(readOnlyState[1]).to.bignumber.equal(timestamp);
});
});
});
// tslint:enable:no-unnecessary-type-assertion

View File

@@ -108,7 +108,6 @@ blockchainTests('Migration tests', env => {
env.txDefaults,
artifacts,
stakingContract.address,
stakingContract.address,
)).address;
const stakingProxyContract = new StakingContract(

View File

@@ -10,12 +10,10 @@ import {
artifacts,
IStakingEventsEpochEndedEventArgs,
IStakingEventsStakingPoolEarnedRewardsInEpochEventArgs,
ReadOnlyProxyContract,
StakingProxyContract,
TestCobbDouglasContract,
TestStakingContract,
TestStakingEvents,
ZrxVaultBackstopContract,
ZrxVaultContract,
} from '../../src';
@@ -33,7 +31,6 @@ export class StakingApiWrapper {
public zrxTokenContract: DummyERC20TokenContract;
public wethContract: WETH9Contract;
public cobbDouglasContract: TestCobbDouglasContract;
public zrxVaultBackstopContract: ZrxVaultBackstopContract;
public utils = {
// Epoch Utils
fastForwardToNextEpochAsync: async (): Promise<void> => {
@@ -176,14 +173,12 @@ export class StakingApiWrapper {
zrxTokenContract: DummyERC20TokenContract,
wethContract: WETH9Contract,
cobbDouglasContract: TestCobbDouglasContract,
zrxVaultBackstopContract: ZrxVaultBackstopContract,
) {
this._web3Wrapper = env.web3Wrapper;
this.zrxVaultContract = zrxVaultContract;
this.zrxTokenContract = zrxTokenContract;
this.wethContract = wethContract;
this.cobbDouglasContract = cobbDouglasContract;
this.zrxVaultBackstopContract = zrxVaultBackstopContract;
this.stakingContractAddress = stakingContract.address;
this.stakingProxyContract = stakingProxyContract;
// disguise the staking proxy as a StakingContract
@@ -249,14 +244,6 @@ export async function deployAndConfigureContractsAsync(
zrxVaultContract.address,
);
// deploy read-only proxy
const readOnlyProxyContract = await ReadOnlyProxyContract.deployFrom0xArtifactAsync(
artifacts.ReadOnlyProxy,
env.provider,
env.txDefaults,
artifacts,
);
// deploy staking proxy
const stakingProxyContract = await StakingProxyContract.deployFrom0xArtifactAsync(
artifacts.StakingProxy,
@@ -264,7 +251,6 @@ export async function deployAndConfigureContractsAsync(
env.txDefaults,
artifacts,
stakingContract.address,
readOnlyProxyContract.address,
);
await stakingProxyContract.addAuthorizedAddress.awaitTransactionSuccessAsync(ownerAddress);
@@ -277,23 +263,10 @@ export async function deployAndConfigureContractsAsync(
artifacts,
);
const zrxVaultBackstopContract = await ZrxVaultBackstopContract.deployFrom0xArtifactAsync(
artifacts.ZrxVaultBackstop,
env.provider,
env.txDefaults,
artifacts,
stakingProxyContract.address,
zrxVaultContract.address,
);
// configure erc20 proxy to accept calls from zrx vault
await erc20ProxyContract.addAuthorizedAddress.awaitTransactionSuccessAsync(zrxVaultContract.address);
// set staking proxy contract in zrx vault
await zrxVaultContract.setStakingProxy.awaitTransactionSuccessAsync(stakingProxyContract.address);
// add zrxVaultBackstop as an authorized address
await zrxVaultContract.addAuthorizedAddress.awaitTransactionSuccessAsync(zrxVaultBackstopContract.address, {
from: ownerAddress,
});
return new StakingApiWrapper(
env,
ownerAddress,
@@ -303,6 +276,5 @@ export async function deployAndConfigureContractsAsync(
zrxTokenContract,
wethContract,
cobbDouglasContract,
zrxVaultBackstopContract,
);
}

View File

@@ -1,51 +0,0 @@
import { ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { blockchainTests, describe, expect, increaseTimeAndMineBlockAsync } from '@0x/contracts-test-utils';
import { StringRevertError } from '@0x/utils';
import { LogWithDecodedArgs } from 'ethereum-types';
import { ZrxVaultInCatastrophicFailureModeEventArgs } from '../src';
import { deployAndConfigureContractsAsync, StakingApiWrapper } from './utils/api_wrapper';
blockchainTests.resets('ZrxVaultBackstop', env => {
let stakingApiWrapper: StakingApiWrapper;
let authorizedAddress: string;
let notAuthorizedAddress: string;
before(async () => {
const accounts = await env.web3Wrapper.getAvailableAddressesAsync();
[authorizedAddress, notAuthorizedAddress] = accounts;
const erc20Wrapper = new ERC20Wrapper(env.provider, [], authorizedAddress);
stakingApiWrapper = await deployAndConfigureContractsAsync(env, authorizedAddress, erc20Wrapper);
});
describe('enterCatastrophicFailureIfProlongedReadOnlyMode', () => {
it('should revert if read-only mode is not set', async () => {
const expectedError = new StringRevertError('READ_ONLY_MODE_NOT_SET');
expect(
stakingApiWrapper.zrxVaultBackstopContract.enterCatastrophicFailureIfProlongedReadOnlyMode.awaitTransactionSuccessAsync(),
).to.revertWith(expectedError);
});
it('should revert if read-only mode has been set for less than 40 days', async () => {
await stakingApiWrapper.stakingProxyContract.setReadOnlyMode.awaitTransactionSuccessAsync(true, {
from: authorizedAddress,
});
const expectedError = new StringRevertError('READ_ONLY_MODE_DURATION_TOO_SHORT');
expect(
stakingApiWrapper.zrxVaultBackstopContract.enterCatastrophicFailureIfProlongedReadOnlyMode.awaitTransactionSuccessAsync(),
).to.revertWith(expectedError);
});
it('should enter catastophic failure mode if read-only mode has been set for 40 days', async () => {
await stakingApiWrapper.stakingProxyContract.setReadOnlyMode.awaitTransactionSuccessAsync(true, {
from: authorizedAddress,
});
const fourtyDaysInSec = 40 * 24 * 60 * 60;
await increaseTimeAndMineBlockAsync(fourtyDaysInSec);
const txReceipt = await stakingApiWrapper.zrxVaultBackstopContract.enterCatastrophicFailureIfProlongedReadOnlyMode.awaitTransactionSuccessAsync(
{ from: notAuthorizedAddress },
);
expect(txReceipt.logs.length).to.equal(1);
// tslint:disable:no-unnecessary-type-assertion
const logArgs = (txReceipt.logs[0] as LogWithDecodedArgs<ZrxVaultInCatastrophicFailureModeEventArgs>).args;
expect(logArgs.sender).to.equal(stakingApiWrapper.zrxVaultBackstopContract.address);
});
});
});