master
sh 74 lines 1.62 KB
Raw
1 #!/usr/bin/env bash
2 #
3 # Copyright (c) 2015 Jeromy Johnson
4 # MIT Licensed; see the LICENSE file in this repository.
5 #
6
7 test_description="Test client mode dht"
8
9 . lib/test-lib.sh
10
11 check_file_fetch() {
12 node=$1
13 fhash=$2
14 fname=$3
15
16 test_expect_success "can fetch file" '
17 ipfsi $node cat $fhash > fetch_out
18 '
19
20 test_expect_success "file looks good" '
21 test_cmp $fname fetch_out
22 '
23 }
24
25 run_single_file_test() {
26 test_expect_success "add a file on node1" '
27 random-data -size=1000000 > filea &&
28 FILEA_HASH=$(ipfsi 1 add -q filea)
29 '
30
31 check_file_fetch 9 $FILEA_HASH filea
32 check_file_fetch 8 $FILEA_HASH filea
33 check_file_fetch 7 $FILEA_HASH filea
34 check_file_fetch 6 $FILEA_HASH filea
35 check_file_fetch 5 $FILEA_HASH filea
36 check_file_fetch 4 $FILEA_HASH filea
37 check_file_fetch 3 $FILEA_HASH filea
38 check_file_fetch 2 $FILEA_HASH filea
39 check_file_fetch 1 $FILEA_HASH filea
40 check_file_fetch 0 $FILEA_HASH filea
41 }
42
43 NNODES=10
44
45 test_expect_success "set up testbed" '
46 iptb testbed create -type localipfs -count $NNODES -force -init &&
47 iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true
48 '
49
50 test_expect_success "start up nodes" '
51 iptb start -wait [0-7] &&
52 iptb start -wait [8-9] -- --routing=dhtclient
53 '
54
55 test_expect_success "connect up nodes" '
56 iptb connect [1-9] 0
57 '
58
59 test_expect_success "add a file on a node in client mode" '
60 random-data -size=1000000 > filea &&
61 FILE_HASH=$(ipfsi 8 add -q filea)
62 '
63
64 test_expect_success "retrieve that file on a node in client mode" '
65 check_file_fetch 9 $FILE_HASH filea
66 '
67
68 run_single_file_test
69
70 test_expect_success "shut down nodes" '
71 iptb stop
72 '
73
74 test_done