From f9edc2d01ba38e6c34155d898bba4d7514e84075 Mon Sep 17 00:00:00 2001 From: owl352 Date: Sat, 28 Dec 2024 15:35:17 +0500 Subject: [PATCH 1/4] fix --- packages/api/src/utils.js | 8 +- packages/api/test/unit/utils.spec.js | 137 +++++++++++++++++++++++++++ 2 files changed, 141 insertions(+), 4 deletions(-) diff --git a/packages/api/src/utils.js b/packages/api/src/utils.js index b2c92ac6f..f7003f913 100644 --- a/packages/api/src/utils.js +++ b/packages/api/src/utils.js @@ -446,7 +446,7 @@ const buildIndexBuffer = (name) => { const getAliasStateByVote = (aliasInfo, alias, identifier) => { let status = null - if (aliasInfo.contestedState === null) { + if (!aliasInfo.contestedState) { return { alias, status: 'ok', @@ -458,12 +458,12 @@ const getAliasStateByVote = (aliasInfo, alias, identifier) => { Buffer.from(aliasInfo.contestedState?.finishedVoteInfo?.wonByIdentityId ?? '', 'base64') ) - if (identifier !== bs58Identifier && bs58Identifier !== '') { + if (identifier === bs58Identifier) { + status = 'ok' + } else if (bs58Identifier !== '' || aliasInfo.contestedState?.finishedVoteInfo?.wonByIdentityId === '') { status = 'locked' } else if (aliasInfo.contestedState?.finishedVoteInfo?.wonByIdentityId === undefined) { status = 'pending' - } else { - status = 'ok' } return { diff --git a/packages/api/test/unit/utils.spec.js b/packages/api/test/unit/utils.spec.js index 8e69c8e1b..449e2ff17 100644 --- a/packages/api/test/unit/utils.spec.js +++ b/packages/api/test/unit/utils.spec.js @@ -329,4 +329,141 @@ describe('Utils', () => { }) }) }) + describe('getAliasStateByVote()', () => { + it('should return ok if our identifier equal to winner identifier', () => { + const mockVote = { + alias: 'pshenmic.dash', + contestedState: { + contendersList: [ + { + identifier: 'n4ay5zy5fRyuqEYkMwlkmmIay6RP9mlhSjLeBK3puwM=', + voteCount: 16, + document: '' + } + ], + abstainVoteTally: 0, + lockVoteTally: 0, + finishedVoteInfo: { + finishedVoteOutcome: 0, + wonByIdentityId: 'n4ay5zy5fRyuqEYkMwlkmmIay6RP9mlhSjLeBK3puwM=', + finishedAtBlockHeight: 24407, + finishedAtCoreBlockHeight: 2158202, + finishedAtBlockTimeMs: 1729411671125, + finishedAtEpoch: 5 + } + } + } + + const info = utils.getAliasStateByVote(mockVote, mockVote.alias, 'BjixEUbqeUZK7BRdqtLgjzwFBovx4BRwS2iwhMriiYqp') + + assert.deepEqual(info, { + alias: mockVote.alias, + status: 'ok', + contested: true + }) + }) + + it('should return ok if we not contested', () => { + const mockVote = { contestedState: null } + + const info = utils.getAliasStateByVote(mockVote, 'alias343', 'BjixEUbqeUZK7BRdqtLgjzwFBovx4BRwS2iwhMriiYqp') + + assert.deepEqual(info, { + alias: 'alias343', + status: 'ok', + contested: false + }) + }) + + it('should return pending if we don\'t have winner', () => { + const mockVote = { + alias: 'pshenmic.dash', + contestedState: { + contendersList: [ + { + identifier: 'n4ay5zy5fRyuqEYkMwlkmmIay6RP9mlhSjLeBK3puwM=', + voteCount: 16, + document: '' + } + ], + abstainVoteTally: 0, + lockVoteTally: 0 + } + } + + const info = utils.getAliasStateByVote(mockVote, mockVote.alias, 'BjixEUbqeUZK7BRdqtLgjzwFBovx4BRwS2iwhMriiYqp') + + assert.deepEqual(info, { + alias: mockVote.alias, + status: 'pending', + contested: true + }) + }) + + it('should return locked if our identifier not equal to winner identifier', () => { + const mockVote = { + alias: 'pshenmic.dash', + contestedState: { + contendersList: [ + { + identifier: 'n4ay5zy5fRyuqEYkMwlkmmIay6RP9mlhSjLeBK3puwM=', + voteCount: 16, + document: '' + } + ], + abstainVoteTally: 0, + lockVoteTally: 0, + finishedVoteInfo: { + finishedVoteOutcome: 0, + wonByIdentityId: 'n4ay5zy5fRyuqEYkMwlkmmIay6RP9mlhSjLeBK3puwM=', + finishedAtBlockHeight: 24407, + finishedAtCoreBlockHeight: 2158202, + finishedAtBlockTimeMs: 1729411671125, + finishedAtEpoch: 5 + } + } + } + + const info = utils.getAliasStateByVote(mockVote, mockVote.alias, 'AjixEUbqeUZK7BRdqtLgjzwFBovx4BRwS2iwhMriiYqp') + + assert.deepEqual(info, { + alias: mockVote.alias, + status: 'locked', + contested: true + }) + }) + + it('should return locked if winner identifier equal "" (empty string)', () => { + const mockVote = { + alias: 'pshenmic.dash', + contestedState: { + contendersList: [ + { + identifier: 'n4ay5zy5fRyuqEYkMwlkmmIay6RP9mlhSjLeBK3puwM=', + voteCount: 16, + document: '' + } + ], + abstainVoteTally: 0, + lockVoteTally: 0, + finishedVoteInfo: { + finishedVoteOutcome: 0, + wonByIdentityId: '', + finishedAtBlockHeight: 24407, + finishedAtCoreBlockHeight: 2158202, + finishedAtBlockTimeMs: 1729411671125, + finishedAtEpoch: 5 + } + } + } + + const info = utils.getAliasStateByVote(mockVote, mockVote.alias, 'AjixEUbqeUZK7BRdqtLgjzwFBovx4BRwS2iwhMriiYqp') + + assert.deepEqual(info, { + alias: mockVote.alias, + status: 'locked', + contested: true + }) + }) + }) }) From 2c1593348b8e4d7b4aa64ef646f9a6efdfa8d745 Mon Sep 17 00:00:00 2001 From: owl352 Date: Sat, 28 Dec 2024 15:39:05 +0500 Subject: [PATCH 2/4] fix --- packages/api/src/utils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/api/src/utils.js b/packages/api/src/utils.js index f7003f913..01b82409d 100644 --- a/packages/api/src/utils.js +++ b/packages/api/src/utils.js @@ -446,6 +446,7 @@ const buildIndexBuffer = (name) => { const getAliasStateByVote = (aliasInfo, alias, identifier) => { let status = null + if (!aliasInfo.contestedState) { return { alias, From 4fc01ff4215c98f60642ffb47e04dda4a7a2581e Mon Sep 17 00:00:00 2001 From: owl352 Date: Sat, 28 Dec 2024 15:39:10 +0500 Subject: [PATCH 3/4] fix --- packages/api/src/utils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/api/src/utils.js b/packages/api/src/utils.js index 01b82409d..515a32fa6 100644 --- a/packages/api/src/utils.js +++ b/packages/api/src/utils.js @@ -445,7 +445,6 @@ const buildIndexBuffer = (name) => { const getAliasStateByVote = (aliasInfo, alias, identifier) => { let status = null - if (!aliasInfo.contestedState) { return { From fa3fd1cd8ac8f02709a70469dc7380046a8efc8e Mon Sep 17 00:00:00 2001 From: owl352 Date: Sat, 28 Dec 2024 15:41:34 +0500 Subject: [PATCH 4/4] lint --- packages/api/src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api/src/utils.js b/packages/api/src/utils.js index 515a32fa6..f7003f913 100644 --- a/packages/api/src/utils.js +++ b/packages/api/src/utils.js @@ -445,7 +445,7 @@ const buildIndexBuffer = (name) => { const getAliasStateByVote = (aliasInfo, alias, identifier) => { let status = null - + if (!aliasInfo.contestedState) { return { alias,