Skip to content

Commit

Permalink
emit DistributeRewards even when amount is 0 (#427)
Browse files Browse the repository at this point in the history
* emit DistributeRewards even when amount is 0

* fix test

* fix test
  • Loading branch information
ianhe8x authored Nov 3, 2024
1 parent 1cf89b1 commit 876f04f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions contracts/RewardsDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ contract RewardsDistributor is IRewardsDistributor, Initializable, OwnableUpgrad
SQToken.safeTransfer(treasury, rewardsReturn);
emit ReturnRewards(runner, rewardsReturn, commission - cappedCommission);
}
} else {
emit DistributeRewards(runner, rewardInfo.lastClaimEra, 0, 0);
}
return rewardInfo.lastClaimEra;
}
Expand Down
2 changes: 1 addition & 1 deletion test/RewardsBooster_migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ describe('RewardsBooster Contract', () => {
// 3 block passed (upgrade, migrateDeploymentBoost, collectAllocationReward) since we queried alReward0,
// and 1 of them counts on old rewards, so we should get 500.5 SQT * 103 (availabe secs) / 1003 (total secs) = 51.397308075772681954
// sometimes the test takes longer than 3 sec for 3 blocks, so result may become 52291
expect(evts[0].amount.div((1e15).toString()).toNumber()).to.within(51397, 52291);
expect(evts[0].amount.div((1e15).toString()).toNumber()).to.be.within(51397, 52291);
// 1 block(collectAllocationReward) passed for new reward pool, so we should get 1.25 SQT more
expect(evts[1].amount).to.lt(etherParse('1.25'));
await blockTravel(999);
Expand Down
10 changes: 6 additions & 4 deletions test/StateChannel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ describe('StateChannel Contract', () => {
// reward distribution should be skipped due to total stake is 0
tx = await rewardsHelper.connect(runner).indexerCatchup(runner.address);
evt = await eventFrom(tx, rewardsDistributor, 'DistributeRewards(address,uint256,uint256,uint256)');
expect(evt).to.be.undefined;
expect(evt.rewards).to.eq(0);
});

/**
Expand Down Expand Up @@ -695,16 +695,18 @@ describe('StateChannel Contract', () => {
await stateChannel.claim(channelId);
balanceAfter = await token.balanceOf(consumer.address);
expect(balanceBefore.sub(balanceAfter)).to.eq(etherParse('0.4'));
let evt = await eventFrom(tx, stateChannel, 'ChannelLabor2(uint256,bytes32,address,uint256)');
const evt = await eventFrom(tx, stateChannel, 'ChannelLabor2(uint256,bytes32,address,uint256)');
expect(evt.amount).to.be.eq(etherParse('0.4'));

// start new era so we can try collect the channel reward
await startNewEra(eraManager);

// reward distribution should be skipped due to total stake is 0
tx = await rewardsHelper.connect(runner).indexerCatchup(runner.address);
evt = await eventFrom(tx, rewardsDistributor, 'DistributeRewards(address,uint256,uint256,uint256)');
expect(evt.rewards).to.eq(etherParse('0.4'));
const evts = await eventsFrom(tx, rewardsDistributor, 'DistributeRewards(address,uint256,uint256,uint256)');
expect(evts.length).to.eq(2);
expect(evts[0].rewards).to.eq(0);
expect(evts[1].rewards).to.eq(etherParse('0.4'));

// delegator
const delegatorRewards = await rewardsDistributor.userRewards(runner.address, delegator.address);
Expand Down

0 comments on commit 876f04f

Please sign in to comment.