Changed nextPoolId to lastPoolId

This commit is contained in:
Greg Hysen
2019-10-08 10:32:39 +09:00
parent a0f5a8b64b
commit b3c7ccec57
8 changed files with 29 additions and 36 deletions

View File

@@ -5,9 +5,9 @@ import * as _ from 'lodash';
import { PoolOperatorActor } from './pool_operator_actor';
export class MakerActor extends PoolOperatorActor {
public async setMakerStakingPoolAsync(poolId: string, revertError?: RevertError): Promise<void> {
public async joinStakingPoolAsMakerAsync(poolId: string, revertError?: RevertError): Promise<void> {
// add maker
const txReceiptPromise = this._stakingApiWrapper.stakingContract.setMakerStakingPool.awaitTransactionSuccessAsync(
const txReceiptPromise = this._stakingApiWrapper.stakingContract.joinStakingPoolAsMaker.awaitTransactionSuccessAsync(
poolId,
{ from: this.getOwner() },
);

View File

@@ -10,8 +10,6 @@ export class PoolOperatorActor extends BaseActor {
addOperatorAsMaker: boolean,
revertError?: RevertError,
): Promise<string> {
// query next pool id
const nextPoolId = await this._stakingApiWrapper.stakingContract.nextPoolId.callAsync();
// create pool
const poolIdPromise = this._stakingApiWrapper.utils.createStakingPoolAsync(
this._owner,
@@ -24,7 +22,8 @@ export class PoolOperatorActor extends BaseActor {
}
const poolId = await poolIdPromise;
// validate pool id
expect(poolId, 'pool id').to.be.bignumber.equal(nextPoolId);
const lastPoolId = await this._stakingApiWrapper.stakingContract.lastPoolId.callAsync();
expect(poolId, 'pool id').to.be.bignumber.equal(lastPoolId);
if (addOperatorAsMaker) {
// check the pool id of the operator

View File

@@ -40,8 +40,8 @@ blockchainTests('Staking Pool Management', env => {
const poolId = await poolOperator.createStakingPoolAsync(operatorShare, false);
expect(poolId).to.be.equal(stakingConstants.INITIAL_POOL_ID);
// check that the next pool id was incremented
const nextPoolId = await stakingApiWrapper.stakingContract.nextPoolId.callAsync();
expect(nextPoolId).to.be.equal(stakingConstants.SECOND_POOL_ID);
const lastPoolId = await stakingApiWrapper.stakingContract.lastPoolId.callAsync();
expect(lastPoolId).to.be.equal(stakingConstants.INITIAL_POOL_ID);
});
it('Should successfully create several staking pools, as long as the operator is only a maker in one', async () => {
// test parameters
@@ -77,8 +77,8 @@ blockchainTests('Staking Pool Management', env => {
const poolId = await poolOperator.createStakingPoolAsync(operatorShare, true);
expect(poolId).to.be.equal(stakingConstants.INITIAL_POOL_ID);
// check that the next pool id was incremented
const nextPoolId = await stakingApiWrapper.stakingContract.nextPoolId.callAsync();
expect(nextPoolId).to.be.equal(stakingConstants.SECOND_POOL_ID);
const lastPoolId = await stakingApiWrapper.stakingContract.lastPoolId.callAsync();
expect(lastPoolId).to.be.equal(stakingConstants.INITIAL_POOL_ID);
});
it('Should throw if operatorShare is > PPM_DENOMINATOR', async () => {
// test parameters
@@ -107,7 +107,7 @@ blockchainTests('Staking Pool Management', env => {
const poolId = await poolOperator.createStakingPoolAsync(operatorShare, true);
expect(poolId).to.be.equal(stakingConstants.INITIAL_POOL_ID);
// maker joins pool
await maker.setMakerStakingPoolAsync(poolId);
await maker.joinStakingPoolAsMakerAsync(poolId);
});
it('Maker should successfully remove themselves from a pool', async () => {
// test parameters
@@ -120,9 +120,9 @@ blockchainTests('Staking Pool Management', env => {
const poolId = await poolOperator.createStakingPoolAsync(operatorShare, true);
expect(poolId).to.be.equal(stakingConstants.INITIAL_POOL_ID);
// maker joins pool
await maker.setMakerStakingPoolAsync(poolId);
await maker.joinStakingPoolAsMakerAsync(poolId);
// maker removes themselves from pool
await maker.setMakerStakingPoolAsync(stakingConstants.NIL_POOL_ID);
await maker.joinStakingPoolAsMakerAsync(stakingConstants.NIL_POOL_ID);
});
it('Should successfully add/remove multiple makers to the same pool', async () => {
// test parameters
@@ -135,9 +135,11 @@ blockchainTests('Staking Pool Management', env => {
const poolId = await poolOperator.createStakingPoolAsync(operatorShare, false);
expect(poolId).to.be.equal(stakingConstants.INITIAL_POOL_ID);
// add makers to pool
await Promise.all(makers.map(async maker => maker.setMakerStakingPoolAsync(poolId)));
await Promise.all(makers.map(async maker => maker.joinStakingPoolAsMakerAsync(poolId)));
// remove makers to pool
await Promise.all(makers.map(async maker => maker.setMakerStakingPoolAsync(stakingConstants.NIL_POOL_ID)));
await Promise.all(
makers.map(async maker => maker.joinStakingPoolAsMakerAsync(stakingConstants.NIL_POOL_ID)),
);
});
it('Operator should successfully decrease their share of rewards', async () => {
// test parameters

View File

@@ -44,7 +44,11 @@ blockchainTests.resets('Stake Statuses', env => {
await stakingApiWrapper.utils.createStakingPoolAsync(poolOperator, 4, false),
await stakingApiWrapper.utils.createStakingPoolAsync(poolOperator, 5, false),
]);
unusedPoolId = await stakingApiWrapper.stakingContract.nextPoolId.callAsync();
const lastPoolId = await stakingApiWrapper.stakingContract.lastPoolId.callAsync();
unusedPoolId = `0x${new BigNumber(lastPoolId)
.plus(1)
.toString(16)
.padStart(64, '0')}`;
});
describe('Stake', () => {
it('should successfully stake zero ZRX', async () => {