fix balance check in server logic
[epoint] / test / basic.sh
1 #!/bin/sh
2
3 set -e
4
5 PORT="8080"
6 SERVER="http://localhost:$PORT"
7 CSTORE="cstore"
8 SSTORE="sstore"
9 CFLAG="-dir=$CSTORE -server=$SERVER"
10 SFLAG="-dir=$SSTORE -addr=:$PORT"
11
12 client() {
13         echo epoint-client $CFLAG "$@" 1>&2
14         epoint-client $CFLAG "$@"
15 }
16
17 # TODO: storage..
18 # send [key|draft|cert] path
19 send() {
20         curl --data-urlencode $1@$2 $SERVER/submit
21 }
22
23 # query q
24 query() {
25         curl $SERVER/$1
26 }
27
28 rm -rf $CSTORE $SSTORE
29
30 epoint-server $SFLAG 2> server.log &
31 echo $! >server.pid
32 sleep 1
33
34 # get server key
35 client c
36
37 # make issuer key
38 IFPR=$(echo isecret | client i unit | client v | awk '/^Id:/ {print $2}')
39
40 # make holder key
41 HFPR=$(echo hsecret | client h $IFPR | client v | awk '/^Id:/ {print $2}')
42
43 # send keys
44 echo isecret | client i '' | client s k
45 echo hsecret | client h $IFPR | client s k
46
47 # make draft: issuer->holder 10
48 echo isecret | client d $HFPR 10 | client s d | client s c | client v | awk '/^Balance:/ {if ($2 != 10) exit 1}'
49 # make draft: holder->issuer 3
50 echo hsecret | client d $IFPR 3 | client s d | client s c | client v | awk '/^Balance:/ {if ($2 != -7) exit 1}'
51
52 # check certs
53 query certby/key.issuer/$IFPR.$IFPR | client v | awk '/^Balance:/ {if ($2 != -7) exit 1}'
54 query certby/key.issuer/$HFPR.$IFPR | client v | awk '/^Balance:/ {if ($2 != 7) exit 1}'
55
56 kill $(cat server.pid)
57 rm -f server.pid
58 echo server is killed 1>&2
59 echo PASS