From 6d07ae9c60362b35f719547d745c0c7779213a59 Mon Sep 17 00:00:00 2001 From: "fateme.r" Date: Tue, 22 Oct 2024 13:08:28 +0330 Subject: [PATCH 1/2] Redeem the invalid commitment right the after reward transaction --- .changeset/brown-games-drop.md | 5 +++++ src/utils/watcherUtils.ts | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changeset/brown-games-drop.md diff --git a/.changeset/brown-games-drop.md b/.changeset/brown-games-drop.md new file mode 100644 index 0000000..51a09be --- /dev/null +++ b/.changeset/brown-games-drop.md @@ -0,0 +1,5 @@ +--- +'@rosen-bridge/watcher': patch +--- + +Fix redeem job to redeem the invalid commitment right the after reward transaction diff --git a/src/utils/watcherUtils.ts b/src/utils/watcherUtils.ts index 5f9b559..6579256 100644 --- a/src/utils/watcherUtils.ts +++ b/src/utils/watcherUtils.ts @@ -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 */ @@ -405,7 +406,7 @@ class WatcherUtils { commitment.eventId ); - if (eventTrigger == null) { + if (eventTrigger == null || eventTrigger.spendBlock !== undefined) { return false; } From f12d4de4876aceef1004e857b134929976d04a0a Mon Sep 17 00:00:00 2001 From: "fateme.r" Date: Tue, 22 Oct 2024 16:29:04 +0330 Subject: [PATCH 2/2] Add unit test for the forth isCommitmentValid case --- tests/ergoUtils/watcherUtils.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/ergoUtils/watcherUtils.ts b/tests/ergoUtils/watcherUtils.ts index cdd5ac1..491f6e7 100644 --- a/tests/ergoUtils/watcherUtils.ts +++ b/tests/ergoUtils/watcherUtils.ts @@ -3,6 +3,7 @@ import { TxStatus } from '../../src/database/entities/observationStatusEntity'; import { commitmentEntity, eventTriggerEntity, + newEventTriggerEntity, observationEntity1, observationEntity3, observationStatusCommitted, @@ -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; + }); + }); });