Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Tests WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Jun 27, 2024
1 parent 49b46bb commit 3cea469
Show file tree
Hide file tree
Showing 11 changed files with 403 additions and 192 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ storybook-static
/.cargo/

/.direnv/
.hc*
48 changes: 24 additions & 24 deletions flake.lock

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

93 changes: 41 additions & 52 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description = "Template for Holochain app development";

inputs = {
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 @@ -15,65 +15,54 @@

profiles.url = "github:holochain-open-dev/profiles/nixify";
};

nixConfig = {
extra-substituters = [
"https://holochain-open-dev.cachix.org"
];
extra-trusted-public-keys = [
"holochain-open-dev.cachix.org-1:3Tr+9in6uo44Ga7qiuRIfOTFXog+2+YbyhwI/Z6Cp4U="
"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="
];
};


outputs = inputs:
inputs.flake-parts.lib.mkFlake
{
inherit inputs;
}
{
imports = [
./zomes/integrity/roles/zome.nix
./zomes/coordinator/roles/zome.nix
# Just for testing purposes
./workdir/dna.nix
./workdir/happ.nix
];

systems = builtins.attrNames inputs.holochain.devShells;
perSystem =
{ inputs'
, config
, pkgs
, system
, ...
}: {
devShells.default = pkgs.mkShell {
inputsFrom = [
inputs'.hc-infra.devShells.synchronized-pnpm
inputs'.holochain.devShells.holonix
];
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
./zomes/integrity/roles/zome.nix
./zomes/coordinator/roles/zome.nix
# Just for testing purposes
./workdir/dna.nix
./workdir/happ.nix
];

systems = builtins.attrNames inputs.holochain.devShells;
perSystem = { inputs', config, pkgs, system, ... }: {
devShells.default = pkgs.mkShell {
inputsFrom = [
inputs'.hc-infra.devShells.synchronized-pnpm
inputs'.holochain.devShells.holonix
];

packages = [
inputs'.scaffolding.packages.hc-scaffold-zome-template
];
};
packages = [ inputs'.scaffolding.packages.hc-scaffold-zome-template ];
};

packages.scaffold = pkgs.symlinkJoin {
name = "scaffold-remote-zome";
paths = [ inputs'.hc-infra.packages.scaffold-remote-zome ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/scaffold-remote-zome \
--add-flags "roles \
--integrity-zome-name roles_integrity \
--coordinator-zome-name roles \
--remote-zome-git-url github:holochain-open-dev/roles \
--remote-npm-package-name roles \
--remote-npm-package-path ui" \
--remote-zome-git-branch main \
'';
};
};
packages.scaffold = pkgs.symlinkJoin {
name = "scaffold-remote-zome";
paths = [ inputs'.hc-infra.packages.scaffold-remote-zome ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/scaffold-remote-zome \
--add-flags "roles \
--integrity-zome-name roles_integrity \
--coordinator-zome-name roles \
--remote-zome-git-url github:holochain-open-dev/roles \
--remote-npm-package-name roles \
--remote-npm-package-path ui" \
--remote-zome-git-branch main \
'';
};
};
};
}
10 changes: 9 additions & 1 deletion 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.0",
"@holochain-open-dev/utils": "^0.300.0",
"typescript": "^5.4.5",
Expand Down
98 changes: 98 additions & 0 deletions tests/src/assign-role-lifecycle.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { toPromise } from '@holochain-open-dev/signals';
import { EntryRecord, HashType, retype } from '@holochain-open-dev/utils';
import { cleanNodeDecoding } from '@holochain-open-dev/utils/dist/clean-node-decoding.js';
import {
ActionHash,
Delete,
Record,
SignedActionHashed,
} from '@holochain/client';
import { dhtSync, runScenario } from '@holochain/tryorama';
import { decode } from '@msgpack/msgpack';
import { assert, expect, test } from 'vitest';

import { sampleRoleClaim } from '../../ui/src/mocks.js';
import { RoleClaim } from '../../ui/src/types.js';
import { setup } from './setup.js';

test('Assign role lifecycle', async () => {
await runScenario(async scenario => {
const { alice, bob } = await setup(scenario);

console.log('heyyy');

let roles = await toPromise(alice.store.allRoles);
assert.equal(roles.length, 1);
assert.equal(roles[0], 'admin');

console.log('heyyy');
let admins = await toPromise(bob.store.assignees.get('admin'));
assert.equal(admins.length, 1);
assert.equal(cleanNodeDecoding(admins[0]), alice.player.agentPubKey);

console.log('heyyy');
// Bob can't assign a role to itself
await expect(() =>
bob.store.client.assignRole('editor', bob.player.agentPubKey),
).rejects.toThrowError();
await alice.store.client.assignRole('editor', bob.player.agentPubKey);
console.log('heyyy');

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

console.log('heyyy');
roles = await toPromise(bob.store.allRoles);
assert.equal(roles.length, 1);
assert.equal(roles[0], 'admin');

console.log('heyyy');
let editors = await toPromise(bob.store.assignees.get('editors'));
assert.equal(editors.length, 1);
assert.equal(
cleanNodeDecoding(editors[0]).toString(),
bob.player.agentPubKey.toString(),
);
console.log('heyyy');

// Bob can't request unassigment of a role to itself
await expect(() =>
bob.store.client.requestUnassignRole('editor', bob.player.agentPubKey),
).rejects.toThrowError();

console.log('heyyy');
await alice.store.client.requestUnassignRole(
'editor',
bob.player.agentPubKey,
);
console.log('heyyy');

// 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]);
console.log('heyyy');

const pendingUnassigments = await toPromise(bob.store.pendingUnassigments);
assert.equal(pendingUnassigments.length, 1);
assert.equal(
retype(pendingUnassigments[0].target, HashType.AGENT).toString(),
bob.player.agentPubKey.toString(),
);

console.log('heyyy');
// Alice can't unassign bob's role
await expect(() =>
alice.store.client.unassignMyRole(
pendingUnassigments[0].create_link_hash,
),
).rejects.toThrowError();
console.log('heyyy');
await bob.store.client.unassignMyRole(
pendingUnassigments[0].create_link_hash,
);
// 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]);
console.log('heyyy');
editors = await toPromise(bob.store.assignees.get('editors'));
assert.equal(editors.length, 0);
});
});
Loading

0 comments on commit 3cea469

Please sign in to comment.