forked from openwallet-foundation/credo-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(indy-vdr): module registration (openwallet-foundation#1285)
Signed-off-by: Karim Stekelenburg <[email protected]>
- Loading branch information
1 parent
95e5b93
commit b05fa52
Showing
11 changed files
with
149 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { IndyVdrModuleConfigOptions } from './IndyVdrModuleConfig' | ||
import type { DependencyManager, Module } from '@aries-framework/core' | ||
|
||
import { IndyVdrModuleConfig } from './IndyVdrModuleConfig' | ||
import { IndyVdrPoolService } from './pool/IndyVdrPoolService' | ||
|
||
/** | ||
* @public | ||
* */ | ||
export class IndyVdrModule implements Module { | ||
public readonly config: IndyVdrModuleConfig | ||
|
||
public constructor(config: IndyVdrModuleConfigOptions) { | ||
this.config = new IndyVdrModuleConfig(config) | ||
} | ||
|
||
public register(dependencyManager: DependencyManager) { | ||
// Config | ||
dependencyManager.registerInstance(IndyVdrModuleConfig, this.config) | ||
|
||
// Services | ||
dependencyManager.registerSingleton(IndyVdrPoolService) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { IndyVdrPoolConfig } from './pool' | ||
|
||
export interface IndyVdrModuleConfigOptions { | ||
/** | ||
* Array of indy networks to connect to. | ||
* | ||
* [@default](https://github.com/default) [] | ||
* | ||
* @example | ||
* ``` | ||
* { | ||
* isProduction: false, | ||
* genesisTransactions: 'xxx', | ||
* indyNamespace: 'localhost:test', | ||
* transactionAuthorAgreement: { | ||
* version: '1', | ||
* acceptanceMechanism: 'accept' | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
networks: [IndyVdrPoolConfig, ...IndyVdrPoolConfig[]] | ||
} | ||
|
||
export class IndyVdrModuleConfig { | ||
private options: IndyVdrModuleConfigOptions | ||
|
||
public constructor(options: IndyVdrModuleConfigOptions) { | ||
this.options = options | ||
} | ||
|
||
/** See {@link IndyVdrModuleConfigOptions.networks} */ | ||
public get networks() { | ||
return this.options.networks | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { DependencyManager } from '@aries-framework/core' | ||
|
||
import { IndyVdrModule } from '../IndyVdrModule' | ||
import { IndyVdrModuleConfig } from '../IndyVdrModuleConfig' | ||
import { IndyVdrPoolService } from '../pool' | ||
|
||
const dependencyManager = { | ||
registerInstance: jest.fn(), | ||
registerSingleton: jest.fn(), | ||
} as unknown as DependencyManager | ||
|
||
describe('IndyVdrModule', () => { | ||
test('registers dependencies on the dependency manager', () => { | ||
const indyVdrModule = new IndyVdrModule({ | ||
networks: [ | ||
{ | ||
isProduction: false, | ||
genesisTransactions: 'xxx', | ||
indyNamespace: 'localhost:test', | ||
transactionAuthorAgreement: { | ||
version: '1', | ||
acceptanceMechanism: 'accept', | ||
}, | ||
}, | ||
], | ||
}) | ||
|
||
indyVdrModule.register(dependencyManager) | ||
|
||
expect(dependencyManager.registerSingleton).toHaveBeenCalledTimes(1) | ||
expect(dependencyManager.registerSingleton).toHaveBeenCalledWith(IndyVdrPoolService) | ||
|
||
expect(dependencyManager.registerInstance).toHaveBeenCalledTimes(1) | ||
expect(dependencyManager.registerInstance).toHaveBeenCalledWith(IndyVdrModuleConfig, indyVdrModule.config) | ||
}) | ||
}) |
15 changes: 15 additions & 0 deletions
15
packages/indy-vdr/src/__tests__/IndyVdrModuleConfig.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { IndyVdrPoolConfig } from '../pool' | ||
|
||
import { IndyVdrModuleConfig } from '../IndyVdrModuleConfig' | ||
|
||
describe('IndyVdrModuleConfig', () => { | ||
test('sets values', () => { | ||
const networkConfig = {} as IndyVdrPoolConfig | ||
|
||
const config = new IndyVdrModuleConfig({ | ||
networks: [networkConfig], | ||
}) | ||
|
||
expect(config.networks).toEqual([networkConfig]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters