Browse Source

zencode wip

Denis Roio 1 year ago
commit
73fa4c96d2
3 changed files with 90 additions and 0 deletions
  1. 19
    0
      BOOK01.zen
  2. 18
    0
      BOOK02.zen
  3. 53
    0
      run_booking.sh

+ 19
- 0
BOOK01.zen View File

@@ -0,0 +1,19 @@
1
+# Process: Check -> Booking -> Order -> Confirmation -> Settlement
2
+
3
+Scenario 'prosume'
4
+Scenario 'simple'
5
+Rule check version 1.0.0
6
+
7
+Given I am 'Alice'
8
+and I have my valid 'keypair'
9
+and I have a valid 'asset'
10
+and I have a 'quantity' inside 'asset'
11
+
12
+When I set 'offer' to '100' as 'number'
13
+and number 'quantity' is more than 'offer'
14
+and I verify 'type' is equal to 'kWh'
15
+and I set 'price' to '10' as 'number'
16
+and I create the booking for '100'
17
+and I create the signature of 'booking'
18
+
19
+Then print my 'booking'

+ 18
- 0
BOOK02.zen View File

@@ -0,0 +1,18 @@
1
+Scenario 'prosume'
2
+Scenario 'simple'
3
+rule check version 1.0.0
4
+
5
+Given I am 'Bob'
6
+and I have a valid 'public key' from 'Alice'
7
+and I have a valid 'booking'
8
+and I have a valid 'asset'
9
+
10
+When I verify the 'booking' is signed by 'Alice'
11
+and I set 'offer' to '100' as 'number'
12
+and number 'quantity' is more than 'offer'
13
+and I verify 'kind' is equal to 'kWh'
14
+and I set 'price' to '10' as 'number'
15
+and I create the order for '100'
16
+and I create the signature of 'order'
17
+
18
+Then print my 'order'

+ 53
- 0
run_booking.sh View File

@@ -0,0 +1,53 @@
1
+#!/usr/bin/env zsh
2
+
3
+set -e
4
+set -u
5
+set -o pipefail
6
+# set -x
7
+# https://coderwall.com/p/fkfaqq/safer-bash-scripts-with-set-euxo-pipefail
8
+
9
+alias zenroom="${1:-../../src/zenroom}"
10
+echo "============================================"
11
+echo "TEST PROSUME SCENARIO FOR ASSET MARKET"
12
+echo "============================================"
13
+
14
+# Process:    Check -> Booking -> Order -> Confirmation -> Settlement
15
+
16
+t=`mktemp -d`
17
+
18
+# Generate Alice's keypair
19
+cat <<EOF | zenroom -z | tee $t/alice_kp.json
20
+Scenario 'simple'
21
+Given that I am known as 'Alice'
22
+When I create the keypair
23
+Then print my data
24
+EOF
25
+
26
+# Publish Alice's public key
27
+cat <<EOF | zenroom -z -k $t/alice_kp.json | tee $t/alice_pub.json
28
+Scenario 'simple'
29
+Given that I am known as 'Alice'
30
+and I have my valid 'public key'
31
+Then print my data
32
+EOF
33
+
34
+cat <<EOF | tee $t/asset.json | json_pp
35
+{ "asset":
36
+   { "ID": "qPtMxufw84bkahCA",
37
+     "time": "2020-2-6 05:12",
38
+	 "kind": "kWh",
39
+	 "quantity": 1000,
40
+	 "service_level": "renewable" } }
41
+EOF
42
+
43
+zenroom -z BOOK01.zen -a $t/asset.json -k $t/alice_kp.json | tee $t/booking.json
44
+
45
+cat <<EOF | zenroom -z -a $t/asset.json -k $t/booking.json | tee $t/asset-booking.json
46
+Scenario 'prosume'
47
+Scenario 'simple'
48
+Given I have a valid 'asset'
49
+and I have a valid 'booking'
50
+Then print all data
51
+EOF
52
+
53
+zenroom -z BOOK02.zen -a $t/asset-booking.json -k $t/alice_pub.json