F. Eugene Aumson f11d8a5bd8
@0x/order-utils refactors for v3: orderParsingUtils, signatureUtils, orderHashUtils, RevertErrors, transactionHashUtils (#2321)
* move orderParsingUtils from order-utils to connect

* Remove many functions from signatureUtils

Removed from the exported object, that is.  All of them are used in
other existing code, so they were all moved to be as local to their
usage as possible.

* remove orderHashUtils.isValidOrderHash()

* Move all *RevertErrors from order-utils...

...into their respective @0x/contracts- packages.

* Refactor @0x/order-utils' orderHashUtils away

- Move existing routines into @0x/contracts-test-utils

- Migrate non-contract-test callers to a newly-exposed getOrderHash()
method in DevUtils.

* Move all *RevertErrors from @0x/utils...

...into their respective @0x/contracts- packages.

* rm transactionHashUtils.isValidTransactionHash()

* DevUtils.sol: Fail yarn test if too big to deploy

* Refactor @0x/order-utils transactionHashUtils away

- Move existing routines into @0x/contracts-test-utils

- Migrate non-contract-test callers to a newly-exposed
getTransactionHash() method in DevUtils.

* Consolidate `Removed export...` CHANGELOG entries

* Rm EthBalanceChecker from devutils wrapper exports

* Stop importing from '.' or '.../src'

* fix builds

* fix prettier; dangling promise

* increase max bundle size
2019-11-14 17:14:24 -05:00

61 lines
2.5 KiB
TypeScript

import { blockchainTests, constants, expect, filterLogsToArguments } from '@0x/contracts-test-utils';
import OwnableRevertErrors = require('../src/ownable_revert_errors');
import { artifacts } from './artifacts';
import { IOwnableEvents, IOwnableOwnershipTransferredEventArgs, TestOwnableContract } from './wrappers';
blockchainTests.resets('Ownable', env => {
let ownable: TestOwnableContract;
let owner: string;
let nonOwner: string;
before(async () => {
const accounts = await env.getAccountAddressesAsync();
owner = await accounts[0];
nonOwner = await accounts[1];
ownable = await TestOwnableContract.deployFrom0xArtifactAsync(
artifacts.TestOwnable,
env.provider,
{ ...env.txDefaults, from: owner },
artifacts,
);
});
describe('onlyOwner', () => {
it('should revert if sender is not the owner', async () => {
const expectedError = new OwnableRevertErrors.OnlyOwnerError(nonOwner, owner);
return expect(ownable.externalOnlyOwner().callAsync({ from: nonOwner })).to.revertWith(expectedError);
});
it('should succeed if sender is the owner', async () => {
const isSuccessful = await ownable.externalOnlyOwner().callAsync({ from: owner });
expect(isSuccessful).to.be.true();
});
});
describe('transferOwnership', () => {
it('should revert if the specified new owner is the zero address', async () => {
const expectedError = new OwnableRevertErrors.TransferOwnerToZeroError();
const tx = ownable.transferOwnership(constants.NULL_ADDRESS).sendTransactionAsync({ from: owner });
return expect(tx).to.revertWith(expectedError);
});
it('should transfer ownership if the specified new owner is not the zero address', async () => {
const receipt = await ownable.transferOwnership(nonOwner).awaitTransactionSuccessAsync({ from: owner });
// Ensure that the correct logs were emitted.
expect(receipt.logs.length).to.be.eq(1);
const [event] = filterLogsToArguments<IOwnableOwnershipTransferredEventArgs>(
receipt.logs,
IOwnableEvents.OwnershipTransferred,
);
expect(event).to.be.deep.eq({ previousOwner: owner, newOwner: nonOwner });
// Ensure that the owner was actually updated
const updatedOwner = await ownable.owner().callAsync();
expect(updatedOwner).to.be.eq(nonOwner);
});
});
});