Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

GetEntryOptions #932

Merged
merged 35 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
547ba44
Remove redundant ValidationData::sources
maackle Jan 28, 2019
0fb7201
Couple source with signature (MISI)
maackle Jan 28, 2019
aa28546
Add unimplemented headers field
maackle Jan 28, 2019
ea1c9a1
Make include ChainHeader with Hold
maackle Jan 29, 2019
ceeafed
Got all tests to compile
maackle Jan 29, 2019
dc53658
Merge remote-tracking branch 'origin/develop' into get-entry-options
maackle Jan 30, 2019
5496150
app_spec test for multiple headers on entry
maackle Jan 30, 2019
1f43c94
Return ChainHeaders -- but doesn't quite work
maackle Jan 30, 2019
c7374fe
Proper storage and retrieval of headers
maackle Jan 30, 2019
eaf0cad
Cleanup and test
maackle Jan 30, 2019
0d34f57
Merge remote-tracking branch 'origin/develop' into get-entry-options
maackle Jan 30, 2019
19c830f
Merge branch 'develop' into get-entry-options
maackle Jan 31, 2019
5ca249b
Better test
maackle Jan 31, 2019
bccb0eb
Merge branch 'get-entry-options' of github.com:holochain/holochain-ru…
maackle Jan 31, 2019
445f336
Fix wasm tests
maackle Jan 31, 2019
9dea47e
Add failing test
maackle Jan 31, 2019
f068968
This doesn't work
maackle Jan 31, 2019
53e4dd2
...but this does!
maackle Jan 31, 2019
9463dd5
Merge branch 'develop' into get-entry-options
maackle Jan 31, 2019
b9d4e9b
Fix integration tests
maackle Jan 31, 2019
5bf4ab7
Fix duplicate problem
maackle Jan 31, 2019
86057db
Fix doc
maackle Jan 31, 2019
f490177
Merge branch 'develop' into get-entry-options
Feb 1, 2019
f18bee4
Merge branch 'develop' into get-entry-options
Feb 2, 2019
e395b2e
Update CHANGELOG.md
thedavidmeister Feb 3, 2019
38fedaa
Update CHANGELOG.md
thedavidmeister Feb 3, 2019
7fbfac2
Merge remote-tracking branch 'origin/develop' into get-entry-options
maackle Feb 3, 2019
cce241c
Update CHANGELOG.md
thedavidmeister Feb 3, 2019
f7d3d32
Allow for multiple local headers for entry
maackle Feb 3, 2019
cb1ac68
Merge branch 'get-entry-options' of github.com:holochain/holochain-ru…
maackle Feb 3, 2019
12b685c
Remove type alias of doom
maackle Feb 3, 2019
fa07a51
Merge branch 'develop' into get-entry-options
maackle Feb 4, 2019
43949f1
chain is not really a chain. rename -> chain_store
maackle Feb 4, 2019
1a23190
Merge remote-tracking branch 'origin/develop' into get-entry-options
maackle Feb 5, 2019
3c103fb
Fix old-style block_on calls
maackle Feb 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Changed
- core now depends on `pretty_assertions` crate
- `ChainHeader::sources()` is now `ChainHeader::provenances()`
- Headers from other agents are stored in the EAV
- `hdk::get_entry_results` supports return of ChainHeaders for all agents who have committed the same entry
- `cmd` crate (which implements the `hc` command line tool) renamed to `cli`
- Encoded values in ribosome function's input/output are u64 (up from u32)
- Capabilities now separated from function declarations in `define_zome!` and calling zome functions no longer uses capability name parameter [#791](https://github.com/holochain/holochain-rust/pull/779)
Expand Down
22 changes: 22 additions & 0 deletions app_spec/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ const dnaPath = path.join(__dirname, "../dist/app_spec.hcpkg")
const dna = Config.dna(dnaPath, 'app-spec')
const agentAlice = Config.agent("alice")
const agentBob = Config.agent("bob")
const agentCarol = Config.agent("carol")

const instanceAlice = Config.instance(agentAlice, dna)
const instanceBob = Config.instance(agentBob, dna)
const instanceCarol = Config.instance(agentCarol, dna)

const scenario1 = new Scenario([instanceAlice])
const scenario2 = new Scenario([instanceAlice, instanceBob])
const scenario3 = new Scenario([instanceAlice, instanceBob, instanceCarol])

scenario2.runTape('agentId', async (t, { alice, bob }) => {
t.ok(alice.agentId)
Expand All @@ -27,6 +30,25 @@ scenario1.runTape('show_env', async (t, { alice }) => {
t.equal(result.Ok.agent_id, '{"nick":"alice","key":"'+alice.agentId+'"}')
})

scenario3.runTape('get sources', async (t, { alice, bob, carol }) => {
const params = {content: 'whatever', in_reply_to: null}
const address = await alice.callSync('blog', 'create_post', params).then(x => x.Ok)
const address1 = await alice.callSync('blog', 'create_post', params).then(x => x.Ok)
const address2 = await bob.callSync('blog', 'create_post', params).then(x => x.Ok)
const address3 = await carol.callSync('blog', 'create_post', params).then(x => x.Ok)
t.equal(address, address1)
t.equal(address, address2)
t.equal(address, address3)
const sources1 = alice.call('blog', 'get_sources', {address}).Ok.sort()
const sources2 = bob.call('blog', 'get_sources', {address}).Ok.sort()
const sources3 = carol.call('blog', 'get_sources', {address}).Ok.sort()
// NB: alice shows up twice because she published the same entry twice
const expected = [alice.agentId, alice.agentId, bob.agentId, carol.agentId].sort()
t.deepEqual(sources1, expected)
t.deepEqual(sources2, expected)
t.deepEqual(sources3, expected)
})

scenario1.runTape('call', async (t, { alice }) => {

const num1 = 2
Expand Down
54 changes: 29 additions & 25 deletions app_spec/zomes/blog/code/src/blog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ use hdk::{
cas::content::Address, entry::Entry, error::HolochainError, json::JsonString,
},
holochain_wasm_utils::api_serialization::{
get_entry::GetEntryOptions,
get_entry::{GetEntryOptions, GetEntryResultType},
get_links::{GetLinksOptions, GetLinksResult},
},
AGENT_ADDRESS,
AGENT_ID_STR,
DNA_NAME,
DNA_ADDRESS,
AGENT_ADDRESS, AGENT_ID_STR, DNA_ADDRESS, DNA_NAME,
};
use post::Post;

Expand All @@ -33,14 +30,36 @@ pub struct Env {
/// inside a zome. In this case it just creates an object with their values
/// and returns it as the result.
pub fn handle_show_env() -> ZomeApiResult<Env> {
Ok(Env{
let _dna_entry = hdk::get_entry(&DNA_ADDRESS)?;
let _agent_entry = hdk::get_entry(&AGENT_ADDRESS)?;
Ok(Env {
dna_name: DNA_NAME.to_string(),
dna_address: DNA_ADDRESS.to_string(),
agent_id: AGENT_ID_STR.to_string(),
agent_address: AGENT_ADDRESS.to_string(),
})
}

pub fn handle_get_sources(address: Address) -> ZomeApiResult<Vec<Address>> {
if let GetEntryResultType::Single(result) = hdk::get_entry_result(
&address,
GetEntryOptions {
headers: true,
..Default::default()
},
)?
.result
{
Ok(result
.headers
.into_iter()
.map(|header| header.provenances().first().unwrap().clone().0)
.collect())
} else {
unimplemented!()
}
}

fn check_sum_args(num1: u32, num2: u32) -> SumInput {
SumInput {
num1: num1,
Expand Down Expand Up @@ -130,23 +149,13 @@ pub fn handle_my_recommended_posts() -> ZomeApiResult<GetLinksResult> {
#[cfg(test)]
pub mod tests {

use blog::check_sum_args;
use blog::SumInput;
use blog::{check_sum_args, post_entry, SumInput};
use hdk::holochain_core_types::entry::{entry_type::AppEntryType, AppEntryValue, Entry};
use post::Post;
use blog::post_entry;
use hdk::holochain_core_types::entry::Entry;
use hdk::holochain_core_types::entry::AppEntryValue;
use hdk::holochain_core_types::entry::entry_type::AppEntryType;

#[test]
fn check_sum_args_test() {
assert_eq!(
check_sum_args(1, 1),
SumInput{
num1: 1,
num2: 1,
},
);
assert_eq!(check_sum_args(1, 1), SumInput { num1: 1, num2: 1 },);
}

#[test]
Expand All @@ -155,12 +164,7 @@ pub mod tests {
post_entry("foos & bars".into()),
Entry::App(
AppEntryType::from("post"),
AppEntryValue::from(
Post::new(
"foos & bars".into(),
"now".into(),
)
),
AppEntryValue::from(Post::new("foos & bars".into(), "now".into(),)),
),
)
}
Expand Down
12 changes: 10 additions & 2 deletions app_spec/zomes/blog/code/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ pub mod post;

use hdk::{
error::ZomeApiResult,
holochain_core_types::{cas::content::Address, entry::Entry, json::JsonString, error::HolochainError},
holochain_core_types::{
cas::content::Address, entry::Entry, error::HolochainError, json::JsonString,
},
holochain_wasm_utils::api_serialization::get_links::GetLinksResult,
};

Expand All @@ -38,6 +40,12 @@ define_zome! {
handler: blog::handle_show_env
}

get_sources: {
inputs: |address: Address|,
outputs: |sources: ZomeApiResult<Vec<Address>>|,
handler: blog::handle_get_sources
}

check_sum: {
inputs: |num1: u32, num2: u32|,
outputs: |sum: ZomeApiResult<JsonString>|,
Expand Down Expand Up @@ -100,7 +108,7 @@ define_zome! {
]

capabilities: {
public (Public) [show_env, check_sum, post_address, create_post, posts_by_agent, get_post, my_posts, my_posts_as_committed, my_posts_immediate_timeout, recommend_post, my_recommended_posts]
public (Public) [show_env, check_sum, get_sources, post_address, create_post, posts_by_agent, get_post, my_posts, my_posts_as_committed, my_posts_immediate_timeout, recommend_post, my_recommended_posts]
}

}
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ boolinator = "2.4.0"
jsonrpc-ws-server = { git = "https://github.com/paritytech/jsonrpc" }
jsonrpc-lite = "0.5.0"
globset = "0.4.2"

pretty_assertions = "0.5.1"

[dev-dependencies]
wabt = "0.7.2"
Expand Down
6 changes: 4 additions & 2 deletions core/src/action.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::{
agent::state::AgentState,
context::Context,
network::{direct_message::DirectMessage, state::NetworkState},
network::{
direct_message::DirectMessage, entry_with_header::EntryWithHeader, state::NetworkState,
},
nucleus::{
state::{NucleusState, ValidationResult},
ExecuteZomeFnResponse, ZomeFnCall,
Expand Down Expand Up @@ -92,7 +94,7 @@ pub enum Action {
// -------------
/// Adds an entry to the local DHT shard.
/// Does not validate, assumes entry is valid.
Hold(Entry),
Hold(EntryWithHeader),

/// Adds a link to the local DHT shard's meta/EAV storage
/// Does not validate, assumes link is valid.
Expand Down
36 changes: 12 additions & 24 deletions core/src/agent/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,12 @@ pub mod tests {
use holochain_cas_implementations::cas::file::FilesystemStorage;
use holochain_core_types::{
cas::content::AddressableContent,
chain_header::{test_chain_header, test_sources, ChainHeader},
chain_header::{test_chain_header, test_provenances, ChainHeader},
entry::{
entry_type::{test_entry_type_b, AppEntryType},
test_entry, test_entry_b, test_entry_c, Entry,
},
json::JsonString,
signature::{test_signature_b, test_signature_c, test_signatures, Signature},
time::test_iso_8601,
};

Expand All @@ -331,8 +330,7 @@ pub mod tests {
let chain_header_b = ChainHeader::new(
&entry.entry_type(),
&entry.address(),
&test_sources(),
&vec![test_signature_b()],
&test_provenances("sig"),
&Some(chain_header_a.address()),
&None,
&None,
Expand Down Expand Up @@ -373,8 +371,7 @@ pub mod tests {
let chain_header_b = ChainHeader::new(
&entry_b.entry_type(),
&entry_b.address(),
&test_sources(),
&test_signatures(),
&test_provenances("sig"),
&Some(chain_header_a.address()),
&None,
&None,
Expand All @@ -385,8 +382,7 @@ pub mod tests {
let chain_header_c = ChainHeader::new(
&entry_c.entry_type(),
&entry_c.address(),
&test_sources(),
&test_signatures(),
&test_provenances("sig"),
&Some(chain_header_b.address()),
&Some(chain_header_a.address()),
&None,
Expand Down Expand Up @@ -448,8 +444,7 @@ pub mod tests {
let chain_header_b = ChainHeader::new(
&entry.entry_type(),
&entry.address(),
&test_sources(),
&vec![test_signature_b()],
&test_provenances("sig-b"),
&Some(chain_header_a.address()), // .link (to previous entry)
&None, // .link_same_type (to previous entry of same type)
&None,
Expand All @@ -459,8 +454,7 @@ pub mod tests {
let chain_header_c = ChainHeader::new(
&entry.entry_type(),
&entry.address(),
&test_sources(),
&vec![test_signature_c()],
&test_provenances("sig-c"),
&Some(chain_header_b.address()),
&Some(chain_header_b.address()),
&None,
Expand All @@ -473,8 +467,7 @@ pub mod tests {
let chain_header_d = ChainHeader::new(
&entry.entry_type(),
&entry.address(),
&test_sources(),
&vec![Signature::from("sig-d")],
&test_provenances("sig-d"),
&Some(chain_header_c.address()),
&None,
&None,
Expand All @@ -487,8 +480,7 @@ pub mod tests {
let chain_header_e = ChainHeader::new(
&entry.entry_type(),
&entry.address(),
&test_sources(),
&vec![Signature::from("sig-e")],
&test_provenances("sig-e"),
&Some(chain_header_d.address()),
&None,
&None,
Expand Down Expand Up @@ -623,8 +615,7 @@ pub mod tests {
let chain_header_f = ChainHeader::new(
&entry.entry_type(),
&entry.address(),
&test_sources(),
&vec![Signature::from("sig-f")],
&test_provenances("sig"),
&Some(chain_header_e.address()),
&None,
&None,
Expand All @@ -634,8 +625,7 @@ pub mod tests {
let chain_header_g = ChainHeader::new(
&entry.entry_type(),
&entry.address(),
&test_sources(),
&vec![Signature::from("sig-g")],
&test_provenances("sig"),
&Some(chain_header_f.address()),
&None,
&None,
Expand All @@ -645,8 +635,7 @@ pub mod tests {
let chain_header_h = ChainHeader::new(
&entry.entry_type(),
&entry.address(),
&test_sources(),
&vec![Signature::from("sig-g")],
&test_provenances("sig"),
&Some(chain_header_g.address()),
&None,
&None,
Expand Down Expand Up @@ -710,8 +699,7 @@ pub mod tests {
let chain_header_i = ChainHeader::new(
&entry.entry_type(),
&entry.address(),
&test_sources(),
&vec![Signature::from("sig-i")],
&test_provenances("sig"),
&Some(chain_header_h.address()),
&None,
&None,
Expand Down
2 changes: 1 addition & 1 deletion core/src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use holochain_core_types::{
use std::sync::Arc;

pub fn find_chain_header(entry: &Entry, context: &Arc<Context>) -> Option<ChainHeader> {
let chain = context.state().unwrap().agent().chain();
let chain = context.state().unwrap().agent().chain_store();
let top_header = context.state().unwrap().agent().top_chain_header();
chain
.iter(&top_header)
Expand Down
Loading