t0170-dht.sh 1.52 KB
Newer Older
1 2 3 4 5 6 7 8 9
#!/bin/sh

test_description="Test dht command"

. lib/test-lib.sh

# start iptb + wait for peering
NUM_NODES=5
test_expect_success 'init iptb' '
10
  iptb init -n $NUM_NODES --bootstrap=none --port=0
11 12
'

13 14
startup_cluster $NUM_NODES

15 16 17 18 19 20 21 22
test_expect_success 'peer ids' '
  PEERID_0=$(iptb get id 0) &&
  PEERID_2=$(iptb get id 2)
'

# ipfs dht findpeer <peerID>
test_expect_success 'findpeer' '
  ipfsi 1 dht findpeer $PEERID_0 | sort >actual &&
23
  ipfsi 0 id -f "<addrs>" | cut -d / -f 1-5 | sort >expected &&
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  test_cmp actual expected
'

# ipfs dht put <key> <value>
test_expect_success 'put' '
  ipfsi 1 dht put planet pluto | sort >putted &&
  [ -s putted ] ||
	test_fsh cat putted
'

# ipfs dht findprovs <key>
test_expect_success 'findprovs' '
  ipfsi 4 dht findprovs planet | sort >provs &&
  sort provs putted | uniq -d >actual &&
  [ -s actual ] ||
	test_fsh cat actual
'

# ipfs dht get <key>
test_expect_success 'get' '
  ipfsi 0 dht put bar foo >actual &&
  ipfsi 4 dht get -v bar >actual &&
  egrep "error: record key does not have selectorfunc" actual > /dev//null ||
	test_fsh cat actual
'

# 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.
test_expect_success 'query' '
  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_fsh cat actual
'

test_expect_success 'stop iptb' '
  iptb stop
'

test_done