Skip to content

Commit

Permalink
modify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vmidyllic committed Sep 1, 2023
1 parent ae82fb1 commit e70f395
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 41 deletions.
7 changes: 2 additions & 5 deletions tests/handlers/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ describe('auth', () => {
birthday: 19960424,
documentType: 99
},
expiration: 1693526400,
expiration: 2793526400,
revocationOpts: {
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
id: rhsUrl
Expand Down Expand Up @@ -252,12 +252,10 @@ describe('auth', () => {
from: issuerId.string()
};

console.log(JSON.stringify(issuerCred));
const msgBytes = byteEncoder.encode(JSON.stringify(authReq));
const authRes = await authHandler.handleAuthorizationRequest(userDID, msgBytes);

const tokenStr = authRes.token;
console.log(tokenStr);
expect(tokenStr).to.be.a('string');
const token = await Token.parse(tokenStr);
expect(token).to.be.a('object');
Expand Down Expand Up @@ -297,7 +295,7 @@ describe('auth', () => {
birthday: 19960424,
documentType: 99
},
expiration: 1693526400,
expiration: 2793526400,
revocationOpts: {
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
id: rhsUrl
Expand Down Expand Up @@ -357,6 +355,5 @@ describe('auth', () => {

const resp = await authHandler.handleAuthorizationRequest(authProfileDID, msgBytes);

Check warning on line 356 in tests/handlers/auth.test.ts

View workflow job for this annotation

GitHub Actions / build (18.16.1)

'resp' is assigned a value but never used

console.log(resp);
});
});
8 changes: 4 additions & 4 deletions tests/identity/id.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ describe('identity', () => {
MerkleTreeType.Claims
);

console.log(JSON.stringify(credential));
expect((await claimsTree.root()).bigInt()).not.to.equal(0);
});
it('createProfile', async () => {
Expand All @@ -129,9 +128,10 @@ describe('identity', () => {
);

const dbProfile = await dataStorage.identity.getProfileByVerifier('http://polygonissuer.com/');
expect(dbProfile.id).to.equal(profileDID.string());
expect(dbProfile.genesisIdentifier).to.equal(did.string());
expect(dbProfile.nonce).to.equal(10);
expect(dbProfile).not.to.be.undefined;
expect(dbProfile!.id).to.equal(profileDID.string());

Check warning on line 132 in tests/identity/id.test.ts

View workflow job for this annotation

GitHub Actions / build (18.16.1)

Forbidden non-null assertion
expect(dbProfile!.genesisIdentifier).to.equal(did.string());

Check warning on line 133 in tests/identity/id.test.ts

View workflow job for this annotation

GitHub Actions / build (18.16.1)

Forbidden non-null assertion
expect(dbProfile!.nonce).to.equal(10);

Check warning on line 134 in tests/identity/id.test.ts

View workflow job for this annotation

GitHub Actions / build (18.16.1)

Forbidden non-null assertion
});
it('sign', async () => {
const seedPhrase: Uint8Array = byteEncoder.encode('seedseedseedseedseedseedseedseed');
Expand Down
22 changes: 10 additions & 12 deletions tests/proofs/mtp-onchain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { ProofService } from '../../src/proof';
import { CircuitId } from '../../src/circuits';
import { ethers } from 'ethers';
import { EthStateStorage } from '../../src/storage/blockchain/state';
import { EthStateStorage, defaultEthConnectionConfig } from '../../src/storage/blockchain/state';

Check warning on line 24 in tests/proofs/mtp-onchain.test.ts

View workflow job for this annotation

GitHub Actions / build (18.16.1)

'defaultEthConnectionConfig' is defined but never used
import { RootInfo, StateProof } from '../../src/storage/entities/state';
import path from 'path';
import { CredentialStatusType, W3CCredential } from '../../src/verifiable';
Expand All @@ -37,13 +37,15 @@ describe('mtp onchain proofs', () => {
let proofService: ProofService;

const rhsUrl = process.env.RHS_URL as string;
const rpcUrl = process.env.RPC_URL as string;

Check warning on line 40 in tests/proofs/mtp-onchain.test.ts

View workflow job for this annotation

GitHub Actions / build (18.16.1)

'rpcUrl' is assigned a value but never used

const walletKey = process.env.WALLET_KEY as string;

const mockStateStorage: IStateStorage = {
getLatestStateById: async () => {
return {
id: 25191641634853875207018381290409317860151551336133597267061715643603096065n,
state: 15316103435703269893947162180693935798669021972402205481551466808302934202991n,
state: 5224437024673068498206105743424598123651101873588696368477339341771571761791n,
replacedByState: 0n,
createdAtTimestamp: 1672245326n,
replacedAtTimestamp: 0n,
Expand Down Expand Up @@ -97,16 +99,13 @@ describe('mtp onchain proofs', () => {
dirname: path.join(__dirname, './testdata')
});

/*
To use ethereum storage

const conf = defaultEthConnectionConfig;
conf.url = infuraUrl;
conf.contractAddress = '0xf6781AD281d9892Df285cf86dF4F6eBec2042d71';
ethStorage = new EthStateStorage(conf);
dataStorage.states = ethStorage;
// const conf =defaultEthConnectionConfig ;
// conf.url = rpcUrl ;
// conf.contractAddress = '0x134B1BE34911E39A8397ec6289782989729807a4';
// const ethStorage = new EthStateStorage(conf);
// dataStorage.states = ethStorage;

*/

const resolvers = new CredentialStatusResolverRegistry();
resolvers.register(
Expand Down Expand Up @@ -155,7 +154,7 @@ describe('mtp onchain proofs', () => {
birthday: 19960424,
documentType: 99
},
expiration: 1693526400,
expiration: 2793526400,
revocationOpts: {
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
nonce: 1000,
Expand Down Expand Up @@ -217,7 +216,6 @@ describe('mtp onchain proofs', () => {
challenge: BigInt(2),
skipRevocation: false
});
console.log(proof);
expect(vp).to.be.undefined;
});
});
9 changes: 3 additions & 6 deletions tests/proofs/mtp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('mtp proofs', () => {
getLatestStateById: async () => {
return {
id: 25191641634853875207018381290409317860151551336133597267061715643603096065n,
state: 15316103435703269893947162180693935798669021972402205481551466808302934202991n,
state: 5224437024673068498206105743424598123651101873588696368477339341771571761791n,
replacedByState: 0n,
createdAtTimestamp: 1672245326n,
replacedAtTimestamp: 0n,
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('mtp proofs', () => {
birthday: 19960424,
documentType: 99
},
expiration: 1693526400,
expiration: 2793526400,
revocationOpts: {
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
nonce: 1000,
Expand Down Expand Up @@ -212,7 +212,6 @@ describe('mtp proofs', () => {
expect(creds.length).to.not.equal(0);

const { proof, vp } = await proofService.generateProof(proofReq, userDID);

Check warning on line 214 in tests/proofs/mtp.test.ts

View workflow job for this annotation

GitHub Actions / build (18.16.1)

'proof' is assigned a value but never used
console.log(proof);
expect(vp).to.be.undefined;
});

Expand Down Expand Up @@ -252,7 +251,7 @@ describe('mtp proofs', () => {
birthday: 19960424,
documentType: 99
},
expiration: 1693526400,
expiration: 2793526400,
revocationOpts: {
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
nonce: 1000,
Expand All @@ -266,7 +265,6 @@ describe('mtp proofs', () => {

const res = await idWallet.addCredentialsToMerkleTree([issuerCred], issuerDID);

// publish to rhs

await idWallet.publishStateToRHS(issuerDID, rhsUrl);

Expand Down Expand Up @@ -320,7 +318,6 @@ describe('mtp proofs', () => {
credential: credsForMyUserDID[0],
skipRevocation: false
});
console.log(proof);
expect(vp).to.be.undefined;
});
});
3 changes: 1 addition & 2 deletions tests/proofs/sig-onchain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('sig onchain proofs', () => {
birthday: 19960424,
documentType: 99
},
expiration: 1693526400,
expiration: 2793526400,
revocationOpts: {
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
id: rhsUrl
Expand Down Expand Up @@ -168,7 +168,6 @@ describe('sig onchain proofs', () => {
challenge: BigInt(2),
skipRevocation: false
});
console.log(proof);

expect(vp).to.be.undefined;

Expand Down
12 changes: 6 additions & 6 deletions tests/proofs/sig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('sig proofs', () => {
birthday: 19960424,
documentType: 99
},
expiration: 1693526400,
expiration: 2793526400,
revocationOpts: {
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
id: rhsUrl
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('sig proofs', () => {
birthday: 19960424,
documentType: 99
},
expiration: 1693526400,
expiration: 2793526400,
revocationOpts: {
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
id: rhsUrl
Expand Down Expand Up @@ -229,7 +229,7 @@ describe('sig proofs', () => {
birthday: 19960424,
documentType: 99
},
expiration: 1693526400,
expiration: 2793526400,
revocationOpts: {
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
id: rhsUrl
Expand Down Expand Up @@ -306,7 +306,7 @@ describe('sig proofs', () => {
id: userDID.string(),
stringTest: 'test'
},
expiration: 1693526400,
expiration: 2793526400,
revocationOpts: {
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
id: rhsUrl
Expand Down Expand Up @@ -380,7 +380,7 @@ describe('sig proofs', () => {
},
isPostalProvider: true
},
expiration: 1693526400,
expiration: 2793526400,
revocationOpts: {
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
id: rhsUrl
Expand Down Expand Up @@ -418,7 +418,7 @@ describe('sig proofs', () => {
price: 15.2,
type: 'DeliverAddressMultiTest'
},
expiration: 1693526400,
expiration: 2793526400,
revocationOpts: {
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
id: rhsUrl
Expand Down
49 changes: 43 additions & 6 deletions tests/rhs/rhs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,45 @@ describe('rhs', () => {
getLatestStateById: async () => {
return {
id: 25191641634853875207018381290409317860151551336133597267061715643603096065n,
state: 15316103435703269893947162180693935798669021972402205481551466808302934202991n,
state: 9237508920537027525017236505396978200808288762330464571183908763595717964946n,
replacedByState: 0n,
createdAtTimestamp: 1672245326n,
replacedAtTimestamp: 0n,
createdAtBlock: 30258020n,
replacedAtBlock: 0n
};
},
publishState: async () => {
return '0xc837f95c984892dbcc3ac41812ecb145fedc26d7003202c50e1b87e226a9b33c';
},
getGISTProof: (): Promise<StateProof> => {
return Promise.resolve({
root: 0n,
existence: false,
siblings: [],
index: 0n,
value: 0n,
auxExistence: false,
auxIndex: 0n,
auxValue: 0n
});
},
getGISTRootInfo: (): Promise<RootInfo> => {
return Promise.resolve({
root: 0n,
replacedByRoot: 0n,
createdAtTimestamp: 0n,
replacedAtTimestamp: 0n,
createdAtBlock: 0n,
replacedAtBlock: 0n
});
}
};
const mockStateStorageForSecondState: IStateStorage = {
getLatestStateById: async () => {
return {
id: 25191641634853875207018381290409317860151551336133597267061715643603096065n,
state: 6331804583810507588859496367559464513815759967776810588505869388511678144501n,
replacedByState: 0n,
createdAtTimestamp: 1672245326n,
replacedAtTimestamp: 0n,
Expand Down Expand Up @@ -232,7 +270,7 @@ describe('rhs', () => {
birthday: 19960424,
documentType: 99
},
expiration: 1693526400,
expiration: 2793526400,
revocationOpts: {
nonce: 1000,
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
Expand Down Expand Up @@ -308,7 +346,7 @@ describe('rhs', () => {
birthday: 19960424,
documentType: 99
},
expiration: 1693526400,
expiration: 2793526400,
revocationOpts: {
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
nonce: 1000,
Expand All @@ -322,8 +360,6 @@ describe('rhs', () => {

await idWallet.addCredentialsToMerkleTree([issuerCred], issuerDID);

// this state is published

// let's add one more credential

const claimReq2: CredentialRequest = {
Expand All @@ -335,7 +371,7 @@ describe('rhs', () => {
birthday: 19960523,
documentType: 1
},
expiration: 1693526400,
expiration: 2793526400,
revocationOpts: {
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
id: rhsUrl,
Expand All @@ -356,6 +392,7 @@ describe('rhs', () => {
await idWallet.publishStateToRHS(issuerDID, rhsUrl, [nonce]);

// state is published to blockchain (2)
dataStorage.states = mockStateStorageForSecondState;

const rhsResolver = new RHSResolver(dataStorage.states);
const rhsStatus = await rhsResolver.resolve(credRHSStatus, { issuerDID });
Expand Down

0 comments on commit e70f395

Please sign in to comment.