Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aliases status fix #395

Merged
merged 4 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/api/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 {
Expand Down
137 changes: 137 additions & 0 deletions packages/api/test/unit/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
})
})
Loading