import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy'; import { DummyERC20TokenContract } from '@0x/contracts-erc20'; 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'; // tslint:disable:no-unnecessary-type-assertion blockchainTests.only('Exchange Integrations', env => { // constants const ZRX_TOKEN_DECIMALS = new BigNumber(18); // tokens & addresses let accounts: string[]; let owner: string; let exchange: string; let zrxTokenContract: DummyERC20TokenContract; let erc20ProxyContract: ERC20ProxyContract; // wrappers let stakingWrapper: StakingWrapper; let erc20Wrapper: ERC20Wrapper; // tests before(async () => { // create accounts accounts = await env.web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; exchange = accounts[1]; // deploy erc20 proxy 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(env.provider, owner, erc20ProxyContract, zrxTokenContract, accounts); await stakingWrapper.deployAndConfigureContractsAsync(); }); blockchainTests.resets('Exchange Tracking in Staking Contract', () => { it('basic exchange tracking', async () => { // 1 try querying an invalid addresses const invalidAddress = '0x0000000000000000000000000000000000000001'; const isInvalidAddressValid = await stakingWrapper.isValidExchangeAddressAsync(invalidAddress); expect(isInvalidAddressValid).to.be.false(); // 2 add valid address await stakingWrapper.addExchangeAddressAsync(exchange); const isValidAddressValid = await stakingWrapper.isValidExchangeAddressAsync(exchange); expect(isValidAddressValid).to.be.true(); // 3 try adding valid address again let revertError = new StakingRevertErrors.ExchangeAddressAlreadyRegisteredError(exchange); let tx = stakingWrapper.addExchangeAddressAsync(exchange); await expect(tx).to.revertWith(revertError); // 4 remove valid address await stakingWrapper.removeExchangeAddressAsync(exchange); const isValidAddressStillValid = await stakingWrapper.isValidExchangeAddressAsync(exchange); expect(isValidAddressStillValid).to.be.false(); // 5 try removing valid address again revertError = new StakingRevertErrors.ExchangeAddressNotRegisteredError(exchange); tx = stakingWrapper.removeExchangeAddressAsync(exchange); await expect(tx).to.revertWith(revertError); // @todo should not be able to add / remove an exchange if not contract owner. }); }); }); // tslint:enable:no-unnecessary-type-assertion