This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1932 from holochain/fallback-build-validation-pac…
…kages-dht-with-smart-validation Add ability to validate entries with full chain validation when author is offline
- Loading branch information
Showing
20 changed files
with
624 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
const { one } = require('../config') | ||
|
||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) | ||
|
||
module.exports = scenario => { | ||
|
||
scenario('Can retrieve header entries using get_entry', async (s, t) => { | ||
const { alice, bob } = await s.players({ alice: one, bob: one }) | ||
await alice.spawn() | ||
await bob.spawn() | ||
|
||
await s.consistency() | ||
|
||
// alice publishes a memo. This is private but should still publish a header | ||
const create_result = await alice.call('app', "blog", "create_memo", { content: "private memo" }) | ||
t.comment(JSON.stringify(create_result)) | ||
t.equal(create_result.Ok.length, 46) | ||
await s.consistency() | ||
|
||
// get all the chain header hashes and check if they are retrievable | ||
const maybe_chain_header_hashes = await alice.call('app', "blog", "get_chain_header_hashes", {}) | ||
t.ok(maybe_chain_header_hashes.Ok) | ||
let chain_header_hashes = maybe_chain_header_hashes.Ok | ||
t.equal(chain_header_hashes.length, 4) // dna, agentId, cap grant, memo | ||
|
||
t.comment(JSON.stringify(chain_header_hashes)) | ||
let chain_headers = [] | ||
|
||
await s.consistency() | ||
|
||
for (let i=0; i< chain_header_hashes.length; i++) { | ||
// can use get_post because it just returns a raw entry given a hash | ||
let header_hash = chain_header_hashes[i] | ||
t.comment(header_hash) | ||
|
||
// check bob can retrieve alices header entries | ||
let header_bob = await bob.call('app', "blog", "get_post", { post_address: header_hash }) | ||
t.ok(header_bob.Ok) | ||
|
||
chain_headers.push(header_bob.Ok) | ||
} | ||
t.comment(JSON.stringify(chain_headers)) | ||
}) | ||
|
||
scenario('Can perform validation of an entry while the author is offline', async (s, t) => { | ||
|
||
const { alice, bob, carol } = await s.players({alice: one, bob: one, carol: one}) | ||
// alice and bob start online | ||
await alice.spawn() | ||
await s.consistency() | ||
await bob.spawn() | ||
await s.consistency() | ||
|
||
// alice publishes the original entry. !This is an entry that requires full chain validation! | ||
const initialContent = "Holo world y'all" | ||
const params = { content: initialContent, in_reply_to: null } | ||
const create_result = await alice.call('app', "blog", "create_post", params) | ||
t.comment(JSON.stringify(create_result)) | ||
t.equal(create_result.Ok.length, 46) | ||
await s.consistency() | ||
|
||
t.comment('waiting for consistency between Alice and Bob') | ||
// bob will receive the entry and hold it | ||
await s.consistency() | ||
t.comment('consistency has been reached') | ||
|
||
// check bob got the content Ok | ||
const bob_result = await bob.call('app', "blog", "get_post", { post_address: create_result.Ok }) | ||
t.ok(bob_result.Ok) | ||
t.equal(JSON.parse(bob_result.Ok.App[1]).content, initialContent) | ||
|
||
// alice then goes offline | ||
t.comment('waiting for alice to go offline') | ||
await alice.kill() | ||
t.comment('alice has gone offline') | ||
|
||
// carol then comes online, will receive the entry via gossip from bob and need to validate | ||
// Since alice is offline the validation package cannot come direct and must | ||
// be regenerated from the published headers (which bob should hold) | ||
t.comment('waiting for Carol to come online') | ||
await carol.spawn() | ||
t.comment('Carol is online') | ||
|
||
t.comment('Waiting for Carol to get all data via gossip') | ||
await s.consistency() | ||
t.comment('consistency has been reached') | ||
|
||
await delay(50000) // keep this until consistency works with dynamic starting agents | ||
|
||
// Bob now go offline to ensure the following get_post uses carols local store only | ||
t.comment('waiting for Bob to go offline') | ||
await bob.kill() | ||
t.comment('Bob has gone offline') | ||
|
||
t.comment('Waiting for Carol to get post') | ||
const carol_result = await carol.call('app', "blog", "get_post", { post_address: create_result.Ok }) | ||
t.ok(carol_result.Ok, 'Carol get_post does not have truth Ok field') | ||
t.equal(JSON.parse(carol_result.Ok.App[1]).content, initialContent) | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.