t0183-namesys-pubsub.sh 2.09 KB
Newer Older
Łukasz Magiera's avatar
Łukasz Magiera committed
1
#!/usr/bin/env bash
vyzo's avatar
vyzo committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

test_description="Test IPNS pubsub"

. lib/test-lib.sh

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

startup_cluster $NUM_NODES --enable-namesys-pubsub

test_expect_success 'peer ids' '
    PEERID_0=$(iptb get id 0)
'

test_expect_success 'check namesys pubsub state' '
    echo enabled > expected &&
    ipfsi 0 name pubsub state > state0 &&
    ipfsi 1 name pubsub state > state1 &&
    ipfsi 2 name pubsub state > state2 &&
    test_cmp expected state0 &&
    test_cmp expected state1 &&
    test_cmp expected state2
'

29
# These commands are *expected* to fail. We haven't published anything yet.
vyzo's avatar
vyzo committed
30
test_expect_success 'subscribe nodes to the publisher topic' '
Łukasz Magiera's avatar
Łukasz Magiera committed
31 32
    ipfsi 1 name resolve /ipns/$PEERID_0 --timeout=1s;
    ipfsi 2 name resolve /ipns/$PEERID_0 --timeout=1s;
33
    true
vyzo's avatar
vyzo committed
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
'

test_expect_success 'check subscriptions' '
    echo /ipns/$PEERID_0 > expected &&
    ipfsi 1 name pubsub subs > subs1 &&
    ipfsi 2 name pubsub subs > subs2 &&
    test_cmp expected subs1 &&
    test_cmp expected subs2
'

test_expect_success 'add an obect on publisher node' '
    echo "ipns is super fun" > file &&
    HASH_FILE=$(ipfsi 0 add -q file)
'

test_expect_success 'publish that object as an ipns entry' '
    ipfsi 0 name publish $HASH_FILE
'

test_expect_success 'wait for the flood' '
    sleep 1
'

test_expect_success 'resolve name in subscriber nodes' '
    echo "/ipfs/$HASH_FILE" > expected &&
    ipfsi 1 name resolve /ipns/$PEERID_0 > name1 &&
    ipfsi 2 name resolve /ipns/$PEERID_0 > name2 &&
    test_cmp expected name1 &&
    test_cmp expected name2
'

test_expect_success 'cancel subscriptions to the publisher topic' '
    ipfsi 1 name pubsub cancel /ipns/$PEERID_0 &&
    ipfsi 2 name pubsub cancel /ipns/$PEERID_0
'

test_expect_success 'check subscriptions' '
    rm -f expected && touch expected &&
    ipfsi 1 name pubsub subs > subs1 &&
    ipfsi 2 name pubsub subs > subs2 &&
    test_cmp expected subs1 &&
    test_cmp expected subs2
'

test_expect_success "shut down iptb" '
    iptb stop
'

test_done