aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-01-19 20:49:10 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-01-30 23:01:35 +0800
commitfca051c5656c29164d9ef05fe5124b98972b79cc (patch)
tree2ad56bafd58fed8af562093763698cc5a4f88672
parent6463cda2045fe9caca3cb3908aa0c66f0bfe683a (diff)
downloaddexon-sol-tools-fca051c5656c29164d9ef05fe5124b98972b79cc.tar
dexon-sol-tools-fca051c5656c29164d9ef05fe5124b98972b79cc.tar.gz
dexon-sol-tools-fca051c5656c29164d9ef05fe5124b98972b79cc.tar.bz2
dexon-sol-tools-fca051c5656c29164d9ef05fe5124b98972b79cc.tar.lz
dexon-sol-tools-fca051c5656c29164d9ef05fe5124b98972b79cc.tar.xz
dexon-sol-tools-fca051c5656c29164d9ef05fe5124b98972b79cc.tar.zst
dexon-sol-tools-fca051c5656c29164d9ef05fe5124b98972b79cc.zip
Remove truffle from tokenTransferProxy tests
-rw-r--r--packages/contracts/test/token_transfer_proxy/auth.ts67
-rw-r--r--packages/contracts/test/token_transfer_proxy/transfer_from.ts9
2 files changed, 37 insertions, 39 deletions
diff --git a/packages/contracts/test/token_transfer_proxy/auth.ts b/packages/contracts/test/token_transfer_proxy/auth.ts
index aa0ad2fc5..414de9834 100644
--- a/packages/contracts/test/token_transfer_proxy/auth.ts
+++ b/packages/contracts/test/token_transfer_proxy/auth.ts
@@ -1,4 +1,7 @@
+import { BlockchainLifecycle } from '@0xproject/dev-utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
+import * as Web3 from 'web3';
import { constants } from '../../util/constants';
import { ContractInstance } from '../../util/types';
@@ -7,38 +10,44 @@ import { chaiSetup } from '../utils/chai_setup';
chaiSetup.configure();
const expect = chai.expect;
const TokenTransferProxy = artifacts.require('./db/TokenTransferProxy.sol');
+// In order to benefit from type-safety, we re-assign the global web3 instance injected by Truffle
+// with type `any` to a variable of type `Web3`.
+const web3: Web3 = (global as any).web3;
+const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
-contract('TokenTransferProxy', (accounts: string[]) => {
- const owner = accounts[0];
- const notOwner = accounts[1];
-
+describe('TokenTransferProxy', () => {
+ const web3Wrapper = new Web3Wrapper(web3.currentProvider);
+ let accounts: string[];
+ let owner: string;
+ let notOwner: string;
+ let address: string;
let tokenTransferProxy: ContractInstance;
- let authorized: string;
- let notAuthorized = owner;
-
before(async () => {
+ accounts = await web3Wrapper.getAvailableAddressesAsync();
+ owner = address = accounts[0];
+ notOwner = accounts[1];
tokenTransferProxy = await TokenTransferProxy.deployed();
});
-
+ beforeEach(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
describe('addAuthorizedAddress', () => {
it('should throw if not called by owner', async () => {
return expect(tokenTransferProxy.addAuthorizedAddress(notOwner, { from: notOwner })).to.be.rejectedWith(
constants.REVERT,
);
});
-
it('should allow owner to add an authorized address', async () => {
- await tokenTransferProxy.addAuthorizedAddress(notAuthorized, {
- from: owner,
- });
- authorized = notAuthorized;
- notAuthorized = null;
- const isAuthorized = await tokenTransferProxy.authorized.call(authorized);
+ await tokenTransferProxy.addAuthorizedAddress(address, { from: owner });
+ const isAuthorized = await tokenTransferProxy.authorized.call(address);
expect(isAuthorized).to.be.true();
});
-
it('should throw if owner attempts to authorize a duplicate address', async () => {
- return expect(tokenTransferProxy.addAuthorizedAddress(authorized, { from: owner })).to.be.rejectedWith(
+ await tokenTransferProxy.addAuthorizedAddress(address, { from: owner });
+ return expect(tokenTransferProxy.addAuthorizedAddress(address, { from: owner })).to.be.rejectedWith(
constants.REVERT,
);
});
@@ -46,27 +55,26 @@ contract('TokenTransferProxy', (accounts: string[]) => {
describe('removeAuthorizedAddress', () => {
it('should throw if not called by owner', async () => {
+ await tokenTransferProxy.addAuthorizedAddress(address, { from: owner });
return expect(
- tokenTransferProxy.removeAuthorizedAddress(authorized, {
+ tokenTransferProxy.removeAuthorizedAddress(address, {
from: notOwner,
}),
).to.be.rejectedWith(constants.REVERT);
});
it('should allow owner to remove an authorized address', async () => {
- await tokenTransferProxy.removeAuthorizedAddress(authorized, {
+ await tokenTransferProxy.addAuthorizedAddress(address, { from: owner });
+ await tokenTransferProxy.removeAuthorizedAddress(address, {
from: owner,
});
- notAuthorized = authorized;
- authorized = null;
-
- const isAuthorized = await tokenTransferProxy.authorized.call(notAuthorized);
+ const isAuthorized = await tokenTransferProxy.authorized.call(address);
expect(isAuthorized).to.be.false();
});
it('should throw if owner attempts to remove an address that is not authorized', async () => {
return expect(
- tokenTransferProxy.removeAuthorizedAddress(notAuthorized, {
+ tokenTransferProxy.removeAuthorizedAddress(address, {
from: owner,
}),
).to.be.rejectedWith(constants.REVERT);
@@ -77,21 +85,16 @@ contract('TokenTransferProxy', (accounts: string[]) => {
it('should return all authorized addresses', async () => {
const initial = await tokenTransferProxy.getAuthorizedAddresses();
expect(initial).to.have.length(1);
- await tokenTransferProxy.addAuthorizedAddress(notAuthorized, {
+ await tokenTransferProxy.addAuthorizedAddress(address, {
from: owner,
});
-
- authorized = notAuthorized;
- notAuthorized = null;
const afterAdd = await tokenTransferProxy.getAuthorizedAddresses();
expect(afterAdd).to.have.length(2);
- expect(afterAdd).to.include(authorized);
+ expect(afterAdd).to.include(address);
- await tokenTransferProxy.removeAuthorizedAddress(authorized, {
+ await tokenTransferProxy.removeAuthorizedAddress(address, {
from: owner,
});
- notAuthorized = authorized;
- authorized = null;
const afterRemove = await tokenTransferProxy.getAuthorizedAddresses();
expect(afterRemove).to.have.length(1);
});
diff --git a/packages/contracts/test/token_transfer_proxy/transfer_from.ts b/packages/contracts/test/token_transfer_proxy/transfer_from.ts
index b5e1c7017..1a5151309 100644
--- a/packages/contracts/test/token_transfer_proxy/transfer_from.ts
+++ b/packages/contracts/test/token_transfer_proxy/transfer_from.ts
@@ -22,13 +22,6 @@ describe('TokenTransferProxy', () => {
let accounts: string[];
let owner: string;
let notAuthorized: string;
- const config = {
- networkId: constants.TESTRPC_NETWORK_ID,
- };
- before(async () => {
- accounts = await web3Wrapper.getAvailableAddressesAsync();
- owner = notAuthorized = accounts[0];
- });
const INIT_BAL = 100000000;
const INIT_ALLOW = 100000000;
@@ -38,6 +31,8 @@ describe('TokenTransferProxy', () => {
let dmyBalances: Balances;
before(async () => {
+ accounts = await web3Wrapper.getAvailableAddressesAsync();
+ owner = notAuthorized = accounts[0];
[tokenTransferProxy, tokenRegistry] = await Promise.all([
TokenTransferProxy.deployed(),
TokenRegistry.deployed(),