Skip to content

Commit

Permalink
test: getOperationHistory test
Browse files Browse the repository at this point in the history
  • Loading branch information
shuffledex committed Sep 13, 2021
1 parent c58a79c commit 6708b67
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/api/entities/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,31 +191,32 @@ export class Account extends Entity<UniqueIdentifiers, string> {

const data: ExtrinsicData[] = [];

// TODO @shuffledex: remove commented lines once middleware team fix missing attributes
transactionList.forEach(
({
block_id,
extrinsic_idx,
address: rawAddress,
nonce,
// nonce,
module_id,
call_id,
params,
success: txSuccess,
spec_version_id,
extrinsic_hash,
// extrinsic_hash,
}) => {
// TODO remove null check once types fixed
/* eslint-disable @typescript-eslint/no-non-null-assertion */
data.push({
blockNumber: new BigNumber(block_id),
extrinsicIdx: extrinsic_idx,
address: rawAddress ?? null,
nonce: nonce!,
nonce: 1, // nonce!,
txTag: extrinsicIdentifierToTxTag({ moduleId: module_id, callId: call_id }),
params,
success: !!txSuccess,
specVersionId: spec_version_id,
extrinsicHash: extrinsic_hash!,
extrinsicHash: '', // extrinsic_hash!,
});
/* eslint-enabled @typescript-eslint/no-non-null-assertion */
}
Expand Down
48 changes: 47 additions & 1 deletion src/api/entities/SecurityToken/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import sinon from 'sinon';

import { Context, Entity, SecurityToken, TransactionQueue } from '~/internal';
import { eventByIndexedArgs } from '~/middleware/queries';
import { eventByIndexedArgs, tickerExternalAgentHistory } from '~/middleware/queries';
import { EventIdEnum, ModuleIdEnum } from '~/middleware/types';
import { dsMockUtils, entityMockUtils, procedureMockUtils } from '~/testUtils/mocks';
import { TokenIdentifier, TokenIdentifierType } from '~/types';
Expand Down Expand Up @@ -624,6 +624,52 @@ describe('SecurityToken class', () => {
});
});

describe('method: getOperationHistory', () => {
test('should return a list of agent operations', async () => {
const ticker = 'TICKER';
const context = dsMockUtils.getContextInstance();
const securityToken = new SecurityToken({ ticker }, context);

const did = 'someDid';
const blockId = new BigNumber(1);
const eventIndex = 'eventId';
const datetime = '2020-10-10';

dsMockUtils.createApolloQueryStub(
tickerExternalAgentHistory({
ticker,
}),
{
tickerExternalAgentHistory: [
/* eslint-disable @typescript-eslint/naming-convention */
{
did,
history: [
{
block_id: blockId.toNumber(),
datetime,
event_idx: eventIndex,
},
],
},
/* eslint-enable @typescript-eslint/naming-convention */
],
}
);

const result = await securityToken.getOperationHistory();

expect(result.length).toEqual(1);
expect(result[0].identity.did).toEqual(did);
expect(result[0].history.length).toEqual(1);
expect(result[0].history[0]).toEqual({
blockNumber: blockId,
blockDate: new Date(`${datetime}Z`),
eventIndex,
});
});
});

describe('method: toJson', () => {
test('should return a human readable version of the entity', () => {
const context = dsMockUtils.getContextInstance();
Expand Down
2 changes: 2 additions & 0 deletions src/api/entities/__tests__/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ describe('Account class', () => {
block_id: blockNumber1.toNumber(),
address: address,
success: 0,
signedby_address: 1,
},
{
module_id: ModuleIdEnum.Asset,
Expand All @@ -173,6 +174,7 @@ describe('Account class', () => {
params: [],
block_id: blockNumber2.toNumber(),
success: 1,
signedby_address: 1,
},
],
};
Expand Down

0 comments on commit 6708b67

Please sign in to comment.