master
sh 81 lines 2.95 KB
Raw
1 #!/usr/bin/env bash
2 #
3 # Copyright (c) 2020 Claudia Richoux
4 # MIT Licensed; see the LICENSE file in this repository.
5 #
6
7 test_description="Test blake3 mhash support"
8
9 . lib/test-lib.sh
10
11 test_init_ipfs
12
13 # the blake3 hash of "foo\n" in UTF8 (which is what comes out of echo when you pipe into `ipfs`) starts with "49dc870df1de7fd60794cebce449f5ccdae575affaa67a24b62acb03e039db92"
14 # without the newline it's "04e0bb39f30b1a3feb89f536c93be15055482df748674b00d26e5a75777702e9". so if you start seeing these values that's your problem
15 BLAKE3RAWCID32BYTE="bafkr4icj3sdq34o6p7lapfgoxtset5om3lsxll72uz5cjnrkzmb6aoo3si"
16 BLAKE3RAWCID64BYTE="bafkr4qcj3sdq34o6p7lapfgoxtset5om3lsxll72uz5cjnrkzmb6aoo3sknmbprpe27pbfrb67tonydgfot5ixuq4skiva76ppbgpjlzc4ua4"
17 BLAKE3RAWCID128BYTE="bafkr5aabjhoiodpr3z75mb4uz26oispvztnok5np7kthujfwflfqhybz3ojjvqf6f4tl54eweh36nzxamyv2pvc6sdsjjcud7z54ez5fpelsqdtax2k3rvuq3wdl5a4blxv3gvsroa3nakfzzknamhu2apf3vvytyiobabrn2bfnfajq66ikjy5lewsp5jyddsg5l7u3emr2ancimryay"
18
19 ### block tests, including for various sizes of hash ###
20
21 test_expect_success "putting a block with an mhash blake3 succeeds (default 32 bytes)" '
22 HASH=$(echo "foo" | ipfs block put --mhtype=blake3 --cid-codec=raw | tee actual_out) &&
23 test $BLAKE3RAWCID32BYTE = "$HASH"
24 '
25
26 test_expect_success "block get output looks right" '
27 ipfs block get $BLAKE3RAWCID32BYTE > blk_get_out &&
28 echo "foo" > blk_get_exp &&
29 test_cmp blk_get_exp blk_get_out
30 '
31
32 test_expect_success "putting a block with an mhash blake3 succeeds: 64 bytes" '
33 HASH=$(echo "foo" | ipfs block put --mhtype=blake3 --mhlen=64 --cid-codec=raw | tee actual_out) &&
34 test $BLAKE3RAWCID64BYTE = "$HASH"
35 '
36
37 test_expect_success "64B block get output looks right" '
38 ipfs block get $BLAKE3RAWCID64BYTE > blk_get_out &&
39 echo "foo" > blk_get_exp &&
40 test_cmp blk_get_exp blk_get_out
41 '
42
43 test_expect_success "putting a block with an mhash blake3 succeeds: 128 bytes" '
44 HASH=$(echo "foo" | ipfs block put --mhtype=blake3 --mhlen=128 --cid-codec=raw | tee actual_out) &&
45 test $BLAKE3RAWCID128BYTE = "$HASH"
46 '
47
48 test_expect_success "32B block get output looks right" '
49 ipfs block get $BLAKE3RAWCID128BYTE > blk_get_out &&
50 echo "foo" > blk_get_exp &&
51 test_cmp blk_get_exp blk_get_out
52 '
53
54 ### dag tests ###
55
56 test_expect_success "dag put works with blake3" '
57 HASH=$(echo "foo" | ipfs dag put --input-codec=raw --store-codec=raw --hash=blake3 | tee actual_out) &&
58 test $BLAKE3RAWCID32BYTE = "$HASH"
59 '
60
61 test_expect_success "dag get output looks right" '
62 ipfs dag get --output-codec=raw $BLAKE3RAWCID32BYTE > dag_get_out &&
63 echo "foo" > dag_get_exp &&
64 test_cmp dag_get_exp dag_get_out
65 '
66
67 ### add and cat tests ###
68
69 test_expect_success "adding a file with just foo in it to ipfs" '
70 echo "foo" > afile &&
71 HASH=$(ipfs add -q --hash=blake3 --raw-leaves afile | tee actual_out) &&
72 test $BLAKE3RAWCID32BYTE = "$HASH"
73 '
74
75 test_expect_success "catting it" '
76 ipfs cat $BLAKE3RAWCID32BYTE > cat_out &&
77 echo "foo" > cat_exp &&
78 test_cmp cat_exp cat_out
79 '
80
81 test_done