add test for weth protocol fees

This commit is contained in:
Michael Zhu 2019-10-31 10:03:31 -07:00
parent bf18b86f9f
commit 5f699b0c47
3 changed files with 45 additions and 5 deletions

View File

@ -20,12 +20,14 @@ contract TestFramework {
function emptyRevert()
external
pure
{
revert();
}
function stringRevert(string calldata message)
external
pure
{
revert(message);
}

View File

@ -327,4 +327,46 @@ blockchainTests.resets('fillOrder integration tests', env => {
const poolStats = await deployment.staking.stakingWrapper.getStakingPoolStatsThisEpoch.callAsync(poolId);
expect(poolStats.feesCollected).to.bignumber.equal(DeploymentManager.protocolFee);
});
it('should collect WETH fees and pay out rewards', async () => {
// Operator and delegator each stake some ZRX; wait an epoch so that the stake is active.
await operator.stakeAsync(toBaseUnitAmount(100), poolId);
await delegator.stakeAsync(toBaseUnitAmount(50), poolId);
await delegator.endEpochAsync();
// Fetch the current balances
await balanceStore.updateBalancesAsync();
// Create and fill the order. One order's worth of protocol fees are now available as rewards.
const order = await maker.signOrderAsync();
const receipt = await taker.fillOrderAsync(order, order.takerAssetAmount, { value: constants.ZERO_AMOUNT });
const rewardsAvailable = DeploymentManager.protocolFee;
const expectedBalances = simulateFill(order, receipt, constants.ZERO_AMOUNT);
// End the epoch. This should wrap the staking proxy's ETH balance.
const endEpochReceipt = await delegator.endEpochAsync();
// Check balances
expectedBalances.burnGas(delegator.address, DeploymentManager.gasPrice.times(endEpochReceipt.gasUsed));
await balanceStore.updateBalancesAsync();
balanceStore.assertEquals(expectedBalances);
// The rewards are split between the operator and delegator based on the pool's operatorShare
const operatorReward = rewardsAvailable
.times(operator.operatorShares[poolId])
.dividedToIntegerBy(constants.PPM_DENOMINATOR);
// Finalize the pool. This should automatically pay the operator in WETH.
const [finalizePoolReceipt] = await delegator.finalizePoolsAsync([poolId]);
// Check balances
expectedBalances.transferAsset(
deployment.staking.stakingProxy.address,
operator.address,
operatorReward,
assetDataUtils.encodeERC20AssetData(deployment.tokens.weth.address),
);
expectedBalances.burnGas(delegator.address, DeploymentManager.gasPrice.times(finalizePoolReceipt.gasUsed));
await balanceStore.updateBalancesAsync();
balanceStore.assertEquals(expectedBalances);
});
});

View File

@ -362,11 +362,7 @@ export class DeploymentManager {
stakingLogic.address,
);
const stakingWrapper = new TestStakingContract(
stakingProxy.address,
environment.provider,
txDefaults,
);
const stakingWrapper = new TestStakingContract(stakingProxy.address, environment.provider, txDefaults);
// Add the zrx vault and the weth contract to the staking proxy.
await stakingWrapper.setWethContract.awaitTransactionSuccessAsync(tokens.weth.address, { from: owner });