@@ -489,8 +489,7 @@ module pyth::pyth_tests{
489
489
let cursor = cursor::new (accumulator_message);
490
490
let header: u32 = deserialize::deserialize_u32 (&mut cursor);
491
491
assert !((header as u64 ) == _PYTHNET_ACCUMULATOR_UPDATE_MAGIC, 0 );
492
- let major = deserialize::deserialize_u8 (&mut cursor);
493
- assert !(major == 1 , 0 );
492
+ let _major = deserialize::deserialize_u8 (&mut cursor);
494
493
let _minor = deserialize::deserialize_u8 (&mut cursor);
495
494
496
495
let trailing_size = deserialize::deserialize_u8 (&mut cursor);
@@ -907,7 +906,6 @@ module pyth::pyth_tests{
907
906
#[test]
908
907
#[expected_failure(abort_code = pyth::accumulator::E_INVALID_PROOF)]
909
908
fun test_create_and_update_single_price_feed_with_accumulator_failure () {
910
- use pyth::price_info::Self ;
911
909
912
910
let (scenario, coins, clock) = setup_test (500 , 23 , ACCUMULATOR_TESTS_EMITTER_ADDRESS , ACCUMULATOR_TESTS_DATA_SOURCE (), ACCUMULATOR_TESTS_INITIAL_GUARDIANS , DEFAULT_BASE_UPDATE_FEE , DEFAULT_COIN_TO_MINT );
913
911
@@ -928,43 +926,151 @@ module pyth::pyth_tests{
928
926
ctx (&mut scenario)
929
927
);
930
928
931
- // Affirm that 1 object, which correspond to the 1 new price info object
932
- // containing the price feeds were created and shared.
933
- let effects = test_scenario::next_tx (&mut scenario, DEPLOYER );
934
- let shared_ids = test_scenario::shared (&effects);
935
- let created_ids = test_scenario::created (&effects);
936
- assert !(vector ::length <ID >(&shared_ids)==1 , 0 );
937
- assert !(vector ::length <ID >(&created_ids)==1 , 0 );
929
+ // clean up test scenario
930
+ test_scenario::next_tx (&mut scenario, DEPLOYER );
931
+ coin::burn_for_testing <SUI >(coins);
938
932
939
- let price_info_object_1 = take_shared <PriceInfoObject >(&scenario);
933
+ cleanup_worm_state_pyth_state_and_clock (worm_state, pyth_state, clock);
934
+ test_scenario::end (scenario);
935
+ }
940
936
941
- // Create authenticated price infos
942
- verified_vaa = get_verified_vaa_from_accumulator_message (&worm_state, TEST_ACCUMULATOR_SINGLE_FEED , &clock);
943
- let auth_price_infos = pyth::create_authenticated_price_infos_using_accumulator (
944
- &pyth_state,
945
- TEST_ACCUMULATOR_SINGLE_FEED ,
937
+ #[test_only]
938
+ const TEST_ACCUMULATOR_INVALID_PROOF_1: vector<u8> = x"504e41550100000000a001000000000100110db9cd8325ccfab0dae92eeb9ea70a1faba5c5e96dc21ff46a8ddc560afc9a60df096b8ff21172804692bbdc958153e838437d8b474cbf45f0dc2a8acae831000000000000000000000171f8dcb863d176e2c420ad6610cf687359612b6fb392e0642b0ca6b1f186aa3b0000000000000000004155575600000000000000000000000000a8bea2b5f12f3177ff9b3929d77c3476ab2d32c602005500b10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6fa75cd3aa3bb5ace5e2516446f71f85be36bd19bb0703f3154bb3db07be59f3f377c0d3f44661d9a8736c68884c8169e8b636ee3043202397384073120dce9e5d0efe24b44b4a0d62da8a1180177cf30b2c0bebbb1adfe8f7985d051d205a01e2504d9f0c06e7e7cb0cf24116098ca202ac5f6ade2e8f5a12ec006b16d46be1f0228b94d950055006e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af5f958f4883f9d2a8b5b1008d1fa01db95cf4a8c7423a695e81ad1eb504f8554c3620c3fd40b40f7d581ac802e2de5cb82a9ae672043202397384073120dce9e5d0efe24b44b4a0d62da8a1180177cf30b2c0bebbb1adfe8f7985d051d205a01e2504d9f0c06e7e7cb0cf24116098ca202ac5f6ade2e8f5a12ec006b16d46be1f0228b94d95";
939
+
940
+ #[test]
941
+ #[expected_failure(abort_code = pyth::accumulator::E_INVALID_PROOF)]
942
+ fun test_accumulator_invalid_proof () {
943
+
944
+ let (scenario, coins, clock) = setup_test (500 , 23 , ACCUMULATOR_TESTS_EMITTER_ADDRESS , ACCUMULATOR_TESTS_DATA_SOURCE (), ACCUMULATOR_TESTS_INITIAL_GUARDIANS , DEFAULT_BASE_UPDATE_FEE , DEFAULT_COIN_TO_MINT );
945
+
946
+ test_scenario::next_tx (&mut scenario, DEPLOYER );
947
+
948
+ let (pyth_state, worm_state) = take_wormhole_and_pyth_states (&scenario);
949
+
950
+ let verified_vaa = get_verified_vaa_from_accumulator_message (&worm_state, TEST_ACCUMULATOR_INVALID_PROOF_1 , &clock);
951
+
952
+ test_scenario::next_tx (&mut scenario, DEPLOYER );
953
+
954
+ pyth::create_price_feeds_using_accumulator (
955
+ &mut pyth_state,
956
+ TEST_ACCUMULATOR_INVALID_PROOF_1 ,
946
957
verified_vaa,
947
- &clock
958
+ &clock,
959
+ ctx (&mut scenario)
948
960
);
949
961
962
+ // clean up test scenario
950
963
test_scenario::next_tx (&mut scenario, DEPLOYER );
951
- auth_price_infos = update_single_price_feed (
964
+ coin::burn_for_testing <SUI >(coins);
965
+
966
+ cleanup_worm_state_pyth_state_and_clock (worm_state, pyth_state, clock);
967
+ test_scenario::end (scenario);
968
+ }
969
+
970
+ #[test_only]
971
+ const TEST_ACCUMULATOR_INVALID_MAJOR_VERSION: vector<u8> = x"504e41553c00000000a001000000000100496b7fbd18dca2f0e690712fd8ca522ff79ca7d9d6d22e9f5d753fba4bd16fff440a811bad710071c79859290bcb1700de49dd8400db90b048437b521200123e010000000000000000000171f8dcb863d176e2c420ad6610cf687359612b6fb392e0642b0ca6b1f186aa3b000000000000000000415557560000000000000000000000000005f5db4488a7cae9f9a6c1938340c0fbf4beb9090200550031ecc21a745e3968a04e9570e4425bc18fa8019c68028196b546d1669c200c6879bc5a3617ec3444d93c06501cf6a0909c38d4ec81d96026b71ec475e87d69c7b5124289adbf24212bed8c15db354391d2378d2e0454d2655c6c34e7e50580fd8c94511322968bbc6da8a1180177cf30b2c0bebbb1adfe8f7985d051d205a01e2504d9f0c06e7e7cb0cf24116098ca202ac5f6ade2e8f5a12ec006b16d46be1f0228b94d95005500944998273e477b495144fb8794c914197f3ccb46be2900f4698fd0ef743c9695a573a6ff665ff63edb5f9a85ad579dc14500a2112c09680fc146134f9a539ca82cb6e3501c801278fd08d80732a24118292866bb049e6e88181a1e1e8b6d3c6bbb95135a73041f3b56a8a1180177cf30b2c0bebbb1adfe8f7985d051d205a01e2504d9f0c06e7e7cb0cf24116098ca202ac5f6ade2e8f5a12ec006b16d46be1f0228b94d95";
972
+
973
+ #[test]
974
+ #[expected_failure(abort_code = pyth::accumulator::E_INVALID_ACCUMULATOR_PAYLOAD)]
975
+ fun test_accumulator_invalid_major_version () {
976
+
977
+ let (scenario, coins, clock) = setup_test (500 , 23 , ACCUMULATOR_TESTS_EMITTER_ADDRESS , ACCUMULATOR_TESTS_DATA_SOURCE (), ACCUMULATOR_TESTS_INITIAL_GUARDIANS , DEFAULT_BASE_UPDATE_FEE , DEFAULT_COIN_TO_MINT );
978
+
979
+ test_scenario::next_tx (&mut scenario, DEPLOYER );
980
+
981
+ let (pyth_state, worm_state) = take_wormhole_and_pyth_states (&scenario);
982
+
983
+ let verified_vaa = get_verified_vaa_from_accumulator_message (&worm_state, TEST_ACCUMULATOR_INVALID_MAJOR_VERSION , &clock);
984
+
985
+ test_scenario::next_tx (&mut scenario, DEPLOYER );
986
+
987
+ pyth::create_price_feeds_using_accumulator (
952
988
&mut pyth_state,
953
- auth_price_infos ,
954
- & mut price_info_object_1 ,
955
- coins ,
956
- &clock
989
+ TEST_ACCUMULATOR_INVALID_MAJOR_VERSION ,
990
+ verified_vaa ,
991
+ &clock ,
992
+ ctx (& mut scenario)
957
993
);
958
994
959
- // assert that price info obejct is as expected
960
- let expected = accumulator_test_1_to_price_info ();
961
- assert !(price_feeds_equal (&expected, &price_info::get_price_info_from_price_info_object (&price_info_object_1)), 0 );
995
+ // clean up test scenario
996
+ test_scenario::next_tx (&mut scenario, DEPLOYER );
997
+ coin::burn_for_testing <SUI >(coins);
998
+
999
+ cleanup_worm_state_pyth_state_and_clock (worm_state, pyth_state, clock);
1000
+ test_scenario::end (scenario);
1001
+ }
1002
+
1003
+ #[test_only]
1004
+ const TEST_ACCUMULATOR_INVALID_WH_MSG : vector <u8 > = x"504e41550100000000a001000000000100e87f98238c5357730936cfdfde3a37249e5219409a4f41b301924b8eb10815a43ea2f96e4fe1bc8cd398250f39448d3b8ca57c96f9cf7a2be292517280683caa010000000000000000000171f8dcb863d176e2c420ad6610cf687359612b6fb392e0642b0ca6b1f186aa3b00000000000000000041555755000000000000000000000000000fb6f9f2b3b6cc1c9ef6708985fef226d92a3c0801005500b10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6fa75cd3aa3bb5ace5e2516446f71f85be36bd19b000000006491cc747be59f3f377c0d3f44661d9a8736c68884c8169e8b636ee301f2ee15ea639b73fa3db9b34a245bdfa015c260c5 ";
1005
+
1006
+ #[test]
1007
+ #[expected_failure(abort_code = pyth::accumulator::E_INVALID_WORMHOLE_MESSAGE)]
1008
+ fun test_accumulator_invalid_wormhole_message () {
1009
+
1010
+ let (scenario, coins, clock) = setup_test (500 , 23 , ACCUMULATOR_TESTS_EMITTER_ADDRESS , ACCUMULATOR_TESTS_DATA_SOURCE (), ACCUMULATOR_TESTS_INITIAL_GUARDIANS , DEFAULT_BASE_UPDATE_FEE , DEFAULT_COIN_TO_MINT );
1011
+
1012
+ test_scenario::next_tx (&mut scenario, DEPLOYER );
1013
+
1014
+ let (pyth_state, worm_state) = take_wormhole_and_pyth_states (&scenario);
1015
+
1016
+ let verified_vaa = get_verified_vaa_from_accumulator_message (&worm_state, TEST_ACCUMULATOR_INVALID_WH_MSG , &clock);
1017
+
1018
+ test_scenario::next_tx (&mut scenario, DEPLOYER );
1019
+
1020
+ pyth::create_price_feeds_using_accumulator (
1021
+ &mut pyth_state,
1022
+ TEST_ACCUMULATOR_INVALID_WH_MSG ,
1023
+ verified_vaa,
1024
+ &clock,
1025
+ ctx (&mut scenario)
1026
+ );
962
1027
963
1028
// clean up test scenario
964
1029
test_scenario::next_tx (&mut scenario, DEPLOYER );
965
- authenticated_vector:: destroy < PriceInfo >(auth_price_infos );
1030
+ coin:: burn_for_testing < SUI >(coins );
966
1031
967
- return_shared (price_info_object_1);
1032
+ cleanup_worm_state_pyth_state_and_clock (worm_state, pyth_state, clock);
1033
+ test_scenario::end (scenario);
1034
+ }
1035
+
1036
+
1037
+ #[test_only]
1038
+ const TEST_ACCUMULATOR_INCREASED_MINOR_VERSION: vector<u8> = x"504e4155010a000000a001000000000100496b7fbd18dca2f0e690712fd8ca522ff79ca7d9d6d22e9f5d753fba4bd16fff440a811bad710071c79859290bcb1700de49dd8400db90b048437b521200123e010000000000000000000171f8dcb863d176e2c420ad6610cf687359612b6fb392e0642b0ca6b1f186aa3b000000000000000000415557560000000000000000000000000005f5db4488a7cae9f9a6c1938340c0fbf4beb9090200550031ecc21a745e3968a04e9570e4425bc18fa8019c68028196b546d1669c200c6879bc5a3617ec3444d93c06501cf6a0909c38d4ec81d96026b71ec475e87d69c7b5124289adbf24212bed8c15db354391d2378d2e0454d2655c6c34e7e50580fd8c94511322968bbc6da8a1180177cf30b2c0bebbb1adfe8f7985d051d205a01e2504d9f0c06e7e7cb0cf24116098ca202ac5f6ade2e8f5a12ec006b16d46be1f0228b94d95005500944998273e477b495144fb8794c914197f3ccb46be2900f4698fd0ef743c9695a573a6ff665ff63edb5f9a85ad579dc14500a2112c09680fc146134f9a539ca82cb6e3501c801278fd08d80732a24118292866bb049e6e88181a1e1e8b6d3c6bbb95135a73041f3b56a8a1180177cf30b2c0bebbb1adfe8f7985d051d205a01e2504d9f0c06e7e7cb0cf24116098ca202ac5f6ade2e8f5a12ec006b16d46be1f0228b94d95";
1039
+ #[test_only]
1040
+ const TEST_ACCUMULATOR_EXTRA_PAYLOAD: vector<u8> = x"504e41550100000000a001000000000100b2d11f181d81b4ff10beca30091754b464dc48bc1f7432d114f64a7a8f660e7964f2a0c6121bae6c1977514d46ee7a29d9395b20a45f2086071715c1dc19ab74000000000000000000000171f8dcb863d176e2c420ad6610cf687359612b6fb392e0642b0ca6b1f186aa3b000000000000000000415557560000000000000000000000000013f83cfdf63a5a1b3189182fa0a52e6de53ba7d002005d0031ecc21a745e3968a04e9570e4425bc18fa8019c68028196b546d1669c200c6879bc5a3617ec3444d93c06501cf6a0909c38d4ec81d96026b71ec475e87d69c7b5124289adbf24212bed8c15db354391d2378d2e000000000000000004a576f4a87f443f7d961a682f508c4f7b06ee1595a8a1180177cf30b2c0bebbb1adfe8f7985d051d205a01e2504d9f0c06e7e7cb0cf24116098ca202ac5f6ade2e8f5a12ec006b16d46be1f0228b94d95005d00944998273e477b495144fb8794c914197f3ccb46be2900f4698fd0ef743c9695a573a6ff665ff63edb5f9a85ad579dc14500a2112c09680fc146134f9a539ca82cb6e3501c801278fd08d80732a24118292866bb0000000000000000045be67ba87a8dfbea404827ccbf07790299b6c023a8a1180177cf30b2c0bebbb1adfe8f7985d051d205a01e2504d9f0c06e7e7cb0cf24116098ca202ac5f6ade2e8f5a12ec006b16d46be1f0228b94d95";
1041
+
1042
+ #[test]
1043
+ fun test_accumulator_forward_compatibility () {
1044
+
1045
+ let (scenario, coins, clock) = setup_test (500 , 23 , ACCUMULATOR_TESTS_EMITTER_ADDRESS , ACCUMULATOR_TESTS_DATA_SOURCE (), ACCUMULATOR_TESTS_INITIAL_GUARDIANS , DEFAULT_BASE_UPDATE_FEE , DEFAULT_COIN_TO_MINT );
1046
+
1047
+ test_scenario::next_tx (&mut scenario, DEPLOYER );
1048
+
1049
+ let (pyth_state, worm_state) = take_wormhole_and_pyth_states (&scenario);
1050
+
1051
+ test_scenario::next_tx (&mut scenario, DEPLOYER );
1052
+
1053
+ pyth::create_price_feeds_using_accumulator (
1054
+ &mut pyth_state,
1055
+ TEST_ACCUMULATOR_EXTRA_PAYLOAD ,
1056
+ get_verified_vaa_from_accumulator_message (&worm_state, TEST_ACCUMULATOR_EXTRA_PAYLOAD , &clock),
1057
+ &clock,
1058
+ ctx (&mut scenario)
1059
+ );
1060
+
1061
+ test_scenario::next_tx (&mut scenario, DEPLOYER );
1062
+
1063
+ pyth::create_price_feeds_using_accumulator (
1064
+ &mut pyth_state,
1065
+ TEST_ACCUMULATOR_INCREASED_MINOR_VERSION ,
1066
+ get_verified_vaa_from_accumulator_message (&worm_state, TEST_ACCUMULATOR_INCREASED_MINOR_VERSION , &clock),
1067
+ &clock,
1068
+ ctx (&mut scenario)
1069
+ );
1070
+
1071
+ // clean up test scenario
1072
+ test_scenario::next_tx (&mut scenario, DEPLOYER );
1073
+ coin::burn_for_testing <SUI >(coins);
968
1074
969
1075
cleanup_worm_state_pyth_state_and_clock (worm_state, pyth_state, clock);
970
1076
test_scenario::end (scenario);
@@ -1030,10 +1136,6 @@ module pyth::pyth_tests{
1030
1136
assert !(vector ::length <ID >(&shared_ids)==3 , 0 );
1031
1137
assert !(vector ::length <ID >(&created_ids)==3 , 0 );
1032
1138
1033
- let price_info_object_1 = take_shared <PriceInfoObject >(&scenario);
1034
- let price_info_object_2 = take_shared <PriceInfoObject >(&scenario);
1035
- let price_info_object_3 = take_shared <PriceInfoObject >(&scenario);
1036
-
1037
1139
// Create authenticated price infos
1038
1140
verified_vaa = get_verified_vaa_from_accumulator_message (&worm_state, TEST_ACCUMULATOR_3_MSGS , &clock);
1039
1141
let auth_price_infos = pyth::create_authenticated_price_infos_using_accumulator (
@@ -1043,57 +1145,30 @@ module pyth::pyth_tests{
1043
1145
&clock
1044
1146
);
1045
1147
1046
- let coins2 = coin::split (&mut coins, 1000 , ctx (&mut scenario));
1047
- let coins3 = coin::split (&mut coins, 1000 , ctx (&mut scenario));
1048
-
1049
- test_scenario::next_tx (&mut scenario, DEPLOYER );
1050
-
1051
- // Update price feeds
1052
- auth_price_infos = update_single_price_feed (
1053
- &mut pyth_state,
1054
- auth_price_infos,
1055
- &mut price_info_object_1,
1056
- coins,
1057
- &clock
1058
- );
1059
-
1060
- auth_price_infos = update_single_price_feed (
1061
- &mut pyth_state,
1062
- auth_price_infos,
1063
- &mut price_info_object_2,
1064
- coins2,
1065
- &clock
1066
- );
1067
-
1068
- auth_price_infos = update_single_price_feed (
1069
- &mut pyth_state,
1070
- auth_price_infos,
1071
- &mut price_info_object_3,
1072
- coins3,
1073
- &clock
1074
- );
1075
-
1076
- // assert price feeds are as expected
1148
+ let idx = 0 ;
1077
1149
let expected_price_infos = accumulator_test_3_to_price_info (0 /*offset argument*/ );
1078
1150
1079
- let price_info_1 = price_info::get_price_info_from_price_info_object (&price_info_object_1);
1080
- assert !(price_feeds_equal (&price_info_1, vector ::borrow (&expected_price_infos, 0 )), 0 );
1081
-
1082
- let price_info_2 = price_info::get_price_info_from_price_info_object (&price_info_object_2);
1083
- assert !(price_feeds_equal (&price_info_2, vector ::borrow (&expected_price_infos, 1 )), 0 );
1084
-
1085
- let price_info_3 = price_info::get_price_info_from_price_info_object (&price_info_object_3);
1086
- assert !(price_feeds_equal (&price_info_3, vector ::borrow (&expected_price_infos, 2 )), 0 );
1087
-
1151
+ while (idx < 3 ){
1152
+ let coin_split = coin::split (&mut coins, 1000 , ctx (&mut scenario));
1153
+ let price_info_object = take_shared <PriceInfoObject >(&scenario);
1154
+ auth_price_infos = update_single_price_feed (
1155
+ &mut pyth_state,
1156
+ auth_price_infos,
1157
+ &mut price_info_object,
1158
+ coin_split,
1159
+ &clock
1160
+ );
1161
+ let price_info = price_info::get_price_info_from_price_info_object (&price_info_object);
1162
+ assert !(price_feeds_equal (&price_info, vector ::borrow (&expected_price_infos, idx)), 0 );
1163
+ return_shared (price_info_object);
1164
+ idx = idx + 1 ;
1165
+ };
1166
+ coin::burn_for_testing <SUI >(coins);
1088
1167
1089
1168
// clean up test scenario
1090
1169
test_scenario::next_tx (&mut scenario, DEPLOYER );
1091
1170
authenticated_vector::destroy <PriceInfo >(auth_price_infos);
1092
1171
1093
- return_shared (price_info_object_1);
1094
- return_shared (price_info_object_2);
1095
- return_shared (price_info_object_3);
1096
-
1097
1172
cleanup_worm_state_pyth_state_and_clock (worm_state, pyth_state, clock);
1098
1173
test_scenario::end (scenario);
1099
1174
}
0 commit comments