-
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.
- Loading branch information
1 parent
b82bcc7
commit e665129
Showing
9 changed files
with
237 additions
and
129 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
# Link Devices process | ||
|
||
```mermaid | ||
sequenceDiagram | ||
|
This file was deleted.
Oops, something went wrong.
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,58 @@ | ||
import { toPromise } from '@holochain-open-dev/signals'; | ||
import { EntryRecord } from '@holochain-open-dev/utils'; | ||
import { ActionHash, Record, encodeHashToBase64 } from '@holochain/client'; | ||
import { dhtSync, runScenario } from '@holochain/tryorama'; | ||
import { decode } from '@msgpack/msgpack'; | ||
import { assert, test } from 'vitest'; | ||
|
||
import { setup } from './setup.js'; | ||
|
||
test('link devices', async () => { | ||
await runScenario(async scenario => { | ||
const { alice, bob } = await setup(scenario); | ||
|
||
// Bob gets the links, should be empty | ||
let linksOutput = await toPromise( | ||
bob.store.linkedDevicesForAgent.get(bob.player.agentPubKey), | ||
); | ||
assert.equal(linksOutput.length, 0); | ||
|
||
const alicePasscode = [1, 3, 7, 2]; | ||
const bobPasscode = [9, 3, 8, 4]; | ||
|
||
await alice.store.client.prepareLinkDevices(alicePasscode); | ||
await bob.store.client.prepareLinkDevices(bobPasscode); | ||
|
||
await alice.store.client.initLinkDevices( | ||
bob.player.agentPubKey, | ||
bobPasscode, | ||
); | ||
await bob.store.client.requestLinkDevices( | ||
alice.player.agentPubKey, | ||
alicePasscode, | ||
); | ||
|
||
// Wait for the created entry to be propagated to the other node. | ||
await dhtSync([alice.player, bob.player], alice.player.cells[0].cell_id[0]); | ||
|
||
// Bob gets the links again | ||
linksOutput = await toPromise( | ||
bob.store.linkedDevicesForAgent.get(bob.player.agentPubKey), | ||
); | ||
assert.equal(linksOutput.length, 1); | ||
assert.deepEqual( | ||
encodeHashToBase64(alice.player.agentPubKey), | ||
encodeHashToBase64(linksOutput[0]), | ||
); | ||
|
||
// Alice gets the links again | ||
linksOutput = await toPromise( | ||
alice.store.linkedDevicesForAgent.get(alice.player.agentPubKey), | ||
); | ||
assert.equal(linksOutput.length, 1); | ||
assert.deepEqual( | ||
encodeHashToBase64(bob.player.agentPubKey), | ||
encodeHashToBase64(linksOutput[0]), | ||
); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,60 +1,83 @@ | ||
import { EntryRecord } from "@holochain-open-dev/utils"; | ||
import { EntryRecord } from '@holochain-open-dev/utils'; | ||
import { | ||
ActionHash, | ||
AgentPubKey, | ||
AppBundleSource, | ||
AppCallZomeRequest, | ||
AppWebsocket, | ||
encodeHashToBase64, | ||
EntryHash, | ||
fakeActionHash, | ||
fakeAgentPubKey, | ||
fakeDnaHash, | ||
fakeEntryHash, | ||
NewEntryAction, | ||
Record, | ||
} from "@holochain/client"; | ||
import { Scenario } from "@holochain/tryorama"; | ||
import { encode } from "@msgpack/msgpack"; | ||
import { dirname } from "path"; | ||
import { fileURLToPath } from "url"; | ||
import { LinkedDevicesClient } from "../../ui/src/linked-devices-client.js"; | ||
import { LinkedDevicesStore } from "../../ui/src/linked-devices-store.js"; | ||
ActionHash, | ||
AgentPubKey, | ||
AppBundleSource, | ||
AppCallZomeRequest, | ||
AppWebsocket, | ||
EntryHash, | ||
NewEntryAction, | ||
Record, | ||
encodeHashToBase64, | ||
fakeActionHash, | ||
fakeAgentPubKey, | ||
fakeDnaHash, | ||
fakeEntryHash, | ||
} from '@holochain/client'; | ||
import { Scenario } from '@holochain/tryorama'; | ||
import { encode } from '@msgpack/msgpack'; | ||
import { dirname } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
import { LinkedDevicesClient } from '../../ui/src/linked-devices-client.js'; | ||
import { LinkedDevicesStore } from '../../ui/src/linked-devices-store.js'; | ||
|
||
export async function setup(scenario: Scenario) { | ||
const testHappUrl = dirname(fileURLToPath(import.meta.url)) + "/../../workdir/linked-devices_test.happ"; | ||
|
||
// Add 2 players with the test hApp to the Scenario. The returned players | ||
// can be destructured. | ||
const [alice, bob] = await scenario.addPlayersWithApps([ | ||
{ appBundleSource: { path: testHappUrl } }, | ||
{ appBundleSource: { path: testHappUrl } }, | ||
]); | ||
|
||
// Shortcut peer discovery through gossip and register all agents in every | ||
// conductor of the scenario. | ||
await scenario.shareAllAgents(); | ||
|
||
const aliceStore = new LinkedDevicesStore( | ||
new LinkedDevicesClient(alice.appWs as any, "linked_devices_test", "linked_devices"), | ||
); | ||
|
||
const bobStore = new LinkedDevicesStore( | ||
new LinkedDevicesClient(bob.appWs as any, "linked_devices_test", "linked_devices"), | ||
); | ||
|
||
// Shortcut peer discovery through gossip and register all agents in every | ||
// conductor of the scenario. | ||
await scenario.shareAllAgents(); | ||
|
||
return { | ||
alice: { | ||
player: alice, | ||
store: aliceStore, | ||
}, | ||
bob: { | ||
player: bob, | ||
store: bobStore, | ||
}, | ||
}; | ||
const testHappUrl = | ||
dirname(fileURLToPath(import.meta.url)) + | ||
'/../../workdir/linked-devices_test.happ'; | ||
|
||
// Add 2 players with the test hApp to the Scenario. The returned players | ||
// can be destructured. | ||
const [alice, bob] = await scenario.addPlayersWithApps([ | ||
{ appBundleSource: { path: testHappUrl } }, | ||
{ appBundleSource: { path: testHappUrl } }, | ||
]); | ||
|
||
await alice.conductor | ||
.adminWs() | ||
.authorizeSigningCredentials(alice.cells[0].cell_id); | ||
|
||
await bob.conductor | ||
.adminWs() | ||
.authorizeSigningCredentials(bob.cells[0].cell_id); | ||
|
||
// Shortcut peer discovery through gossip and register all agents in every | ||
// conductor of the scenario. | ||
await scenario.shareAllAgents(); | ||
|
||
const aliceStore = new LinkedDevicesStore( | ||
new LinkedDevicesClient( | ||
alice.appWs as any, | ||
'linked_devices_test', | ||
'linked_devices', | ||
), | ||
); | ||
|
||
const bobStore = new LinkedDevicesStore( | ||
new LinkedDevicesClient( | ||
bob.appWs as any, | ||
'linked_devices_test', | ||
'linked_devices', | ||
), | ||
); | ||
|
||
// Shortcut peer discovery through gossip and register all agents in every | ||
// conductor of the scenario. | ||
await scenario.shareAllAgents(); | ||
|
||
// Prevent race condition when two zome calls are made instantly at the beginning of the lifecycle that cause a ChainHeadMoved error because they trigger 2 parallel init workflows | ||
await aliceStore.client.getLinkingAgents(); | ||
await bobStore.client.getLinkingAgents(); | ||
|
||
return { | ||
alice: { | ||
player: alice, | ||
store: aliceStore, | ||
}, | ||
bob: { | ||
player: bob, | ||
store: bobStore, | ||
}, | ||
}; | ||
} |
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
Oops, something went wrong.