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

84 lines
4.0 KiB
TypeScript

import { blockchainTests, expect, filterLogsToArguments } from '@0x/contracts-test-utils';
import { AuthorizableRevertErrors } from '@0x/contracts-utils';
import { BigNumber } from '@0x/utils';
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import * as _ from 'lodash';
import { artifacts } from '../artifacts';
import { IStakingEventsParamsSetEventArgs, TestMixinParamsContract } from '../wrappers';
import { constants as stakingConstants } from '../../src/constants';
import { StakingParams } from '../../src/types';
blockchainTests('Configurable Parameters unit tests', env => {
let testContract: TestMixinParamsContract;
let authorizedAddress: string;
let notAuthorizedAddress: string;
before(async () => {
[authorizedAddress, notAuthorizedAddress] = await env.getAccountAddressesAsync();
testContract = await TestMixinParamsContract.deployFrom0xArtifactAsync(
artifacts.TestMixinParams,
env.provider,
env.txDefaults,
artifacts,
);
await testContract.addAuthorizedAddress(authorizedAddress).awaitTransactionSuccessAsync();
});
blockchainTests.resets('setParams()', () => {
async function setParamsAndAssertAsync(
params: Partial<StakingParams>,
from?: string,
): Promise<TransactionReceiptWithDecodedLogs> {
const _params = {
...stakingConstants.DEFAULT_PARAMS,
...params,
};
const receipt = await testContract
.setParams(
new BigNumber(_params.epochDurationInSeconds),
new BigNumber(_params.rewardDelegatedStakeWeight),
new BigNumber(_params.minimumPoolStake),
new BigNumber(_params.cobbDouglasAlphaNumerator),
new BigNumber(_params.cobbDouglasAlphaDenominator),
)
.awaitTransactionSuccessAsync({ from });
// Assert event.
const events = filterLogsToArguments<IStakingEventsParamsSetEventArgs>(receipt.logs, 'ParamsSet');
expect(events.length).to.eq(1);
const event = events[0];
expect(event.epochDurationInSeconds).to.bignumber.eq(_params.epochDurationInSeconds);
expect(event.rewardDelegatedStakeWeight).to.bignumber.eq(_params.rewardDelegatedStakeWeight);
expect(event.minimumPoolStake).to.bignumber.eq(_params.minimumPoolStake);
expect(event.cobbDouglasAlphaNumerator).to.bignumber.eq(_params.cobbDouglasAlphaNumerator);
expect(event.cobbDouglasAlphaDenominator).to.bignumber.eq(_params.cobbDouglasAlphaDenominator);
// Assert `getParams()`.
const actual = await testContract.getParams().callAsync();
expect(actual[0]).to.bignumber.eq(_params.epochDurationInSeconds);
expect(actual[1]).to.bignumber.eq(_params.rewardDelegatedStakeWeight);
expect(actual[2]).to.bignumber.eq(_params.minimumPoolStake);
expect(actual[3]).to.bignumber.eq(_params.cobbDouglasAlphaNumerator);
expect(actual[4]).to.bignumber.eq(_params.cobbDouglasAlphaDenominator);
return receipt;
}
it('throws if not called by an authorized address', async () => {
const tx = setParamsAndAssertAsync({}, notAuthorizedAddress);
const expectedError = new AuthorizableRevertErrors.SenderNotAuthorizedError(notAuthorizedAddress);
return expect(tx).to.revertWith(expectedError);
});
it('throws if `assertValidStorageParams()` throws`', async () => {
await testContract.setShouldFailAssertValidStorageParams(true).awaitTransactionSuccessAsync();
const tx = setParamsAndAssertAsync({});
return expect(tx).to.revertWith('ASSERT_VALID_STORAGE_PARAMS_FAILED');
});
it('works if called by owner', async () => {
return setParamsAndAssertAsync({});
});
});
});
// tslint:enable:no-unnecessary-type-assertion