-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
t0183-namesys-pubsub.sh
executable file
·125 lines (100 loc) · 3.91 KB
/
t0183-namesys-pubsub.sh
1
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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env bash
test_description="Test IPNS pubsub"
. lib/test-lib.sh
# start iptb + wait for peering
NUM_NODES=5
test_expect_success 'init iptb' '
iptb testbed create -type localipfs -count $NUM_NODES -init
'
run_ipnspubsub_tests() {
test_expect_success 'peer ids' '
PEERID_0_BASE36=$(ipfsi 0 key list --ipns-base=base36 -l | grep self | head -n 1 | cut -d " " -f1) &&
PEERID_0_B58MH=$(ipfsi 0 key list --ipns-base=b58mh -l | grep self | head -n 1 | cut -d " " -f1)
'
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
'
# These commands are *expected* to fail. We haven't published anything yet.
test_expect_success 'subscribe nodes to the publisher topic' '
ipfsi 1 name resolve /ipns/$PEERID_0_BASE36 --timeout=1s;
ipfsi 2 name resolve /ipns/$PEERID_0_BASE36 --timeout=1s;
true
'
test_expect_success 'check subscriptions' '
echo /ipns/$PEERID_0_BASE36 > expected_base36 &&
echo /ipns/$PEERID_0_B58MH > expected_b58mh &&
ipfsi 1 name pubsub subs > subs1 &&
ipfsi 2 name pubsub subs > subs2 &&
ipfsi 1 name pubsub subs --ipns-base=b58mh > subs1_b58mh &&
ipfsi 2 name pubsub subs --ipns-base=b58mh > subs2_b58mh &&
test_cmp expected_base36 subs1 &&
test_cmp expected_base36 subs2 &&
test_cmp expected_b58mh subs1_b58mh &&
test_cmp expected_b58mh subs2_b58mh
'
test_expect_success 'add an object 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_BASE36 > name1 &&
ipfsi 2 name resolve /ipns/$PEERID_0_BASE36 > 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_BASE36 &&
ipfsi 2 name pubsub cancel /ipns/$PEERID_0_BASE36
'
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 everything with ipns-pubsub enabled via config
test_expect_success 'enable ipns over pubsub' '
iptb run -- ipfs config --json Ipns.UsePubsub true
'
startup_cluster $NUM_NODES
run_ipnspubsub_tests
# Test again, this time CLI parameter override the config
test_expect_success 'enable ipns over pubsub' '
iptb run -- ipfs config --json Ipns.UsePubsub false
'
startup_cluster $NUM_NODES --enable-namesys-pubsub
run_ipnspubsub_tests
# Confirm negative CLI flag takes precedence over positive config
test_expect_success 'enable the pubsub-ipns via config' '
iptb run -- ipfs config --json Ipns.UsePubsub true
'
startup_cluster $NUM_NODES --enable-namesys-pubsub=false
test_expect_success 'ipns pubsub cmd fails because it was disabled via cli flag' '
test_expect_code 1 ipfsi 1 name pubsub subs 2> pubsubipns_cmd_out
'
test_expect_success "ipns pubsub cmd produces error" "
echo -e \"Error: IPNS pubsub subsystem is not enabled\nUse 'ipfs name pubsub subs --help' for information about this command\" > expected &&
test_cmp expected pubsubipns_cmd_out
"
test_expect_success 'stop iptb' '
iptb stop
'
test_done