* 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
83 lines
4.0 KiB
TypeScript
83 lines
4.0 KiB
TypeScript
import { blockchainTests, expect, filterLogsToArguments } from '@0x/contracts-test-utils';
|
|
import { AuthorizableRevertErrors, 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
|