This repository was archived by the owner on Apr 25, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +175
-0
lines changed Expand file tree Collapse file tree 3 files changed +175
-0
lines changed Original file line number Diff line number Diff line change 1+ use std:: { env, fs, path:: PathBuf } ;
2+
3+ use duct:: cmd;
4+ use nix:: sys:: stat:: { stat, Mode } ;
5+
6+ const DIR : & str = concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/tests" ) ;
7+
8+ const CLIENT_BIN : & str = env ! ( "CARGO_BIN_EXE_client" ) ;
9+ const SERVER_BIN : & str = env ! ( "CARGO_BIN_EXE_server" ) ;
10+
11+ #[ test]
12+ fn run_execs ( ) {
13+ let all_tests_succeed = fs:: read_dir ( DIR )
14+ . expect ( "read test directory" )
15+ . filter_map ( |readdir| {
16+ let entry = readdir. expect ( "read entry" ) ;
17+ if Mode :: from_bits_truncate ( stat ( & entry. path ( ) ) . expect ( "stat file" ) . st_mode )
18+ . intersects ( Mode :: S_IXUSR | Mode :: S_IXGRP | Mode :: S_IXOTH )
19+ {
20+ Some ( entry. path ( ) )
21+ } else {
22+ None
23+ }
24+ } )
25+ . map ( |exec| {
26+ print ! ( "test {:?} ... " , exec) ;
27+
28+ let path = env:: join_paths (
29+ env:: split_paths ( & env:: var_os ( "PATH" ) . unwrap ( ) )
30+ . chain ( [ PathBuf :: from ( DIR ) ] . iter ( ) . cloned ( ) )
31+ . chain (
32+ [ PathBuf :: from ( CLIENT_BIN ) , PathBuf :: from ( SERVER_BIN ) ]
33+ . iter ( )
34+ . cloned ( )
35+ . map ( |mut dir| {
36+ dir. pop ( ) ;
37+ dir
38+ } ) ,
39+ ) ,
40+ )
41+ . expect ( "valid PATH's element" ) ;
42+
43+ cmd ! ( exec) . dir ( DIR ) . env ( "PATH" , path) . run ( )
44+ } )
45+ . map ( |ret| match ret {
46+ Ok ( _) => {
47+ println ! ( "ok" ) ;
48+ true
49+ }
50+ Err ( err) => {
51+ println ! ( "{}" , err) ;
52+ false
53+ }
54+ } )
55+ . all ( |is_success| is_success) ;
56+
57+ if !all_tests_succeed {
58+ panic ! ( "some test failed" )
59+ }
60+ }
Original file line number Diff line number Diff line change 1+ set -eumo pipefail
2+
3+ readonly node_count=3
4+ readonly host_name=127.0.0.1
5+ readonly tick=0.1
6+
7+ tmpdir=$( mktemp -d)
8+ cd " $tmpdir "
9+
10+ trap cleanup EXIT QUIT
11+ cleanup () {
12+ local err=$?
13+ local pid
14+
15+ for pid in $nodes
16+ do
17+ kill -9 $pid
18+ done
19+
20+ for pid in $nodes
21+ do
22+ set +e
23+ wait $pid 2> /dev/null
24+ local ret=$?
25+ set -e
26+
27+ if [ $ret -ne 137 ]
28+ then
29+ err=$ret
30+ fi
31+ done
32+
33+ rm -rf " $tmpdir "
34+
35+ exit $err
36+ }
37+
38+ fail () {
39+ echo $@
40+ exit 1
41+ }
42+
43+ readonly port_base=$(( RANDOM + 1024 ))
44+ readonly port_top=$(( port_base + 2 * node_count - 1 ))
45+ nodes=' '
46+ start_network () {
47+ [ -n " $nodes " ] && fail ' nodes already started'
48+
49+ local port configs=()
50+
51+ for port in $( seq $port_base 2 $port_top )
52+ do
53+ configs[$(( ${# configs[@]} + 1 )) ]=$( server config new $host_name :{$port ,$(( port+ 1 )) })
54+ done
55+
56+ local i
57+ for i in $( seq $node_count )
58+ do
59+ local j node_config=${configs[i]}
60+ for j in $( seq $node_count )
61+ do
62+ [ $i -eq $j ] && continue
63+ node_config+=$' \n ' $( echo " ${configs[j]} " | server config get-node)
64+ done
65+
66+ echo " $node_config "
67+ echo " $node_config " | server run &
68+ nodes+=" $! "
69+ done
70+
71+ for port in $( seq $port_base $port_top )
72+ do
73+ while ! nc -q 0 localhost $port < /dev/null
74+ do
75+ sleep 0.1
76+ done
77+ done
78+ }
79+
80+ get_node_rpc () {
81+ [ -z " $nodes " ] && fail ' asking for client to stopped nodes'
82+
83+ echo http://$host_name :$(( port_base+ 1 ))
84+ }
85+
86+ wait_for_sequence () {
87+ local config=$1
88+ local seq=$2
89+
90+ until echo " $config " | client get-last-sequence | xargs test " $seq " -eq
91+ do
92+ echo " $config " | client get-last-sequence
93+ sleep $tick
94+ done
95+ }
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ source ./lib.sh
4+
5+ start_network
6+
7+ sender=$( client config new $( get_node_rpc) )
8+ recipient_pubkley=$( client config new $( get_node_rpc) |
9+ client config get-public-key)
10+
11+ echo " $sender " |
12+ client send-asset 1 " $recipient_pubkley " 10
13+ wait_for_sequence " $sender " 1
14+
15+ txs=$( client config new $( get_node_rpc) | client get-latest-transactions)
16+
17+ [ " $( echo " $txs " | wc -l) " -eq 1 ]
18+ echo " $txs " | grep -q " $( echo " $sender " | client config get-public-key) "
19+ echo " $txs " | grep -q " $recipient_pubkley "
20+ echo " $txs " | grep -q 10
You can’t perform that action at this time.
0 commit comments