Skip to content

Commit 9278867

Browse files
committed
fix(p2p): add test for issue ipfs#5523
License: MIT Signed-off-by: Overbool <[email protected]>
1 parent d3e653e commit 9278867

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

core/commands/p2p.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func checkPort(target ma.Multiaddr) error {
230230
}
231231

232232
if port == 0 {
233-
return fmt.Errorf("port can't be 0")
233+
return fmt.Errorf("port can not be 0")
234234
}
235235

236236
return nil

test/sharness/t0180-p2p.sh

+20-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ test_description="Test experimental p2p commands"
66

77
# start iptb + wait for peering
88
test_expect_success 'init iptb' '
9-
iptb init -n 2 --bootstrap=none --port=0
9+
iptb init -n 3 --bootstrap=none --port=0
1010
'
1111

1212
test_expect_success 'generate test data' '
1313
echo "ABCDEF" > test0.bin &&
1414
echo "012345" > test1.bin
1515
'
1616

17-
startup_cluster 2
17+
startup_cluster 3
1818

1919
test_expect_success 'peer ids' '
2020
PEERID_0=$(iptb get id 0) &&
@@ -36,6 +36,7 @@ test_expect_success 'fail without config option being enabled' '
3636
test_expect_success "enable filestore config setting" '
3737
ipfsi 0 config --json Experimental.Libp2pStreamMounting true
3838
ipfsi 1 config --json Experimental.Libp2pStreamMounting true
39+
ipfsi 2 config --json Experimental.Libp2pStreamMounting true
3940
'
4041

4142
test_expect_success 'start p2p listener' '
@@ -129,6 +130,23 @@ test_expect_success 'C->S Close local listener' '
129130

130131
check_test_ports
131132

133+
# Checking port
134+
135+
test_expect_success "cannot accept 0 port in 'ipfs p2p listen'" '
136+
test_must_fail ipfsi 0 p2p listen /x/p2p-test/0 /ip4/127.0.0.1/tcp/0
137+
'
138+
139+
test_expect_success "'ipfs p2p forward' accept 0 port" '
140+
ipfsi 2 p2p forward /x/p2p-test/0 /ip4/127.0.0.1/tcp/0 /ipfs/$PEERID_0
141+
'
142+
143+
test_expect_success "'ipfs p2p ls' output looks good" '
144+
echo "true" > forward_0_expected &&
145+
ipfsi 2 p2p ls | awk '\''{print $2}'\'' | sed "s/.*\///" | awk -F: '\''{if($1>0)print"true"}'\'' > forward_0_actual
146+
ipfsi 2 p2p close -p /x/p2p-test/0
147+
test_cmp forward_0_expected forward_0_actual
148+
'
149+
132150
# Listing streams
133151

134152
test_expect_success "'ipfs p2p ls' succeeds" '

0 commit comments

Comments
 (0)