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

feat: add isInitialized agent property #293

Merged
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
7 changes: 7 additions & 0 deletions src/agent/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class Agent {
protected messageReceiver: MessageReceiver
protected messageSender: MessageSender
public inboundTransporter?: InboundTransporter
private _isInitialized = false

public readonly connections!: ConnectionsModule
public readonly proofs!: ProofsModule
Expand Down Expand Up @@ -114,6 +115,10 @@ export class Agent {
return this.eventEmitter
}

public get isInitialized() {
return this._isInitialized
}

public async init() {
await this.wallet.init()

Expand All @@ -126,6 +131,8 @@ export class Agent {
if (this.inboundTransporter) {
await this.inboundTransporter.start(this)
}

this._isInitialized = true
}

public get publicDid() {
Expand Down
14 changes: 13 additions & 1 deletion src/agent/__tests__/Agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,21 @@ import { Dispatcher } from '../Dispatcher'
import { EnvelopeService } from '../EnvelopeService'
import { getBaseConfig } from '../../__tests__/helpers'

const config = getBaseConfig('DI Test')
const config = getBaseConfig('Agent Class Test')

describe('Agent', () => {
describe('Initialization', () => {
it('isInitialized should only return true after initialization', async () => {
expect.assertions(2)

const agent = new Agent(config)

expect(agent.isInitialized).toBe(false)
await agent.init()
expect(agent.isInitialized).toBe(true)
})
})

describe('Dependency Injection', () => {
it('should be able to resolve registered instances', () => {
const agent = new Agent(config)
Expand Down