-
Notifications
You must be signed in to change notification settings - Fork 951
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BE-776 Fix calculation of block hash (#141)
Also added test for validating hash chain Signed-off-by: Atsushi Neki <atsushin@fast.au.fujitsu.com>
- Loading branch information
Showing
3 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
|
||
channel=commonchannel | ||
while getopts "c:" opt; do | ||
case "$opt" in | ||
c) | ||
channel=$OPTARG | ||
;; | ||
esac | ||
done | ||
|
||
docker exec explorerdb.mynetwork.com \ | ||
psql -t -U postgres fabricexplorer -c \ | ||
"select array_to_json(array_agg(row_to_json(t))) | ||
from ( | ||
select blocks.blocknum, blocks.prehash, blocks.blockhash from blocks | ||
join channel on blocks.channel_genesis_hash = channel.channel_genesis_hash | ||
where channel.name='${channel}' | ||
order by blocknum | ||
) t" > result.json | ||
|
||
length=$(jq 'length' result.json) | ||
i=0 | ||
while [ $i -lt $(expr $length - 1) ]; do | ||
current=$i | ||
i=$(expr $i + 1) | ||
next=$i | ||
bh=$(jq '.['$current'].blockhash' result.json) | ||
ph=$(jq '.['$next'].prehash' result.json) | ||
echo $bh | ||
echo $ph | ||
if [ $bh != $ph ]; then | ||
echo "FAIL... Invalid blockhash chain : $(jq '.['$current'].blocknum' result.json)" | ||
exit 1 | ||
fi | ||
done | ||
|
||
echo 'PASS!!! Valid blockhash chain' | ||
exit 0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters