Skip to content

Commit 2a0d04e

Browse files
committed
feat: e2e tests, remove .SearchValue override
1 parent c0210e3 commit 2a0d04e

File tree

9 files changed

+156
-17
lines changed

9 files changed

+156
-17
lines changed

core/corehttp/routing.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,12 @@ func (it *peerChanIter) Val() types.Record {
111111
return nil
112112
}
113113

114-
// We don't know what type of protocol this peer provides. It is likely Bitswap
115-
// but it might not be. Therefore, we set an unknown protocol with an unknown schema.
116114
rec := &types.PeerRecord{
117115
Schema: types.SchemaPeer,
118116
ID: &it.next.ID,
117+
// We need to add this here, otherwise contentrouter will ignore the peer
118+
// as it does not have transport bitswap available.
119+
Protocols: []string{"transport-bitswap"},
119120
}
120121

121122
for _, addr := range it.next.Addrs {

docs/examples/kubo-as-a-library/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ go 1.20
77
replace github.com/ipfs/kubo => ./../../..
88

99
require (
10-
github.com/ipfs/boxo v0.12.1-0.20230824094523-a2001ba61544
10+
github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff
1111
github.com/ipfs/kubo v0.0.0-00010101000000-000000000000
1212
github.com/libp2p/go-libp2p v0.30.0
1313
github.com/multiformats/go-multiaddr v0.11.0

docs/examples/kubo-as-a-library/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
300300
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
301301
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
302302
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
303-
github.com/ipfs/boxo v0.12.1-0.20230824094523-a2001ba61544 h1:XVq+wUNFx1Ufakz35MAWk+Rr5bAC7lwx1NbJ6Mslp48=
304-
github.com/ipfs/boxo v0.12.1-0.20230824094523-a2001ba61544/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk=
303+
github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff h1:IpyDgsSCTbMcEqKVsbE8S73lV2e9V2J/Tr82zpYb/mg=
304+
github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk=
305305
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
306306
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
307307
github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/fsnotify/fsnotify v1.6.0
1616
github.com/google/uuid v1.3.0
1717
github.com/hashicorp/go-multierror v1.1.1
18-
github.com/ipfs/boxo v0.12.1-0.20230824094523-a2001ba61544
18+
github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff
1919
github.com/ipfs/go-block-format v0.1.2
2020
github.com/ipfs/go-cid v0.4.1
2121
github.com/ipfs/go-cidutil v0.1.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
335335
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
336336
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
337337
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
338-
github.com/ipfs/boxo v0.12.1-0.20230824094523-a2001ba61544 h1:XVq+wUNFx1Ufakz35MAWk+Rr5bAC7lwx1NbJ6Mslp48=
339-
github.com/ipfs/boxo v0.12.1-0.20230824094523-a2001ba61544/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk=
338+
github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff h1:IpyDgsSCTbMcEqKVsbE8S73lV2e9V2J/Tr82zpYb/mg=
339+
github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk=
340340
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
341341
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
342342
github.com/ipfs/go-bitswap v0.11.0 h1:j1WVvhDX1yhG32NTC9xfxnqycqYIlhzEzLXG/cU1HyQ=

routing/wrapper.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,3 @@ type httpRoutingWrapper struct {
2929
func (c *httpRoutingWrapper) Bootstrap(ctx context.Context) error {
3030
return nil
3131
}
32-
33-
func (c *httpRoutingWrapper) SearchValue(context.Context, string, ...routing.Option) (<-chan []byte, error) {
34-
out := make(chan []byte)
35-
close(out)
36-
return out, routing.ErrNotSupported
37-
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package cli
2+
3+
import (
4+
"testing"
5+
6+
"github.com/ipfs/boxo/ipns"
7+
"github.com/ipfs/kubo/config"
8+
"github.com/ipfs/kubo/test/cli/harness"
9+
"github.com/ipfs/kubo/test/cli/testutils"
10+
"github.com/stretchr/testify/assert"
11+
"github.com/stretchr/testify/require"
12+
)
13+
14+
func TestRoutingV1Proxy(t *testing.T) {
15+
t.Parallel()
16+
17+
setupNodes := func(t *testing.T) harness.Nodes {
18+
nodes := harness.NewT(t).NewNodes(2).Init()
19+
20+
// Node 0 uses DHT and exposes the Routing API.
21+
nodes[0].UpdateConfig(func(cfg *config.Config) {
22+
cfg.Gateway.ExposeRoutingAPI = config.True
23+
cfg.Routing.Type = config.NewOptionalString("dht")
24+
})
25+
nodes[0].StartDaemon()
26+
27+
// Node 1 uses Node 0 as Routing V1 source, no DHT.
28+
nodes[1].UpdateConfig(func(cfg *config.Config) {
29+
cfg.Routing.Type = config.NewOptionalString("custom")
30+
cfg.Routing.Methods = config.Methods{
31+
config.MethodNameFindPeers: {RouterName: "KuboA"},
32+
config.MethodNameFindProviders: {RouterName: "KuboA"},
33+
config.MethodNameGetIPNS: {RouterName: "KuboA"},
34+
config.MethodNamePutIPNS: {RouterName: "KuboA"},
35+
config.MethodNameProvide: {RouterName: "KuboA"},
36+
}
37+
cfg.Routing.Routers = config.Routers{
38+
"KuboA": config.RouterParser{
39+
Router: config.Router{
40+
Type: config.RouterTypeHTTP,
41+
Parameters: &config.HTTPRouterParams{
42+
Endpoint: nodes[0].GatewayURL(),
43+
},
44+
},
45+
},
46+
}
47+
})
48+
nodes[1].StartDaemon()
49+
50+
// Connect them.
51+
nodes.Connect()
52+
53+
return nodes
54+
}
55+
56+
t.Run("Kubo can find provider for CID via Routing V1", func(t *testing.T) {
57+
t.Parallel()
58+
nodes := setupNodes(t)
59+
60+
cidStr := nodes[0].IPFSAddStr(testutils.RandomStr(1000))
61+
62+
res := nodes[1].IPFS("routing", "findprovs", cidStr)
63+
assert.Equal(t, nodes[0].PeerID().String(), res.Stdout.Trimmed())
64+
})
65+
66+
t.Run("Kubo can find peer via Routing V1", func(t *testing.T) {
67+
t.Parallel()
68+
nodes := setupNodes(t)
69+
70+
// Start lonely node that is not connected to other nodes.
71+
node := harness.NewT(t).NewNode().Init()
72+
node.UpdateConfig(func(cfg *config.Config) {
73+
cfg.Routing.Type = config.NewOptionalString("dht")
74+
})
75+
node.StartDaemon()
76+
77+
// Connect Node 0 to Lonely Node.
78+
nodes[0].Connect(node)
79+
80+
// Node 1 must find Lonely Node through Node 0 Routing V1.
81+
res := nodes[1].IPFS("routing", "findpeer", node.PeerID().String())
82+
assert.Equal(t, node.SwarmAddrs()[0].String(), res.Stdout.Trimmed())
83+
})
84+
85+
t.Run("Kubo can retrieve IPNS record via Routing V1", func(t *testing.T) {
86+
t.Parallel()
87+
nodes := setupNodes(t)
88+
89+
nodeName := "/ipns/" + ipns.NameFromPeer(nodes[0].PeerID()).String()
90+
91+
// Can't resolve the name as isn't published yet.
92+
res := nodes[1].RunIPFS("routing", "get", nodeName)
93+
require.Error(t, res.ExitErr)
94+
95+
// Publish record on Node 0.
96+
path := "/ipfs/" + nodes[0].IPFSAddStr(testutils.RandomStr(1000))
97+
nodes[0].IPFS("name", "publish", "--allow-offline", path)
98+
99+
// Get record on Node 1 (no DHT).
100+
res = nodes[1].IPFS("routing", "get", nodeName)
101+
record, err := ipns.UnmarshalRecord(res.Stdout.Bytes())
102+
require.NoError(t, err)
103+
value, err := record.Value()
104+
require.NoError(t, err)
105+
require.Equal(t, path, value.String())
106+
})
107+
108+
t.Run("Kubo can resolve IPNS name via Routing V1", func(t *testing.T) {
109+
t.Parallel()
110+
nodes := setupNodes(t)
111+
112+
nodeName := "/ipns/" + ipns.NameFromPeer(nodes[0].PeerID()).String()
113+
114+
// Can't resolve the name as isn't published yet.
115+
res := nodes[1].RunIPFS("routing", "get", nodeName)
116+
require.Error(t, res.ExitErr)
117+
118+
// Publish name.
119+
path := "/ipfs/" + nodes[0].IPFSAddStr(testutils.RandomStr(1000))
120+
nodes[0].IPFS("name", "publish", "--allow-offline", path)
121+
122+
// Resolve IPNS name
123+
res = nodes[1].IPFS("name", "resolve", nodeName)
124+
require.Equal(t, path, res.Stdout.Trimmed())
125+
})
126+
127+
t.Run("Kubo can provide IPNS record via Routing V1", func(t *testing.T) {
128+
t.Parallel()
129+
nodes := setupNodes(t)
130+
131+
// Publish something on Node 1 (no DHT).
132+
nodeName := "/ipns/" + ipns.NameFromPeer(nodes[1].PeerID()).String()
133+
path := "/ipfs/" + nodes[1].IPFSAddStr(testutils.RandomStr(1000))
134+
nodes[1].IPFS("name", "publish", "--allow-offline", path)
135+
136+
// Retrieve through Node 0.
137+
res := nodes[0].IPFS("routing", "get", nodeName)
138+
record, err := ipns.UnmarshalRecord(res.Stdout.Bytes())
139+
require.NoError(t, err)
140+
value, err := record.Value()
141+
require.NoError(t, err)
142+
require.Equal(t, path, value.String())
143+
})
144+
}

test/dependencies/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ replace github.com/ipfs/kubo => ../../
77
require (
88
github.com/Kubuxu/gocovmerge v0.0.0-20161216165753-7ecaa51963cd
99
github.com/golangci/golangci-lint v1.54.1
10-
github.com/ipfs/boxo v0.12.1-0.20230824094523-a2001ba61544
10+
github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff
1111
github.com/ipfs/go-cid v0.4.1
1212
github.com/ipfs/go-cidutil v0.1.0
1313
github.com/ipfs/go-datastore v0.6.0

test/dependencies/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
396396
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
397397
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
398398
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
399-
github.com/ipfs/boxo v0.12.1-0.20230824094523-a2001ba61544 h1:XVq+wUNFx1Ufakz35MAWk+Rr5bAC7lwx1NbJ6Mslp48=
400-
github.com/ipfs/boxo v0.12.1-0.20230824094523-a2001ba61544/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk=
399+
github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff h1:IpyDgsSCTbMcEqKVsbE8S73lV2e9V2J/Tr82zpYb/mg=
400+
github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk=
401401
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
402402
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
403403
github.com/ipfs/go-block-format v0.1.2 h1:GAjkfhVx1f4YTODS6Esrj1wt2HhrtwTnhEr+DyPUaJo=

0 commit comments

Comments
 (0)