Skip to content

Commit 46d0023

Browse files
committed
added tests of total count and block height in transfer history
1 parent 2342e41 commit 46d0023

File tree

1 file changed

+44
-15
lines changed

1 file changed

+44
-15
lines changed

tests/integration.sh

+44-15
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,9 @@ function test_deposit() {
527527

528528
function unix_time_of_tx() {
529529
set -e
530-
local tx_hash="$1"
530+
local tx="$1"
531531

532-
date -d "$(secretcli q tx "$tx_hash" | jq -r '.timestamp')" '+%s'
532+
date -d "$(jq -r '.timestamp' <<<"$tx")" '+%s'
533533
}
534534

535535
function get_tx_history() {
@@ -544,6 +544,10 @@ function get_tx_history() {
544544
local transfer_history_response
545545
transfer_history_query='{"transfer_history":{"address":"'"$account"'","key":"'"$viewing_key"'","page_size":'"$page_size"',"page":'"$page"'}}'
546546
transfer_history_response="$(compute_query "$contract_addr" "$transfer_history_query")"
547+
log "$transfer_history_response"
548+
# There's no good way of tracking the exact expected value,
549+
# so we just check that the `total` field is a number
550+
jq -e '.transfer_history.total | numbers' <<<"$transfer_history_response" > /dev/null
547551
jq -r '.transfer_history.txs' <<<"$transfer_history_response"
548552
}
549553

@@ -560,6 +564,7 @@ function check_latest_tx_history() {
560564
local receiver="$6"
561565
local amount="$7"
562566
local timestamp="$8"
567+
local block_height="$9"
563568

564569
local txs
565570
local tx
@@ -573,6 +578,7 @@ function check_latest_tx_history() {
573578
assert_eq "$(jq -r '.coins.amount' <<<"$tx")" "$amount"
574579
assert_eq "$(jq -r '.coins.denom' <<<"$tx")" 'SSCRT'
575580
assert_eq "$(jq -r '.timestamp' <<<"$tx")" "$timestamp"
581+
assert_eq "$(jq -r '.block_height' <<<"$tx")" "$block_height"
576582

577583
jq -r '.id' <<<"$tx"
578584
}
@@ -621,14 +627,20 @@ function test_transfer() {
621627
transfer_response="$(data_of wait_for_compute_tx "$tx_hash" 'waiting for transfer from "a" to "b" to process')"
622628
assert_eq "$transfer_response" "$(pad_space '{"transfer":{"status":"success"}}')"
623629

630+
local native_tx
631+
native_tx="$(secretcli q tx "$tx_hash")"
624632
local timestamp
625-
timestamp="$(unix_time_of_tx "$tx_hash")"
633+
timestamp="$(unix_time_of_tx "$native_tx")"
634+
local block_height
635+
block_height="$(jq -r '.height' <<<"$native_tx")"
626636

627637
# Check for both "a" and "b" that they recorded the transfer
628638
local -A tx_ids
629639
for key in a b; do
630640
log "querying the transfer history of \"$key\""
631-
tx_ids[$key]="$(check_latest_tx_history "$contract_addr" "${ADDRESS[$key]}" "${VK[$key]}" "${ADDRESS[a]}" "${ADDRESS[a]}" "${ADDRESS[b]}" 400000 "$timestamp")"
641+
tx_ids[$key]="$(
642+
check_latest_tx_history "$contract_addr" "${ADDRESS[$key]}" "${VK[$key]}" "${ADDRESS[a]}" "${ADDRESS[a]}" "${ADDRESS[b]}" 400000 "$timestamp" "$block_height"
643+
)"
632644
done
633645

634646
assert_eq "${tx_ids[a]}" "${tx_ids[b]}"
@@ -776,8 +788,12 @@ function test_send() {
776788
"$((original_count + 1))"
777789
log 'received send response'
778790

791+
local native_tx
792+
native_tx="$(secretcli q tx "$tx_hash")"
779793
local timestamp
780-
timestamp="$(unix_time_of_tx "$tx_hash")"
794+
timestamp="$(unix_time_of_tx "$native_tx")"
795+
local block_height
796+
block_height="$(jq -r '.height' <<<"$native_tx")"
781797

782798
# Check that the receiver got the message
783799
log 'checking whether state was updated in the receiver'
@@ -790,7 +806,7 @@ function test_send() {
790806

791807
# Check that "a" recorded the transfer
792808
log 'querying the transfer history of "a"'
793-
check_latest_tx_history "$contract_addr" "${ADDRESS[a]}" "${VK[a]}" "${ADDRESS[a]}" "${ADDRESS[a]}" "$receiver_addr" 400000 "$timestamp" >/dev/null
809+
check_latest_tx_history "$contract_addr" "${ADDRESS[a]}" "${VK[a]}" "${ADDRESS[a]}" "${ADDRESS[a]}" "$receiver_addr" 400000 "$timestamp" "$block_height" >/dev/null
794810

795811
# Check that "a" has fewer funds
796812
assert_eq "$(get_balance "$contract_addr" 'a')" 600000
@@ -915,14 +931,21 @@ function test_transfer_from() {
915931
tx_hash="$(compute_execute "$contract_addr" "$transfer_message" ${FROM[b]} --gas 200000)"
916932
transfer_response="$(data_of wait_for_compute_tx "$tx_hash" 'waiting for transfer from "a" to "c" by "b" to process')"
917933
assert_eq "$transfer_response" "$(pad_space '{"transfer_from":{"status":"success"}}')"
934+
935+
local native_tx
936+
native_tx="$(secretcli q tx "$tx_hash")"
918937
local timestamp
919-
timestamp="$(unix_time_of_tx "$tx_hash")"
938+
timestamp="$(unix_time_of_tx "$native_tx")"
939+
local block_height
940+
block_height="$(jq -r '.height' <<<"$native_tx")"
920941

921942
# Check for both "a", "b", and "c" that they recorded the transfer
922943
local -A tx_ids
923944
for key in a b c; do
924945
log "querying the transfer history of \"$key\""
925-
tx_ids[$key]="$(check_latest_tx_history "$contract_addr" "${ADDRESS[$key]}" "${VK[$key]}" "${ADDRESS[b]}" "${ADDRESS[a]}" "${ADDRESS[c]}" 400000 "$timestamp")"
946+
tx_ids[$key]="$(
947+
check_latest_tx_history "$contract_addr" "${ADDRESS[$key]}" "${VK[$key]}" "${ADDRESS[b]}" "${ADDRESS[a]}" "${ADDRESS[c]}" 400000 "$timestamp" "$block_height"
948+
)"
926949
done
927950

928951
assert_eq "${tx_ids[a]}" "${tx_ids[b]}"
@@ -1018,8 +1041,12 @@ function test_send_from() {
10181041
"$((original_count + 1))"
10191042
log 'received send response'
10201043

1044+
local native_tx
1045+
native_tx="$(secretcli q tx "$tx_hash")"
10211046
local timestamp
1022-
timestamp="$(unix_time_of_tx "$tx_hash")"
1047+
timestamp="$(unix_time_of_tx "$native_tx")"
1048+
local block_height
1049+
block_height="$(jq -r '.height' <<<"$native_tx")"
10231050

10241051
# Check that the receiver got the message
10251052
log 'checking whether state was updated in the receiver'
@@ -1034,7 +1061,9 @@ function test_send_from() {
10341061
local -A tx_ids
10351062
for key in a b; do
10361063
log "querying the transfer history of \"$key\""
1037-
tx_ids[$key]="$(check_latest_tx_history "$contract_addr" "${ADDRESS[$key]}" "${VK[$key]}" "${ADDRESS[b]}" "${ADDRESS[a]}" "$receiver_addr" 400000 "$timestamp")"
1064+
tx_ids[$key]="$(
1065+
check_latest_tx_history "$contract_addr" "${ADDRESS[$key]}" "${VK[$key]}" "${ADDRESS[b]}" "${ADDRESS[a]}" "$receiver_addr" 400000 "$timestamp" "$block_height"
1066+
)"
10381067
done
10391068

10401069
assert_eq "${tx_ids[a]}" "${tx_ids[b]}"
@@ -1082,11 +1111,11 @@ function main() {
10821111

10831112
# To make testing faster, check the logs and try to reuse the deployed contract and VKs from previous runs.
10841113
# Remember to comment out the contract deployment and `test_viewing_key` if you do.
1085-
# local contract_addr='secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg'
1086-
# VK[a]='api_key_Ij3ZwkDOTqMPnmCLGn3F2uX0pMpETw2LTyCkQ0sDMv8='
1087-
# VK[b]='api_key_hV3SlzQMC4YK50GbDrpbjicGOMQpolfPI+O6pMp6oQY='
1088-
# VK[c]='api_key_7Bv00UvQCkZ7SltDn205R0GBugq/l8GnRX6N0JIBQuA='
1089-
# VK[d]='api_key_A3Y3mFe87d2fEq90kNlPSIUSmVgoao448ZpyDAJkB/4='
1114+
local contract_addr='secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg'
1115+
VK[a]='api_key_U6FcuhP2km6UHtYeFSyaZbggcgMJQAiTMlNWV3X4iXQ='
1116+
VK[b]='api_key_YoQlmqnOkkEoh81XzFkiZ3z7+ZAJh9kyFXvtaMBhiFU='
1117+
VK[c]='api_key_/cdkitEbzaHZA41OB6cGcz1XGnQk6LYTAfSBWTOU5aQ='
1118+
VK[d]='api_key_WQYkuGOco/mSHgtKWG0f7b2UcrSG3s1fIqm1X/wIGDo='
10901119

10911120
log "contract address: $contract_addr"
10921121

0 commit comments

Comments
 (0)