Skip to content

Commit

Permalink
Add boilerplate holo app
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Line committed Jul 13, 2019
1 parent d990ce8 commit 15cc949
Show file tree
Hide file tree
Showing 11 changed files with 288 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
node_modules/
target/
.hc
3 changes: 3 additions & 0 deletions .hcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
test
README.md
94 changes: 94 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.

# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
#
# the holochain-vagrant box is generated by running:
# nix-shell --run hc-test
# from inside the /vagrant dir, which prewarms nix, rust and npm
config.vm.box = "holochain-vagrant"
config.vm.box_url = "https://holochain.love/box"
# uncomment this to use the raw nixos base box instead of the holochain box
# config.vm.box = "nixos/nixos-18.03-x86_64"

# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
# config.vm.network "forwarded_port", guest: 80, host: 8080

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"

# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"

# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"

# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
vb.gui = false
# Customize the amount of memory on the VM:
vb.memory = "4096"
vb.cpus = "4"
vb.customize ["modifyvm", :id, "--hwvirtex", "off"]
end

# View the documentation for the provider you are using for more
# information on available options.

# requires the vagrant-nixos-plugin to work
# `vagrant plugin install vagrant-nixos-plugin`
# add some simple dev tools
# add some swap space to allow for more RAM on small devices
config.vm.provision :nixos,
run: 'always',
expression: {
swapDevices: [ { device: "/swapfile", size: 16384 } ],
environment: {
systemPackages: [
# htop is handy for diagnosing runaway memory and cpu usage
:htop,

# sometimes windows can mess with line endings
# dos2unix can fix that inside the box
# mostly a debugging tool, ultimately the correct line endings need to
# be committed
:dos2unix,
:vim
]
}
}

end
14 changes: 14 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Holochain App Name",
"description": "A Holochain app",
"authors": [
{
"identifier": "Author Name <[email protected]>",
"public_key_source": "",
"signature": ""
}
],
"version": "0.1.0",
"dht": {},
"properties": null
}
19 changes: 19 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
let
holonix-release-tag = "further-bad-assigning";
holonix-release-sha256 = "1mhrp677p45ihajnjanav7cjvfhb2qn4g262vr06wy1zkj20mm0g";

holonix = import (fetchTarball {
url = "https://github.com/holochain/holonix/archive/${holonix-release-tag}.tar.gz";
sha256 = "${holonix-release-sha256}";
});
in
with holonix.pkgs;
{
core-shell = stdenv.mkDerivation (holonix.shell // {
name = "dev-shell";

buildInputs = []
++ holonix.shell.buildInputs
;
});
}
35 changes: 35 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const path = require('path')
const tape = require('tape')

const { Diorama, tapeExecutor, backwardCompatibilityMiddleware } = require('@holochain/diorama')

process.on('unhandledRejection', error => {
// Will print "unhandledRejection err is not defined"
console.error('got unhandledRejection:', error);
});

const dnaPath = path.join(__dirname, "../dist/holo-barcelona-hackathon.dna.json")
const dna = Diorama.dna(dnaPath, 'holo-barcelona-hackathon')

const diorama = new Diorama({
instances: {
alice: dna,
bob: dna,
},
bridges: [],
debugLog: false,
executor: tapeExecutor(require('tape')),
middleware: backwardCompatibilityMiddleware,
})

diorama.registerScenario("description of example test", async (s, t, { alice }) => {
// Make a call to a Zome function
// indicating the function, and passing it an input
const addr = await alice.call("my_zome", "create_my_entry", {"entry" : {"content":"sample content"}})
const result = await alice.call("my_zome", "get_my_entry", {"address": addr.Ok})

// check for equality of the actual and expected results
t.deepEqual(result, { Ok: { App: [ 'my_entry', '{"content":"sample content"}' ] } })
})

diorama.run()
10 changes: 10 additions & 0 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"devDependencies": {},
"dependencies": {
"@holochain/diorama": "^0.1.2",
"faucet": "0.0.1",
"json3": "*",
"sleep": "^5.2.3",
"tape": "^4.9.1"
}
}
11 changes: 11 additions & 0 deletions zomes/main/code/.hcbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"steps": {
"cargo": [
"build",
"--release",
"--target=wasm32-unknown-unknown",
"--target-dir=target"
]
},
"artifact": "target/wasm32-unknown-unknown/release/main.wasm"
}
18 changes: 18 additions & 0 deletions zomes/main/code/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "main"
version = "0.1.0"
authors = ["Igor Line <[email protected]>"]
edition = "2018"

[dependencies]
serde = "=1.0.89"
serde_json = { version = "=1.0.39", features = ["preserve_order"] }
serde_derive = "=1.0.89"
hdk = { git = "https://github.com/holochain/holochain-rust", tag = "v0.0.21-alpha1" }
hdk-proc-macros = { git = "https://github.com/holochain/holochain-rust", tag = "v0.0.21-alpha1" }
holochain_wasm_utils = { git = "https://github.com/holochain/holochain-rust", tag = "v0.0.21-alpha1" }
holochain_json_derive = { version = "0.0.1-alpha2" }

[lib]
path = "src/lib.rs"
crate-type = ["cdylib"]
77 changes: 77 additions & 0 deletions zomes/main/code/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#![feature(try_from, proc_macro_hygiene)]
#[macro_use]
extern crate hdk;
extern crate hdk_proc_macros;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
#[macro_use]
extern crate holochain_json_derive;

use hdk::{
entry_definition::ValidatingEntryType,
error::ZomeApiResult,
};
use hdk::holochain_core_types::{
entry::Entry,
dna::entry_types::Sharing,
};

use hdk::holochain_json_api::{
json::JsonString,
error::JsonError
};

use hdk::holochain_persistence_api::{
cas::content::Address
};

use hdk_proc_macros::zome;

// see https://developer.holochain.org/api/0.0.18-alpha1/hdk/ for info on using the hdk library

// This is a sample zome that defines an entry type "MyEntry" that can be committed to the
// agent's chain via the exposed function create_my_entry

#[derive(Serialize, Deserialize, Debug, DefaultJson,Clone)]
pub struct MyEntry {
content: String,
}

#[zome]
mod my_zome {

#[genesis]
fn genesis() {
Ok(())
}

#[entry_def]
fn my_entry_def() -> ValidatingEntryType {
entry!(
name: "my_entry",
description: "this is a same entry defintion",
sharing: Sharing::Public,
validation_package: || {
hdk::ValidationPackageDefinition::Entry
},
validation: | _validation_data: hdk::EntryValidationData<MyEntry>| {
Ok(())
}
)
}

#[zome_fn("hc_public")]
fn create_my_entry(entry: MyEntry) -> ZomeApiResult<Address> {
let entry = Entry::App("my_entry".into(), entry.into());
let address = hdk::commit_entry(&entry)?;
Ok(address)
}

#[zome_fn("hc_public")]
fn get_my_entry(address: Address) -> ZomeApiResult<Option<Entry>> {
hdk::get_entry(&address)
}

}
3 changes: 3 additions & 0 deletions zomes/main/zome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"description": "The main App"
}

0 comments on commit 15cc949

Please sign in to comment.