You’ll learn how to add an entry type to your zome.
An entry is a piece of data in your source chain that’s been validated.
We’ll also show you how to define and validate an entry type that represents a person, and to create and read this data through zome calls.
You will also set up tests and your GUI.

/// NB: The tryorama config patterns are still not quite stabilized./// See the tryorama README [https://github.com/holochain/tryorama]/// for a potentially more accurate exampleconstpath=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);});constdnaPath=path.join(__dirname,'../dist/cc_tuts.dna.json');constorchestrator=newOrchestrator({middleware:combine(// use the tape harness to run the tests, injects the tape API into each scenario// as the second argumenttapeExecutor(require('tape')),// specify that all "players" in the test are on the local machine, rather than// on remote machineslocalOnly,),});constdna=Config.dna(dnaPath,'cc_tuts');constconfig=Config.gen({cc_tuts:dna,},{network:{type:'sim2h',sim2h_url:'ws://localhost:9000',},},);orchestrator.registerScenario('Test hello holo',async(s,t)=>{const{alice,bob}=awaits.players({alice:config,bob:config},true);constresult=awaitalice.call('cc_tuts','hello','hello_holo',{});t.ok(result.Ok);t.deepEqual(result,{Ok:'Hello Holo'});constcreate_result=awaitalice.call('cc_tuts','hello','create_person',{person:{name:'Alice'},});t.ok(create_result.Ok);constalice_person_address=create_result.Ok;awaits.consistency();constretrieve_result=awaitalice.call('cc_tuts','hello','retrieve_person',{address:alice_person_address},);t.ok(retrieve_result.Ok);t.deepEqual(retrieve_result,{Ok:{name:'Alice'}});});orchestrator.run();

Obviously, right now, these tests will fail. Can you guess what the first failure will be? Let’s have a look.

Enter the nix-shell if you don’t already have it open:

nix-shell https://holochain.love

Run the test:

Run in nix-shell https://holochain.love

hc test

The test fails on the create_person function because it doesn’t exist yet:

Now, you can create actual person entries and store them on your source chain.

Note:
Validation is very important. It’s the “rules of the game” for your Holochain app. It is meaningful to emphasize that although we are returning Ok(()), we’re still validating that the data type checks as a Person with a name property containing a String. Essentially, this rule says that the person entry must be in this format.

You now need a way for your UI to actually create a person entry. Holochain has a concept called hc_public, which is a way of telling the runtime to make this function available to call from outside the zome.

Add the following lines below the previous person_entry_def function:

Add a public function that takes a Person and returns a result with an Address: