@0x/contracts-staking: Rebase against 3.0

This commit is contained in:
Lawrence Forman
2019-09-22 13:11:42 -04:00
parent e4126189df
commit eac4520406
15 changed files with 54 additions and 39 deletions

View File

@@ -24,7 +24,7 @@ blockchainTests('Migration tests', env => {
before(async () => {
[authorizedAddress, notAuthorizedAddress] = await env.getAccountAddressesAsync();
stakingContract = await StakingContract.deployFrom0xArtifactAsync(
artifacts.Staking,
artifacts.TestStakingNoWETH,
env.provider,
env.txDefaults,
artifacts,

View File

@@ -1,4 +1,4 @@
import { blockchainTests, expect, filterLogsToArguments } from '@0x/contracts-test-utils';
import { blockchainTests, constants, expect, filterLogsToArguments, randomAddress } from '@0x/contracts-test-utils';
import { AuthorizableRevertErrors, BigNumber } from '@0x/utils';
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import * as _ from 'lodash';
@@ -89,6 +89,43 @@ blockchainTests('Configurable Parameters unit tests', env => {
it('works if called by owner', async () => {
return setParamsAndAssertAsync({});
});
describe('WETH allowance', () => {
it('rescinds allowance for old vaults and grants unlimited allowance to new ones', async () => {
const [oldEthVaultAddress, oldRewardVaultAddress, newEthVaultAddress, newRewardVaultAddress] = _.times(
4,
() => randomAddress(),
);
await testContract.setVaultAddresses.awaitTransactionSuccessAsync(
oldEthVaultAddress,
oldRewardVaultAddress,
);
const { logs } = await setParamsAndAssertAsync({
ethVaultAddress: newEthVaultAddress,
rewardVaultAddress: newRewardVaultAddress,
});
const approveEvents = filterLogsToArguments<TestMixinParamsWETHApproveEventArgs>(
logs,
TestMixinParamsEvents.WETHApprove,
);
expect(approveEvents[0]).to.deep.eq({
spender: oldEthVaultAddress,
amount: constants.ZERO_AMOUNT,
});
expect(approveEvents[1]).to.deep.eq({
spender: newEthVaultAddress,
amount: constants.MAX_UINT256,
});
expect(approveEvents[2]).to.deep.eq({
spender: oldRewardVaultAddress,
amount: constants.ZERO_AMOUNT,
});
expect(approveEvents[3]).to.deep.eq({
spender: newRewardVaultAddress,
amount: constants.MAX_UINT256,
});
});
});
});
});
// tslint:enable:no-unnecessary-type-assertion

View File

@@ -1,7 +1,7 @@
import { ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { artifacts as erc20Artifacts, DummyERC20TokenContract, WETH9Contract } from '@0x/contracts-erc20';
import { BlockchainTestsEnvironment, constants, filterLogsToArguments, txDefaults } from '@0x/contracts-test-utils';
import { BigNumber, logUtils } from '@0x/utils';
import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import { BlockParamLiteral, ContractArtifact, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import * as _ from 'lodash';
@@ -52,14 +52,11 @@ export class StakingApiWrapper {
skipToNextEpochAndFinalizeAsync: async (): Promise<DecodedLogs> => {
await this.utils.fastForwardToNextEpochAsync();
const endOfEpochInfo = await this.utils.endEpochAsync();
let totalGasUsed = 0;
const allLogs = [] as DecodedLogs;
for (const poolId of endOfEpochInfo.activePoolIds) {
const receipt = await this.stakingContract.finalizePool.awaitTransactionSuccessAsync(poolId);
totalGasUsed += receipt.gasUsed;
allLogs.splice(allLogs.length, 0, ...(receipt.logs as DecodedLogs));
}
logUtils.log(`Finalization cost ${totalGasUsed} gas`);
return allLogs;
},