t0170-dht.sh 1.68 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
  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
'

34 35 36 37 38
test_expect_success "add a ref so we can find providers for it" '
	echo "some stuff" > afile &&
	HASH=$(ipfsi 3 add -q afile)
'

39 40
# ipfs dht findprovs <key>
test_expect_success 'findprovs' '
41 42 43
	ipfsi 4 dht findprovs $HASH > provs &&
	iptb get id 3 > expected &&
	test_cmp provs expected
44 45 46 47 48 49 50 51 52 53 54 55 56
'

# 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.
57 58
# TODO: flaky. tracked by https://github.com/ipfs/go-ipfs/issues/2620
test_expect_failure 'query' '
59 60 61 62 63 64 65 66 67 68 69 70 71
  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