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

refactor: remove dependency on indy ledger service from sov did resolver/registrar #1086

Merged

Conversation

sairanjit
Copy link
Contributor

@sairanjit sairanjit commented Nov 6, 2022

resolves: #1066 and #1067
Signed-off-by: Sai Ranjit Tummalapalli [email protected]

@sairanjit sairanjit requested a review from a team as a code owner November 6, 2022 07:54
@codecov-commenter
Copy link

codecov-commenter commented Nov 6, 2022

Codecov Report

Merging #1086 (224f98d) into main (574e6a6) will decrease coverage by 0.15%.
The diff coverage is 86.00%.

@@            Coverage Diff             @@
##             main    #1086      +/-   ##
==========================================
- Coverage   88.44%   88.28%   -0.16%     
==========================================
  Files         706      706              
  Lines       16342    16397      +55     
  Branches     2640     2652      +12     
==========================================
+ Hits        14453    14476      +23     
- Misses       1882     1914      +32     
  Partials        7        7              
Impacted Files Coverage Δ
packages/core/src/modules/ledger/LedgerApi.ts 97.61% <ø> (ø)
...e/src/modules/ledger/services/IndyLedgerService.ts 53.84% <57.14%> (-16.69%) ⬇️
...modules/dids/methods/sov/IndySdkSovDidRegistrar.ts 94.20% <86.66%> (ø)
.../modules/dids/methods/sov/IndySdkSovDidResolver.ts 88.09% <88.09%> (ø)
...ore/src/modules/ledger/services/IndyPoolService.ts 96.05% <90.00%> (-3.95%) ⬇️
packages/core/src/modules/dids/DidsModuleConfig.ts 100.00% <100.00%> (ø)
...ackages/core/src/modules/dids/methods/sov/index.ts 100.00% <100.00%> (ø)
packages/core/src/agent/MessageReceiver.ts 81.98% <0.00%> (-2.71%) ⬇️
packages/core/src/wallet/IndyWallet.ts 55.43% <0.00%> (-1.13%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@sairanjit sairanjit changed the title feat: add getPoolForNamespace method in IndyPoolService refactor: remove dependency on indy ledger service from sov did resolver/registrar Nov 6, 2022
@TimoGlastra
Copy link
Contributor

Will put in a thorough review soon, but this is awesome! Thanks @sairanjit!

Copy link
Contributor

@TimoGlastra TimoGlastra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @sairanjit, left some comments

alias: string,
role?: Indy.NymRole
) {
const pool = this.indyPoolService.ledgerWritePool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This takes the pool from the ledgerWritePool, however you also added a config option to set the indyNamespace. I think we should get the pool based on the indyNamespace from the indyPoolService and use that as the pool to write to the ledger instead.

did: string,
endpoints: IndyEndpointAttrib
): Promise<void> {
const pool = this.indyPoolService.ledgerWritePool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, should use pool based on the indyNamespace variable. I think for both methods we can pass the pool as an argument to this method.

@@ -178,6 +240,7 @@ export interface SovDidCreateOptions extends DidCreateOptions {
// As did:sov is so limited, we require everything needed to construct the did document to be passed
// through the options object. Once we support did:indy we can allow the didDocument property.
didDocument?: never
indyNamespace?: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indyNamespace property should be added to the options object

@@ -102,7 +98,8 @@ export class SovDidRegistrar implements DidRegistrar {
// Build did document.
const didDocument = didDocumentBuilder.build()

const didIndyNamespace = this.indyPoolService.ledgerWritePool.config.indyNamespace
const pool = this.indyPoolService.getPoolForNamespace(options.indyNamespace)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can pass this pool to the registerPublicDid and setEndpointsForDid methods

return didResponse
}

public async getEndpointsForDid(agentContext: AgentContext, did: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public async getEndpointsForDid(agentContext: AgentContext, did: string) {
private async getEndpointsForDid(agentContext: AgentContext, did: string) {

indySdkSovDidResolver = new IndySdkSovDidResolver(
indyPoolServiceMock,
agentConfig.agentDependencies,
new LoggerMock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agentConfig.logger

@@ -55,6 +55,9 @@ export class LedgerApi {
await this.ledgerService.connectToPools()
}

/**
* @deprecated use agent.dids.create instead
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👍

@@ -131,6 +140,9 @@ export class IndyLedgerService {
}
}

/**
* @deprecated
*/
public async getEndpointsForDid(agentContext: AgentContext, did: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you moved some methods to the indy pool service. Can we update all methods in the indy ledger service to call those new methods instead? As they're private in this class we can migrate them (instead of duplicate) without any issues

@@ -59,6 +59,9 @@ export class IndyLedgerService {
return this.indyPoolService.connectToPools()
}

/**
* @deprecated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also mark getDidIndyWriteNamespace as deprecated?

@@ -14,6 +14,7 @@ import { FileSystem } from '../../../storage/FileSystem'
import { isSelfCertifiedDid } from '../../../utils/did'
import { isIndyError } from '../../../utils/indyError'
import { allSettled, onlyFulfilled, onlyRejected } from '../../../utils/promises'
import { assertIndyWallet } from '../../../wallet/util/assertIndyWallet'
import { IndyPool } from '../IndyPool'
import { LedgerError } from '../error/LedgerError'
import { LedgerNotConfiguredError } from '../error/LedgerNotConfiguredError'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also mark get ledgerWritePool as deprecated?

@TimoGlastra TimoGlastra linked an issue Nov 10, 2022 that may be closed by this pull request
Comment on lines 70 to 76
jest
.spyOn(poolService, 'submitWriteRequest')
.mockRejectedValue(
new Error(
'Unable to satisfy matching TAA with mechanism "accept" and version "1.0" in pool.\n Found ["accept"] and version 2.0 in pool.'
)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not actually testing anymore that it throws an error if the config version does not match, we're just throwing a mocked error now. Can we move these tests to the pool service tests? (As that's where the logic is moved to right?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, Can I keep the same tests in both IndyLedgerService.test.ts and IndyPoolService.test.ts ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean exactly? What we're testing here doesn't really test anything, but I do think we should have this test in the indy pool service. Doest hat answer your question?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will update the test to catch the actual error from the function instead of mocking it and move the tests from IndyLedgerService.test.ts to IndyPoolService.test.ts. Is It right now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After moving the tests to IndyPoolService.test.ts there are no tests left in the IndyLedgerService.test.ts file. So, Can I delete the IndyLedgerService.test.ts file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes if there's no tests left that's fine 👍

Copy link
Contributor

@TimoGlastra TimoGlastra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@TimoGlastra TimoGlastra merged commit 85d62ec into openwallet-foundation:main Nov 11, 2022
Artemkaaas pushed a commit to sicpa-dlab/aries-framework-javascript that referenced this pull request Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants