Xianny f0d7d10fe7
update abi-gen with new method interfaces (#2325)
* update abi-gen with new method interfaces

* wip: get all packages to build

* wip: get all packages to build

* Fix two contract wrapper calls

* Export necessary types part of the contract wrapper public interfaces

* Revive and fix wrapper_unit_tests

* Remove duplicate type

* Fix lib_exchange_rich_error_decoder tests

* Fix remaining test failures in contracts-* packages

* Prettier fixes

* remove transactionHelper

* lint and update changelogs

* Fix prettier

* Revert changes to reference docs

* Add back changelog already published and add revert changelog entry

* Add missing CHANGELOG entries

* Add missing comma

* Update mesh-rpc-client dep

* Update Mesh RPC logic in @0x/orderbook to v6.0.1-beta

* Align package versions
2019-11-14 11:22:29 -05:00

60 lines
2.5 KiB
TypeScript

import { blockchainTests, constants, expect, filterLogsToArguments } from '@0x/contracts-test-utils';
import { OwnableRevertErrors } from '@0x/utils';
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);
});
});
});