Merge pull request #2280 from 0xProject/fix/3.0/handleNopInMoveStake

Force no-op when moving stake, in some scenarios
This commit is contained in:
Greg Hysz 2019-10-22 16:51:46 -07:00 committed by GitHub
commit c9607e8b2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 5 deletions

View File

@ -111,6 +111,17 @@ contract MixinStake is
{
address staker = msg.sender;
// Sanity check: no-op if no stake is being moved.
if (amount == 0) {
return;
}
// Sanity check: no-op if moving stake from undelegated to undelegated.
if (from.status == IStructs.StakeStatus.UNDELEGATED &&
to.status == IStructs.StakeStatus.UNDELEGATED) {
return;
}
// handle delegation
if (from.status == IStructs.StakeStatus.DELEGATED) {
_undelegateStake(

View File

@ -373,7 +373,7 @@ blockchainTests.resets('MixinStake unit tests', env => {
expect(increaseNextBalanceEvents).to.be.length(0);
});
it('moves the owner stake between the same pointer when both are undelegated', async () => {
it('does nothing when moving the owner stake from undelegated to undelegated', async () => {
const amount = getRandomInteger(0, 100e18);
const { logs } = await testContract.moveStake.awaitTransactionSuccessAsync(
{ status: StakeStatus.Undelegated, poolId: VALID_POOL_IDS[0] },
@ -381,10 +381,18 @@ blockchainTests.resets('MixinStake unit tests', env => {
amount,
);
const events = filterLogsToArguments<MoveStakeStorageEventArgs>(logs, StakeEvents.MoveStakeStorage);
expect(events).to.be.length(1);
expect(events[0].fromBalanceSlot).to.eq(stakerUndelegatedStakeSlot);
expect(events[0].toBalanceSlot).to.eq(stakerUndelegatedStakeSlot);
expect(events[0].amount).to.bignumber.eq(amount);
expect(events).to.be.length(0);
});
it('does nothing when moving zero stake', async () => {
const amount = new BigNumber(0);
const { logs } = await testContract.moveStake.awaitTransactionSuccessAsync(
{ status: StakeStatus.Delegated, poolId: VALID_POOL_IDS[0] },
{ status: StakeStatus.Delegated, poolId: VALID_POOL_IDS[1] },
amount,
);
const events = filterLogsToArguments<MoveStakeStorageEventArgs>(logs, StakeEvents.MoveStakeStorage);
expect(events).to.be.length(0);
});
it('moves the owner stake between the same pointer when both are delegated', async () => {