aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/asset_proxy_dispatcher/auth.ts
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-04-17 08:33:55 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-21 04:56:18 +0800
commitc19fb1dffcca820e1e82b5baad4b126abda8d112 (patch)
treeb899bd223172aed975e0fc3f5aca9e4b5a17c8bc /packages/contracts/test/asset_proxy_dispatcher/auth.ts
parent436a6605fb990d4c7aaea5688aefad73dee4d748 (diff)
downloaddexon-sol-tools-c19fb1dffcca820e1e82b5baad4b126abda8d112.tar.gz
dexon-sol-tools-c19fb1dffcca820e1e82b5baad4b126abda8d112.tar.zst
dexon-sol-tools-c19fb1dffcca820e1e82b5baad4b126abda8d112.zip
Removed ERC20 V1 Proxy + TokenTransferProxy
Diffstat (limited to 'packages/contracts/test/asset_proxy_dispatcher/auth.ts')
-rw-r--r--packages/contracts/test/asset_proxy_dispatcher/auth.ts104
1 files changed, 104 insertions, 0 deletions
diff --git a/packages/contracts/test/asset_proxy_dispatcher/auth.ts b/packages/contracts/test/asset_proxy_dispatcher/auth.ts
new file mode 100644
index 000000000..ded5ff287
--- /dev/null
+++ b/packages/contracts/test/asset_proxy_dispatcher/auth.ts
@@ -0,0 +1,104 @@
+import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
+import * as chai from 'chai';
+import * as Web3 from 'web3';
+
+import { AssetProxyDispatcherContract } from '../../src/contract_wrappers/generated/asset_proxy_dispatcher';
+import { constants } from '../../src/utils/constants';
+import { ContractName } from '../../src/utils/types';
+import { chaiSetup } from '../utils/chai_setup';
+import { deployer } from '../utils/deployer';
+import { provider, web3Wrapper } from '../utils/web3_wrapper';
+
+chaiSetup.configure();
+const expect = chai.expect;
+const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
+
+describe('AssetProxyDispatcher - Auth', () => {
+ let owner: string;
+ let notOwner: string;
+ let address: string;
+ let assetProxyDispatcher: AssetProxyDispatcherContract;
+ before(async () => {
+ const accounts = await web3Wrapper.getAvailableAddressesAsync();
+ owner = address = accounts[0];
+ notOwner = accounts[1];
+ const assetProxyDispatcherInstance = await deployer.deployAsync(ContractName.AssetProxyDispatcher);
+ assetProxyDispatcher = new AssetProxyDispatcherContract(
+ assetProxyDispatcherInstance.abi,
+ assetProxyDispatcherInstance.address,
+ provider,
+ );
+ });
+ beforeEach(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
+ describe('addAuthorizedAddress', () => {
+ it('should throw if not called by owner', async () => {
+ return expect(
+ assetProxyDispatcher.addAuthorizedAddress.sendTransactionAsync(notOwner, { from: notOwner }),
+ ).to.be.rejectedWith(constants.REVERT);
+ });
+ it('should allow owner to add an authorized address', async () => {
+ await assetProxyDispatcher.addAuthorizedAddress.sendTransactionAsync(address, { from: owner });
+ const isAuthorized = await assetProxyDispatcher.authorized.callAsync(address);
+ expect(isAuthorized).to.be.true();
+ });
+ it('should throw if owner attempts to authorize a duplicate address', async () => {
+ await assetProxyDispatcher.addAuthorizedAddress.sendTransactionAsync(address, { from: owner });
+ return expect(
+ assetProxyDispatcher.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }),
+ ).to.be.rejectedWith(constants.REVERT);
+ });
+ });
+
+ describe('removeAuthorizedAddress', () => {
+ it('should throw if not called by owner', async () => {
+ await assetProxyDispatcher.addAuthorizedAddress.sendTransactionAsync(address, { from: owner });
+ return expect(
+ assetProxyDispatcher.removeAuthorizedAddress.sendTransactionAsync(address, {
+ from: notOwner,
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
+ });
+
+ it('should allow owner to remove an authorized address', async () => {
+ await assetProxyDispatcher.addAuthorizedAddress.sendTransactionAsync(address, { from: owner });
+ await assetProxyDispatcher.removeAuthorizedAddress.sendTransactionAsync(address, {
+ from: owner,
+ });
+ const isAuthorized = await assetProxyDispatcher.authorized.callAsync(address);
+ expect(isAuthorized).to.be.false();
+ });
+
+ it('should throw if owner attempts to remove an address that is not authorized', async () => {
+ return expect(
+ assetProxyDispatcher.removeAuthorizedAddress.sendTransactionAsync(address, {
+ from: owner,
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
+ });
+ });
+
+ describe('getAuthorizedAddresses', () => {
+ it('should return all authorized addresses', async () => {
+ const initial = await assetProxyDispatcher.getAuthorizedAddresses.callAsync();
+ expect(initial).to.have.length(0);
+ await assetProxyDispatcher.addAuthorizedAddress.sendTransactionAsync(address, {
+ from: owner,
+ });
+ const afterAdd = await assetProxyDispatcher.getAuthorizedAddresses.callAsync();
+ expect(afterAdd).to.have.length(1);
+ expect(afterAdd).to.include(address);
+
+ await assetProxyDispatcher.removeAuthorizedAddress.sendTransactionAsync(address, {
+ from: owner,
+ });
+ const afterRemove = await assetProxyDispatcher.getAuthorizedAddresses.callAsync();
+ expect(afterRemove).to.have.length(0);
+ });
+ });
+});