Skip to content

Commit

Permalink
feat: proofs,data models, requests testing done
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth9890 committed Mar 7, 2024
1 parent 963d6b6 commit 0aba14f
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/data-model/data-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class DataModel {
return this.sdk.createDataModel_mutation({
input: createModelInput,
});
} catch (error: any) {
} catch (error) {
throw new Error(errorHandler(error));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/organization/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class Organization {
return await this.sdk.addMemberToOrganization_mutation({
input: memberInput,
});
} catch (error: any) {
} catch (error) {
throw new Error(errorHandler(error));
}
}
Expand Down
245 changes: 195 additions & 50 deletions src/testMutationsAndQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ function generateRandomString() {
return result;
}

// error handler
// transactions
// some minor backend errors in getRequestsReceived

const testMutationsAndQueries = async () => {
const gatewayInstance = new Gateway({
apiKey: 'm9Y5ntNcTlwQ2LbRpYr6K_VhxJXuZJ6Q',
Expand All @@ -28,12 +32,12 @@ const testMutationsAndQueries = async () => {
});
try {
// ORGANIZATIONS
const { createOrganization } =
await gatewayInstance.organization.createOrganization({
name: 'Create sample organization',
description: 'Sample organization description',
username: generateRandomString(),
});
// const { createOrganization } =
// await gatewayInstance.organization.createOrganization({
// name: 'Create sample organization',
// description: 'Sample organization description',
// username: generateRandomString(),
// });

// THESE ARE WORKING FINE JUST COMMENTED THEM TO PREVENT ERROR AS THERE IS ONLY 1 USER IN ORG
// const { addMemberToOrganization } =
Expand All @@ -58,67 +62,208 @@ const testMutationsAndQueries = async () => {
// user: { type: 'GATEWAY_ID', value: USER_GATEWAY_ID },
// });

const { updateOrganization } =
await gatewayInstance.organization.updateOrganization({
id: createOrganization.id,
description: 'updated description',
// const { updateOrganization } =
// await gatewayInstance.organization.updateOrganization({
// id: createOrganization.id,
// description: 'updated description',
// });

// const { organization } = await gatewayInstance.organization.getOrganization(
// OrganizationIdentifierType.ORG_ID,
// createOrganization.id,
// );

// const { organizations } =
// await gatewayInstance.organization.getOrganizations({
// filter: { verified: true },
// });

console.log('\n ORGS DONE \n');

// PDA
// let obj = {
// dataModelId: '74719072-0268-4c06-84d5-73ba8a4e51fb',
// description: 'Description of the PDA',
// title: 'Favorite Person on Crypto Twitter',
// claim: {
// name: '@gateway_xyz',
// age: 20,
// },
// owner: {
// type: UserIdentifierType.GATEWAY_ID,
// value: USER_GATEWAY_ID,
// },
// };
// const { createPDA } = await gatewayInstance.pda.createPDA(obj);

// const { updatePDA } = await gatewayInstance.pda.updatePDA({
// id: createPDA.id,
// title: 'Changed PDA title',
// });

// const { PDA } = await gatewayInstance.pda.getPDA(createPDA.id);

await gatewayInstance.pda.getPDAs();

// const { issuedPDAs } = await gatewayInstance.pda.getIssuedPDAs({
// skip: 0,
// take: 20,
// filter: { dataModelIds: ['74719072-0268-4c06-84d5-73ba8a4e51fb'] },
// });

// await gatewayInstance.pda.getIssuedPDAsCount();

// await gatewayInstance.pda.getPDACount();

console.log('\n PDAS DONE \n');
// Transactions

// const { transactions } =
// await gatewayInstance.transaction.getTransactions();
// console.log(transactions[0], transactions.length);
// await gatewayInstance.transaction.getTransaction('<-- transaction id -->');

// await gatewayInstance.transaction.getTransactionCount();

console.log('\n TRANSACTIONS DONE \n');

// Data Models

const { createDataModel } = await gatewayInstance.dataModel.createDataModel(
{
description: 'testing',
permissions: 'ALL',
title: 'testing',
schema: {
type: 'object',
default: {},
title: 'Root Schema',
required: ['name', 'age'],
properties: {
name: {
type: 'string',
title: 'name',
},
age: {
type: 'integer',
title: 'age',
examples: ['Tell us what your experience was like'],
},
},
},
},
);

await gatewayInstance.dataModel.getDataModel(
'74719072-0268-4c06-84d5-73ba8a4e51fb',
);

await gatewayInstance.dataModel.getDataModels();

await gatewayInstance.dataModel.getDataModelsCount();

await gatewayInstance.dataModel.getDataModelsMetaData();

await gatewayInstance.dataModel.getIssuersByDataModel(
'74719072-0268-4c06-84d5-73ba8a4e51fb',
);

await gatewayInstance.dataModel.getTotalofIssuersByDataModel(
'74719072-0268-4c06-84d5-73ba8a4e51fb',
);

await gatewayInstance.dataModel.getIssuersByDataModelCount(
'74719072-0268-4c06-84d5-73ba8a4e51fb',
);

console.log('\n DATA MODELS DONE \n');
// Data Requests template
const { createDataRequestTemplate } =
await gatewayInstance.dataRequestTemplate.createDataRequestTemplate({
title: 'Create Data Request Template Example',
description: 'Lorem ipsum dolor sit amet.',
dataModels: [
{
id: '74719072-0268-4c06-84d5-73ba8a4e51fb',
required: true,
claimValidations: {
type: 'object',
properties: {
name: {
type: 'string',
},
age: {
type: 'number',
},
},
required: ['name', 'age'],
},
},
],
});

const { organization } = await gatewayInstance.organization.getOrganization(
OrganizationIdentifierType.ORG_ID,
createOrganization.id,
await gatewayInstance.dataRequestTemplate.getDataRequestTemplate(
createDataRequestTemplate.id,
);

await gatewayInstance.dataRequestTemplate.getDataRequestTemplates({
filter: { user: { type: 'GATEWAY_ID', value: USER_GATEWAY_ID } },
});

await gatewayInstance.dataRequestTemplate.getDataRequestsTemplateCount();

await gatewayInstance.dataRequestTemplate.getDataRequestsTemplatesMetadata();

await gatewayInstance.dataRequestTemplate.getVerifiersByDataRequestTemplate(
createDataRequestTemplate.id,
);

const { organizations } =
await gatewayInstance.organization.getOrganizations({
// filter: { verified: true },
await gatewayInstance.dataRequestTemplate.getVerifiersByDataRequestTemplateCount(
createDataRequestTemplate.id,
);
console.log('\n DATA REQUESTS TEMPLATE DONE \n');

// Data requests
const { createDataRequest } =
await gatewayInstance.request.createDataRequest({
dataRequestTemplateId: createDataRequestTemplate.id,
dataUse:
'Web3 is an idea for a new iteration of the World Wide Web which incorporates concepts such as decentralization, blockchain technologies, and token-based economics.',
owner: { type: 'GATEWAY_ID', value: USER_GATEWAY_ID },
});
console.log(organizations[0].description, organizations.length);

console.log('\n \n');
await gatewayInstance.request.getDataRequest(createDataRequest.id);

// PDA
let obj = {
dataModelId: '74719072-0268-4c06-84d5-73ba8a4e51fb',
description: 'Description of the PDA',
title: 'Favorite Person on Crypto Twitter',
claim: {
name: '@gateway_xyz',
age: 20,
},
owner: {
type: UserIdentifierType.GATEWAY_ID,
value: USER_GATEWAY_ID,
},
};
const { createPDA } = await gatewayInstance.pda.createPDA(obj);
await gatewayInstance.request.getDataRequestCount();

await gatewayInstance.request.getDataRequestStatus(createDataRequest.id);

const { updatePDA } = await gatewayInstance.pda.updatePDA({
id: createPDA.id,
title: 'Changed PDA title',
await gatewayInstance.request.getDataRequests({
dataTemplateIds: [createDataRequest.id],
});

const { PDA } = await gatewayInstance.pda.getPDA(createPDA.id);
// await gatewayInstance.request.getRequestsReceived();

await gatewayInstance.request.getRequestsSent();

const { issuedPDAs } = await gatewayInstance.pda.getIssuedPDAs({
skip: 0,
take: 20,
filter: { dataModelIds: ['74719072-0268-4c06-84d5-73ba8a4e51fb'] },
console.log('\n DATA REQUESTS DONE \n');
// Proofs

// await gatewayInstance.proof.getProofs();

await gatewayInstance.proof.getProofsByPDAIds({
pdaIds: ['c75a800b-5649-461b-86ab-a4864c6578ee'],
});

await gatewayInstance.pda.getIssuedPDAsCount();
await gatewayInstance.proof.getReceivedProofs();

await gatewayInstance.pda.getPDACount();
await gatewayInstance.proof.getReceivedProofsCount();

console.log('\n \n');
// Transactions
await gatewayInstance.proof.getSentProofs();

const { transactions } =
await gatewayInstance.transaction.getTransactions();
console.log(transactions[0], transactions.length);
await gatewayInstance.transaction.getTransaction('<-- transaction id -->');
await gatewayInstance.proof.getSentProofsCount();

await gatewayInstance.transaction.getTransactionCount();
console.log('\n PROOFS DONE \n');
} catch (error) {
console.log(error);
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const STRING_VALIDATION_LENGTH = 3;
export const STRING_VALIDATION_LENGTH = 2;
export const TEST_DEFAULT_TIMEOUT = 10000;
export const DEFAULT_TAKE_LIMIT = 15;
26 changes: 13 additions & 13 deletions src/utils/errorHandler.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export const errorHandler = (error: any): string => {
return error.response.errors[0].message;
// if (typeof error === 'object' && error !== null) {
// if (
// Array.isArray(error.errors) &&
// error.errors.length > 0 &&
// 'message' in error.errors[0]
// ) {
// return error.errors[0].message;
// } else if ('message' in error) {
// return error.message;
// }
// }
// return 'Something went wrong!';
// return error.response.errors[0].message;
if (typeof error === 'object' && error !== null) {
if (
Array.isArray(error.errors) &&
error.errors.length > 0 &&
'message' in error.errors[0]
) {
return error.errors[0].message;
} else if ('message' in error) {
return error.message;
}
}
return 'Something went wrong!';
};

0 comments on commit 0aba14f

Please sign in to comment.