Skip to content

Commit

Permalink
feat: oracle + jq (#6)
Browse files Browse the repository at this point in the history
* chore: tidy up

* feat: jq aggregation; also:
- rationalise test containers
- tidy integrity validation function

* chore: update e2e
  • Loading branch information
8e8b2c authored Jun 6, 2024
1 parent decc5a1 commit 218938e
Show file tree
Hide file tree
Showing 53 changed files with 2,482 additions and 699 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ jobs:
- run: npx puppeteer browsers install chrome
- run: npm run build:client
- run: npm run build:external-id-attestor
- run: npm run build:mock-oracle
- name: Save client build for possible publish
uses: actions/upload-artifact@v4
if: always()
Expand All @@ -156,6 +157,10 @@ jobs:
-t holoom/external-id-attestor \
-f docker/external-id-attestor/Dockerfile \
packages/external-id-attestor
docker build \
-t holoom/mock-oracle \
-f docker/mock-oracle/Dockerfile \
packages/mock-oracle
docker build -t holoom/rocket docker/rocket
- name: Start frontend in background
run: npm run dev -w @holoom/e2e &
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"cSpell.language": "en,en-GB",
"cSpell.words": [
"Dalek",
"Faceit",
Expand Down
110 changes: 110 additions & 0 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ hdi = "=0.3.6"
hdk = "=0.2.6"
holo_hash = { version = "=0.2.6", features = ["encoding"] }
serde = "=1.0.166"
serde_json = "1.0.109"
bincode = "1.3.3"
alloy-primitives = { version = "0.6.3", features = ["serde", "k256"] }
ed25519-dalek = { version = "2.1.1", features = ["serde"] }
Expand All @@ -31,6 +32,12 @@ rocket_okapi = { version = "0.8.0", features = ["swagger"] }
[workspace.dependencies.holoom_types]
path = "crates/holoom_types"

[workspace.dependencies.jaq_wrapper]
path = "crates/jaq_wrapper"

[workspace.dependencies.username_registry_utils]
path = "crates/username_registry_utils"

[workspace.dependencies.username_registry_validation]
path = "crates/username_registry_validation"

Expand Down
1 change: 1 addition & 0 deletions crates/holoom_dna_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ holochain = { workspace = true, default-features = false, features = [


[dev-dependencies]
username_registry_utils = { workspace = true }
username_registry_validation = { workspace = true }
tokio = "1.32.0"
holochain_keystore = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions crates/holoom_dna_tests/src/tests/username_registry/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod oracle;
mod user_metadata;
mod username_attestation;
mod wallet_attestation;
161 changes: 161 additions & 0 deletions crates/holoom_dna_tests/src/tests/username_registry/oracle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
use hdk::prelude::*;

use holochain::conductor::api::error::ConductorApiResult;
use holoom_types::{
JqExecution, OracleDocument, OracleDocumentListSnapshot,
RefreshJqExecutionForNamedRelationPayload, RelateOracleDocumentPayload, SnapshotInput,
};
use username_registry_utils::deserialize_record_entry;

use crate::TestSetup;

#[tokio::test(flavor = "multi_thread")]
async fn can_fetch_documents_by_relation() {
let setup = TestSetup::authority_only().await;

let foo1_record: Record = setup
.authority_call(
"username_registry",
"create_oracle_document",
OracleDocument {
name: "foo/1".into(),
json_data: "{\"type\":\"foo\",\"value\":1}".into(),
},
)
.await
.unwrap();

let foo2_record: Record = setup
.authority_call(
"username_registry",
"create_oracle_document",
OracleDocument {
name: "foo/2".into(),
json_data: "{\"type\":\"foo\",\"value\":2}".into(),
},
)
.await
.unwrap();

let res: ConductorApiResult<()> = setup
.authority_call(
"username_registry",
"relate_oracle_document",
RelateOracleDocumentPayload {
name: "foo/1".into(),
relation: "foo".into(),
},
)
.await;
assert!(res.is_ok());

let res: ConductorApiResult<()> = setup
.authority_call(
"username_registry",
"relate_oracle_document",
RelateOracleDocumentPayload {
name: "foo/2".into(),
relation: "foo".into(),
},
)
.await;
assert!(res.is_ok());

let identifiers: Vec<String> = setup
.authority_call(
"username_registry",
"get_related_oracle_document",
String::from("foo"),
)
.await
.unwrap();

let expected_identifiers = vec![String::from("foo/1"), String::from("foo/2")];
assert_eq!(identifiers, expected_identifiers);

let snapshot_record: Record = setup
.authority_call(
"username_registry",
"refresh_oracle_document_snapshot_for_relation",
String::from("foo"),
)
.await
.unwrap();

let snapshot: OracleDocumentListSnapshot = deserialize_record_entry(snapshot_record).unwrap();

assert_eq!(
snapshot.identifiers_input,
SnapshotInput::RelationSnapshot(expected_identifiers)
);
assert_eq!(
snapshot.resolved_documents,
vec![
foo1_record.action_address().clone(),
foo2_record.action_address().clone()
]
);

let jq_execution_record: Record = setup
.authority_call(
"username_registry",
"refresh_jq_execution_for_named_relation",
RefreshJqExecutionForNamedRelationPayload {
relation_name: "foo".into(),
program: "[.[].value]".into(),
},
)
.await
.unwrap();

let jq_execution: JqExecution = deserialize_record_entry(jq_execution_record).unwrap();
assert_eq!(jq_execution.output, String::from("[1,2]"));

let revised_foo2_record: Record = setup
.authority_call(
"username_registry",
"create_oracle_document",
OracleDocument {
name: "foo/2".into(),
json_data: "{\"type\":\"foo\",\"value\":\"two\"}".into(),
},
)
.await
.unwrap();

let revised_snapshot_record: Record = setup
.authority_call(
"username_registry",
"refresh_oracle_document_snapshot_for_relation",
String::from("foo"),
)
.await
.unwrap();

let revised_snapshot: OracleDocumentListSnapshot =
deserialize_record_entry(revised_snapshot_record).unwrap();

assert_eq!(
revised_snapshot.resolved_documents,
vec![
foo1_record.action_address().clone(),
revised_foo2_record.action_address().clone()
]
);

let revised_jq_execution_record: Record = setup
.authority_call(
"username_registry",
"refresh_jq_execution_for_named_relation",
RefreshJqExecutionForNamedRelationPayload {
relation_name: "foo".into(),
program: "[.[].value]".into(),
},
)
.await
.unwrap();

let revised_jq_execution: JqExecution =
deserialize_record_entry(revised_jq_execution_record).unwrap();
assert_eq!(revised_jq_execution.output, String::from("[1,\"two\"]"));
}
Loading

0 comments on commit 218938e

Please sign in to comment.