Raw multihashes: fix some sharness tests

This fixes some tests which expect "refs local" and "repo gc" outputs to match
the CIDs produced when adding data. These operations are now outputting CIDv1-raw
hashes, regardless of the original CIDs used to address those blocks, so some tests
fail.

The fix is usually:

* To use "block stat" to check if a block was correctly gc'ed
* To convert the CIDs to multihash (using cid-fmt) and compare those instead
This commit is contained in:
Hector Sanjuan 2020-03-09 17:58:59 +01:00 committed by Adin Schmahmann
parent 8d2d9185fb
commit 4ac3ed3ebd
4 changed files with 42 additions and 33 deletions

View File

@ -109,17 +109,25 @@ test_expect_success "remove direct pin" '
'
test_expect_success "'ipfs repo gc' removes file" '
ipfs repo gc >actual7 &&
grep "removed $HASH" actual7
ipfs block stat $HASH &&
ipfs repo gc &&
test_must_fail ipfs block stat $HASH
'
# Convert all to a base32-multihash as refs local outputs cidv1 raw
# Technically converting refs local output would suffice, but this is more
# future proof if we ever switch to adding the files with cid-version 1.
test_expect_success "'ipfs refs local' no longer shows file" '
EMPTY_DIR=QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn &&
ipfs refs local >actual8 &&
grep "QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y" actual8 &&
grep "$EMPTY_DIR" actual8 &&
grep "$HASH_WELCOME_DOCS" actual8 &&
test_must_fail grep "$HASH" actual8
HASH_MH=`cid-fmt -b base32 "%M" "$HASH"` &&
HARDCODED_HASH_MH=`cid-fmt -b base32 "%M" "QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y"` &&
EMPTY_DIR_MH=`cid-fmt -b base32 "%M" "$EMPTY_DIR"` &&
HASH_WELCOME_DOCS_MH=`cid-fmt -b base32 "%M" "$HASH_WELCOME_DOCS"` &&
ipfs refs local | cid-fmt -b base32 --filter "%M" >actual8 &&
grep "$HARDCODED_HASH_MH" actual8 &&
grep "$EMPTY_DIR_MH" actual8 &&
grep "$HASH_WELCOME_DOCS_MH" actual8 &&
test_must_fail grep "$HASH_MH" actual8
'
test_expect_success "adding multiblock random file succeeds" '

View File

@ -207,11 +207,10 @@ test_expect_success "pin lists look good" '
'
test_expect_success "'ipfs repo gc' succeeds" '
ipfs repo gc >gc_out_actual2 &&
echo "removed $HASH_FILE3" > gc_out_exp2 &&
echo "removed $HASH_FILE5" >> gc_out_exp2 &&
echo "removed $HASH_DIR3" >> gc_out_exp2 &&
test_includes_lines gc_out_exp2 gc_out_actual2
ipfs repo gc &&
test_must_fail ipfs block stat $HASH_FILE3 &&
test_must_fail ipfs block stat $HASH_FILE5 &&
test_must_fail ipfs block stat $HASH_DIR3
'
# use object links for HASH_DIR1 here because its children

View File

@ -13,27 +13,27 @@ test_gc_robust_part1() {
test_expect_success "add a 1MB file with --raw-leaves" '
random 1048576 56 > afile &&
HASH1=`ipfs add --raw-leaves -q afile`
HASH1=`ipfs add --raw-leaves -q --cid-version 1 afile` &&
REFS=`ipfs refs -r $HASH1` &&
read LEAF1 LEAF2 LEAF3 LEAF4 < <(echo $REFS)
'
HASH1FILE=.ipfs/blocks/L3/CIQNIPL4GP62ZMNNSLZ2G33Z3T5VAN3YHCJTGT5FG45XWH5FGZRXL3A.data
LEAF1=bafkreibkrcw7hf6nhr6dvwecqxc5rqc7u7pkhkti53byyznqp23dk5fc2y
LEAF1FILE=.ipfs/blocks/C2/AFKREIBKRCW7HF6NHR6DVWECQXC5RQC7U7PKHKTI53BYYZNQP23DK5FC2Y.data
LEAF2=bafkreidfsuir43gjphndxxqa45gjvnrzbet3crpumyjcblk3rtn7zamq6q
LEAF2FILE=.ipfs/blocks/Q6/BAFKREIDFSUIR43GJPHNDXXQA45GJVNRZBET3CRPUMYJCBLK3RTN7ZAMQ6Q
LEAF3=bafkreihsipwnaj3mrc5plg24lpy6dw2bpixl2pe5iapzvc6ct2n33uhqjm
LEAF4=bafkreihrzs3rh4yxel4olv54vxettu5hv6wxy3krh6huzwhjub7kusnen4
test_expect_success "find data blocks for added file" '
HASH1MH=`cid-fmt -b base32 "%M" $HASH1` &&
LEAF1MH=`cid-fmt -b base32 "%M" $LEAF1` &&
LEAF2MH=`cid-fmt -b base32 "%M" $LEAF2` &&
HASH1FILE=`find .ipfs/blocks -type f | grep -i $HASH1MH` &&
LEAF1FILE=`find .ipfs/blocks -type f | grep -i $LEAF1MH` &&
LEAF2FILE=`find .ipfs/blocks -type f | grep -i $LEAF2MH`
'
test_expect_success "remove a leaf node from the repo manually" '
rm "$LEAF1FILE"
'
test_expect_success "check that the node is removed" '
test_must_fail ipfs cat $HASH1
'
test_expect_success "check that the node is removed" '
test_must_fail ipfs cat $HASH1
'
test_expect_success "'ipfs repo gc' should still be fine" '
ipfs repo gc
@ -69,12 +69,14 @@ test_gc_robust_part1() {
grep -q "permission denied" block_rm_err
'
# repo gc outputs raw multihashes. We chech HASH1 with block stat rather than
# grepping the output since it's not a raw multihash
test_expect_success "'ipfs repo gc' should still run and remove as much as possible" '
test_must_fail ipfs repo gc 2>&1 | tee repo_gc_out &&
grep -q "removed $HASH1" repo_gc_out &&
grep -q "could not remove $LEAF2" repo_gc_out &&
grep -q "removed $LEAF3" repo_gc_out &&
grep -q "removed $LEAF4" repo_gc_out
grep -q "removed $LEAF4" repo_gc_out &&
test_must_fail ipfs block stat $HASH1
'
test_expect_success "fix the permission problem" '
@ -155,12 +157,12 @@ test_gc_robust_part2() {
test_init_ipfs
test_gc_robust_part1
test_gc_robust_part2
#test_gc_robust_part2
test_launch_ipfs_daemon_without_network
test_gc_robust_part1
test_gc_robust_part2
#test_gc_robust_part2
test_kill_ipfs_daemon

View File

@ -34,11 +34,11 @@ test_expect_success "check hashes" '
'
test_expect_success "make sure CIDv1 hash really is in the repo" '
ipfs refs local | grep -q $AHASHv1
ipfs block stat $AHASHv1
'
test_expect_success "make sure CIDv0 hash really is in the repo" '
ipfs refs local | grep -q $AHASHv0
ipfs block stat $AHASHv0
'
test_expect_success "run gc" '
@ -46,7 +46,7 @@ test_expect_success "run gc" '
'
test_expect_success "make sure the CIDv0 hash is in the repo" '
ipfs refs local | grep -q $AHASHv0
ipfs block stat $AHASHv0
'
test_expect_success "make sure we can get CIDv0 added file" '