-
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
8e26d63
commit b73c1a4
Showing
1 changed file
with
84 additions
and
0 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,84 @@ | ||
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, expect, test } from 'vitest'; | ||
|
||
import { setup } from './setup.js'; | ||
|
||
test('link devices can edit posts for the starting agent', async () => { | ||
await runScenario(async scenario => { | ||
const { alice, bob } = await setup(scenario); | ||
|
||
const postRecord: Record = await alice.player.appWs.callZome({ | ||
role_name: 'linked_devices_test', | ||
zome_name: 'example', | ||
fn_name: 'create_post', | ||
payload: { | ||
title: 'hello', | ||
content: 'world', | ||
}, | ||
}); | ||
|
||
await expect(() => | ||
bob.player.appWs.callZome({ | ||
role_name: 'linked_devices_test', | ||
zome_name: 'example', | ||
fn_name: 'delete_post', | ||
payload: postRecord.signed_action.hashed.hash, | ||
}), | ||
).rejects.toThrowError(); | ||
|
||
// 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]), | ||
); | ||
|
||
await bob.player.appWs.callZome({ | ||
role_name: 'linked_devices_test', | ||
zome_name: 'example', | ||
fn_name: 'delete_post', | ||
payload: postRecord.signed_action.hashed.hash, | ||
}); | ||
}); | ||
}); |