| 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright (c) Jakub Sztandera |
| 4 | # MIT Licensed; see the LICENSE file in this repository. |
| 5 | # |
| 6 | |
| 7 | test_description="Test ipfs blockstore repo read check." |
| 8 | |
| 9 | . lib/test-lib.sh |
| 10 | |
| 11 | rm -rf "$IPF_PATH/*" |
| 12 | |
| 13 | test_init_ipfs |
| 14 | |
| 15 | |
| 16 | H_BLOCK1=$(echo "Block 1" | ipfs add -q) |
| 17 | H_BLOCK2=$(echo "Block 2" | ipfs add -q) |
| 18 | |
| 19 | BS_BLOCK1="XZ/CIQPDDQH5PDJTF4QSNMPFC45FQZH5MBSWCX2W254P7L7HGNHW5MQXZA.data" |
| 20 | BS_BLOCK2="CK/CIQNYWBOKHY7TCY7FUOBXKVJ66YRMARDT3KC7PPY6UWWPZR4YA67CKQ.data" |
| 21 | |
| 22 | |
| 23 | test_expect_success 'blocks are swapped' ' |
| 24 | ipfs cat $H_BLOCK2 > noswap && |
| 25 | cp -f "$IPFS_PATH/blocks/$BS_BLOCK1" "$IPFS_PATH/blocks/$BS_BLOCK2" && |
| 26 | ipfs cat $H_BLOCK2 > swap && |
| 27 | test_must_fail test_cmp noswap swap |
| 28 | ' |
| 29 | |
| 30 | ipfs config --bool Datastore.HashOnRead true |
| 31 | |
| 32 | test_check_bad_blocks() { |
| 33 | test_expect_success 'getting modified block fails' ' |
| 34 | (test_must_fail ipfs cat $H_BLOCK2 2> err_msg) && |
| 35 | grep "block in storage has different hash than requested" err_msg |
| 36 | ' |
| 37 | |
| 38 | test_expect_success "block shows up in repo verify" ' |
| 39 | test_expect_code 1 ipfs repo verify | cid-fmt --filter -b base32 "%M" > verify_out && |
| 40 | H_BLOCK2_MH=`cid-fmt -b base32 "%M" $H_BLOCK2` && |
| 41 | grep "$H_BLOCK2_MH" verify_out |
| 42 | ' |
| 43 | } |
| 44 | |
| 45 | test_check_bad_blocks |
| 46 | |
| 47 | test_expect_success "can add and cat a raw-leaf file" ' |
| 48 | HASH=$(echo "stuff" | ipfs add -q --raw-leaves) && |
| 49 | ipfs cat $HASH > /dev/null |
| 50 | ' |
| 51 | |
| 52 | test_launch_ipfs_daemon |
| 53 | test_check_bad_blocks |
| 54 | test_kill_ipfs_daemon |
| 55 | |
| 56 | test_done |