@@ -527,9 +527,9 @@ function test_deposit() {
527
527
528
528
function unix_time_of_tx() {
529
529
set -e
530
- local tx_hash =" $1 "
530
+ local tx =" $1 "
531
531
532
- date -d " $( secretcli q tx " $tx_hash " | jq -r ' .timestamp' ) " ' +%s'
532
+ date -d " $( jq -r ' .timestamp' <<< " $tx " ) " ' +%s'
533
533
}
534
534
535
535
function get_tx_history() {
@@ -544,6 +544,10 @@ function get_tx_history() {
544
544
local transfer_history_response
545
545
transfer_history_query=' {"transfer_history":{"address":"' " $account " ' ","key":"' " $viewing_key " ' ","page_size":' " $page_size " ' ,"page":' " $page " ' }}'
546
546
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
547
551
jq -r ' .transfer_history.txs' <<< " $transfer_history_response"
548
552
}
549
553
@@ -560,6 +564,7 @@ function check_latest_tx_history() {
560
564
local receiver=" $6 "
561
565
local amount=" $7 "
562
566
local timestamp=" $8 "
567
+ local block_height=" $9 "
563
568
564
569
local txs
565
570
local tx
@@ -573,6 +578,7 @@ function check_latest_tx_history() {
573
578
assert_eq " $( jq -r ' .coins.amount' <<< " $tx" ) " " $amount "
574
579
assert_eq " $( jq -r ' .coins.denom' <<< " $tx" ) " ' SSCRT'
575
580
assert_eq " $( jq -r ' .timestamp' <<< " $tx" ) " " $timestamp "
581
+ assert_eq " $( jq -r ' .block_height' <<< " $tx" ) " " $block_height "
576
582
577
583
jq -r ' .id' <<< " $tx"
578
584
}
@@ -621,14 +627,20 @@ function test_transfer() {
621
627
transfer_response=" $( data_of wait_for_compute_tx " $tx_hash " ' waiting for transfer from "a" to "b" to process' ) "
622
628
assert_eq " $transfer_response " " $( pad_space ' {"transfer":{"status":"success"}}' ) "
623
629
630
+ local native_tx
631
+ native_tx=" $( secretcli q tx " $tx_hash " ) "
624
632
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" ) "
626
636
627
637
# Check for both "a" and "b" that they recorded the transfer
628
638
local -A tx_ids
629
639
for key in a b; do
630
640
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
+ ) "
632
644
done
633
645
634
646
assert_eq " ${tx_ids[a]} " " ${tx_ids[b]} "
@@ -776,8 +788,12 @@ function test_send() {
776
788
" $(( original_count + 1 )) "
777
789
log ' received send response'
778
790
791
+ local native_tx
792
+ native_tx=" $( secretcli q tx " $tx_hash " ) "
779
793
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" ) "
781
797
782
798
# Check that the receiver got the message
783
799
log ' checking whether state was updated in the receiver'
@@ -790,7 +806,7 @@ function test_send() {
790
806
791
807
# Check that "a" recorded the transfer
792
808
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
794
810
795
811
# Check that "a" has fewer funds
796
812
assert_eq " $( get_balance " $contract_addr " ' a' ) " 600000
@@ -915,14 +931,21 @@ function test_transfer_from() {
915
931
tx_hash=" $( compute_execute " $contract_addr " " $transfer_message " ${FROM[b]} --gas 200000) "
916
932
transfer_response=" $( data_of wait_for_compute_tx " $tx_hash " ' waiting for transfer from "a" to "c" by "b" to process' ) "
917
933
assert_eq " $transfer_response " " $( pad_space ' {"transfer_from":{"status":"success"}}' ) "
934
+
935
+ local native_tx
936
+ native_tx=" $( secretcli q tx " $tx_hash " ) "
918
937
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" ) "
920
941
921
942
# Check for both "a", "b", and "c" that they recorded the transfer
922
943
local -A tx_ids
923
944
for key in a b c; do
924
945
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
+ ) "
926
949
done
927
950
928
951
assert_eq " ${tx_ids[a]} " " ${tx_ids[b]} "
@@ -1018,8 +1041,12 @@ function test_send_from() {
1018
1041
" $(( original_count + 1 )) "
1019
1042
log ' received send response'
1020
1043
1044
+ local native_tx
1045
+ native_tx=" $( secretcli q tx " $tx_hash " ) "
1021
1046
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" ) "
1023
1050
1024
1051
# Check that the receiver got the message
1025
1052
log ' checking whether state was updated in the receiver'
@@ -1034,7 +1061,9 @@ function test_send_from() {
1034
1061
local -A tx_ids
1035
1062
for key in a b; do
1036
1063
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
+ ) "
1038
1067
done
1039
1068
1040
1069
assert_eq " ${tx_ids[a]} " " ${tx_ids[b]} "
@@ -1082,11 +1111,11 @@ function main() {
1082
1111
1083
1112
# To make testing faster, check the logs and try to reuse the deployed contract and VKs from previous runs.
1084
1113
# 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 ='
1090
1119
1091
1120
log " contract address: $contract_addr "
1092
1121
0 commit comments