protocol/contracts/zero-ex/test/initial_migration_test.ts
Lawrence Forman 2fce332ed7
ZeroEx: TransformERC20, TokenSpender (#2545)
* `@0x/contracts-utils`: Convert more 0.6 contracts

* `@0x/contracts-erc20`: Add solidity 0.6 contracts.

* `@0x/utils`: Add new `ZeroExRevertErrors` revert types

* `@0x/contracts-zero-ex`: Introduce the `TransformERC20` feature.

* `@0x/subproviders`: Update ganache-core.
`@0x/web3-wrapper`: Update ganache-core.

* `@0x/contracts-zero-ex`: Make `TokenSpender`'s puppet contract a distinct contract type and rename `getTokenSpenderPuppet()` to `getAllowanceTarget()`

* `@0x/zero-ex`: Rebase and use "slot" instead of "offset" language in storage buckets.

* `@0x/web3-wrapper`: Add `getAccountNonceAsync()` to `Web3Wrapper`

* `@0x/contracts-zero-ex`: Revamp TransformERC20.

* `@0x/contracts-zero-ex`: Remove `payable` from `IERC20Transformer.transform()` and disable hex capitalization linter rule because of prettier conflicts.

* `@0x/contracts-zero-ex`: Use `immutable` owner in `Puppet` instead of `Ownable`.

* `@x/utils`: Address review feedback.

* `@0x/contracts-zero-ex`: Address review feedback.

* `@0x/contracts-utils`: Address review feedback.

* `@0x/contracts-zero-ex`: Return deployment nonce in `transform()`.

* `@0x/contracts-zero-ex`: Finish returning deployment nonce in `transform()`.

* `@0x/contracts-zero-ex`: Fix doc-gen bug.

* `@0x/contracts-zero-ex`: Address review comments.

* `@0x/utils`: Add `NegativeTransformERC20OutputERror`

* `@0x/contracts-zero-ex`: Revert if the taker's output amount decreases.

Co-authored-by: Lawrence Forman <me@merklejerk.com>
2020-05-20 22:47:21 -04:00

91 lines
3.4 KiB
TypeScript

import { blockchainTests, expect, randomAddress } from '@0x/contracts-test-utils';
import { ZeroExRevertErrors } from '@0x/utils';
import { artifacts } from './artifacts';
import { BootstrapFeatures, deployBootstrapFeaturesAsync, toFeatureAdddresses } from './utils/migration';
import {
IBootstrapContract,
InitialMigrationContract,
IOwnableContract,
TestInitialMigrationContract,
ZeroExContract,
} from './wrappers';
blockchainTests.resets('Initial migration', env => {
let owner: string;
let zeroEx: ZeroExContract;
let migrator: TestInitialMigrationContract;
let bootstrapFeature: IBootstrapContract;
let features: BootstrapFeatures;
before(async () => {
[owner] = await env.getAccountAddressesAsync();
features = await deployBootstrapFeaturesAsync(env.provider, env.txDefaults);
migrator = await TestInitialMigrationContract.deployFrom0xArtifactAsync(
artifacts.TestInitialMigration,
env.provider,
env.txDefaults,
artifacts,
env.txDefaults.from as string,
);
bootstrapFeature = new IBootstrapContract(
await migrator.bootstrapFeature().callAsync(),
env.provider,
env.txDefaults,
{},
);
const deployCall = migrator.deploy(owner, toFeatureAdddresses(features));
zeroEx = new ZeroExContract(await deployCall.callAsync(), env.provider, env.txDefaults);
await deployCall.awaitTransactionSuccessAsync();
});
it('Self-destructs after deployment', async () => {
const dieRecipient = await migrator.dieRecipient().callAsync();
expect(dieRecipient).to.eq(owner);
});
it('Non-deployer cannot call deploy()', async () => {
const notDeployer = randomAddress();
const tx = migrator.deploy(owner, toFeatureAdddresses(features)).callAsync({ from: notDeployer });
return expect(tx).to.revertWith('InitialMigration/INVALID_SENDER');
});
it('External contract cannot call die()', async () => {
const _migrator = await InitialMigrationContract.deployFrom0xArtifactAsync(
artifacts.InitialMigration,
env.provider,
env.txDefaults,
artifacts,
env.txDefaults.from as string,
);
const tx = _migrator.die(owner).callAsync();
return expect(tx).to.revertWith('InitialMigration/INVALID_SENDER');
});
describe('bootstrapping', () => {
it('Migrator cannot call bootstrap() again', async () => {
const tx = migrator.callBootstrap(zeroEx.address).awaitTransactionSuccessAsync();
const selector = bootstrapFeature.getSelector('bootstrap');
return expect(tx).to.revertWith(new ZeroExRevertErrors.Proxy.NotImplementedError(selector));
});
it('Bootstrap feature self destructs after deployment', async () => {
const doesExist = await env.web3Wrapper.doesContractExistAtAddressAsync(bootstrapFeature.address);
expect(doesExist).to.eq(false);
});
});
describe('Ownable feature', () => {
let ownable: IOwnableContract;
before(async () => {
ownable = new IOwnableContract(zeroEx.address, env.provider, env.txDefaults);
});
it('has the correct owner', async () => {
const actualOwner = await ownable.owner().callAsync();
expect(actualOwner).to.eq(owner);
});
});
});