@@ -38,6 +38,7 @@ import {
3838 extract_htlc_secret ,
3939 encode_create_order_output ,
4040 encode_input_for_fill_order ,
41+ encode_input_for_freeze_order ,
4142 encode_input_for_conclude_order ,
4243 SignatureHashType ,
4344 encode_input_for_withdraw_from_delegation ,
@@ -66,12 +67,14 @@ import {
6667 encode_input_for_change_token_metadata_uri ,
6768} from "../pkg/wasm_wrappers.js" ;
6869
70+ // Taken from TESTNET_FORK_HEIGHT_5_ORDERS_V1 in common/src/chain/config/builder.rs.
71+ // This will be updated to the actual height after we choose one.
72+ const ORDERS_V1_TESTNET_FORK_HEIGHT = 999999999 ;
73+
6974function assert_eq_arrays ( arr1 , arr2 ) {
70- assert ( arr1 . length == arr2 . length , "array lengths are different" ) ;
75+ const equal = arr1 . length == arr2 . length && arr1 . every ( ( value , index ) => value == arr2 [ index ] ) ;
7176
72- arr1 . forEach ( ( elem , idx ) => {
73- assert ( elem == arr2 [ idx ] , `element at index ${ idx } is different` ) ;
74- } ) ;
77+ assert ( equal , `array1 [${ arr1 } ] differs from array2 [${ arr2 } ]` ) ;
7578}
7679
7780function assert ( condition , message ) {
@@ -962,14 +965,20 @@ export async function run_test() {
962965 console . log ( "create order tokens for coins encoding ok" ) ;
963966
964967 const order_id = "tordr1xxt0avjtt4flkq0tnlyphmdm4aaj9vmkx5r2m4g863nw3lgf7nzs7mlkqc" ;
965- const fill_order_input = encode_input_for_fill_order (
968+ // Note: the exact heights don't matter as long as they are at the "correct side" of the fork.
969+ const order_v0_height = Math . floor ( Math . random ( ) * ORDERS_V1_TESTNET_FORK_HEIGHT ) ;
970+ const order_v1_height = order_v0_height + ORDERS_V1_TESTNET_FORK_HEIGHT ;
971+ // Note: the nonce is ignored since orders v1.
972+ const order_v1_nonce = Math . floor ( Math . random ( ) * 1000000 ) ;
973+ const fill_order_v0_input = encode_input_for_fill_order (
966974 order_id ,
967975 Amount . from_atoms ( "40000" ) ,
968976 address ,
969977 BigInt ( 1 ) ,
978+ BigInt ( order_v0_height ) ,
970979 Network . Testnet
971980 ) ;
972- const expected_fill_order_input = [
981+ const expected_fill_order_v0_input = [
973982 2 , 4 , 7 , 49 , 150 , 254 , 178 , 75 , 93 , 83 , 251 ,
974983 1 , 235 , 159 , 200 , 27 , 237 , 187 , 175 , 123 , 34 , 179 ,
975984 118 , 53 , 6 , 173 , 213 , 7 , 212 , 102 , 232 , 253 , 9 ,
@@ -978,24 +987,94 @@ export async function run_test() {
978987 103 , 207 , 80 , 217 , 178
979988 ] ;
980989
981- assert_eq_arrays ( fill_order_input , expected_fill_order_input ) ;
982- console . log ( "fill order encoding ok" ) ;
990+ assert_eq_arrays ( fill_order_v0_input , expected_fill_order_v0_input ) ;
991+ console . log ( "fill order v0 encoding ok" ) ;
983992
984- const conclude_order_input = encode_input_for_conclude_order (
993+ const fill_order_v1_input = encode_input_for_fill_order (
994+ order_id ,
995+ Amount . from_atoms ( "40000" ) ,
996+ address ,
997+ BigInt ( order_v1_nonce ) ,
998+ BigInt ( order_v1_height ) ,
999+ Network . Testnet
1000+ ) ;
1001+ const expected_fill_order_v1_input = [
1002+ 3 , 0 , 49 , 150 , 254 , 178 , 75 , 93 ,
1003+ 83 , 251 , 1 , 235 , 159 , 200 , 27 , 237 ,
1004+ 187 , 175 , 123 , 34 , 179 , 118 , 53 , 6 ,
1005+ 173 , 213 , 7 , 212 , 102 , 232 , 253 , 9 ,
1006+ 244 , 197 , 2 , 113 , 2 , 0 , 1 , 91 ,
1007+ 58 , 110 , 176 , 100 , 207 , 6 , 194 , 41 ,
1008+ 193 , 30 , 91 , 4 , 195 , 202 , 103 , 207 ,
1009+ 80 , 217 , 178
1010+ ] ;
1011+
1012+ assert_eq_arrays ( fill_order_v1_input , expected_fill_order_v1_input ) ;
1013+ console . log ( "fill order v1 encoding ok" ) ;
1014+
1015+ const conclude_order_v0_input = encode_input_for_conclude_order (
9851016 order_id ,
9861017 BigInt ( 1 ) ,
1018+ BigInt ( order_v0_height ) ,
9871019 Network . Testnet
9881020 ) ;
989- const expected_conclude_order_input = [
1021+ const expected_conclude_order_v0_input = [
9901022 2 , 4 , 6 , 49 , 150 , 254 , 178 , 75 ,
9911023 93 , 83 , 251 , 1 , 235 , 159 , 200 , 27 ,
9921024 237 , 187 , 175 , 123 , 34 , 179 , 118 , 53 ,
9931025 6 , 173 , 213 , 7 , 212 , 102 , 232 , 253 ,
9941026 9 , 244 , 197
9951027 ] ;
9961028
997- assert_eq_arrays ( conclude_order_input , expected_conclude_order_input ) ;
998- console . log ( "conclude order encoding ok" ) ;
1029+ assert_eq_arrays ( conclude_order_v0_input , expected_conclude_order_v0_input ) ;
1030+ console . log ( "conclude order v0 encoding ok" ) ;
1031+
1032+ const conclude_order_v1_input = encode_input_for_conclude_order (
1033+ order_id ,
1034+ BigInt ( order_v1_nonce ) ,
1035+ BigInt ( order_v1_height ) ,
1036+ Network . Testnet
1037+ ) ;
1038+ const expected_conclude_order_v1_input = [
1039+ 3 , 2 , 49 , 150 , 254 , 178 , 75 , 93 ,
1040+ 83 , 251 , 1 , 235 , 159 , 200 , 27 , 237 ,
1041+ 187 , 175 , 123 , 34 , 179 , 118 , 53 , 6 ,
1042+ 173 , 213 , 7 , 212 , 102 , 232 , 253 , 9 ,
1043+ 244 , 197
1044+ ] ;
1045+
1046+ assert_eq_arrays ( conclude_order_v1_input , expected_conclude_order_v1_input ) ;
1047+ console . log ( "conclude order v1 encoding ok" ) ;
1048+
1049+ const freeze_order_input = encode_input_for_freeze_order (
1050+ order_id ,
1051+ BigInt ( order_v1_height ) ,
1052+ Network . Testnet
1053+ ) ;
1054+ const expected_freeze_order_input = [
1055+ 3 , 1 , 49 , 150 , 254 , 178 , 75 , 93 ,
1056+ 83 , 251 , 1 , 235 , 159 , 200 , 27 , 237 ,
1057+ 187 , 175 , 123 , 34 , 179 , 118 , 53 , 6 ,
1058+ 173 , 213 , 7 , 212 , 102 , 232 , 253 , 9 ,
1059+ 244 , 197
1060+ ] ;
1061+
1062+ assert_eq_arrays ( freeze_order_input , expected_freeze_order_input ) ;
1063+ console . log ( "freeze order encoding ok" ) ;
1064+
1065+ try {
1066+ encode_input_for_freeze_order (
1067+ order_id ,
1068+ BigInt ( order_v0_height ) ,
1069+ Network . Testnet
1070+ ) ;
1071+ throw new Error ( "Freezing an order before v1 worked somehow!" ) ;
1072+ } catch ( e ) {
1073+ if ( ! e . includes ( "Orders V1 not activated" ) ) {
1074+ throw e ;
1075+ }
1076+ console . log ( "Tested order freezing before v1 successfully" ) ;
1077+ }
9991078
10001079 try {
10011080 const invalid_inputs = "invalid inputs" ;
0 commit comments