Remove truffle from tokenTransferProxy tests
This commit is contained in:
parent
6463cda204
commit
fca051c565
@ -1,4 +1,7 @@
|
|||||||
|
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||||
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
|
import * as Web3 from 'web3';
|
||||||
|
|
||||||
import { constants } from '../../util/constants';
|
import { constants } from '../../util/constants';
|
||||||
import { ContractInstance } from '../../util/types';
|
import { ContractInstance } from '../../util/types';
|
||||||
@ -7,38 +10,44 @@ import { chaiSetup } from '../utils/chai_setup';
|
|||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
const TokenTransferProxy = artifacts.require('./db/TokenTransferProxy.sol');
|
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[]) => {
|
describe('TokenTransferProxy', () => {
|
||||||
const owner = accounts[0];
|
const web3Wrapper = new Web3Wrapper(web3.currentProvider);
|
||||||
const notOwner = accounts[1];
|
let accounts: string[];
|
||||||
|
let owner: string;
|
||||||
|
let notOwner: string;
|
||||||
|
let address: string;
|
||||||
let tokenTransferProxy: ContractInstance;
|
let tokenTransferProxy: ContractInstance;
|
||||||
let authorized: string;
|
|
||||||
let notAuthorized = owner;
|
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||||
|
owner = address = accounts[0];
|
||||||
|
notOwner = accounts[1];
|
||||||
tokenTransferProxy = await TokenTransferProxy.deployed();
|
tokenTransferProxy = await TokenTransferProxy.deployed();
|
||||||
});
|
});
|
||||||
|
beforeEach(async () => {
|
||||||
|
await blockchainLifecycle.startAsync();
|
||||||
|
});
|
||||||
|
afterEach(async () => {
|
||||||
|
await blockchainLifecycle.revertAsync();
|
||||||
|
});
|
||||||
describe('addAuthorizedAddress', () => {
|
describe('addAuthorizedAddress', () => {
|
||||||
it('should throw if not called by owner', async () => {
|
it('should throw if not called by owner', async () => {
|
||||||
return expect(tokenTransferProxy.addAuthorizedAddress(notOwner, { from: notOwner })).to.be.rejectedWith(
|
return expect(tokenTransferProxy.addAuthorizedAddress(notOwner, { from: notOwner })).to.be.rejectedWith(
|
||||||
constants.REVERT,
|
constants.REVERT,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow owner to add an authorized address', async () => {
|
it('should allow owner to add an authorized address', async () => {
|
||||||
await tokenTransferProxy.addAuthorizedAddress(notAuthorized, {
|
await tokenTransferProxy.addAuthorizedAddress(address, { from: owner });
|
||||||
from: owner,
|
const isAuthorized = await tokenTransferProxy.authorized.call(address);
|
||||||
});
|
|
||||||
authorized = notAuthorized;
|
|
||||||
notAuthorized = null;
|
|
||||||
const isAuthorized = await tokenTransferProxy.authorized.call(authorized);
|
|
||||||
expect(isAuthorized).to.be.true();
|
expect(isAuthorized).to.be.true();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw if owner attempts to authorize a duplicate address', async () => {
|
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,
|
constants.REVERT,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -46,27 +55,26 @@ contract('TokenTransferProxy', (accounts: string[]) => {
|
|||||||
|
|
||||||
describe('removeAuthorizedAddress', () => {
|
describe('removeAuthorizedAddress', () => {
|
||||||
it('should throw if not called by owner', async () => {
|
it('should throw if not called by owner', async () => {
|
||||||
|
await tokenTransferProxy.addAuthorizedAddress(address, { from: owner });
|
||||||
return expect(
|
return expect(
|
||||||
tokenTransferProxy.removeAuthorizedAddress(authorized, {
|
tokenTransferProxy.removeAuthorizedAddress(address, {
|
||||||
from: notOwner,
|
from: notOwner,
|
||||||
}),
|
}),
|
||||||
).to.be.rejectedWith(constants.REVERT);
|
).to.be.rejectedWith(constants.REVERT);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow owner to remove an authorized address', async () => {
|
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,
|
from: owner,
|
||||||
});
|
});
|
||||||
notAuthorized = authorized;
|
const isAuthorized = await tokenTransferProxy.authorized.call(address);
|
||||||
authorized = null;
|
|
||||||
|
|
||||||
const isAuthorized = await tokenTransferProxy.authorized.call(notAuthorized);
|
|
||||||
expect(isAuthorized).to.be.false();
|
expect(isAuthorized).to.be.false();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw if owner attempts to remove an address that is not authorized', async () => {
|
it('should throw if owner attempts to remove an address that is not authorized', async () => {
|
||||||
return expect(
|
return expect(
|
||||||
tokenTransferProxy.removeAuthorizedAddress(notAuthorized, {
|
tokenTransferProxy.removeAuthorizedAddress(address, {
|
||||||
from: owner,
|
from: owner,
|
||||||
}),
|
}),
|
||||||
).to.be.rejectedWith(constants.REVERT);
|
).to.be.rejectedWith(constants.REVERT);
|
||||||
@ -77,21 +85,16 @@ contract('TokenTransferProxy', (accounts: string[]) => {
|
|||||||
it('should return all authorized addresses', async () => {
|
it('should return all authorized addresses', async () => {
|
||||||
const initial = await tokenTransferProxy.getAuthorizedAddresses();
|
const initial = await tokenTransferProxy.getAuthorizedAddresses();
|
||||||
expect(initial).to.have.length(1);
|
expect(initial).to.have.length(1);
|
||||||
await tokenTransferProxy.addAuthorizedAddress(notAuthorized, {
|
await tokenTransferProxy.addAuthorizedAddress(address, {
|
||||||
from: owner,
|
from: owner,
|
||||||
});
|
});
|
||||||
|
|
||||||
authorized = notAuthorized;
|
|
||||||
notAuthorized = null;
|
|
||||||
const afterAdd = await tokenTransferProxy.getAuthorizedAddresses();
|
const afterAdd = await tokenTransferProxy.getAuthorizedAddresses();
|
||||||
expect(afterAdd).to.have.length(2);
|
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,
|
from: owner,
|
||||||
});
|
});
|
||||||
notAuthorized = authorized;
|
|
||||||
authorized = null;
|
|
||||||
const afterRemove = await tokenTransferProxy.getAuthorizedAddresses();
|
const afterRemove = await tokenTransferProxy.getAuthorizedAddresses();
|
||||||
expect(afterRemove).to.have.length(1);
|
expect(afterRemove).to.have.length(1);
|
||||||
});
|
});
|
||||||
|
@ -22,13 +22,6 @@ describe('TokenTransferProxy', () => {
|
|||||||
let accounts: string[];
|
let accounts: string[];
|
||||||
let owner: string;
|
let owner: string;
|
||||||
let notAuthorized: 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_BAL = 100000000;
|
||||||
const INIT_ALLOW = 100000000;
|
const INIT_ALLOW = 100000000;
|
||||||
|
|
||||||
@ -38,6 +31,8 @@ describe('TokenTransferProxy', () => {
|
|||||||
let dmyBalances: Balances;
|
let dmyBalances: Balances;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||||
|
owner = notAuthorized = accounts[0];
|
||||||
[tokenTransferProxy, tokenRegistry] = await Promise.all([
|
[tokenTransferProxy, tokenRegistry] = await Promise.all([
|
||||||
TokenTransferProxy.deployed(),
|
TokenTransferProxy.deployed(),
|
||||||
TokenRegistry.deployed(),
|
TokenRegistry.deployed(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user