Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test delegation store #12

Merged
merged 4 commits into from Mar 26, 2024
Merged

Test delegation store #12

merged 4 commits into from Mar 26, 2024

Conversation

expede
Copy link
Member

@expede expede commented Mar 22, 2024

Wrote some tests for the (now fixed?) delegation store. It still has some commented-out work for the predicate language, but that is queued up for after we get the basics working for the server.

Changes

  • Fix logic in get_chain
  • Add some delegation store tests
  • Add a store.insert(delegation) method as a convenience to not need to take the CID manually
  • Test the underlying jq-style Selector logic that was causing issues at the higher levels
  • Break up delegation::store into delegation::store::memory and ::traits, just like the other stores

src/delegation/agent.rs Outdated Show resolved Hide resolved
@expede expede marked this pull request as ready for review March 26, 2024 02:01
Comment on lines +27 to +31
> where
Ipld: Encode<C>,
Payload<DID>: TryFrom<Named<Ipld>>,
Named<Ipld>: From<Payload<DID>>,
{
Copy link
Member Author

@expede expede Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change in the above file using to_ipld_envelope was way more subtle than it should have been. basically previously the payload types individually implemented libipld::Encode<C>, but that was (evidently) confusing. It took longer than I'd like to admit to find the bug it caused.

@@ -46,9 +46,9 @@ impl<T> Select<T> {

impl<T: Selectable> Select<T> {
pub fn get(self, ctx: &Ipld) -> Result<T, SelectorError> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Try behaviour in this method could probably be more elegant, but I really don't want to have to write more custom Try (AKA .?) parsing 😅

@@ -160,7 +160,7 @@ impl<
where
Named<Ipld>: From<delegation::Payload<DID>>,
delegation::Payload<DID>: TryFrom<Named<Ipld>>,
Delegation<DID, V, Enc>: Encode<Enc>,
Ipld: Encode<Enc>,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted in an Issue comment above

@@ -173,7 +173,7 @@ where
// FIXME
}

fn insert(
fn insert_keyed(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lets us automagically calculate the CID on insert, but let the trait implementer work with the lower level interface rather than forcing them to figure out the CID stuff themselves.

for delegate_pred in delegation.payload.policy.iter() {
let comparison =
target_pred.harmonize(delegate_pred, vec![], vec![]);
// FIXME
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sitting in a commented-out FIXME until we write the predicate subsumption logic (which I'll switch back to after fixing a couple other things that I'm unblocking)

}

#[test_log::test]
fn test_looking_for_narrower_command() -> TestResult {
Copy link
Member Author

@expede expede Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a copy of the original integration test, but without the Agent bits. i.e. testing a smaller surface.


pub trait Store<T, DID: Did, V: varsig::Header<C>, C: Codec + Into<u64> + TryFrom<u64>> {
Copy link
Member Author

@expede expede Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just made the modules layout the same as all of the other stores. This probably should be in its own PR, but it was driving me up the wall while working 😅

Comment on lines +18 to +20
Ipld: Encode<C>,
Payload<DID>: TryFrom<Named<Ipld>>,
Named<Ipld>: From<Payload<DID>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This combination of constraints comes up repeatedly a bit.
Perhaps worth keeping in the back of our minds whether we should turn this into a trait that combines all these constraints? Personally I'd also appreciate getting away from From and TryFrom for parsing. IMO they can make code & compiler errors less readable.
Not in this PR though! Let's just keep it in mind.

@matheus23 matheus23 merged commit 13510c5 into v1.0-rc.1 Mar 26, 2024
11 of 20 checks passed
@matheus23 matheus23 deleted the test-deleg-store branch March 26, 2024 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants