fix(cmds): CIDv1 and correct multicodecs in 'block put' and 'cid codecs' (#8568)
BREAKING CHANGES: - see https://github.com/ipfs/go-ipfs/pull/8568#issue-1063653194 Co-authored-by: Marcin Rataj <lidel@lidel.org>
Lucas Molas committed
Apr 21, 2022 at 13:19 UTC
7b5fe809f0a88ab738f537e942313231cc771f7d
9 files changed
+204
-58
CHANGELOG.md
+17
@@ -1,5 +1,22 @@
1
# go-ipfs changelog
2
3
+## v0.13 (DRAFT)
4
+
5
+### BREAKING CHANGES
6
+
7
+- `ipfs block put` command produces CIDv1 with `raw` codec by default now
8
+ - `ipfs block put --cid-codec` makes `block put` return CID with alternative codec
9
+ - this impacts only the returned CID, it does not trigger any validation or data transformation
10
+ - codec names are validated against tables from https://github.com/multiformats/go-multicodec
11
+ - `ipfs block put --format` is deprecated. It used incorrect codec names and should be avoided for new deployments. Use it only if you need the old, invalid behavior, namely:
12
+ - `ipfs block put --format=v0` will produce CIDv0 (implicit dag-pb)
13
+ - `ipfs block put --format=cbor` will produce CIDv1 with dag-cbor (!)
14
+ - `ipfs block put --format=protobuf` will produce CIDv1 with dag-pb (!)
15
+- `ipfs cid codecs` command
16
+ - it now lists codecs from https://github.com/multiformats/go-multicodec
17
+ - `ipfs cid codecs --supported` can be passed to only show codecs supported in various go-ipfs commands
18
+
19
+
20
## v0.12.2 and v0.11.1 2022-04-08
21
22
This patch release fixes a security issue wherein traversing some malformed DAGs can cause the node to panic.
core/commands/block.go
+37
-25
@@ -31,8 +31,8 @@ var BlockCmd = &cmds.Command{
31
Tagline: "Interact with raw IPFS blocks.",
32
ShortDescription: `
33
'ipfs block' is a plumbing command used to manipulate raw IPFS blocks.
34
-Reads from stdin or writes to stdout, and <key> is a base58 encoded
35
-multihash.
34
+Reads from stdin or writes to stdout. A block is identified by a Multihash
35
+passed with a valid CID.
36
`,
37
},
38
@@ -51,14 +51,14 @@ var blockStatCmd = &cmds.Command{
51
'ipfs block stat' is a plumbing command for retrieving information
52
on raw IPFS blocks. It outputs the following to stdout:
53
54
- Key - the base58 encoded multihash
54
+ Key - the CID of the block
55
Size - the size of the block in bytes
56
57
`,
58
},
59
60
Arguments: []cmds.Argument{
61
- cmds.StringArg("key", true, false, "The base58 multihash of an existing block to stat.").EnableStdin(),
61
+ cmds.StringArg("cid", true, false, "The CID of an existing block to stat.").EnableStdin(),
62
},
63
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
64
api, err := cmdenv.GetApi(env, req)
@@ -90,12 +90,12 @@ var blockGetCmd = &cmds.Command{
90
Tagline: "Get a raw IPFS block.",
91
ShortDescription: `
92
'ipfs block get' is a plumbing command for retrieving raw IPFS blocks.
93
-It outputs to stdout, and <key> is a base58 encoded multihash.
93
+It takes a <cid>, and outputs the block to stdout.
94
`,
95
},
96
97
Arguments: []cmds.Argument{
98
- cmds.StringArg("key", true, false, "The base58 multihash of an existing block to get.").EnableStdin(),
98
+ cmds.StringArg("cid", true, false, "The CID of an existing block to get.").EnableStdin(),
99
},
100
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
101
api, err := cmdenv.GetApi(env, req)
@@ -113,9 +113,10 @@ It outputs to stdout, and <key> is a base58 encoded multihash.
113
}
114
115
const (
116
- blockFormatOptionName = "format"
117
- mhtypeOptionName = "mhtype"
118
- mhlenOptionName = "mhlen"
116
+ blockFormatOptionName = "format"
117
+ blockCidCodecOptionName = "cid-codec"
118
+ mhtypeOptionName = "mhtype"
119
+ mhlenOptionName = "mhlen"
120
)
121
122
var blockPutCmd = &cmds.Command{
@@ -123,10 +124,17 @@ var blockPutCmd = &cmds.Command{
124
Tagline: "Store input as an IPFS block.",
125
ShortDescription: `
126
'ipfs block put' is a plumbing command for storing raw IPFS blocks.
126
-It reads from stdin, and outputs the block's CID to stdout.
127
+It reads data from stdin, and outputs the block's CID to stdout.
128
128
-Unless specified, this command returns dag-pb CIDv0 CIDs. Setting 'mhtype' to anything
129
-other than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
129
+Unless cid-codec is specified, this command returns raw (0x55) CIDv1 CIDs.
130
+
131
+Passing alternative --cid-codec does not modify imported data, nor run any
132
+validation. It is provided solely for convenience for users who create blocks
133
+in userland.
134
+
135
+NOTE:
136
+Do not use --format for any new code. It got superseded by --cid-codec and left
137
+only for backward compatibility when a legacy CIDv0 is required (--format=v0).
138
`,
139
},
140
@@ -134,11 +142,12 @@ other than 'sha2-256' or format to anything other than 'v0' will result in CIDv1
142
cmds.FileArg("data", true, true, "The data to be stored as an IPFS block.").EnableStdin(),
143
},
144
Options: []cmds.Option{
137
- cmds.StringOption(blockFormatOptionName, "f", "cid format for blocks to be created with."),
138
- cmds.StringOption(mhtypeOptionName, "multihash hash function").WithDefault("sha2-256"),
139
- cmds.IntOption(mhlenOptionName, "multihash hash length").WithDefault(-1),
140
- cmds.BoolOption(pinOptionName, "pin added blocks recursively").WithDefault(false),
145
+ cmds.StringOption(blockCidCodecOptionName, "Multicodec to use in returned CID").WithDefault("raw"),
146
+ cmds.StringOption(mhtypeOptionName, "Multihash hash function").WithDefault("sha2-256"),
147
+ cmds.IntOption(mhlenOptionName, "Multihash hash length").WithDefault(-1),
148
+ cmds.BoolOption(pinOptionName, "Pin added blocks recursively").WithDefault(false),
149
cmdutils.AllowBigBlockOption,
150
+ cmds.StringOption(blockFormatOptionName, "f", "Use legacy format for returned CID (DEPRECATED)"),
151
},
152
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
153
api, err := cmdenv.GetApi(env, req)
@@ -157,13 +166,15 @@ other than 'sha2-256' or format to anything other than 'v0' will result in CIDv1
166
return errors.New("missing option \"mhlen\"")
167
}
168
160
- format, formatSet := req.Options[blockFormatOptionName].(string)
161
- if !formatSet {
162
- if mhtval != mh.SHA2_256 || (mhlen != -1 && mhlen != 32) {
163
- format = "protobuf"
164
- } else {
165
- format = "v0"
169
+ cidCodec, _ := req.Options[blockCidCodecOptionName].(string)
170
+ format, _ := req.Options[blockFormatOptionName].(string) // deprecated
171
+
172
+ // use of legacy 'format' needs to supress 'cid-codec'
173
+ if format != "" {
174
+ if cidCodec != "" && cidCodec != "raw" {
175
+ return fmt.Errorf("unable to use %q (deprecated) and a custom %q at the same time", blockFormatOptionName, blockCidCodecOptionName)
176
}
177
+ cidCodec = "" // makes it no-op
178
}
179
180
pin, _ := req.Options[pinOptionName].(bool)
@@ -177,6 +188,7 @@ other than 'sha2-256' or format to anything other than 'v0' will result in CIDv1
188
189
p, err := api.Block().Put(req.Context, file,
190
options.Block.Hash(mhtval, mhlen),
191
+ options.Block.CidCodec(cidCodec),
192
options.Block.Format(format),
193
options.Block.Pin(pin))
194
if err != nil {
@@ -219,14 +231,14 @@ type removedBlock struct {
231
232
var blockRmCmd = &cmds.Command{
233
Helptext: cmds.HelpText{
222
- Tagline: "Remove IPFS block(s).",
234
+ Tagline: "Remove IPFS block(s) from the local datastore.",
235
ShortDescription: `
236
'ipfs block rm' is a plumbing command for removing raw ipfs blocks.
225
-It takes a list of base58 encoded multihashes to remove.
237
+It takes a list of CIDs to remove from the local datastore..
238
`,
239
},
240
Arguments: []cmds.Argument{
229
- cmds.StringArg("hash", true, true, "Bash58 encoded multihash of block(s) to remove."),
241
+ cmds.StringArg("cid", true, true, "CIDs of block(s) to remove."),
242
},
243
Options: []cmds.Option{
244
cmds.BoolOption(forceOptionName, "f", "Ignore nonexistent blocks."),
core/commands/cid.go
+48
-12
@@ -11,7 +11,9 @@ import (
11
cidutil "github.com/ipfs/go-cidutil"
12
cmds "github.com/ipfs/go-ipfs-cmds"
13
verifcid "github.com/ipfs/go-verifcid"
14
+ "github.com/ipld/go-ipld-prime/multicodec"
15
mbase "github.com/multiformats/go-multibase"
16
+ mc "github.com/multiformats/go-multicodec"
17
mhash "github.com/multiformats/go-multihash"
18
)
19
@@ -46,7 +48,7 @@ The optional format string is a printf style format string:
48
` + cidutil.FormatRef,
49
},
50
Arguments: []cmds.Argument{
49
- cmds.StringArg("cid", true, true, "Cids to format.").EnableStdin(),
51
+ cmds.StringArg("cid", true, true, "CIDs to format.").EnableStdin(),
52
},
53
Options: []cmds.Option{
54
cmds.StringOption(cidFormatOptionName, "Printf style format string.").WithDefault("%s"),
@@ -63,14 +65,14 @@ The optional format string is a printf style format string:
65
opts := cidFormatOpts{}
66
67
if strings.IndexByte(fmtStr, '%') == -1 {
66
- return fmt.Errorf("invalid format string: %s", fmtStr)
68
+ return fmt.Errorf("invalid format string: %q", fmtStr)
69
}
70
opts.fmtStr = fmtStr
71
72
if codecStr != "" {
73
codec, ok := cid.Codecs[codecStr]
74
if !ok {
73
- return fmt.Errorf("unknown IPLD codec: %s", codecStr)
75
+ return fmt.Errorf("unknown IPLD codec: %q", codecStr)
76
}
77
opts.newCodec = codec
78
} // otherwise, leave it as 0 (not a valid IPLD codec)
@@ -80,13 +82,13 @@ The optional format string is a printf style format string:
82
// noop
83
case "0":
84
if opts.newCodec != 0 && opts.newCodec != cid.DagProtobuf {
83
- return fmt.Errorf("cannot convert to CIDv0 with any codec other than DagPB")
85
+ return fmt.Errorf("cannot convert to CIDv0 with any codec other than dag-pb")
86
}
87
opts.verConv = toCidV0
88
case "1":
89
opts.verConv = toCidV1
90
default:
89
- return fmt.Errorf("invalid cid version: %s", verStr)
91
+ return fmt.Errorf("invalid cid version: %q", verStr)
92
}
93
94
if baseStr != "" {
@@ -123,9 +125,13 @@ type CidFormatRes struct {
125
var base32Cmd = &cmds.Command{
126
Helptext: cmds.HelpText{
127
Tagline: "Convert CIDs to Base32 CID version 1.",
128
+ ShortDescription: `
129
+'ipfs cid base32' normalizes passes CIDs to their canonical case-insensitive encoding.
130
+Useful when processing third-party CIDs which could come with arbitrary formats.
131
+`,
132
},
133
Arguments: []cmds.Argument{
128
- cmds.StringArg("cid", true, true, "Cids to convert.").EnableStdin(),
134
+ cmds.StringArg("cid", true, true, "CIDs to convert.").EnableStdin(),
135
},
136
Run: func(req *cmds.Request, resp cmds.ResponseEmitter, env cmds.Environment) error {
137
opts := cidFormatOpts{
@@ -232,7 +238,7 @@ func emitCids(req *cmds.Request, resp cmds.ResponseEmitter, opts cidFormatOpts)
238
239
func toCidV0(c cid.Cid) (cid.Cid, error) {
240
if c.Type() != cid.DagProtobuf {
235
- return cid.Cid{}, fmt.Errorf("can't convert non-protobuf nodes to cidv0")
241
+ return cid.Cid{}, fmt.Errorf("can't convert non-dag-pb nodes to cidv0")
242
}
243
return cid.NewCidV0(c.Hash()), nil
244
}
@@ -254,6 +260,9 @@ const (
260
var basesCmd = &cmds.Command{
261
Helptext: cmds.HelpText{
262
Tagline: "List available multibase encodings.",
263
+ ShortDescription: `
264
+'ipfs cid bases' relies on https://github.com/multiformats/go-multibase
265
+`,
266
},
267
Options: []cmds.Option{
268
cmds.BoolOption(prefixOptionName, "also include the single letter prefixes in addition to the code"),
@@ -296,21 +305,45 @@ var basesCmd = &cmds.Command{
305
}
306
307
const (
299
- codecsNumericOptionName = "numeric"
308
+ codecsNumericOptionName = "numeric"
309
+ codecsSupportedOptionName = "supported"
310
)
311
312
var codecsCmd = &cmds.Command{
313
Helptext: cmds.HelpText{
314
Tagline: "List available CID codecs.",
315
+ ShortDescription: `
316
+'ipfs cid codecs' relies on https://github.com/multiformats/go-multicodec
317
+`,
318
},
319
Options: []cmds.Option{
307
- cmds.BoolOption(codecsNumericOptionName, "also include numeric codes"),
320
+ cmds.BoolOption(codecsNumericOptionName, "n", "also include numeric codes"),
321
+ cmds.BoolOption(codecsSupportedOptionName, "s", "list only codecs supported by go-ipfs commands"),
322
},
323
Run: func(req *cmds.Request, resp cmds.ResponseEmitter, env cmds.Environment) error {
324
+ listSupported, _ := req.Options[codecsSupportedOptionName].(bool)
325
+ supportedCodecs := make(map[uint64]struct{})
326
+ if listSupported {
327
+ for _, code := range multicodec.ListEncoders() {
328
+ supportedCodecs[code] = struct{}{}
329
+ }
330
+ for _, code := range multicodec.ListDecoders() {
331
+ supportedCodecs[code] = struct{}{}
332
+ }
333
+ // add libp2p-key
334
+ supportedCodecs[uint64(mc.Libp2pKey)] = struct{}{}
335
+ }
336
+
337
var res []CodeAndName
311
- // use CodecToStr as there are multiple names for a given code
312
- for code, name := range cid.CodecToStr {
313
- res = append(res, CodeAndName{int(code), name})
338
+ for _, code := range mc.KnownCodes() {
339
+ if code.Tag() == "ipld" {
340
+ if listSupported {
341
+ if _, ok := supportedCodecs[uint64(code)]; !ok {
342
+ continue
343
+ }
344
+ }
345
+ res = append(res, CodeAndName{int(code), mc.Code(code).String()})
346
+ }
347
}
348
return cmds.EmitOnce(resp, res)
349
},
@@ -334,6 +367,9 @@ var codecsCmd = &cmds.Command{
367
var hashesCmd = &cmds.Command{
368
Helptext: cmds.HelpText{
369
Tagline: "List available multihashes.",
370
+ ShortDescription: `
371
+'ipfs cid hashes' relies on https://github.com/multiformats/go-multihash
372
+`,
373
},
374
Options: codecsCmd.Options,
375
Run: func(req *cmds.Request, resp cmds.ResponseEmitter, env cmds.Environment) error {
core/coreapi/block.go
+2
-2
@@ -31,7 +31,7 @@ func (api *BlockAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Bloc
31
ctx, span := tracing.Span(ctx, "CoreAPI.BlockAPI", "Put")
32
defer span.End()
33
34
- settings, pref, err := caopts.BlockPutOptions(opts...)
34
+ settings, err := caopts.BlockPutOptions(opts...)
35
if err != nil {
36
return nil, err
37
}
@@ -41,7 +41,7 @@ func (api *BlockAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Bloc
41
return nil, err
42
}
43
44
- bcid, err := pref.Sum(data)
44
+ bcid, err := settings.CidPrefix.Sum(data)
45
if err != nil {
46
return nil, err
47
}
go.mod
+2
-2
@@ -57,7 +57,7 @@ require (
57
github.com/ipfs/go-unixfs v0.3.1
58
github.com/ipfs/go-unixfsnode v1.1.3
59
github.com/ipfs/go-verifcid v0.0.1
60
- github.com/ipfs/interface-go-ipfs-core v0.6.2
60
+ github.com/ipfs/interface-go-ipfs-core v0.7.0
61
github.com/ipfs/tar-utils v0.0.2
62
github.com/ipld/go-car v0.3.2
63
github.com/ipld/go-car/v2 v2.1.1
@@ -96,7 +96,7 @@ require (
96
github.com/multiformats/go-multiaddr v0.5.0
97
github.com/multiformats/go-multiaddr-dns v0.3.1
98
github.com/multiformats/go-multibase v0.0.3
99
- github.com/multiformats/go-multicodec v0.4.0
99
+ github.com/multiformats/go-multicodec v0.4.1
100
github.com/multiformats/go-multihash v0.1.0
101
github.com/opentracing/opentracing-go v1.2.0
102
github.com/pkg/errors v0.9.1
go.sum
+4
-4
@@ -605,8 +605,8 @@ github.com/ipfs/go-unixfsnode v1.1.3/go.mod h1:ZZxUM5wXBC+G0Co9FjrYTOm+UlhZTjxLf
605
github.com/ipfs/go-verifcid v0.0.1 h1:m2HI7zIuR5TFyQ1b79Da5N9dnnCP1vcu2QqawmWlK2E=
606
github.com/ipfs/go-verifcid v0.0.1/go.mod h1:5Hrva5KBeIog4A+UpqlaIU+DEstipcJYQQZc0g37pY0=
607
github.com/ipfs/interface-go-ipfs-core v0.4.0/go.mod h1:UJBcU6iNennuI05amq3FQ7g0JHUkibHFAfhfUIy927o=
608
-github.com/ipfs/interface-go-ipfs-core v0.6.2 h1:nnkq9zhb5O8lPzkZeynEymc83RqkTRqfYH4x5JNUkT4=
609
-github.com/ipfs/interface-go-ipfs-core v0.6.2/go.mod h1:h3NuO3wzv2KuKazt0zDF2/i8AFRqiKHusyh5DUQQdPA=
608
+github.com/ipfs/interface-go-ipfs-core v0.7.0 h1:7tb+2upz8oCcjIyjo1atdMk+P+u7wPmI+GksBlLE8js=
609
+github.com/ipfs/interface-go-ipfs-core v0.7.0/go.mod h1:lF27E/nnSPbylPqKVXGZghal2hzifs3MmjyiEjnc9FY=
610
github.com/ipfs/tar-utils v0.0.2 h1:UNgHB4x/PPzbMkmJi+7EqC9LNMPDztOVSnx1HAqSNg4=
611
github.com/ipfs/tar-utils v0.0.2/go.mod h1:4qlnRWgTVljIMhSG2SqRYn66NT+3wrv/kZt9V+eqxDM=
612
github.com/ipld/go-car v0.3.2 h1:V9wt/80FNfbMRWSD98W5br6fyjUAyVgI2lDOTZX16Lg=
@@ -1188,8 +1188,8 @@ github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPw
1188
github.com/multiformats/go-multicodec v0.2.0/go.mod h1:/y4YVwkfMyry5kFbMTbLJKErhycTIftytRV+llXdyS4=
1189
github.com/multiformats/go-multicodec v0.3.0/go.mod h1:qGGaQmioCDh+TeFOnxrbU0DaIPw8yFgAZgFG0V7p1qQ=
1190
github.com/multiformats/go-multicodec v0.3.1-0.20210902112759-1539a079fd61/go.mod h1:1Hj/eHRaVWSXiSNNfcEPcwZleTmdNP81xlxDLnWU9GQ=
1191
-github.com/multiformats/go-multicodec v0.4.0 h1:fbqb6ky7erjdD+/zaEBJgZWu1i8D6i/wmPywGK7sdow=
1192
-github.com/multiformats/go-multicodec v0.4.0/go.mod h1:1Hj/eHRaVWSXiSNNfcEPcwZleTmdNP81xlxDLnWU9GQ=
1191
+github.com/multiformats/go-multicodec v0.4.1 h1:BSJbf+zpghcZMZrwTYBGwy0CPcVZGWiC72Cp8bBd4R4=
1192
+github.com/multiformats/go-multicodec v0.4.1/go.mod h1:1Hj/eHRaVWSXiSNNfcEPcwZleTmdNP81xlxDLnWU9GQ=
1193
github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=
1194
github.com/multiformats/go-multihash v0.0.5/go.mod h1:lt/HCbqlQwlPBz7lv0sQCdtfcMtlJvakRUn/0Ual8po=
1195
github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
test/sharness/t0050-block.sh
+50
-8
@@ -10,16 +10,18 @@ test_description="Test block command"
10
11
test_init_ipfs
12
13
-HASH="QmRKqGMAM6EZngbpjSqrvYzq5Qd8b1bSWymjSUY9zQSNDk"
14
-HASHB="QmdnpnsaEj69isdw5sNzp3h3HkaDz7xKq7BmvFFBzNr5e7"
13
+HASH="bafkreibmlvvgdyihetgocpof6xk64kjjzdeq2e4c7hqs3krdheosk4tgj4"
14
+HASHB="bafkreihfsphazrk2ilejpekyltjeh5k4yvwgjuwg26ueafohqioeo3sdca"
15
+
16
+HASHV0="QmRKqGMAM6EZngbpjSqrvYzq5Qd8b1bSWymjSUY9zQSNDk"
17
+HASHBV0="QmdnpnsaEj69isdw5sNzp3h3HkaDz7xKq7BmvFFBzNr5e7"
18
16
-#
19
# "block put tests"
20
#
21
22
test_expect_success "'ipfs block put' succeeds" '
23
echo "Hello Mars!" >expected_in &&
22
- ipfs block put <expected_in >actual_out
24
+ ipfs block put <expected_in | tee actual_out
25
'
26
27
test_expect_success "'ipfs block put' output looks good" '
@@ -30,7 +32,7 @@ test_expect_success "'ipfs block put' output looks good" '
32
test_expect_success "'ipfs block put' with 2 files succeeds" '
33
echo "Hello Mars!" > a &&
34
echo "Hello Venus!" > b &&
33
- ipfs block put a b >actual_out
35
+ ipfs block put a b | tee actual_out
36
'
37
38
test_expect_success "'ipfs block put' output looks good" '
@@ -39,6 +41,15 @@ test_expect_success "'ipfs block put' output looks good" '
41
test_cmp expected_out actual_out
42
'
43
44
+test_expect_success "can set cid codec on block put" '
45
+ CODEC_HASH=$(ipfs block put --cid-codec=dag-pb ../t0051-object-data/testPut.pb)
46
+'
47
+
48
+test_expect_success "block get output looks right" '
49
+ ipfs block get $CODEC_HASH > pb_block_out &&
50
+ test_cmp pb_block_out ../t0051-object-data/testPut.pb
51
+'
52
+
53
#
54
# "block get" tests
55
#
@@ -196,7 +207,9 @@ test_expect_success "multi-block 'ipfs block rm -q' produces no output" '
207
test ! -s block_rm_out
208
'
209
199
-test_expect_success "can set cid format on block put" '
210
+# --format used 'protobuf' for 'dag-pb' which was invalid, but we keep
211
+# for backward-compatibility
212
+test_expect_success "can set deprecated --format=protobuf on block put" '
213
HASH=$(ipfs block put --format=protobuf ../t0051-object-data/testPut.pb)
214
'
215
@@ -211,7 +224,22 @@ test_expect_success "block get output looks right" '
224
test_cmp pb_block_out ../t0051-object-data/testPut.pb
225
'
226
214
-test_expect_success "can set multihash type and length on block put" '
227
+test_expect_success "can set --cid-codec=dag-pb on block put" '
228
+ HASH=$(ipfs block put --cid-codec=dag-pb ../t0051-object-data/testPut.pb)
229
+'
230
+
231
+test_expect_success "created an object correctly!" '
232
+ ipfs object get $HASH > obj_out &&
233
+ echo "{\"Links\":[],\"Data\":\"test json for sharness test\"}" > obj_exp &&
234
+ test_cmp obj_out obj_exp
235
+'
236
+
237
+test_expect_success "block get output looks right" '
238
+ ipfs block get $HASH > pb_block_out &&
239
+ test_cmp pb_block_out ../t0051-object-data/testPut.pb
240
+'
241
+
242
+test_expect_success "can set multihash type and length on block put with --format=raw (deprecated)" '
243
HASH=$(echo "foooo" | ipfs block put --format=raw --mhtype=sha3 --mhlen=20)
244
'
245
@@ -219,6 +247,11 @@ test_expect_success "output looks good" '
247
test "bafkrifctrq4xazzixy2v4ezymjcvzpskqdwlxra" = "$HASH"
248
'
249
250
+test_expect_success "can't use both legacy format and custom cid-codec at the same time" '
251
+ test_expect_code 1 ipfs block put --format=dag-cbor --cid-codec=dag-json < ../t0051-object-data/testPut.pb 2> output &&
252
+ test_should_contain "unable to use \"format\" (deprecated) and a custom \"cid-codec\" at the same time" output
253
+'
254
+
255
test_expect_success "can read block with different hash" '
256
ipfs block get $HASH > blk_get_out &&
257
echo "foooo" > blk_get_exp &&
@@ -232,14 +265,23 @@ test_expect_success "'ipfs block stat' with nothing from stdin doesn't crash" '
265
test_expect_code 1 ipfs block stat < /dev/null 2> stat_out
266
'
267
268
+# lol
269
test_expect_success "no panic in output" '
270
test_expect_code 1 grep "panic" stat_out
271
'
272
239
-test_expect_success "can set multihash type and length on block put without format" '
273
+test_expect_success "can set multihash type and length on block put without format or cid-codec" '
274
HASH=$(echo "foooo" | ipfs block put --mhtype=sha3 --mhlen=20)
275
'
276
277
+test_expect_success "output looks good" '
278
+ test "bafkrifctrq4xazzixy2v4ezymjcvzpskqdwlxra" = "$HASH"
279
+'
280
+
281
+test_expect_success "can set multihash type and length on block put with cid-codec=dag-pb" '
282
+ HASH=$(echo "foooo" | ipfs block put --mhtype=sha3 --mhlen=20 --cid-codec=dag-pb)
283
+'
284
+
285
test_expect_success "output looks good" '
286
test "bafybifctrq4xazzixy2v4ezymjcvzpskqdwlxra" = "$HASH"
287
'
test/sharness/t0110-gateway.sh
+1
-1
@@ -262,7 +262,7 @@ test_expect_success "try fetching it from gateway" '
262
263
test_expect_success "Add compact blocks" '
264
ipfs block put ../t0110-gateway-data/foo.block &&
265
- FOO2_HASH=$(ipfs block put ../t0110-gateway-data/foofoo.block) &&
265
+ FOO2_HASH=$(ipfs block put --cid-codec=dag-pb ../t0110-gateway-data/foofoo.block) &&
266
printf "foofoo" > expected
267
'
268
test/sharness/t0290-cid.sh
+43
-4
@@ -103,11 +103,19 @@ Z 90 base58flickr
103
EOF
104
105
cat <<EOF > codecs_expect
106
+ 81 cbor
107
85 raw
107
- 112 protobuf
108
- 113 cbor
108
+ 112 dag-pb
109
+ 113 dag-cbor
110
+ 114 libp2p-key
111
120 git-raw
112
+ 123 torrent-info
113
+ 124 torrent-file
114
+ 129 leofcoin-block
115
+ 130 leofcoin-tx
116
+ 131 leofcoin-pr
117
133 dag-jose
118
+ 134 dag-cose
119
144 eth-block
120
145 eth-block-list
121
146 eth-tx-trie
@@ -117,16 +125,36 @@ cat <<EOF > codecs_expect
125
150 eth-state-trie
126
151 eth-account-snapshot
127
152 eth-storage-trie
128
+ 153 eth-receipt-log-trie
129
+ 154 eth-reciept-log
130
176 bitcoin-block
131
177 bitcoin-tx
132
+ 178 bitcoin-witness-commitment
133
192 zcash-block
134
193 zcash-tx
135
+ 208 stellar-block
136
+ 209 stellar-tx
137
224 decred-block
138
225 decred-tx
139
240 dash-block
140
241 dash-tx
128
-61697 fil-commitment-unsealed
129
-61698 fil-commitment-sealed
141
+ 250 swarm-manifest
142
+ 251 swarm-feed
143
+ 297 dag-json
144
+ 496 swhid-1-snp
145
+ 512 json
146
+EOF
147
+
148
+cat <<EOF > supported_codecs_expect
149
+ 81 cbor
150
+ 85 raw
151
+ 112 dag-pb
152
+ 113 dag-cbor
153
+ 114 libp2p-key
154
+ 120 git-raw
155
+ 133 dag-jose
156
+ 297 dag-json
157
+ 512 json
158
EOF
159
160
cat <<EOF > hashes_expect
@@ -232,6 +260,17 @@ test_expect_success "cid codecs --numeric" '
260
test_cmp codecs_expect actual
261
'
262
263
+test_expect_success "cid codecs --supported" '
264
+ cut -c 8- supported_codecs_expect > expect &&
265
+ ipfs cid codecs --supported > actual
266
+ test_cmp expect actual
267
+'
268
+
269
+test_expect_success "cid codecs --supported --numeric" '
270
+ ipfs cid codecs --supported --numeric > actual &&
271
+ test_cmp supported_codecs_expect actual
272
+'
273
+
274
test_expect_success "cid hashes" '
275
cut -c 8- hashes_expect > expect &&
276
ipfs cid hashes > actual