-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add support for postgres wallet type (#699)
Signed-off-by: Sai Ranjit Tummalapalli <[email protected]> Co-authored-by: Timo Glastra <[email protected]>
- Loading branch information
1 parent
4146778
commit 83ff0f3
Showing
10 changed files
with
392 additions
and
21 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import type { SubjectMessage } from '../../../tests/transport/SubjectInboundTransport' | ||
import type { IndyPostgresStorageConfig } from '../../node/src' | ||
import type { ConnectionRecord } from '../src/modules/connections' | ||
|
||
import { Subject } from 'rxjs' | ||
|
||
import { SubjectInboundTransport } from '../../../tests/transport/SubjectInboundTransport' | ||
import { SubjectOutboundTransport } from '../../../tests/transport/SubjectOutboundTransport' | ||
import { loadPostgresPlugin, WalletScheme } from '../../node/src' | ||
import { Agent } from '../src/agent/Agent' | ||
|
||
import { waitForBasicMessage, getBasePostgresConfig } from './helpers' | ||
|
||
const alicePostgresConfig = getBasePostgresConfig('AgentsAlice', { | ||
endpoints: ['rxjs:alice'], | ||
}) | ||
const bobPostgresConfig = getBasePostgresConfig('AgentsBob', { | ||
endpoints: ['rxjs:bob'], | ||
}) | ||
|
||
describe('postgres agents', () => { | ||
let aliceAgent: Agent | ||
let bobAgent: Agent | ||
let aliceConnection: ConnectionRecord | ||
let bobConnection: ConnectionRecord | ||
|
||
afterAll(async () => { | ||
await bobAgent.shutdown() | ||
await bobAgent.wallet.delete() | ||
await aliceAgent.shutdown() | ||
await aliceAgent.wallet.delete() | ||
}) | ||
|
||
test('make a connection between postgres agents', async () => { | ||
const aliceMessages = new Subject<SubjectMessage>() | ||
const bobMessages = new Subject<SubjectMessage>() | ||
|
||
const subjectMap = { | ||
'rxjs:alice': aliceMessages, | ||
'rxjs:bob': bobMessages, | ||
} | ||
|
||
const storageConfig: IndyPostgresStorageConfig = { | ||
type: 'postgres_storage', | ||
config: { | ||
url: 'localhost:5432', | ||
wallet_scheme: WalletScheme.DatabasePerWallet, | ||
}, | ||
credentials: { | ||
account: 'postgres', | ||
password: 'postgres', | ||
admin_account: 'postgres', | ||
admin_password: 'postgres', | ||
}, | ||
} | ||
|
||
// loading the postgres wallet plugin | ||
await loadPostgresPlugin(storageConfig.config, storageConfig.credentials) | ||
|
||
aliceAgent = new Agent(alicePostgresConfig.config, alicePostgresConfig.agentDependencies) | ||
aliceAgent.registerInboundTransport(new SubjectInboundTransport(aliceMessages)) | ||
aliceAgent.registerOutboundTransport(new SubjectOutboundTransport(subjectMap)) | ||
await aliceAgent.initialize() | ||
|
||
bobAgent = new Agent(bobPostgresConfig.config, bobPostgresConfig.agentDependencies) | ||
bobAgent.registerInboundTransport(new SubjectInboundTransport(bobMessages)) | ||
bobAgent.registerOutboundTransport(new SubjectOutboundTransport(subjectMap)) | ||
await bobAgent.initialize() | ||
|
||
const aliceConnectionAtAliceBob = await aliceAgent.connections.createConnection() | ||
const bobConnectionAtBobAlice = await bobAgent.connections.receiveInvitation(aliceConnectionAtAliceBob.invitation) | ||
|
||
aliceConnection = await aliceAgent.connections.returnWhenIsConnected(aliceConnectionAtAliceBob.connectionRecord.id) | ||
bobConnection = await bobAgent.connections.returnWhenIsConnected(bobConnectionAtBobAlice.id) | ||
|
||
expect(aliceConnection).toBeConnectedWith(bobConnection) | ||
expect(bobConnection).toBeConnectedWith(aliceConnection) | ||
}) | ||
|
||
test('send a message to connection', async () => { | ||
const message = 'hello, world' | ||
await aliceAgent.basicMessages.sendMessage(aliceConnection.id, message) | ||
|
||
const basicMessage = await waitForBasicMessage(bobAgent, { | ||
content: message, | ||
}) | ||
|
||
expect(basicMessage.content).toBe(message) | ||
}) | ||
|
||
test('can shutdown and re-initialize the same postgres agent', async () => { | ||
expect(aliceAgent.isInitialized).toBe(true) | ||
await aliceAgent.shutdown() | ||
expect(aliceAgent.isInitialized).toBe(false) | ||
await aliceAgent.initialize() | ||
expect(aliceAgent.isInitialized).toBe(true) | ||
}) | ||
}) |
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
Oops, something went wrong.