aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/asset_proxy/authorizable.ts
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-04-23 08:25:28 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-24 01:50:09 +0800
commit432b064601776d4daacfc2415c3da41c91a24d27 (patch)
tree40e4e240dbd3e7a5441d3d2c5a52f3a64b2a8ac6 /packages/contracts/test/asset_proxy/authorizable.ts
parenta8a0a5cbfb7299cd22181c8713e1da6dec412dae (diff)
downloaddexon-sol-tools-432b064601776d4daacfc2415c3da41c91a24d27.tar
dexon-sol-tools-432b064601776d4daacfc2415c3da41c91a24d27.tar.gz
dexon-sol-tools-432b064601776d4daacfc2415c3da41c91a24d27.tar.bz2
dexon-sol-tools-432b064601776d4daacfc2415c3da41c91a24d27.tar.lz
dexon-sol-tools-432b064601776d4daacfc2415c3da41c91a24d27.tar.xz
dexon-sol-tools-432b064601776d4daacfc2415c3da41c91a24d27.tar.zst
dexon-sol-tools-432b064601776d4daacfc2415c3da41c91a24d27.zip
Fix tests
Diffstat (limited to 'packages/contracts/test/asset_proxy/authorizable.ts')
-rw-r--r--packages/contracts/test/asset_proxy/authorizable.ts100
1 files changed, 100 insertions, 0 deletions
diff --git a/packages/contracts/test/asset_proxy/authorizable.ts b/packages/contracts/test/asset_proxy/authorizable.ts
new file mode 100644
index 000000000..cc4f78a31
--- /dev/null
+++ b/packages/contracts/test/asset_proxy/authorizable.ts
@@ -0,0 +1,100 @@
+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 { AuthorizableContract } from '../../src/contract_wrappers/generated/authorizable';
+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('Authorizable', () => {
+ let owner: string;
+ let notOwner: string;
+ let address: string;
+ let authorizable: AuthorizableContract;
+ before(async () => {
+ const accounts = await web3Wrapper.getAvailableAddressesAsync();
+ owner = address = accounts[0];
+ notOwner = accounts[1];
+ const authorizableInstance = await deployer.deployAsync(ContractName.Authorizable);
+ authorizable = new AuthorizableContract(authorizableInstance.abi, authorizableInstance.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(
+ authorizable.addAuthorizedAddress.sendTransactionAsync(notOwner, { from: notOwner }),
+ ).to.be.rejectedWith(constants.REVERT);
+ });
+ it('should allow owner to add an authorized address', async () => {
+ await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner });
+ const isAuthorized = await authorizable.authorized.callAsync(address);
+ expect(isAuthorized).to.be.true();
+ });
+ it('should throw if owner attempts to authorize a duplicate address', async () => {
+ await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner });
+ return expect(
+ authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }),
+ ).to.be.rejectedWith(constants.REVERT);
+ });
+ });
+
+ describe('removeAuthorizedAddress', () => {
+ it('should throw if not called by owner', async () => {
+ await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner });
+ return expect(
+ authorizable.removeAuthorizedAddress.sendTransactionAsync(address, {
+ from: notOwner,
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
+ });
+
+ it('should allow owner to remove an authorized address', async () => {
+ await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner });
+ await authorizable.removeAuthorizedAddress.sendTransactionAsync(address, {
+ from: owner,
+ });
+ const isAuthorized = await authorizable.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(
+ authorizable.removeAuthorizedAddress.sendTransactionAsync(address, {
+ from: owner,
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
+ });
+ });
+
+ describe('getAuthorizedAddresses', () => {
+ it('should return all authorized addresses', async () => {
+ const initial = await authorizable.getAuthorizedAddresses.callAsync();
+ expect(initial).to.have.length(0);
+ await authorizable.addAuthorizedAddress.sendTransactionAsync(address, {
+ from: owner,
+ });
+ const afterAdd = await authorizable.getAuthorizedAddresses.callAsync();
+ expect(afterAdd).to.have.length(1);
+ expect(afterAdd).to.include(address);
+
+ await authorizable.removeAuthorizedAddress.sendTransactionAsync(address, {
+ from: owner,
+ });
+ const afterRemove = await authorizable.getAuthorizedAddresses.callAsync();
+ expect(afterRemove).to.have.length(0);
+ });
+ });
+});