|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# Copyright (c) 2017 Jeromy Johnson |
| 4 | +# MIT Licensed; see the LICENSE file in this repository. |
| 5 | +# |
| 6 | + |
| 7 | +test_description="Test two ipfs nodes transferring a file" |
| 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 | +check_dir_fetch() { |
| 26 | + node=$1 |
| 27 | + ref=$2 |
| 28 | + |
| 29 | + test_expect_success "node can fetch all refs for dir" ' |
| 30 | + ipfsi $node refs -r $ref > /dev/null |
| 31 | + ' |
| 32 | +} |
| 33 | + |
| 34 | +run_single_file_test() { |
| 35 | + test_expect_success "add a file on node1" ' |
| 36 | + random 1000000 > filea && |
| 37 | + FILEA_HASH=$(ipfsi 1 add -q filea) |
| 38 | + ' |
| 39 | + |
| 40 | + check_file_fetch 0 $FILEA_HASH filea |
| 41 | +} |
| 42 | + |
| 43 | +run_random_dir_test() { |
| 44 | + test_expect_success "create a bunch of random files" ' |
| 45 | + random-files -depth=3 -dirs=4 -files=5 -seed=5 foobar > /dev/null |
| 46 | + ' |
| 47 | + |
| 48 | + test_expect_success "add those on node 0" ' |
| 49 | + DIR_HASH=$(ipfsi 0 add -r -q foobar | tail -n1) |
| 50 | + ' |
| 51 | + |
| 52 | + check_dir_fetch 1 $DIR_HASH |
| 53 | +} |
| 54 | + |
| 55 | +run_advanced_test() { |
| 56 | + startup_cluster 2 "$@" |
| 57 | + |
| 58 | + test_expect_success "clean repo before test" ' |
| 59 | + ipfsi 0 repo gc > /dev/null && |
| 60 | + ipfsi 1 repo gc > /dev/null |
| 61 | + ' |
| 62 | + |
| 63 | + run_single_file_test |
| 64 | + |
| 65 | + run_random_dir_test |
| 66 | + |
| 67 | + test_expect_success "node0 data transferred looks correct" ' |
| 68 | + ipfsi 0 bitswap stat > stat0 && |
| 69 | + grep "blocks sent: 126" stat0 > /dev/null && |
| 70 | + grep "blocks received: 5" stat0 > /dev/null && |
| 71 | + grep "data sent: 228113" stat0 > /dev/null && |
| 72 | + grep "data received: 1000256" stat0 > /dev/null |
| 73 | + ' |
| 74 | + |
| 75 | + test_expect_success "node1 data transferred looks correct" ' |
| 76 | + ipfsi 1 bitswap stat > stat1 && |
| 77 | + grep "blocks received: 126" stat1 > /dev/null && |
| 78 | + grep "blocks sent: 5" stat1 > /dev/null && |
| 79 | + grep "data received: 228113" stat1 > /dev/null && |
| 80 | + grep "data sent: 1000256" stat1 > /dev/null |
| 81 | + ' |
| 82 | + |
| 83 | + test_expect_success "shut down nodes" ' |
| 84 | + iptb stop |
| 85 | + ' |
| 86 | +} |
| 87 | + |
| 88 | +test_expect_success "set up tcp testbed" ' |
| 89 | + iptb init -n 2 -p 0 -f --bootstrap=none |
| 90 | +' |
| 91 | + |
| 92 | +# test multiplex muxer |
| 93 | +export LIBP2P_MUX_PREFS="/mplex/6.7.0" |
| 94 | +run_advanced_test "--enable-mplex-experiment" |
| 95 | +unset LIBP2P_MUX_PREFS |
| 96 | + |
| 97 | +# test default configuration |
| 98 | +run_advanced_test |
| 99 | + |
| 100 | + |
| 101 | +test_done |
0 commit comments