Skip to content

A peer-to-peer stack for code collaboration

e2e tests with daemon

Thomas Scholtes997692b77777
diff --git a/cloudbuild.yaml b/cloudbuild.yaml
index e4ad6e7..303c2f1 100644
--- a/cloudbuild.yaml
+++ b/cloudbuild.yaml
@@ -170,8 +170,12 @@ steps:
- "-c"
- |
set -euxo pipefail
+
export RAD_IPFS_API_URL=http://ipfs-test-network:5001
export RADPATH="$(pwd)/rad"
+
+ stack exec -- radicle-daemon &
+
stack test :e2e
stack exec -- radicle test/machine-backends.rad radicle-server
diff --git a/examples/radicle-counter b/examples/radicle-counter
index 053d4b0..6c7f6e9 100755
--- a/examples/radicle-counter
+++ b/examples/radicle-counter
@@ -3,42 +3,42 @@
usage() {
cat <<USAGEDOC
USAGE
- $0 <chain> <cmd>
+ $0 <machine> <cmd>
-Initialize and interact with a simple counter chain.
+Initialize and interact with a simple counter machine.
- <chain> init
- Initializes the chain with a prelude that defines the counter semantics.
+ <machine> init
+ Initializes the machine with a prelude that defines the counter semantics.
- <chain> get-value
+ <machine> get-value
Prints the current value of the counter.
- <chain> increment
+ <machine> increment
Increments the value of the counter by one and prints it.
EXAMPLE
- > $0 my-chain-id init
- > $0 my-chain-id get-value
+ > $0 my-machine-id init
+ > $0 my-machine-id get-value
0
- > $0 my-chain-id increment
+ > $0 my-machine-id increment
1
- > $0 my-chain-id get-value
+ > $0 my-machine-id get-value
1
USAGEDOC
exit 1
}
-chain=
+machine=
cmd=
while [[ $# -gt 0 ]]; do
case "$1" in
-h | --help ) usage;;
* )
- if [[ -z "$chain" ]]; then
- chain=$1
+ if [[ -z "$machine" ]]; then
+ machine=$1
elif [[ -z "$cmd" ]]; then
cmd=$1
else
@@ -49,8 +49,8 @@ while [[ $# -gt 0 ]]; do
shift
done
-if [[ -z "$chain" ]]; then
- echo "Argument <chain> is missing"
+if [[ -z "$machine" ]]; then
+ echo "Argument <machine> is missing"
exit 1
elif [[ -z "$cmd" ]]; then
echo "Argument <cmd> is missing"
@@ -61,19 +61,19 @@ case "$cmd" in
init )
radicle - <<-SCRIPT
(load! "rad/examples/counter.rad")
- (counter/init-chain! "${chain}")
+ (counter/init-machine! "${machine}")
SCRIPT
;;
get-value )
radicle - <<-SCRIPT
(load! "rad/examples/counter.rad")
- (counter/get-value "${chain}")
+ (counter/get-value "${machine}")
SCRIPT
;;
increment )
radicle - <<-SCRIPT
(load! "rad/examples/counter.rad")
- (counter/increment! "${chain}")
+ (counter/increment! "${machine}")
SCRIPT
;;
* )
diff --git a/rad/examples/counter.rad b/rad/examples/counter.rad
index 7cf0f3c..760d823 100644
--- a/rad/examples/counter.rad
+++ b/rad/examples/counter.rad
@@ -1,12 +1,12 @@
-;; A "counter" chain that exposes an `increment` mutator and a `get-value`
+;; A "counter" machine that exposes an `increment` mutator and a `get-value`
;; accessor.
;;
-;; This file provides functions to interact with a counter chain.
+;; This file provides functions to interact with a counter machine
;;
-;; (counter/init-chain! "my-chain-id") ;; => :ok
-;; (counter/get-value "my-chain-id") ;; => 0
-;; (counter/increment! "my-chain-id") ;; => 1
-;; (counter/get-value "my-chain-id") ;; => 1
+;; (counter/init-machine! "my-machine-id") ;; => :ok
+;; (counter/get-value "my-machine-id") ;; => 0
+;; (counter/increment! "my-machine-id") ;; => 1
+;; (counter/get-value "my-machine-id") ;; => 1
;;
(load! (find-module-file! "prelude.rad"))
@@ -28,26 +28,21 @@
]
)
-(def counter/init-chain!
- "Send the counter application prelude to a chain."
- (fn [chain-id]
- (chain/send! chain-id counter/prelude)
+(def counter/init-machine!
+ "Send the counter application prelude to a machine"
+ (fn [machine-id]
+ (daemon/send! machine-id counter/prelude)
:done
))
(def counter/increment!
- "Increment the counter of a chain and return the new counter value."
- (fn [chain-id]
- (def chain (chain/load-chain! chain-id))
- (def expr '(increment))
- (def result (lookup :result (chain/eval-in-chain expr chain)))
- (chain/send! chain-id [expr])
- result
-))
+ "Increment the counter of amachineand return the new counter value"
+ (fn [machine-id]
+ (first (daemon/send! machine-id '[(increment)]))
+ ))
(def counter/get-value
- "Get the current counter value of a chain."
- (fn [chain-id]
- (def chain (chain/load-chain! chain-id))
- (lookup :result (chain/eval-in-chain '(get-value) chain))
-))
+ "Get the current counter value of a machine"
+ (fn [machine-id]
+ (daemon/query! machine-id '(get-value))
+ ))
diff --git a/test/docker-compose.yaml b/test/docker-compose.yaml
index 9c88538..2c84979 100644
--- a/test/docker-compose.yaml
+++ b/test/docker-compose.yaml
@@ -24,6 +24,8 @@ services:
image: eu.gcr.io/opensourcecoin/ipfs-test-network
ports:
- "19301:5001"
+ command:
+ - --enable-pubsub-experiment
volumes:
diff --git a/test/e2e/CounterAppTest.hs b/test/e2e/CounterAppTest.hs
index 7160e8a..81d6369 100644
--- a/test/e2e/CounterAppTest.hs
+++ b/test/e2e/CounterAppTest.hs
@@ -20,19 +20,18 @@ test_counter_app = testCaseSteps "counter app" $ \step -> do
machineId <- runTestCommand "rad-machines" ["create"]
step "Initialize machine"
- let machineUrl = "ipfs://" <> machineId
- void $ runTestCommand "examples/radicle-counter" [machineUrl, "init"]
+ void $ runTestCommand "examples/radicle-counter" [machineId, "init"]
- initialValue <- runTestCommand "examples/radicle-counter" [machineUrl, "get-value"]
+ initialValue <- runTestCommand "examples/radicle-counter" [machineId, "get-value"]
assertEqual "(get-value) on counter chain" "0" initialValue
forM_ [(1::Int)..3] $ \i -> do
step $ "Increment to " <> show i
- valueInc <- runTestCommand "examples/radicle-counter" [machineUrl, "increment"]
+ valueInc <- runTestCommand "examples/radicle-counter" [machineId, "increment"]
assertEqual "(increment) on counter chain" (show i) valueInc
- valueGet <- runTestCommand "examples/radicle-counter" [machineUrl, "get-value"]
+ valueGet <- runTestCommand "examples/radicle-counter" [machineId, "get-value"]
assertEqual "(get-value) on counter chain" (show i) valueGet
-- | Run a command with the given arguments and return stdout.