Skip to content

Commit

Permalink
Receipts as invocations
Browse files Browse the repository at this point in the history
  • Loading branch information
expede committed Mar 26, 2024
1 parent bc0a275 commit 96b0fe1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 31 deletions.
11 changes: 5 additions & 6 deletions src/ability/ucan/assert.rs
@@ -1,19 +1,18 @@
use crate::ability::command::Command;
use crate::task::Task;
use libipld_core::{cid::Cid, ipld::Ipld};
use libipld_core::cid::Cid;

// Things that you can assert include content and receipts

#[derive(Debug, PartialEq)]
pub struct Ran<T, E> {
ran: Cid,
out: Box<Result<T, E>>,
fx: Vec<Task>, // FIXME may be more than "just" a task
next: Vec<Task>, // FIXME may be more than "just" a task
}

impl<T, E> Command for Ran<T, E> {
const COMMAND: &'static str = "/ucan/assert/ran";
// const COMMAND: &'static str = "/ucan/ran";????
const COMMAND: &'static str = "/ucan/ran";
}

///////////////
Expand All @@ -23,8 +22,8 @@ impl<T, E> Command for Ran<T, E> {
#[derive(Debug, PartialEq)]
pub struct Claim<T> {
claim: T,
} // Where Ipld: From<T>
}

impl<T> Command for Claim<T> {
const COMMAND: &'static str = "/ucan/assert/claim";
const COMMAND: &'static str = "/ucan/claim";
}
2 changes: 1 addition & 1 deletion src/delegation/policy/selector/filter.rs
Expand Up @@ -297,7 +297,7 @@ mod tests {
use super::*;

proptest! {
#[test]
#[test_log::test]
fn test_filter_round_trip(filter: Filter) {
let serialized = filter.to_string();
let deserialized = serialized.parse();
Expand Down
61 changes: 37 additions & 24 deletions src/delegation/policy/selector/select.rs
@@ -1,7 +1,6 @@
use super::Selector; // FIXME cycle?
use super::Selector;
use super::{error::SelectorErrorReason, filter::Filter, Selectable, SelectorError};
use libipld_core::ipld::Ipld;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::fmt;
use std::str::FromStr;
Expand Down Expand Up @@ -200,27 +199,35 @@ mod tests {
use proptest::prelude::*;
use testresult::TestResult;

fn simple() -> Ipld {
libipld::ipld!({
"foo": 42,
"bar": "baz",
"qux": true
})
}

fn email() -> Ipld {
libipld::ipld!({
"from": "alice@example.com",
"to": ["bob@example.com", "fraud@example.com"],
"cc": ["carol@example.com"],
"subject": "Quarterly Reports",
"body": "Here's Q2 the reports ..."
})
}

fn nested_data() -> Ipld {
libipld::ipld!({
"name": "Alice",
"age": 42,
"friends": ["Bob", "Charlie"]
})
}

mod get {
use super::*;

fn nested_data() -> Ipld {
Ipld::Map(
vec![
("name".to_string(), Ipld::String("Alice".to_string())),
("age".to_string(), Ipld::Integer(42)),
(
"friends".to_string(),
Ipld::List(vec![
Ipld::String("Bob".to_string()),
Ipld::String("Charlie".to_string()),
]),
),
]
.into_iter()
.collect(),
)
}

proptest! {
#[test_log::test]
fn test_identity(data: ipld::Newtype) {
Expand Down Expand Up @@ -248,13 +255,19 @@ mod tests {
let selector: Select<Ipld> = Select::new(filters);

let cleaned_data = match data.0.clone() {
Ipld::Map(mut m) => {
m.remove("foo").map_or(Ipld::Null, |v| v)
}
ipld => ipld
Ipld::Map(mut m) => m.remove("foo").map_or(Ipld::Null, |v| v),
ipld => ipld,
};
prop_assert_eq!(selector.get(&cleaned_data)?, Ipld::Null);
}
}

#[test_log::test]
fn test_eq_dot_field_ending_try_null() -> TestResult {
let s = Select::from_str(".from.not?")?;

pretty::assert_eq!(s.get(&email()), Ok(Ipld::Null));
Ok(())
}
}
}

0 comments on commit 96b0fe1

Please sign in to comment.