Skip to content

Commit

Permalink
identities tests
Browse files Browse the repository at this point in the history
  • Loading branch information
owl352 committed Dec 9, 2024
1 parent f4886ee commit 397b8f9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 10 deletions.
1 change: 0 additions & 1 deletion packages/api/src/dao/IdentitiesDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const DataContract = require('../models/DataContract')
const PaginatedResultSet = require('../models/PaginatedResultSet')
const { IDENTITY_CREDIT_WITHDRAWAL, IDENTITY_TOP_UP } = require('../enums/StateTransitionEnum')
const { getAliasInfo, decodeStateTransition, getAliasStateByVote } = require('../utils')
const { base58 } = require('@scure/base')

module.exports = class IdentitiesDAO {
constructor (knex, dapi, client) {
Expand Down
80 changes: 71 additions & 9 deletions packages/api/test/integration/identities.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ describe('Identities routes', () => {

mock.method(DAPI.prototype, 'getContestedState', async () => null)

mock.method(DAPI.prototype, 'getIdentityKeys', async () => null)

mock.method(tenderdashRpc, 'getBlockByHeight', async () => ({
block: {
header: {
Expand All @@ -195,7 +197,18 @@ describe('Identities routes', () => {
describe('getIdentityByIdentifier()', async () => {
it('should return identity by identifier', async () => {
const block = await fixtures.block(knex)
const identity = await fixtures.identity(knex, { block_hash: block.hash })
const owner = await fixtures.identity(knex, { block_hash: block.hash })

const transaction = await fixtures.transaction(knex, {
block_hash: block.hash,
type: StateTransitionEnum.IDENTITY_CREATE,
owner: owner.identifier,
data: ''
})
const identity = await fixtures.identity(knex, {
block_hash: block.hash,
state_transition_hash: transaction.hash
})
const { alias } = await fixtures.identity_alias(knex,
{
alias: 'test.dash',
Expand All @@ -214,7 +227,7 @@ describe('Identities routes', () => {
balance: 0,
timestamp: block.timestamp.toISOString(),
txHash: identity.txHash,
totalTxs: 1,
totalTxs: 0,
totalTransfers: 0,
totalDocuments: 0,
totalDataContracts: 0,
Expand All @@ -223,7 +236,14 @@ describe('Identities routes', () => {
alias,
contested: false,
status: 'ok'
}]
}],
totalGasSpent: 0,
averageGasSpent: 0,
topUpsGasSpent: 0,
withdrawalsGasSpent: 0,
lastWithdrawalHash: null,
publicKeys: [],
fundingCoreTx: null
}

assert.deepEqual(body, expectedIdentity)
Expand Down Expand Up @@ -384,7 +404,14 @@ describe('Identities routes', () => {
isSystem: false,
aliases: [
aliases.find((_alias) => _alias.identity_identifier === _identity.identity.identifier).alias
].map(alias => ({ alias, status: 'ok', contested: false }))
].map(alias => ({ alias, status: 'ok', contested: false })),
totalGasSpent: null,
averageGasSpent: null,
topUpsGasSpent: null,
withdrawalsGasSpent: null,
lastWithdrawalHash: null,
publicKeys: [],
fundingCoreTx: null
}))

assert.deepEqual(body.resultSet, expectedIdentities)
Expand Down Expand Up @@ -426,7 +453,14 @@ describe('Identities routes', () => {
isSystem: false,
aliases: [
aliases.find((_alias) => _alias.identity_identifier === _identity.identity.identifier).alias
].map(alias => ({ alias, status: 'ok', contested: false }))
].map(alias => ({ alias, status: 'ok', contested: false })),
totalGasSpent: null,
averageGasSpent: null,
topUpsGasSpent: null,
withdrawalsGasSpent: null,
lastWithdrawalHash: null,
publicKeys: [],
fundingCoreTx: null
}))

assert.deepEqual(body.resultSet, expectedIdentities)
Expand Down Expand Up @@ -469,7 +503,14 @@ describe('Identities routes', () => {
isSystem: false,
aliases: [
aliases.find((_alias) => _alias.identity_identifier === _identity.identity.identifier).alias
].map(alias => ({ alias, status: 'ok', contested: false }))
].map(alias => ({ alias, status: 'ok', contested: false })),
totalGasSpent: null,
averageGasSpent: null,
topUpsGasSpent: null,
withdrawalsGasSpent: null,
lastWithdrawalHash: null,
publicKeys: [],
fundingCoreTx: null
}))

assert.deepEqual(body.resultSet, expectedIdentities)
Expand Down Expand Up @@ -513,7 +554,14 @@ describe('Identities routes', () => {
isSystem: false,
aliases: [
aliases.find((_alias) => _alias.identity_identifier === _identity.identity.identifier).alias
].map(alias => ({ alias, status: 'ok', contested: false }))
].map(alias => ({ alias, status: 'ok', contested: false })),
totalGasSpent: null,
averageGasSpent: null,
topUpsGasSpent: null,
withdrawalsGasSpent: null,
lastWithdrawalHash: null,
publicKeys: [],
fundingCoreTx: null
}))

assert.deepEqual(body.resultSet, expectedIdentities)
Expand Down Expand Up @@ -572,7 +620,14 @@ describe('Identities routes', () => {
isSystem: false,
aliases: [
aliases.find((_alias) => _alias.identity_identifier === _identity.identity.identifier).alias
].map(alias => ({ alias, status: 'ok', contested: false }))
].map(alias => ({ alias, status: 'ok', contested: false })),
totalGasSpent: null,
averageGasSpent: null,
topUpsGasSpent: null,
withdrawalsGasSpent: null,
lastWithdrawalHash: null,
publicKeys: [],
fundingCoreTx: null
}))

assert.deepEqual(body.resultSet, expectedIdentities)
Expand Down Expand Up @@ -643,7 +698,14 @@ describe('Identities routes', () => {
isSystem: false,
aliases: [
aliases.find((_alias) => _alias.identity_identifier === _identity.identity.identifier).alias
].map(alias => ({ alias, status: 'ok', contested: false }))
].map(alias => ({ alias, status: 'ok', contested: false })),
totalGasSpent: null,
averageGasSpent: null,
topUpsGasSpent: null,
withdrawalsGasSpent: null,
lastWithdrawalHash: null,
publicKeys: [],
fundingCoreTx: null
}))

assert.deepEqual(body.resultSet, expectedIdentities)
Expand Down

0 comments on commit 397b8f9

Please sign in to comment.