Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Make wrappers small again #2243

Merged
merged 9 commits into from
Oct 16, 2019
Merged
90 changes: 16 additions & 74 deletions contracts/asset-proxy/test/authorizable.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
chaiSetup,
constants,
expectTransactionFailedAsync,
provider,
txDefaults,
web3Wrapper,
} from '@0x/contracts-test-utils';
import { chaiSetup, expectTransactionFailedAsync, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { RevertReason } from '@0x/types';
import { BigNumber } from '@0x/utils';
Expand Down Expand Up @@ -60,21 +53,13 @@ describe('Authorizable', () => {
});

it('should allow owner to add an authorized address', async () => {
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
address,
{ from: owner },
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
const isAuthorized = await authorizable.authorized.callAsync(address);
expect(isAuthorized).to.be.true();
});

it('should revert if owner attempts to authorize a duplicate address', async () => {
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
address,
{ from: owner },
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
return expectTransactionFailedAsync(
authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }),
RevertReason.TargetAlreadyAuthorized,
Expand All @@ -84,28 +69,16 @@ describe('Authorizable', () => {

describe('removeAuthorizedAddress', () => {
it('should revert if not called by owner', async () => {
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
address,
{ from: owner },
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
await expectTransactionFailedAsync(
authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { from: notOwner }),
RevertReason.OnlyContractOwner,
);
});

it('should allow owner to remove an authorized address', async () => {
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
address,
{ from: owner },
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
await authorizable.removeAuthorizedAddress.awaitTransactionSuccessAsync(
address,
{ from: owner },
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
await authorizable.removeAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
const isAuthorized = await authorizable.authorized.callAsync(address);
expect(isAuthorized).to.be.false();
});
Expand All @@ -122,11 +95,7 @@ describe('Authorizable', () => {

describe('removeAuthorizedAddressAtIndex', () => {
it('should revert if not called by owner', async () => {
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
address,
{ from: owner },
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
const index = new BigNumber(0);
await expectTransactionFailedAsync(
authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address, index, {
Expand All @@ -137,11 +106,7 @@ describe('Authorizable', () => {
});

it('should revert if index is >= authorities.length', async () => {
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
address,
{ from: owner },
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
const index = new BigNumber(1);
return expectTransactionFailedAsync(
authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address, index, {
Expand All @@ -164,16 +129,8 @@ describe('Authorizable', () => {
it('should revert if address at index does not match target', async () => {
const address1 = address;
const address2 = notOwner;
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
address1,
{ from: owner },
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
address2,
{ from: owner },
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address1, { from: owner });
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address2, { from: owner });
const address1Index = new BigNumber(0);
return expectTransactionFailedAsync(
authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address2, address1Index, {
Expand All @@ -184,18 +141,11 @@ describe('Authorizable', () => {
});

it('should allow owner to remove an authorized address', async () => {
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
address,
{ from: owner },
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
const index = new BigNumber(0);
await authorizable.removeAuthorizedAddressAtIndex.awaitTransactionSuccessAsync(
address,
index,
{ from: owner },
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
await authorizable.removeAuthorizedAddressAtIndex.awaitTransactionSuccessAsync(address, index, {
from: owner,
});
const isAuthorized = await authorizable.authorized.callAsync(address);
expect(isAuthorized).to.be.false();
});
Expand All @@ -205,19 +155,11 @@ describe('Authorizable', () => {
it('should return all authorized addresses', async () => {
const initial = await authorizable.getAuthorizedAddresses.callAsync();
expect(initial).to.have.length(0);
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
address,
{ from: owner },
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
const afterAdd = await authorizable.getAuthorizedAddresses.callAsync();
expect(afterAdd).to.have.length(1);
expect(afterAdd).to.include(address);
await authorizable.removeAuthorizedAddress.awaitTransactionSuccessAsync(
address,
{ from: owner },
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
await authorizable.removeAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
const afterRemove = await authorizable.getAuthorizedAddresses.callAsync();
expect(afterRemove).to.have.length(0);
});
Expand Down
91 changes: 29 additions & 62 deletions contracts/asset-proxy/test/erc1155_proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,8 @@ describe('ERC1155Proxy', () => {
const usedAddresses = ([owner, notAuthorized, authorized, spender, receiver] = _.slice(accounts, 0, 5));
erc1155ProxyWrapper = new ERC1155ProxyWrapper(provider, usedAddresses, owner);
erc1155Proxy = await erc1155ProxyWrapper.deployProxyAsync();
await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(
authorized,
{ from: owner },
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(
erc1155Proxy.address,
{ from: owner },
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(authorized, { from: owner });
await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(erc1155Proxy.address, { from: owner });
// deploy & configure ERC1155 tokens and receiver
[erc1155Wrapper] = await erc1155ProxyWrapper.deployDummyContractsAsync();
erc1155Contract = erc1155Wrapper.getContract();
Expand Down Expand Up @@ -696,25 +688,18 @@ describe('ERC1155Proxy', () => {
const tokenUri = '';
for (const tokenToCreate of tokensToCreate) {
// create token
await erc1155Wrapper.getContract().createWithType.awaitTransactionSuccessAsync(
tokenToCreate,
tokenUri,
{
await erc1155Wrapper
.getContract()
.createWithType.awaitTransactionSuccessAsync(tokenToCreate, tokenUri, {
from: owner,
},
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
});

// mint balance for spender
await erc1155Wrapper.getContract().mintFungible.awaitTransactionSuccessAsync(
tokenToCreate,
[spender],
[spenderInitialBalance],
{
await erc1155Wrapper
.getContract()
.mintFungible.awaitTransactionSuccessAsync(tokenToCreate, [spender], [spenderInitialBalance], {
from: owner,
},
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
});
}
///// Step 2/5 /////
// Check balances before transfer
Expand Down Expand Up @@ -805,25 +790,18 @@ describe('ERC1155Proxy', () => {
const tokenUri = '';
for (const tokenToCreate of tokensToCreate) {
// create token
await erc1155Wrapper.getContract().createWithType.awaitTransactionSuccessAsync(
tokenToCreate,
tokenUri,
{
await erc1155Wrapper
.getContract()
.createWithType.awaitTransactionSuccessAsync(tokenToCreate, tokenUri, {
from: owner,
},
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
});

// mint balance for spender
await erc1155Wrapper.getContract().mintFungible.awaitTransactionSuccessAsync(
tokenToCreate,
[spender],
[spenderInitialBalance],
{
await erc1155Wrapper
.getContract()
.mintFungible.awaitTransactionSuccessAsync(tokenToCreate, [spender], [spenderInitialBalance], {
from: owner,
},
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
});
}
///// Step 2/5 /////
// Check balances before transfer
Expand Down Expand Up @@ -937,25 +915,18 @@ describe('ERC1155Proxy', () => {
const tokenUri = '';
for (const tokenToCreate of tokensToCreate) {
// create token
await erc1155Wrapper.getContract().createWithType.awaitTransactionSuccessAsync(
tokenToCreate,
tokenUri,
{
await erc1155Wrapper
.getContract()
.createWithType.awaitTransactionSuccessAsync(tokenToCreate, tokenUri, {
from: owner,
},
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
});

// mint balance for spender
await erc1155Wrapper.getContract().mintFungible.awaitTransactionSuccessAsync(
tokenToCreate,
[spender],
[spenderInitialBalance],
{
await erc1155Wrapper
.getContract()
.mintFungible.awaitTransactionSuccessAsync(tokenToCreate, [spender], [spenderInitialBalance], {
from: owner,
},
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
});
}
///// Step 2/5 /////
// Check balances before transfer
Expand Down Expand Up @@ -1667,13 +1638,9 @@ describe('ERC1155Proxy', () => {
it('should propagate revert reason from erc1155 contract failure', async () => {
// disable transfers
const shouldRejectTransfer = true;
await erc1155Receiver.setRejectTransferFlag.awaitTransactionSuccessAsync(
shouldRejectTransfer,
{
from: owner,
},
{ timeoutMs: constants.AWAIT_TRANSACTION_MINED_MS },
);
await erc1155Receiver.setRejectTransferFlag.awaitTransactionSuccessAsync(shouldRejectTransfer, {
from: owner,
});
// setup test parameters
const tokenHolders = [spender, receiverContract];
const tokensToTransfer = fungibleTokens.slice(0, 1);
Expand Down
Loading