set -e
source common.sh

fork_version=$1


echo "-- deploy --"

deploy ../contract/vm_dummy/test_files/feature_crypto_verify_proof.lua

get_receipt $txhash

status=$(cat receipt.json | jq .status | sed 's/"//g')
address=$(cat receipt.json | jq .contractAddress | sed 's/"//g')

assert_equals "$status" "CREATED"


echo "-- call 1 --"

txhash=$(../bin/aergocli --keystore . --password bmttest \
  contract call AmPpcKvToDCUkhT1FJjdbNvR4kNDhLFJGHkSqfjWe3QmHm96qv4R \
  $address verifyProofRaw "[]" | jq .hash | sed 's/"//g')

get_receipt $txhash

status=$(cat receipt.json | jq .status | sed 's/"//g')
ret=$(cat receipt.json | jq .ret | sed 's/"//g')
gasUsed=$(cat receipt.json | jq .gasUsed | sed 's/"//g')

assert_equals "$status"   "SUCCESS"
#assert_equals "$ret"      ""

if [ "$consensus" = "raft" ]; then
  assert_equals "$gasUsed"  "0"
elif [ "$fork_version" -ge "4" ]; then
  assert_equals "$gasUsed"  "160281"
else
  assert_equals "$gasUsed"  "154137"
fi


echo "-- call 2 --"

txhash=$(../bin/aergocli --keystore . --password bmttest \
  contract call AmPpcKvToDCUkhT1FJjdbNvR4kNDhLFJGHkSqfjWe3QmHm96qv4R \
  $address verifyProofHex "[]" | jq .hash | sed 's/"//g')

get_receipt $txhash

status=$(cat receipt.json | jq .status | sed 's/"//g')
ret=$(cat receipt.json | jq .ret | sed 's/"//g')
gasUsed=$(cat receipt.json | jq .gasUsed | sed 's/"//g')

assert_equals "$status"   "SUCCESS"
#assert_equals "$ret"      ""

if [ "$consensus" = "raft" ]; then
  assert_equals "$gasUsed"  "0"
elif [ "$fork_version" -ge "4" ]; then
  assert_equals "$gasUsed"  "108404"
else
  assert_equals "$gasUsed"  "108404"
fi
