fixes to routing put command (#10205)
* fix(commands): routing put command returns the IPNS ID rather than the host's ID * fix(commands): routing put command errors with the allow-offline hint if the error is an offline error * fix: test expects correct error message --------- Co-authored-by: Henrique Dias <hacdias@gmail.com>
Adin Schmahmann committed
Nov 8, 2023 at 01:07 UTC
9371d18b5325030807abc1c064efc36055205cf3
3 files changed
+6
-5
core/commands/routing.go
+4
-3
@@ -14,6 +14,7 @@ import (
14
iface "github.com/ipfs/boxo/coreiface"
15
"github.com/ipfs/boxo/coreiface/options"
16
dag "github.com/ipfs/boxo/ipld/merkledag"
17
+ "github.com/ipfs/boxo/ipns"
18
cid "github.com/ipfs/go-cid"
19
cmds "github.com/ipfs/go-ipfs-cmds"
20
ipld "github.com/ipfs/go-ipld-format"
@@ -451,12 +452,12 @@ identified by QmFoo.
452
options.Put.AllowOffline(allowOffline),
453
}
454
454
- err = api.Routing().Put(req.Context, req.Arguments[0], data, opts...)
455
+ ipnsName, err := ipns.NameFromString(req.Arguments[0])
456
if err != nil {
457
return err
458
}
459
459
- id, err := api.Key().Self(req.Context)
460
+ err = api.Routing().Put(req.Context, req.Arguments[0], data, opts...)
461
if err != nil {
462
if err == iface.ErrOffline {
463
err = errAllowOffline
@@ -466,7 +467,7 @@ identified by QmFoo.
467
468
return res.Emit(routing.QueryEvent{
469
Type: routing.Value,
469
- ID: id.ID(),
470
+ ID: ipnsName.Peer(),
471
})
472
},
473
Encoders: cmds.EncoderMap{
test/cli/dht_legacy_test.go
+1
-1
@@ -131,7 +131,7 @@ func TestLegacyDHT(t *testing.T) {
131
node.WriteBytes("foo", []byte("foo"))
132
res := node.RunIPFS("dht", "put", "/ipns/"+node.PeerID().String(), "foo")
133
assert.Equal(t, 1, res.ExitCode())
134
- assert.Contains(t, res.Stderr.String(), "this action must be run in online mode")
134
+ assert.Contains(t, res.Stderr.String(), "can't put while offline: pass `--allow-offline` to override")
135
})
136
})
137
}
test/cli/routing_dht_test.go
+1
-1
@@ -111,7 +111,7 @@ func testRoutingDHT(t *testing.T, enablePubsub bool) {
111
node.WriteBytes("foo", []byte("foo"))
112
res := node.RunIPFS("routing", "put", "/ipns/"+node.PeerID().String(), "foo")
113
assert.Equal(t, 1, res.ExitCode())
114
- assert.Contains(t, res.Stderr.String(), "this action must be run in online mode")
114
+ assert.Contains(t, res.Stderr.String(), "can't put while offline: pass `--allow-offline` to override")
115
})
116
})
117
})