use mocha extensions in staking tests

This commit is contained in:
Michael Zhu 2019-08-26 10:58:34 -07:00
parent dbda3a04b2
commit 0d5e037081
9 changed files with 36 additions and 132 deletions

View File

@ -1,7 +1,5 @@
import { chaiSetup } from '@0x/contracts-test-utils';
import { StakingRevertErrors } from '@0x/order-utils';
import { expect } from '@0x/contracts-test-utils';
import { BigNumber, RevertError } from '@0x/utils';
import * as chai from 'chai';
import * as _ from 'lodash';
import { StakingWrapper } from '../utils/staking_wrapper';
@ -9,9 +7,6 @@ import { DelegatorBalances, StakerBalances } from '../utils/types';
import { StakerActor } from './staker_actor';
chaiSetup.configure();
const expect = chai.expect;
export class DelegatorActor extends StakerActor {
constructor(owner: string, stakingWrapper: StakingWrapper) {
super(owner, stakingWrapper);

View File

@ -1,7 +1,5 @@
import { chaiSetup } from '@0x/contracts-test-utils';
import { StakingRevertErrors } from '@0x/order-utils';
import { expect } from '@0x/contracts-test-utils';
import { RevertError } from '@0x/utils';
import * as chai from 'chai';
import * as _ from 'lodash';
import { constants as stakingConstants } from '../utils/constants';
@ -9,9 +7,6 @@ import { StakingWrapper } from '../utils/staking_wrapper';
import { BaseActor } from './base_actor';
chaiSetup.configure();
const expect = chai.expect;
export class PoolOperatorActor extends BaseActor {
constructor(owner: string, stakingWrapper: StakingWrapper) {
super(owner, stakingWrapper);

View File

@ -1,7 +1,5 @@
import { chaiSetup } from '@0x/contracts-test-utils';
import { StakingRevertErrors } from '@0x/order-utils';
import { expect } from '@0x/contracts-test-utils';
import { BigNumber, RevertError } from '@0x/utils';
import * as chai from 'chai';
import * as _ from 'lodash';
import { StakingWrapper } from '../utils/staking_wrapper';
@ -9,9 +7,6 @@ import { StakerBalances } from '../utils/types';
import { BaseActor } from './base_actor';
chaiSetup.configure();
const expect = chai.expect;
export class StakerActor extends BaseActor {
constructor(owner: string, stakingWrapper: StakingWrapper) {
super(owner, stakingWrapper);

View File

@ -1,19 +1,14 @@
import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { chaiSetup, provider, web3Wrapper } from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { blockchainTests, expect } from '@0x/contracts-test-utils';
import { StakingRevertErrors } from '@0x/order-utils';
import { BigNumber } from '@0x/utils';
import * as chai from 'chai';
import * as _ from 'lodash';
import { StakingWrapper } from './utils/staking_wrapper';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
// tslint:disable:no-unnecessary-type-assertion
describe('Exchange Integrations', () => {
blockchainTests.only('Exchange Integrations', env => {
// constants
const ZRX_TOKEN_DECIMALS = new BigNumber(18);
// tokens & addresses
@ -26,34 +21,22 @@ describe('Exchange Integrations', () => {
let stakingWrapper: StakingWrapper;
let erc20Wrapper: ERC20Wrapper;
// tests
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => {
// create accounts
accounts = await web3Wrapper.getAvailableAddressesAsync();
accounts = await env.web3Wrapper.getAvailableAddressesAsync();
owner = accounts[0];
exchange = accounts[1];
// 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();
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('Exchange Tracking in Staking Contract', () => {
blockchainTests.resets('Exchange Tracking in Staking Contract', () => {
it('basic exchange tracking', async () => {
// 1 try querying an invalid addresses
const invalidAddress = '0x0000000000000000000000000000000000000001';
@ -64,7 +47,7 @@ describe('Exchange Integrations', () => {
const isValidAddressValid = await stakingWrapper.isValidExchangeAddressAsync(exchange);
expect(isValidAddressValid).to.be.true();
// 3 try adding valid address again
let revertError = new StakingRevertErrors.ExchangeAddressAlreadyRegisteredError(exchange);
let revertError = new StakingRevertErrors.ExchangeAlreadyRegisteredError(exchange);
let tx = stakingWrapper.addExchangeAddressAsync(exchange);
await expect(tx).to.revertWith(revertError);
// 4 remove valid address

View File

@ -1,10 +1,8 @@
import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { chaiSetup, provider, web3Wrapper } from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { blockchainTests, expect } from '@0x/contracts-test-utils';
import { StakingRevertErrors } from '@0x/order-utils';
import { BigNumber } from '@0x/utils';
import * as chai from 'chai';
import * as ethUtil from 'ethereumjs-util';
import * as _ from 'lodash';
@ -13,11 +11,8 @@ import { PoolOperatorActor } from './actors/pool_operator_actor';
import { constants as stakingConstants } from './utils/constants';
import { StakingWrapper } from './utils/staking_wrapper';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
// tslint:disable:no-unnecessary-type-assertion
describe('Staking Pool Management', () => {
blockchainTests.only('Staking Pool Management', env => {
// constants
const ZRX_TOKEN_DECIMALS = new BigNumber(18);
// tokens & addresses
@ -30,34 +25,22 @@ describe('Staking Pool Management', () => {
let stakingWrapper: StakingWrapper;
let erc20Wrapper: ERC20Wrapper;
// tests
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => {
// create accounts
accounts = await web3Wrapper.getAvailableAddressesAsync();
accounts = await env.web3Wrapper.getAvailableAddressesAsync();
owner = accounts[0];
users = accounts.slice(1);
// 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();
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('Staking Pool Management', () => {
blockchainTests.resets('Staking Pool Management', () => {
it('Should successfully create a pool', async () => {
// test parameters
const operatorAddress = users[0];

View File

@ -1,18 +1,14 @@
import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { chaiSetup, provider, web3Wrapper } from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { blockchainTests, expect } from '@0x/contracts-test-utils';
import { StakingRevertErrors } from '@0x/order-utils';
import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
import { Simulation } from './utils/Simulation';
import { StakingWrapper } from './utils/staking_wrapper';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
// tslint:disable:no-unnecessary-type-assertion
describe('End-To-End Simulations', () => {
blockchainTests.only('End-To-End Simulations', env => {
// constants
const ZRX_TOKEN_DECIMALS = new BigNumber(18);
// tokens & addresses
@ -26,37 +22,25 @@ describe('End-To-End Simulations', () => {
let stakingWrapper: StakingWrapper;
let erc20Wrapper: ERC20Wrapper;
// tests
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => {
// create accounts
accounts = await web3Wrapper.getAvailableAddressesAsync();
accounts = await env.web3Wrapper.getAvailableAddressesAsync();
owner = accounts[0];
exchange = accounts[1];
users = accounts.slice(2);
users = [...users, ...users]; // @TODO figure out how to get more addresses from `web3Wrapper`
// 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();
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('Simulations', () => {
blockchainTests.resets('Simulations', () => {
it('Should successfully simulate (no delegators / no shadow balances)', async () => {
// @TODO - get computations more accurate
const simulationParams = {

View File

@ -1,7 +1,6 @@
import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { chaiSetup, provider, web3Wrapper } from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { blockchainTests } from '@0x/contracts-test-utils';
import { StakingRevertErrors } from '@0x/order-utils';
import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
@ -10,10 +9,8 @@ import { DelegatorActor } from './actors/delegator_actor';
import { StakerActor } from './actors/staker_actor';
import { StakingWrapper } from './utils/staking_wrapper';
chaiSetup.configure();
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
// tslint:disable:no-unnecessary-type-assertion
describe('Staking & Delegating', () => {
blockchainTests.only('Staking & Delegating', env => {
// constants
const ZRX_TOKEN_DECIMALS = new BigNumber(18);
// tokens & addresses
@ -26,34 +23,22 @@ describe('Staking & Delegating', () => {
let stakingWrapper: StakingWrapper;
let erc20Wrapper: ERC20Wrapper;
// tests
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => {
// create accounts
accounts = await web3Wrapper.getAvailableAddressesAsync();
accounts = await env.web3Wrapper.getAvailableAddressesAsync();
owner = accounts[0];
stakers = 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();
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('Staking', () => {
blockchainTests.resets('Staking', () => {
it('basic staking/unstaking', async () => {
// setup test parameters
const amountToStake = StakingWrapper.toBaseUnitAmount(10);
@ -80,7 +65,7 @@ describe('Staking & Delegating', () => {
});
});
describe('Delegating', () => {
blockchainTests.resets('Delegating', () => {
it('basic delegating/undelegating', async () => {
// setup test parameters
const amountToDelegate = StakingWrapper.toBaseUnitAmount(10);

View File

@ -1,18 +1,14 @@
import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { chaiSetup, provider, web3Wrapper } from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { blockchainTests, expect } from '@0x/contracts-test-utils';
import { StakingRevertErrors } from '@0x/order-utils';
import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
import { StakingWrapper } from './utils/staking_wrapper';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
// tslint:disable:no-unnecessary-type-assertion
describe('Staking Vaults', () => {
blockchainTests.only('Staking Vaults', env => {
// constants
const ZRX_TOKEN_DECIMALS = new BigNumber(18);
// tokens & addresses
@ -25,34 +21,22 @@ describe('Staking Vaults', () => {
let stakingWrapper: StakingWrapper;
let erc20Wrapper: ERC20Wrapper;
// tests
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => {
// create accounts
accounts = await web3Wrapper.getAvailableAddressesAsync();
accounts = await env.web3Wrapper.getAvailableAddressesAsync();
owner = accounts[0];
users = accounts.slice(1);
// 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();
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('Reward Vault', () => {
blockchainTests.resets('Reward Vault', () => {
it.skip('basic management', async () => {
// 1 setup test parameters
const poolOperator = users[0];

View File

@ -164,7 +164,7 @@ function defineBlockchainSuite<T>(
const env = BlockchainTestsEnvironmentSingleton.create();
return describeCall(description, function(this: ISuiteCallbackContext): void {
before(async () => env.blockchainLifecycle.startAsync());
before(async () => env.blockchainLifecycle.revertAsync());
after(async () => env.blockchainLifecycle.revertAsync());
callback.call(this, env);
});
}