Merge pull request #2280 from 0xProject/fix/3.0/handleNopInMoveStake
Force no-op when moving stake, in some scenarios
This commit is contained in:
commit
c9607e8b2c
@ -111,6 +111,17 @@ contract MixinStake is
|
|||||||
{
|
{
|
||||||
address staker = msg.sender;
|
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
|
// handle delegation
|
||||||
if (from.status == IStructs.StakeStatus.DELEGATED) {
|
if (from.status == IStructs.StakeStatus.DELEGATED) {
|
||||||
_undelegateStake(
|
_undelegateStake(
|
||||||
|
@ -373,7 +373,7 @@ blockchainTests.resets('MixinStake unit tests', env => {
|
|||||||
expect(increaseNextBalanceEvents).to.be.length(0);
|
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 amount = getRandomInteger(0, 100e18);
|
||||||
const { logs } = await testContract.moveStake.awaitTransactionSuccessAsync(
|
const { logs } = await testContract.moveStake.awaitTransactionSuccessAsync(
|
||||||
{ status: StakeStatus.Undelegated, poolId: VALID_POOL_IDS[0] },
|
{ status: StakeStatus.Undelegated, poolId: VALID_POOL_IDS[0] },
|
||||||
@ -381,10 +381,18 @@ blockchainTests.resets('MixinStake unit tests', env => {
|
|||||||
amount,
|
amount,
|
||||||
);
|
);
|
||||||
const events = filterLogsToArguments<MoveStakeStorageEventArgs>(logs, StakeEvents.MoveStakeStorage);
|
const events = filterLogsToArguments<MoveStakeStorageEventArgs>(logs, StakeEvents.MoveStakeStorage);
|
||||||
expect(events).to.be.length(1);
|
expect(events).to.be.length(0);
|
||||||
expect(events[0].fromBalanceSlot).to.eq(stakerUndelegatedStakeSlot);
|
});
|
||||||
expect(events[0].toBalanceSlot).to.eq(stakerUndelegatedStakeSlot);
|
|
||||||
expect(events[0].amount).to.bignumber.eq(amount);
|
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 () => {
|
it('moves the owner stake between the same pointer when both are delegated', async () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user