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,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