-
Notifications
You must be signed in to change notification settings - Fork 2
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
7f8d12b
commit 8c4bab7
Showing
26 changed files
with
294 additions
and
349 deletions.
There are no files selected for viewing
46 changes: 16 additions & 30 deletions
46
...role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case collection_name}}.test.ts.hbs
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,50 +1,36 @@ | ||
import { assert, test } from "vitest"; | ||
|
||
import { runScenario, pause, CallableCell } from '@holochain/tryorama'; | ||
import { runScenario, dhtSync } from '@holochain/tryorama'; | ||
import { NewEntryAction, ActionHash, Record, AppBundleSource, fakeActionHash, fakeAgentPubKey, fakeEntryHash } from '@holochain/client'; | ||
import { EntryRecord } from '@holochain-open-dev/utils'; | ||
import { decode } from '@msgpack/msgpack'; | ||
import { EntryRecord } from '@holochain-open-dev/utils'; | ||
import { toPromise } from '@holochain-open-dev/stores'; | ||
|
||
import { create{{pascal_case referenceable.name}} } from './common.js'; | ||
import { {{pascal_case referenceable.name}} } from '../../../../ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/types.js'; | ||
import { setup, sample{{pascal_case referenceable.name}} } from './common.js'; | ||
|
||
test('create a {{pascal_case referenceable.name}} and get {{lower_case collection_name}}', async () => { | ||
await runScenario(async scenario => { | ||
// Construct proper paths for your app. | ||
// This assumes app bundle created by the `hc app pack` command. | ||
const testAppPath = process.cwd() + '/../workdir/{{app_name}}.happ'; | ||
|
||
// Set up the app to be installed | ||
const appSource = { appBundleSource: { path: testAppPath } }; | ||
|
||
// Add 2 players with the test app to the Scenario. The returned players | ||
// can be destructured. | ||
const [alice, bob] = await scenario.addPlayersWithApps([appSource, appSource]); | ||
|
||
// Shortcut peer discovery through gossip and register all agents in every | ||
// conductor of the scenario. | ||
await scenario.shareAllAgents(); | ||
const { alice, bob } = await setup(scenario); | ||
|
||
// Bob gets {{lower_case collection_name}} | ||
let collectionOutput: Record[] = await bob.cells[0].callZome({ | ||
zome_name: "{{coordinator_zome_manifest.name}}", | ||
fn_name: "get_{{snake_case collection_name}}", | ||
payload: {{#if (eq collection_type.type "Global")}}null{{else}}alice.agentPubKey{{/if}} | ||
}); | ||
let collectionOutput: ActionHash[] = await toPromise(bob.store.{{camel_case collection_name}}); | ||
assert.equal(collectionOutput.length, 0); | ||
|
||
// Alice creates a {{pascal_case referenceable.name}} | ||
const createdRecord: Record = await create{{pascal_case referenceable.name}}(alice.cells[0]); | ||
assert.ok(createdRecord); | ||
const {{camel_case referenceable.name}}: EntryRecord<{{pascal_case referenceable.name}}> = await bob.store.create{{pascal_case referenceable.name}}(sample{{pascal_case referenceable.name}}()); | ||
assert.ok({{camel_case referenceable.name}}); | ||
|
||
await pause(1200); | ||
await dhtSync( | ||
[alice.player, bob.player], | ||
alice.player.cells[0].cell_id[0] | ||
); | ||
|
||
// Bob gets {{lower_case collection_name}} again | ||
collectionOutput = await bob.cells[0].callZome({ | ||
zome_name: "{{coordinator_zome_manifest.name}}", | ||
fn_name: "get_{{snake_case collection_name}}", | ||
payload: {{#if (eq collection_type.type "Global")}}null{{else}}alice.agentPubKey{{/if}} | ||
}); | ||
collectionOutput = await toPromise(bob.store.{{camel_case collection_name}}); | ||
assert.equal(collectionOutput.length, 1); | ||
assert.deepEqual(createdRecord, collectionOutput[0]); | ||
assert.deepEqual({{camel_case_case}}.actionHash, collectionOutput[0]); | ||
}); | ||
}); | ||
|
60 changes: 58 additions & 2 deletions
60
...tes/app/coordinator-zome/tests/src/{{dna_role_name}}/{{zome_manifest.name}}/common.ts.hbs
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,3 +1,59 @@ | ||
import { CallableCell } from '@holochain/tryorama'; | ||
import { NewEntryAction, ActionHash, Record, AppBundleSource, fakeActionHash, fakeAgentPubKey, fakeEntryHash, fakeDnaHash } from '@holochain/client'; | ||
import { | ||
NewEntryAction, | ||
encodeHashToBase64, | ||
ActionHash, | ||
Record, | ||
AppBundleSource, | ||
fakeActionHash, | ||
fakeAgentPubKey, | ||
fakeEntryHash, | ||
fakeDnaHash, | ||
AppAgentCallZomeRequest, | ||
AppAgentWebsocket | ||
} from '@holochain/client'; | ||
import { encode } from '@msgpack/msgpack'; | ||
import { Scenario, dhtSync } from '@holochain/tryorama'; | ||
import { dirname } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import { {{pascal_case app_name}}Client } from '../../ui/src/{{kebab_case zome_manifest.name}}-client.js'; | ||
import { {{pascal_case app_name}}Store } from '../../ui/src/{{kebab_case zome_manifest.name}}-store.js'; | ||
|
||
export async function setup(scenario: Scenario) { | ||
const testHappUrl = | ||
dirname(fileURLToPath(import.meta.url)) + '/../../../../workdir/{{app_name}}.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 {{pascal_case zome_manifest.name}}Store( | ||
new {{pascal_case zome_manifest.name}}Client(alice.appAgentWs as any, '{{dna_role_name}}', '{{snake_case zome_manifest.name}}') | ||
); | ||
|
||
const bobStore = new {{pascal_case zome_manifest.name}}Store( | ||
new {{pascal_case zome_manifest.name}}Client(bob.appAgentWs as any, '{{dna_role_name}}', '{{snake_case zome_manifest.name}}') | ||
); | ||
|
||
// 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, | ||
}, | ||
}; | ||
} | ||
|
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.