tests for pool management

This commit is contained in:
Greg Hysen
2019-06-01 17:00:27 -07:00
parent a17f123608
commit 8293784629
4 changed files with 34 additions and 14 deletions

View File

@@ -224,7 +224,7 @@ describe('Staking Core', () => {
expect(ownerRewardFloatingPoint).to.be.bignumber.equal(expectedOwnerReward);
});
it.only('pools', async() => {
it('pool management', async() => {
// create first pool
const operatorAddress = stakers[0];
const operatorShare = 39;
@@ -245,16 +245,31 @@ describe('Staking Core', () => {
const makerAddressesForPool = await stakingWrapper.getMakerAddressesForPool(poolId);
expect(makerAddressesForPool).to.be.deep.equal([makerAddress]);
// try to add the same maker address again
//await stakingWrapper.addMakerToPoolAsync(poolId, makerAddress, makerSignature, operatorAddress);
await expectTransactionFailedAsync(
stakingWrapper.addMakerToPoolAsync(poolId, makerAddress, makerSignature, operatorAddress),
RevertReason.MakerAddressAlreadyRegistered
);
// try to add a new maker address from an address other than the pool operator
const notOperatorAddress = owner;
const anotherMakerAddress = makers[1];
const anotherMakerSignature = "0x";
await expectTransactionFailedAsync(
stakingWrapper.addMakerToPoolAsync(poolId, anotherMakerAddress, anotherMakerSignature, notOperatorAddress),
RevertReason.OnlyCallableByPoolOperator
);
// try to remove the maker address from an address other than the operator
await expectTransactionFailedAsync(
stakingWrapper.removeMakerFromPoolAsync(poolId, makerAddress, notOperatorAddress),
RevertReason.OnlyCallableByPoolOperator
);
// remove maker from pool
// check that maker was removed
// try to add
await stakingWrapper.removeMakerFromPoolAsync(poolId, makerAddress, operatorAddress);
// check the pool id of the maker
const poolIdOfMakerAfterRemoving = await stakingWrapper.getMakerPoolId(makerAddress);
expect(poolIdOfMakerAfterRemoving).to.be.equal(stakingConstants.NIL_POOL_ID);
// check the list of makers for the pool
const makerAddressesForPoolAfterRemoving = await stakingWrapper.getMakerAddressesForPool(poolId);
expect(makerAddressesForPoolAfterRemoving).to.be.deep.equal([]);
});
});
});

View File

@@ -1,3 +1,4 @@
export const constants = {
INITIAL_POOL_ID: "0x0000000000000000000000000000000100000000000000000000000000000000",
NIL_POOL_ID: "0x0000000000000000000000000000000000000000000000000000000000000000",
};

View File

@@ -146,15 +146,16 @@ export class StakingWrapper {
const poolId = (createPoolLog as any).args.poolId;
return poolId;
}
public async addMakerToPoolAsync(poolId: string, makerAddress: string, makerSignature: string, operatorAddress: string): Promise<void> {
public async addMakerToPoolAsync(poolId: string, makerAddress: string, makerSignature: string, operatorAddress: string): Promise<TransactionReceiptWithDecodedLogs> {
const calldata = this.getStakingContract().addMakerToPool.getABIEncodedTransactionData(poolId, makerAddress, makerSignature);
await this._executeTransactionAsync(calldata, operatorAddress);
const txReceipt = await this._executeTransactionAsync(calldata, operatorAddress);
return txReceipt;
}
/*
public async removeMakerFromPoolAsync(poolId: string, makerAddress: string): Promise<void> {
public async removeMakerFromPoolAsync(poolId: string, makerAddress: string, operatorAddress: string): Promise<TransactionReceiptWithDecodedLogs> {
const calldata = this.getStakingContract().removeMakerFromPool.getABIEncodedTransactionData(poolId, makerAddress);
const txReceipt = await this._executeTransactionAsync(calldata, operatorAddress);
return txReceipt;
}
*/
public async getMakerPoolId(makerAddress: string): Promise<string> {
const calldata = this.getStakingContract().getMakerPoolId.getABIEncodedTransactionData(makerAddress);
const poolId = await this._callAsync(calldata);