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

Alpha into Beta #1417

Merged
merged 6 commits into from
Jan 2, 2025
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
4 changes: 4 additions & 0 deletions src/api/entities/Account/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ describe('Account class', () => {

dsMockUtils.createApolloQueryMock(
extrinsicsByArgs(
false,
{
blockId: blockNumber1.toString(),
address,
Expand Down Expand Up @@ -328,6 +329,7 @@ describe('Account class', () => {

dsMockUtils.createApolloQueryMock(
extrinsicsByArgs(
false,
{
blockId: blockNumber1.toString(),
address,
Expand Down Expand Up @@ -367,6 +369,7 @@ describe('Account class', () => {

dsMockUtils.createApolloQueryMock(
extrinsicsByArgs(
false,
{
blockId: undefined,
address,
Expand Down Expand Up @@ -396,6 +399,7 @@ describe('Account class', () => {

dsMockUtils.createApolloQueryMock(
extrinsicsByArgs(
false,
{
blockId: undefined,
address,
Expand Down
1 change: 1 addition & 0 deletions src/api/entities/Account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export class Account extends Entity<UniqueIdentifiers, string> {
},
} = await context.queryMiddleware<Ensured<Query, 'extrinsics'>>(
extrinsicsByArgs(
context.isSqIdPadded,
{
blockId: blockNumber ? blockNumber.toString() : undefined,
address,
Expand Down
6 changes: 4 additions & 2 deletions src/api/entities/Identity/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ describe('Identity class', () => {
assetIds.forEach(assetId =>
when(getAssetIdFromMiddlewareSpy).calledWith({ id: assetId }).mockReturnValue(assetId)
);
dsMockUtils.createApolloQueryMock(assetHoldersQuery({ identityId: did }), {
dsMockUtils.createApolloQueryMock(assetHoldersQuery(false, { identityId: did }), {
assetHolders: {
nodes: assetIds.map(assetId => ({ asset: { id: assetId } })),
totalCount: 2,
Expand All @@ -638,6 +638,7 @@ describe('Identity class', () => {

dsMockUtils.createApolloQueryMock(
assetHoldersQuery(
false,
{ identityId: did },
new BigNumber(1),
new BigNumber(0),
Expand Down Expand Up @@ -673,7 +674,7 @@ describe('Identity class', () => {
when(getAssetIdFromMiddlewareSpy).calledWith({ id: assetId }).mockReturnValue(assetId)
);

dsMockUtils.createApolloQueryMock(nftHoldersQuery({ identityId: did }), {
dsMockUtils.createApolloQueryMock(nftHoldersQuery(false, { identityId: did }), {
nftHolders: {
nodes: assetIds.map(assetId => ({ asset: { id: assetId }, nftIds: [] })),
totalCount: 2,
Expand All @@ -687,6 +688,7 @@ describe('Identity class', () => {

dsMockUtils.createApolloQueryMock(
nftHoldersQuery(
false,
{ identityId: did },
new BigNumber(1),
new BigNumber(0),
Expand Down
7 changes: 6 additions & 1 deletion src/api/entities/Identity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ export class Identity extends Entity<UniqueIdentifiers, string> {
},
} = await context.queryMiddleware<Ensured<Query, 'assetHolders'>>(
assetHoldersQuery(
context.isSqIdPadded,
{
identityId: did,
},
Expand Down Expand Up @@ -437,6 +438,7 @@ export class Identity extends Entity<UniqueIdentifiers, string> {
},
} = await context.queryMiddleware<Ensured<Query, 'nftHolders'>>(
nftHoldersQuery(
context.isSqIdPadded,
{
identityId: did,
},
Expand Down Expand Up @@ -740,7 +742,10 @@ export class Identity extends Entity<UniqueIdentifiers, string> {
let start: BigNumber | undefined;

while (!allFetched) {
const { data, next } = await this.getHeldAssets({ size: MAX_PAGE_SIZE, start });
const { data, next } = await this.getHeldAssets({
size: MAX_PAGE_SIZE,
start,
});
start = next ? new BigNumber(next) : undefined;
allFetched = !next;
assets = [...assets, ...data];
Expand Down
25 changes: 18 additions & 7 deletions src/api/entities/Instruction/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ describe('Instruction class', () => {
const start = new BigNumber(0);
const size = new BigNumber(1);
dsMockUtils.createApolloQueryMock(
instructionAffirmationsQuery({ instructionId: id.toString() }, size, start),
instructionAffirmationsQuery(false, { instructionId: id.toString() }, size, start),
{
instructionAffirmations: {
nodes: [
Expand All @@ -871,7 +871,7 @@ describe('Instruction class', () => {
expect(count).toEqual(new BigNumber(1));

dsMockUtils.createApolloQueryMock(
instructionAffirmationsQuery({ instructionId: id.toString() }),
instructionAffirmationsQuery(false, { instructionId: id.toString() }),
{
instructionAffirmations: {
nodes: [],
Expand Down Expand Up @@ -1956,9 +1956,10 @@ describe('Instruction class', () => {
describe('method: getMediators', () => {
const mediatorDid1 = 'mediatorDid1';
const mediatorDid2 = 'mediatorDid2';
const mediatorDid3 = 'mediatorDid3';

describe('querying the middleware', () => {
it('should return the instruction mediators', async () => {
it('should return the instruction mediators with affirmation info', async () => {
dsMockUtils.createApolloQueryMock(
instructionsQuery(false, {
id: id.toString(),
Expand All @@ -1967,15 +1968,15 @@ describe('Instruction class', () => {
instructions: {
nodes: [
{
mediators: [mediatorDid1, mediatorDid2],
mediators: [mediatorDid1, mediatorDid2, mediatorDid3],
},
],
},
}
);
const expiry = new Date('2050/01/01');
dsMockUtils.createApolloQueryMock(
instructionAffirmationsQuery({
instructionAffirmationsQuery(false, {
instructionId: id.toString(),
isMediator: true,
}),
Expand All @@ -1985,7 +1986,12 @@ describe('Instruction class', () => {
{
identity: mediatorDid2,
status: AffirmStatusEnum.Affirmed,
expiry,
expiry: expiry.toISOString(),
},
{
identity: mediatorDid3,
status: AffirmStatusEnum.Affirmed,
expiry: null,
},
],
},
Expand All @@ -2004,6 +2010,11 @@ describe('Instruction class', () => {
status: AffirmationStatus.Affirmed,
expiry,
},
{
identity: expect.objectContaining({ did: mediatorDid3 }),
status: AffirmationStatus.Affirmed,
expiry: undefined,
},
]);
});
});
Expand Down Expand Up @@ -2039,7 +2050,7 @@ describe('Instruction class', () => {
describe('querying the middleware', () => {
it('should return the affirmation status of offchain legs', async () => {
dsMockUtils.createApolloQueryMock(
offChainAffirmationsQuery({
offChainAffirmationsQuery(false, {
instructionId: id.toString(),
}),
{
Expand Down
19 changes: 10 additions & 9 deletions src/api/entities/Instruction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export class Instruction extends Entity<UniqueIdentifiers, string> {
},
},
} = await context.queryMiddleware<Ensured<Query, 'instructions'>>(
instructionsQuery(false, {
instructionsQuery(context.isSqIdPadded, {
id: id.toString(),
})
);
Expand Down Expand Up @@ -520,6 +520,7 @@ export class Instruction extends Entity<UniqueIdentifiers, string> {
},
} = await context.queryMiddleware<Ensured<Query, 'instructionAffirmations'>>(
instructionAffirmationsQuery(
context.isSqIdPadded,
{
instructionId: id.toString(),
},
Expand Down Expand Up @@ -951,7 +952,7 @@ export class Instruction extends Entity<UniqueIdentifiers, string> {
] = await Promise.all([
this.getInstructionFromMiddleware(),
context.queryMiddleware<Ensured<Query, 'instructionAffirmations'>>(
instructionAffirmationsQuery({
instructionAffirmationsQuery(context.isSqIdPadded, {
instructionId: id.toString(),
isMediator: true,
})
Expand All @@ -961,14 +962,14 @@ export class Instruction extends Entity<UniqueIdentifiers, string> {
const getMediatorAffirmationStatus = (
mediatorAffirmation?: MiddlewareInstructionAffirmation
): Omit<MediatorAffirmation, 'identity'> => {
let status = AffirmationStatus.Pending;
if (mediatorAffirmation) {
status = middlewareAffirmStatusToAffirmationStatus(mediatorAffirmation.status);
if (mediatorAffirmation.expiry) {
return { status, expiry: mediatorAffirmation.expiry };
}
const status = middlewareAffirmStatusToAffirmationStatus(mediatorAffirmation.status);
return {
status,
expiry: mediatorAffirmation.expiry ? new Date(mediatorAffirmation.expiry) : undefined,
};
}
return { status };
return { status: AffirmationStatus.Pending };
};

return (mediators as string[]).map(mediator => {
Expand Down Expand Up @@ -1026,7 +1027,7 @@ export class Instruction extends Entity<UniqueIdentifiers, string> {
instructionAffirmations: { nodes: offChainAffirmations },
},
} = await context.queryMiddleware<Ensured<Query, 'instructionAffirmations'>>(
offChainAffirmationsQuery({
offChainAffirmationsQuery(context.isSqIdPadded, {
instructionId: id.toString(),
})
);
Expand Down
6 changes: 3 additions & 3 deletions src/api/procedures/registerIdentity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ISubmittableResult } from '@polkadot/types/types';

import { Account, Context, Identity, PolymeshError, Procedure } from '~/internal';
import { Context, Identity, PolymeshError, Procedure } from '~/internal';
import { ErrorCode, RegisterIdentityParams, RoleType, TxTags } from '~/types';
import { ExtrinsicParams, TransactionSpec } from '~/types/internal';
import {
Expand All @@ -11,7 +11,7 @@ import {
signerToString,
stringToAccountId,
} from '~/utils/conversion';
import { filterEventRecords, optionize } from '~/utils/internal';
import { asAccount, filterEventRecords, optionize } from '~/utils/internal';

/**
* @hidden
Expand Down Expand Up @@ -45,7 +45,7 @@ export async function prepareRegisterIdentity(
} = this;
const { targetAccount, secondaryAccounts = [], createCdd = false, expiry } = args;

const account = new Account({ address: targetAccount.toString() }, context);
const account = asAccount(targetAccount, context);

const identityExists = await account.getIdentity();

Expand Down
8 changes: 4 additions & 4 deletions src/middleware/__tests__/queries/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ describe('assetHoldersQuery', () => {
start: 0,
};

let result = assetHoldersQuery(variables);
let result = assetHoldersQuery(false, variables);

expect(result.query).toBeDefined();
expect(result.variables).toEqual(variables);

result = assetHoldersQuery(variables, new BigNumber(1), new BigNumber(0));
result = assetHoldersQuery(false, variables, new BigNumber(1), new BigNumber(0));

expect(result.query).toBeDefined();
expect(result.variables).toEqual({
Expand All @@ -54,12 +54,12 @@ describe('nftHoldersQuery', () => {
start: 0,
};

let result = nftHoldersQuery(variables);
let result = nftHoldersQuery(false, variables);

expect(result.query).toBeDefined();
expect(result.variables).toEqual(variables);

result = nftHoldersQuery(variables, new BigNumber(1), new BigNumber(0));
result = nftHoldersQuery(false, variables, new BigNumber(1), new BigNumber(0));

expect(result.query).toBeDefined();
expect(result.variables).toEqual({
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/__tests__/queries/extrinsics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('extrinsicByHash', () => {

describe('extrinsicsByArgs', () => {
it('should pass the variables to the grapqhl query', () => {
let result = extrinsicsByArgs({});
let result = extrinsicsByArgs(false, {});

expect(result.query).toBeDefined();
expect(result.variables).toEqual({ size: DEFAULT_GQL_PAGE_SIZE, start: 0 });
Expand All @@ -32,7 +32,7 @@ describe('extrinsicsByArgs', () => {
start: 0,
};

result = extrinsicsByArgs(variables);
result = extrinsicsByArgs(false, variables);

expect(result.query).toBeDefined();
expect(result.variables).toEqual(variables);
Expand Down
20 changes: 20 additions & 0 deletions src/middleware/queries/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,21 @@ export function assetQuery(
* Get asset held by a DID
*/
export function assetHoldersQuery(
isSqIdPadded: boolean,
filters: QueryArgs<AssetHolder, 'identityId'>,
size?: BigNumber,
start?: BigNumber,
orderBy = AssetHoldersOrderBy.AssetIdAsc
): QueryOptions<PaginatedQueryArgs<QueryArgs<DistributionPayment, 'distributionId'>>> {
if (isSqIdPadded) {
if (orderBy === AssetHoldersOrderBy.CreatedAtAsc) {
orderBy = AssetHoldersOrderBy.CreatedBlockIdAsc;
}
if (orderBy === AssetHoldersOrderBy.CreatedAtDesc) {
orderBy = AssetHoldersOrderBy.CreatedBlockIdDesc;
}
}

const query = gql`
query AssetHoldersQuery($identityId: String!, $size: Int, $start: Int) {
assetHolders(
Expand Down Expand Up @@ -89,11 +99,21 @@ export function assetHoldersQuery(
* Get NFTs held by a DID
*/
export function nftHoldersQuery(
isSqIdPadded: boolean,
filters: QueryArgs<NftHolder, 'identityId'>,
size?: BigNumber,
start?: BigNumber,
orderBy = NftHoldersOrderBy.AssetIdAsc
): QueryOptions<PaginatedQueryArgs<QueryArgs<NftHolder, 'identityId'>>> {
if (isSqIdPadded) {
if (orderBy === NftHoldersOrderBy.CreatedAtAsc) {
orderBy = NftHoldersOrderBy.CreatedBlockIdAsc;
}
if (orderBy === NftHoldersOrderBy.CreatedAtDesc) {
orderBy = NftHoldersOrderBy.CreatedBlockIdDesc;
}
}

const query = gql`
query NftHolderQuery($identityId: String!, $size: Int, $start: Int) {
nftHolders(
Expand Down
5 changes: 2 additions & 3 deletions src/middleware/queries/authorizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ export function authorizationsQuery(
): QueryOptions<PaginatedQueryArgs<QueryArgs<Authorization, AuthorizationArgs>>> {
const { args, filter } = createAuthorizationFilters(filters);

const idField = paddedIds ? 'id' : 'authId: id';
const orderBy = paddedIds
? `${AuthorizationsOrderBy.CreatedBlockIdAsc}`
? `${AuthorizationsOrderBy.CreatedEventIdAsc}`
: `${AuthorizationsOrderBy.CreatedAtAsc}, ${AuthorizationsOrderBy.CreatedBlockIdAsc}`;

const query = gql`
Expand All @@ -76,7 +75,7 @@ export function authorizationsQuery(
) {
totalCount
nodes {
${idField}
id
type
fromId
toId
Expand Down
9 changes: 0 additions & 9 deletions src/middleware/queries/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,3 @@ export function removeUndefinedValues(
): Record<string | number | symbol, unknown> {
return Object.fromEntries(Object.entries(variables).filter(([, value]) => value !== undefined));
}

/**
* Pad ID for subquery
*
* @hidden
*/
export function padSqId(id: string): string {
return id.padStart(10, '0');
}
Loading
Loading