t0170-dht.sh 2.51 KB
Newer Older
1 2 3 4 5 6
#!/bin/sh

test_description="Test dht command"

. lib/test-lib.sh

Steven Allen's avatar
Steven Allen committed
7 8 9
TEST_DHT_VALUE="CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC8hSwYY1FXqjT5M36O/Q5fBeDhXE5ePvGAeN3MIibfChqQpgqBbXQi1gAp4TQypSTKl/AMy7hfzsKauieim7jHMgIYAB4pLoBQD1qGVn/n7CqzAR3gDg9umIGuAy15oT0uaqMDqSepfnyxEyPDqfDklgvmS/MAwfBHjH2IPcMIaFgZ6d6gVlhmwuH8WVQ/geumDqyKuU9Jy+SUozmxEu2Baylg4fuqxaxoqOiPFZeWKSCFAngFj3NPmLApE0Fy48/eEZ+t7iP6s/raupP4+Jk/AFNDJNos4VxUnLJpZ1g6W5vYkkt1kXbMTaqxFVryCdCW2UEOwEzjGPGkcIE4RJrHAgMBAAE="
TEST_DHT_PATH="/pk/QmepgFW7BHEtU4pZJdxaNiv75mKLLRQnPi1KaaXmQN4V1a"

10 11 12
# start iptb + wait for peering
NUM_NODES=5
test_expect_success 'init iptb' '
Łukasz Magiera's avatar
Łukasz Magiera committed
13
  iptb init -n $NUM_NODES --bootstrap=none --port=0
14 15
'

16 17
startup_cluster $NUM_NODES

18
test_expect_success 'peer ids' '
Łukasz Magiera's avatar
Łukasz Magiera committed
19 20
  PEERID_0=$(iptb get id 0) &&
  PEERID_2=$(iptb get id 2)
21 22 23 24
'

# ipfs dht findpeer <peerID>
test_expect_success 'findpeer' '
Łukasz Magiera's avatar
Łukasz Magiera committed
25 26 27
  ipfsi 1 dht findpeer $PEERID_0 | sort >actual &&
  ipfsi 0 id -f "<addrs>" | cut -d / -f 1-5 | sort >expected &&
  test_cmp actual expected
28 29 30
'

# ipfs dht put <key> <value>
Steven Allen's avatar
Steven Allen committed
31
test_expect_success 'put with good keys' '
32
  echo "$TEST_DHT_VALUE" | b64decode | ipfsi 0 dht put "$TEST_DHT_PATH" | sort >putted &&
Łukasz Magiera's avatar
Łukasz Magiera committed
33 34
  [ -s putted ] ||
  test_fsh cat putted
35 36
'

Steven Allen's avatar
Steven Allen committed
37 38 39 40 41 42 43
# ipfs dht get <key>
test_expect_success 'get with good keys' '
  HASH="$(echo "hello world" | ipfsi 2 add -q)" &&
  ipfsi 2 name publish "/ipfs/$HASH" &&
  ipfsi 1 dht get "/ipns/$PEERID_2" | grep -aq "/ipfs/$HASH"
'

44
test_expect_failure 'put with bad keys (issue #4611)' '
Steven Allen's avatar
Steven Allen committed
45 46 47 48 49
  ! ipfsi 0 dht put "foo" "bar" &&
  ! ipfsi 0 dht put "/pk/foo" "bar" &&
  ! ipfsi 0 dht put "/ipns/foo" "bar"
'

50
test_expect_failure 'get with bad keys (issue #4611)' '
Steven Allen's avatar
Steven Allen committed
51 52 53 54
  ! ipfsi 0 dht get "foo" &&
  ! ipfsi 0 dht get "/pk/foo"
'

55
test_expect_success "add a ref so we can find providers for it" '
Łukasz Magiera's avatar
Łukasz Magiera committed
56 57
  echo "some stuff" > afile &&
  HASH=$(ipfsi 3 add -q afile)
58 59
'

60 61
# ipfs dht findprovs <key>
test_expect_success 'findprovs' '
Łukasz Magiera's avatar
Łukasz Magiera committed
62 63 64
  ipfsi 4 dht findprovs $HASH > provs &&
  iptb get id 3 > expected &&
  test_cmp provs expected
65 66 67 68 69 70
'


# ipfs dht query <peerID>
## We query 3 different keys, to statisically lower the chance that the queryer
## turns out to be the closest to what a key hashes to.
71
# TODO: flaky. tracked by https://github.com/ipfs/go-ipfs/issues/2620
72
test_expect_success 'query' '
Łukasz Magiera's avatar
Łukasz Magiera committed
73 74 75 76 77 78
  ipfsi 3 dht query banana >actual &&
  ipfsi 3 dht query apple >>actual &&
  ipfsi 3 dht query pear >>actual &&
  PEERS=$(wc -l actual | cut -d '"'"' '"'"' -f 1) &&
  [ -s actual ] ||
  test_might_fail test_fsh cat actual
79 80 81
'

test_expect_success 'stop iptb' '
Łukasz Magiera's avatar
Łukasz Magiera committed
82
  iptb stop
83 84 85
'

test_done