1
+ #! /usr/bin/env bash
2
+
3
+ set -eu
4
+
5
+ TEST_TMP=" $( rm -rf " $0 .tmpdir" && mkdir -p " $0 .tmpdir" && (cd " $0 .tmpdir" && pwd)) "
6
+ TEST_LOGS=" $( mkdir -p " $0 .logs" && (cd " $0 .logs" && pwd)) "
7
+ FABLO_HOME=" $TEST_TMP /../../.."
8
+
9
+ export FABLO_HOME
10
+
11
+ CONFIG=" $FABLO_HOME /samples/fablo-config-hlf3-bft-1orgs-1chaincode.json"
12
+
13
+ networkUp () {
14
+ " $FABLO_HOME /fablo-build.sh"
15
+ (cd " $TEST_TMP " && " $FABLO_HOME /fablo.sh" generate " $CONFIG " )
16
+ (cd " $TEST_TMP " && " $FABLO_HOME /fablo.sh" up)
17
+ }
18
+
19
+ dumpLogs () {
20
+ echo " Saving logs of $1 to $TEST_LOGS /$1 .log"
21
+ mkdir -p " $TEST_LOGS "
22
+ docker logs " $1 " > " $TEST_LOGS /$1 .log" 2>&1
23
+ }
24
+
25
+ networkDown () {
26
+ rm -rf " $TEST_LOGS "
27
+ (for name in $( docker ps --format ' {{.Names}}' ) ; do dumpLogs " $name " ; done)
28
+ dumpLogs orderer0.group1.orderer.example.com
29
+ (cd " $TEST_TMP " && " $FABLO_HOME /fablo.sh" down)
30
+ }
31
+
32
+ waitForContainer () {
33
+ sh " $TEST_TMP /../wait-for-container.sh" " $1 " " $2 "
34
+ }
35
+
36
+ waitForChaincode () {
37
+ (cd " $TEST_TMP " && sh ../wait-for-chaincode.sh " $1 " " $2 " " $3 " " $4 " )
38
+ }
39
+
40
+ expectInvoke () {
41
+ (cd " $TEST_TMP " && sh ../expect-invoke-cli.sh " $1 " " $2 " " $3 " " $4 " " $5 " " " )
42
+ }
43
+
44
+ expectCommand () {
45
+ sh " $TEST_TMP /../expect-command.sh" " $1 " " $2 "
46
+ }
47
+
48
+ trap networkDown EXIT
49
+ trap ' networkDown ; echo "Test failed" ; exit 1' ERR SIGINT
50
+
51
+ # start the network
52
+ networkUp
53
+
54
+ waitForContainer " orderer0.group1.orderer.example.com" " Channel created"
55
+ waitForContainer " orderer1.group1.orderer.example.com" " Channel created"
56
+ waitForContainer " orderer2.group1.orderer.example.com" " Channel created"
57
+ waitForContainer " orderer3.group1.orderer.example.com" " Channel created"
58
+ waitForContainer " ca.org1.example.com" " Listening on https://0.0.0.0:7054"
59
+ waitForContainer " peer0.org1.example.com" " Joining gossip network of channel my-channel1 with 1 organizations"
60
+ waitForContainer " peer1.org1.example.com" " Joining gossip network of channel my-channel1 with 1 organizations"
61
+ waitForContainer " peer0.org1.example.com" " Learning about the configured anchor peers of Org1MSP for channel my-channel1"
62
+ waitForContainer " peer0.org1.example.com" " Anchor peer.*with same endpoint, skipping connecting to myself"
63
+ waitForContainer " peer0.org1.example.com" " Membership view has changed. peers went online:.*peer1.org1.example.com:7042"
64
+ waitForContainer " peer1.org1.example.com" " Learning about the configured anchor peers of Org1MSP for channel my-channel1"
65
+ waitForContainer " peer1.org1.example.com" " Membership view has changed. peers went online:.*peer0.org1.example.com:7041"
66
+
67
+ # Test simple chaincode
68
+ expectInvoke " peer0.org1.example.com" " my-channel1" " chaincode1" \
69
+ ' {"Args":["KVContract:put", "name", "Willy Wonka"]}' \
70
+ ' {\"success\":\"OK\"}'
71
+ expectInvoke " peer1.org1.example.com" " my-channel1" " chaincode1" \
72
+ ' {"Args":["KVContract:get", "name"]}' \
73
+ ' {\"success\":\"Willy Wonka\"}'
74
+
75
+ # Verify channel query scripts
76
+ (cd " $TEST_TMP " && " $FABLO_HOME /fablo.sh" channel fetch newest my-channel1 org1 peer1)
77
+ expectCommand " cat \" $TEST_TMP /newest.block\" " " KVContract:get"
78
+
79
+ (cd " $TEST_TMP " && " $FABLO_HOME /fablo.sh" channel fetch 3 my-channel1 org1 peer1 " another.block" )
80
+ expectCommand " cat \" $TEST_TMP /another.block\" " " KVContract:put"
81
+
82
+ (cd " $TEST_TMP " && " $FABLO_HOME /fablo.sh" channel fetch config my-channel1 org1 peer1 " channel-config.json" )
83
+ expectCommand " cat \" $TEST_TMP /channel-config.json\" " " \" mod_policy\" : \" Admins\" ,"
84
+
85
+ expectCommand " (cd \" $TEST_TMP \" && \" $FABLO_HOME /fablo.sh\" channel getinfo my-channel1 org1 peer1)" " \" height\" :5"
86
+
87
+ echo " 🎉 Test passed! 🎉"
0 commit comments