Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Jul 5, 2024
1 parent d5fd6ca commit 12279c4
Show file tree
Hide file tree
Showing 26 changed files with 2,529 additions and 886 deletions.
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

inputs = {
notifications.url = "github:darksoil-studio/notifications/main";
versions.url = "github:holochain/holochain?dir=versions/0_3_rc";
versions.url = "github:holochain/holochain?dir=versions/0_3";

holochain.url = "github:holochain/holochain";
holochain.inputs.versions.follows = "versions";
Expand All @@ -18,9 +18,13 @@
};

nixConfig = {
extra-substituters = [ "https://holochain-open-dev.cachix.org" ];
extra-substituters = [
"https://holochain-open-dev.cachix.org"
"https://darksoil-studio.cachix.org"
];
extra-trusted-public-keys = [
"holochain-open-dev.cachix.org-1:3Tr+9in6uo44Ga7qiuRIfOTFXog+2+YbyhwI/Z6Cp4U="
"darksoil-studio.cachix.org-1:UEi+aujy44s41XL/pscLw37KEVpTEIn8N/kn7jO8rkc="
];
};

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"network": "hc s clean && pnpm build:happ && BOOTSTRAP_PORT=$(port) SIGNAL_PORT=$(port) UI_PORT=8888 concurrently -k \"pnpm -F @darksoil-studio/tasks start\" \"pnpm launch\" \"holochain-playground\" \"pnpm local-services\"",
"launch": "echo pass | RUST_LOG=warn hc launch --piped -n $AGENTS workdir/tasks_test.happ --ui-port $UI_PORT network --bootstrap http://127.0.0.1:$BOOTSTRAP_PORT webrtc ws://127.0.0.1:$SIGNAL_PORT",
"local-services": "hc run-local-services --bootstrap-port $BOOTSTRAP_PORT --signal-port $SIGNAL_PORT",
"test": "pnpm build:happ && nix flake check -L && pnpm -F tests test",
"build:happ": "nix build -L .#tasks_test_app -o workdir/tasks_test.happ"
"test": "pnpm build:happ && pnpm -F tests test",
"build:happ": "nix build -L .#tasks_test_happ -o workdir/tasks_test.happ"
},
"devDependencies": {
"@holochain-playground/cli": "^0.300.0-rc",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@msgpack/msgpack": "^2.8.0",
"@holochain/client": "^0.17.0",
"@holochain/tryorama": "^0.16.0-dev.7",
"@holochain/tryorama": "^0.16.0",
"@holochain-open-dev/signals": "^0.300.3",
"@holochain-open-dev/utils": "^0.300.0",
"typescript": "^5.4.5",
Expand Down
111 changes: 111 additions & 0 deletions tests/src/dependent-tasks.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { toPromise } from '@holochain-open-dev/signals';
import { EntryRecord } from '@holochain-open-dev/utils';
import { cleanNodeDecoding } from '@holochain-open-dev/utils/dist/clean-node-decoding.js';
import {
ActionHash,
Delete,
Record,
SignedActionHashed,
encodeHashToBase64,
} from '@holochain/client';
import { dhtSync, pause, runScenario } from '@holochain/tryorama';
import { decode } from '@msgpack/msgpack';
import { assert, expect, test } from 'vitest';

import { sampleTask } from '../../ui/src/mocks.js';
import { Task } from '../../ui/src/types.js';
import { waitUntil } from '../../ui/src/utils.js';
import { setup } from './setup.js';

test('create and update Task', async () => {
await runScenario(async scenario => {
const { alice, bob } = await setup(scenario);

// Alice creates a Task
const dependency: EntryRecord<Task> = await alice.store.client.createTask(
await sampleTask(alice.store.client),
);
assert.ok(dependency);
const originalDependencyActionHash = dependency.actionHash;

// Bob creates a dependent Task
const dependent: EntryRecord<Task> = await alice.store.client.createTask(
await sampleTask(alice.store.client, {
status: 'Blocked',
dependencies: [
{
original_revision_hash: dependency.actionHash,
last_revision_hash: dependency.actionHash,
optional: false,
status: 'Ready',
},
],
}),
);
const originalDependentActionHash = dependent.actionHash;
assert.ok(dependency);

const dependentTasks = await toPromise(
alice.store.tasks.get(dependency.actionHash).dependentTasks.live,
);
assert.equal(dependentTasks.length, 1);
assert.equal(
encodeHashToBase64(dependentTasks[0]),
encodeHashToBase64(dependent.actionHash),
);

// Task is not ready: it's blocked by its dependency
await expect(() =>
bob.store.client.updateTask(
originalDependentActionHash,
dependent.actionHash,
{
...dependent.entry,
original_create_hash: originalDependentActionHash,
status: 'Ready',
},
),
).rejects.toThrowError();

await alice.store.client.updateTask(
originalDependencyActionHash,
dependency.actionHash,
{
...dependency.entry,
original_create_hash: originalDependencyActionHash,
status: 'Done',
},
);

// 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]);

// await bob.store.client.updateTask(
// originalDependentActionHash,
// dependent.actionHash,
// {
// ...dependent.entry,
// dependencies: [
// {
// original_revision_hash: dependency.actionHash,
// last_revision_hash: updatedDependency.actionHash,
// optional: false,
// status: 'Done',
// },
// ],
// status: 'Ready',
// },
// );

// Task status should be automatically updated by the store
await waitUntil(
async () =>
(
await toPromise(
bob.store.tasks.get(dependent.actionHash).latestVersion,
)
).entry.status === 'Ready',
30_000,
);
});
});
114 changes: 61 additions & 53 deletions tests/src/setup.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,70 @@
import {
AgentPubKey,
EntryHash,
NewEntryAction,
ActionHash,
Record,
AppBundleSource,
fakeActionHash,
fakeAgentPubKey,
fakeEntryHash,
fakeDnaHash,
AppCallZomeRequest,
AppWebsocket,
encodeHashToBase64
import { EntryRecord } from '@holochain-open-dev/utils';
import {
ActionHash,
AgentPubKey,
AppBundleSource,
AppCallZomeRequest,
AppWebsocket,
EntryHash,
NewEntryAction,
Record,
encodeHashToBase64,
fakeActionHash,
fakeAgentPubKey,
fakeDnaHash,
fakeEntryHash,
} from '@holochain/client';
import { encode } from '@msgpack/msgpack';
import { Scenario } from '@holochain/tryorama';
import { EntryRecord } from '@holochain-open-dev/utils';
import { encode } from '@msgpack/msgpack';
import { dirname } from 'path';
import { fileURLToPath } from 'url';

import { TasksClient } from '../../ui/src/tasks-client.js';
import { TasksStore } from '../../ui/src/tasks-store.js';

export async function setup(scenario: Scenario) {
const testHappUrl =
dirname(fileURLToPath(import.meta.url)) + '/../../workdir/tasks_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 TasksStore(
new TasksClient(alice.appWs as any, 'tasks_test', 'tasks')
);

const bobStore = new TasksStore(
new TasksClient(bob.appWs as any, 'tasks_test', 'tasks')
);

// 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/tasks_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();

await alice.conductor
.adminWs()
.authorizeSigningCredentials(alice.cells[0].cell_id);

await bob.conductor
.adminWs()
.authorizeSigningCredentials(bob.cells[0].cell_id);

const aliceStore = new TasksStore(
new TasksClient(alice.appWs as any, 'tasks_test', 'tasks'),
);

const bobStore = new TasksStore(
new TasksClient(bob.appWs as any, 'tasks_test', 'tasks'),
);

// 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,
},
};
}
Loading

0 comments on commit 12279c4

Please sign in to comment.