Skip to content

Commit

Permalink
Merge branch 'bugfix-commitment-redeem' into 'dev'
Browse files Browse the repository at this point in the history
Redeem the invalid commitment right the after reward transaction

See merge request ergo/rosen-bridge/watcher!314
  • Loading branch information
zargarzadehm committed Oct 22, 2024
2 parents 389a724 + f12d4de commit 1075d05
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/brown-games-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/watcher': patch
---

Fix redeem job to redeem the invalid commitment right the after reward transaction
3 changes: 2 additions & 1 deletion src/utils/watcherUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ class WatcherUtils {
* 1 - Not triggered after the specified period
* 2 - Created after the related trigger
* 3 - It's a duplicate commitment and a valid one merged to create the trigger (WID exists in trigger)
* 4 - It's information is not valid and trigger was spent without rewarding the commitment
* @param commitment
* @returns true if the commitment is still valid and false otherwise
*/
Expand All @@ -405,7 +406,7 @@ class WatcherUtils {
commitment.eventId
);

if (eventTrigger == null) {
if (eventTrigger == null || eventTrigger.spendBlock !== undefined) {
return false;
}

Expand Down
20 changes: 20 additions & 0 deletions tests/ergoUtils/watcherUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TxStatus } from '../../src/database/entities/observationStatusEntity';
import {
commitmentEntity,
eventTriggerEntity,
newEventTriggerEntity,
observationEntity1,
observationEntity3,
observationStatusCommitted,
Expand Down Expand Up @@ -572,4 +573,23 @@ describe('Testing the WatcherUtils & TransactionUtils', () => {
chai.spy.restore(ErgoNetwork);
});
});

describe('isCommitmentValid', () => {
/**
* @target isCommitmentValid should return false if related trigger is spent
* @dependencies
* - DataBase
* @scenario
* - mock eventTriggerByEventId to return a spent trigger object
* @expected
* - to return false when spendBlock is set for the trigger
*/
it('should return false if related trigger is spent', async () => {
chai.spy.on(dataBase, 'eventTriggerByEventId', () => ({
spendBlock: 'spendBlock',
}));
const result = await watcherUtils.isCommitmentValid(commitmentEntity);
expect(result).to.be.false;
});
});
});

0 comments on commit 1075d05

Please sign in to comment.