| 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright (c) 2014 Jeromy Johnson |
| 4 | # MIT Licensed; see the LICENSE file in this repository. |
| 5 | # |
| 6 | |
| 7 | test_description="Test ipfs swarm command" |
| 8 | |
| 9 | . lib/test-lib.sh |
| 10 | |
| 11 | test_init_ipfs |
| 12 | |
| 13 | test_launch_ipfs_daemon |
| 14 | |
| 15 | test_expect_success 'disconnected: peers is empty' ' |
| 16 | ipfs swarm peers >actual && |
| 17 | test_must_be_empty actual |
| 18 | ' |
| 19 | |
| 20 | test_expect_success 'disconnected: addrs local has localhost' ' |
| 21 | ipfs swarm addrs local >actual && |
| 22 | grep "/ip4/127.0.0.1" actual |
| 23 | ' |
| 24 | |
| 25 | test_expect_success 'disconnected: addrs local matches ipfs id' ' |
| 26 | ipfs id -f="<addrs>\\n" | sort >expected && |
| 27 | ipfs swarm addrs local --id | sort >actual && |
| 28 | test_cmp expected actual |
| 29 | ' |
| 30 | |
| 31 | test_expect_success "ipfs id self works" ' |
| 32 | myid=$(ipfs id -f="<id>") && |
| 33 | ipfs id --timeout=1s $myid > output |
| 34 | ' |
| 35 | |
| 36 | test_expect_success "output looks good" ' |
| 37 | grep $myid output && |
| 38 | grep PublicKey output |
| 39 | ' |
| 40 | |
| 41 | addr="/ip4/127.0.0.1/tcp/9898/p2p/QmUWKoHbjsqsSMesRC2Zoscs8edyFz6F77auBB1YBBhgpX" |
| 42 | |
| 43 | test_expect_success "can't trigger a dial backoff with swarm connect" ' |
| 44 | test_expect_code 1 ipfs swarm connect $addr 2> connect_out |
| 45 | test_expect_code 1 ipfs swarm connect $addr 2>> connect_out |
| 46 | test_expect_code 1 ipfs swarm connect $addr 2>> connect_out |
| 47 | test_expect_code 1 grep "backoff" connect_out |
| 48 | ' |
| 49 | |
| 50 | test_kill_ipfs_daemon |
| 51 | |
| 52 | announceCfg='["/ip4/127.0.0.1/tcp/4001", "/ip4/1.2.3.4/tcp/1234"]' |
| 53 | test_expect_success "test_config_set succeeds" " |
| 54 | ipfs config --json Addresses.Announce '$announceCfg' |
| 55 | " |
| 56 | |
| 57 | test_launch_ipfs_daemon |
| 58 | |
| 59 | test_expect_success 'Addresses.Announce affects addresses' ' |
| 60 | ipfs swarm addrs local >actual && |
| 61 | test_should_contain "/ip4/1.2.3.4/tcp/1234" actual && |
| 62 | ipfs id -f"<addrs>" | xargs -n1 echo >actual && |
| 63 | test_should_contain "/ip4/1.2.3.4/tcp/1234" actual |
| 64 | ' |
| 65 | |
| 66 | test_kill_ipfs_daemon |
| 67 | |
| 68 | |
| 69 | announceCfg='["/ip4/127.0.0.1/tcp/4001", "/ip4/1.2.3.4/tcp/1234"]' |
| 70 | test_expect_success "test_config_set succeeds" " |
| 71 | ipfs config --json Addresses.Announce '$announceCfg' |
| 72 | " |
| 73 | # Include "/ip4/1.2.3.4/tcp/1234" to ensure we deduplicate addrs already present in Swarm.Announce |
| 74 | appendAnnounceCfg='["/dnsaddr/dynamic.example.com", "/ip4/10.20.30.40/tcp/4321", "/ip4/1.2.3.4/tcp/1234"]' |
| 75 | test_expect_success "test_config_set Announce and AppendAnnounce succeeds" " |
| 76 | ipfs config --json Addresses.Announce '$announceCfg' && |
| 77 | ipfs config --json Addresses.AppendAnnounce '$appendAnnounceCfg' |
| 78 | " |
| 79 | |
| 80 | test_launch_ipfs_daemon |
| 81 | |
| 82 | test_expect_success 'Addresses.AppendAnnounce is applied on top of Announce' ' |
| 83 | ipfs swarm addrs local >actual && |
| 84 | test_should_contain "/ip4/1.2.3.4/tcp/1234" actual && |
| 85 | test_should_contain "/dnsaddr/dynamic.example.com" actual && |
| 86 | test_should_contain "/ip4/10.20.30.40/tcp/4321" actual && |
| 87 | ipfs id -f"<addrs>" | xargs -n1 echo | tee actual && |
| 88 | test_should_contain "/ip4/1.2.3.4/tcp/1234/p2p" actual && |
| 89 | test_should_contain "/dnsaddr/dynamic.example.com/p2p/" actual && |
| 90 | test_should_contain "/ip4/10.20.30.40/tcp/4321/p2p/" actual |
| 91 | ' |
| 92 | |
| 93 | test_kill_ipfs_daemon |
| 94 | |
| 95 | noAnnounceCfg='["/ip4/1.2.3.4/tcp/1234", "/ip4/10.20.30.40/tcp/4321"]' |
| 96 | test_expect_success "test_config_set succeeds" " |
| 97 | ipfs config --json Addresses.NoAnnounce '$noAnnounceCfg' |
| 98 | " |
| 99 | |
| 100 | test_launch_ipfs_daemon |
| 101 | |
| 102 | test_expect_success "Addresses.NoAnnounce affects addresses from Announce and AppendAnnounce" ' |
| 103 | ipfs swarm addrs local >actual && |
| 104 | test_should_not_contain "/ip4/1.2.3.4/tcp/1234" actual && |
| 105 | test_should_not_contain "/ip4/10.20.30.40/tcp/4321" actual && |
| 106 | ipfs id -f"<addrs>" | xargs -n1 echo >actual && |
| 107 | test_should_not_contain "/ip4/1.2.3.4/tcp/1234" actual && |
| 108 | test_should_not_contain "/ip4/10.20.30.40/tcp/4321" actual |
| 109 | ' |
| 110 | |
| 111 | test_kill_ipfs_daemon |
| 112 | |
| 113 | noAnnounceCfg='["/ip4/1.2.3.4/ipcidr/16"]' |
| 114 | test_expect_success "test_config_set succeeds" " |
| 115 | ipfs config --json Addresses.NoAnnounce '$noAnnounceCfg' |
| 116 | " |
| 117 | |
| 118 | test_launch_ipfs_daemon |
| 119 | |
| 120 | test_expect_success "Addresses.NoAnnounce with /ipcidr affects addresses" ' |
| 121 | ipfs swarm addrs local >actual && |
| 122 | test_should_not_contain "/ip4/1.2.3.4/tcp/1234" actual && |
| 123 | ipfs id -f"<addrs>" | xargs -n1 echo >actual && |
| 124 | test_should_not_contain "/ip4/1.2.3.4/tcp/1234" actual |
| 125 | ' |
| 126 | |
| 127 | test_kill_ipfs_daemon |
| 128 | |
| 129 | test_launch_ipfs_daemon |
| 130 | |
| 131 | test_expect_success "'ipfs swarm peering ls' lists peerings" ' |
| 132 | ipfs swarm peering ls |
| 133 | ' |
| 134 | |
| 135 | peeringID='QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N' |
| 136 | peeringID2='QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5K' |
| 137 | peeringAddr='/ip4/1.2.3.4/tcp/1234/p2p/QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N' |
| 138 | peeringAddr2='/ip4/1.2.3.4/tcp/1234/p2p/QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5K' |
| 139 | test_expect_success "'ipfs swarm peering add' adds a peering" ' |
| 140 | ipfs swarm peering ls > peeringls && |
| 141 | ! test_should_contain ${peeringID} peeringls && |
| 142 | ! test_should_contain ${peeringID2} peeringls && |
| 143 | ipfs swarm peering add ${peeringAddr} ${peeringAddr2} |
| 144 | ' |
| 145 | |
| 146 | test_expect_success 'a peering is added' ' |
| 147 | ipfs swarm peering ls > peeringadd && |
| 148 | test_should_contain ${peeringID} peeringadd && |
| 149 | test_should_contain ${peeringID2} peeringadd |
| 150 | ' |
| 151 | |
| 152 | test_expect_success "'swarm peering rm' removes a peering" ' |
| 153 | ipfs swarm peering rm ${peeringID} |
| 154 | ' |
| 155 | |
| 156 | test_expect_success 'peering is removed' ' |
| 157 | ipfs swarm peering ls > peeringrm && |
| 158 | ! test_should_contain ${peeringID} peeringrm |
| 159 | ' |
| 160 | |
| 161 | test_kill_ipfs_daemon |
| 162 | |
| 163 | test_expect_success "set up tcp testbed" ' |
| 164 | iptb testbed create -type localipfs -count 2 -force -init |
| 165 | ' |
| 166 | |
| 167 | startup_cluster 2 |
| 168 | |
| 169 | test_expect_success "disconnect work without specifying a transport address" ' |
| 170 | [ $(ipfsi 0 swarm peers | wc -l) -eq 1 ] && |
| 171 | ipfsi 0 swarm disconnect "/p2p/$(iptb attr get 1 id)" && |
| 172 | [ $(ipfsi 0 swarm peers | wc -l) -eq 0 ] |
| 173 | ' |
| 174 | |
| 175 | test_expect_success "connect work without specifying a transport address" ' |
| 176 | [ $(ipfsi 0 swarm peers | wc -l) -eq 0 ] && |
| 177 | ipfsi 0 swarm connect "/p2p/$(iptb attr get 1 id)" && |
| 178 | [ $(ipfsi 0 swarm peers | wc -l) -eq 1 ] |
| 179 | ' |
| 180 | |
| 181 | test_expect_success "/p2p addresses work" ' |
| 182 | [ $(ipfsi 0 swarm peers | wc -l) -eq 1 ] && |
| 183 | ipfsi 0 swarm disconnect "/p2p/$(iptb attr get 1 id)" && |
| 184 | [ $(ipfsi 0 swarm peers | wc -l) -eq 0 ] && |
| 185 | ipfsi 0 swarm connect "/p2p/$(iptb attr get 1 id)" && |
| 186 | [ $(ipfsi 0 swarm peers | wc -l) -eq 1 ] |
| 187 | ' |
| 188 | |
| 189 | test_expect_success "ipfs id is consistent for node 0" ' |
| 190 | ipfsi 1 id "$(iptb attr get 0 id)" > 1see0 && |
| 191 | ipfsi 0 id > 0see0 && |
| 192 | test_cmp 1see0 0see0 |
| 193 | ' |
| 194 | |
| 195 | test_expect_success "ipfs id is consistent for node 1" ' |
| 196 | ipfsi 0 id "$(iptb attr get 1 id)" > 0see1 && |
| 197 | ipfsi 1 id > 1see1 && |
| 198 | test_cmp 0see1 1see1 |
| 199 | ' |
| 200 | |
| 201 | test_expect_success "addresses contain /p2p/..." ' |
| 202 | test_should_contain "/p2p/$(iptb attr get 1 id)\"" 0see1 && |
| 203 | test_should_contain "/p2p/$(iptb attr get 1 id)\"" 1see1 && |
| 204 | test_should_contain "/p2p/$(iptb attr get 0 id)\"" 1see0 && |
| 205 | test_should_contain "/p2p/$(iptb attr get 0 id)\"" 0see0 |
| 206 | ' |
| 207 | |
| 208 | test_expect_success "stopping cluster" ' |
| 209 | iptb stop |
| 210 | ' |
| 211 | |
| 212 | test_done |