index.js test file from micro blog tutorial
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
/// NB: The tryorama config patterns are still not quite stabilized. | |
/// See the tryorama README [https://github.com/holochain/tryorama] | |
/// for a potentially more accurate example | |
const path = require('path'); | |
const { | |
Orchestrator, | |
Config, | |
combine, | |
localOnly, | |
tapeExecutor, | |
} = require('@holochain/tryorama'); | |
process.on('unhandledRejection', error => { | |
// Will print "unhandledRejection err is not defined" | |
console.error('got unhandledRejection:', error); | |
}); | |
const dnaPath = path.join(__dirname, '../dist/txrx.dna.json'); | |
const orchestrator = new Orchestrator({ | |
middleware: combine( | |
// use the tape harness to run the tests, injects the tape API into each scenario | |
// as the second argument | |
tapeExecutor(require('tape')), | |
// specify that all "players" in the test are on the local machine, rather than | |
// on remote machines | |
localOnly, | |
), | |
}); | |
const dna = Config.dna(dnaPath, 'txrx'); | |
const config = Config.gen( | |
{ | |
txrx: dna, | |
}, | |
{ | |
network: { | |
type: 'sim2h', | |
sim2h_url: 'ws://localhost:9000', | |
}, | |
// logger: Config.logger({ type: "error" }), | |
}, | |
); | |
orchestrator.registerScenario('Test hello holo', async (s, t) => { | |
const {alice, bob} = await s.players({alice: config, bob: config}, true); | |
// Make a call to the `hello_holo` Zome function | |
// passing no arguments. | |
const result = await alice.call('txrx', 'txrx', 'hello_holo', {}); | |
// Make sure the result is ok. | |
t.ok(result.Ok, "HELLO HOLO WORKED"); | |
// Check that the result matches what you expected. | |
t.deepEqual(result, {Ok: 'Hello Holo'}); | |
const timestamp = Date.now(); | |
const create_result = await alice.call('txrx', 'txrx', 'create_post', { | |
message: 'Hello blog', | |
timestamp: timestamp, | |
}); | |
t.ok(create_result.Ok, "CREATE A POST WORKED"); | |
await s.consistency(); | |
const alice_address = alice.instance('txrx').agentAddress; | |
const retrieve_result = await alice.call( | |
'txrx', | |
'txrx', | |
'retrieve_posts', | |
{agent_address: alice_address}, | |
); | |
t.ok(retrieve_result.Ok, "RETRIEVED A POST WORKED"); | |
const alice_posts = retrieve_result.Ok; | |
var post = { | |
message: 'Hello blog', | |
timestamp: timestamp, | |
author_id: alice_address, | |
}; | |
t.deepEqual(alice_posts, [post]); | |
await s.consistency(); | |
const bob_retrieve_result = await bob.call( | |
'txrx', | |
'txrx', | |
'retrieve_posts', | |
{agent_address: alice_address}, | |
); | |
t.ok(bob_retrieve_result.Ok); | |
const alice_posts_bob = bob_retrieve_result.Ok; | |
t.deepEqual(alice_posts_bob, [post]); | |
}); | |
orchestrator.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment