|
|
@@ -92,31 +92,7 @@ fn test_governance_set_fee_works() {
|
|
|
|
|
|
let mut balance = fee_contract.balanceOf(user);
|
|
|
start_prank(CheatTarget::One(pyth.contract_address), user);
|
|
|
- pyth
|
|
|
- .update_price_feeds(
|
|
|
- ByteArrayImpl::new(
|
|
|
- array_try_into(
|
|
|
- array![
|
|
|
- 141887862745809943100421399774809552050876420277163116849842965275903806689,
|
|
|
- 210740906737592158039211995620336526131859667363627655742687286503264782608,
|
|
|
- 437230063624699337579360546580839669896712252828825008570863758867641146081,
|
|
|
- 3498691308882995183871222184377409432186747119716981166996399082193594993,
|
|
|
- 1390200166945919815453709407753165121175395927094647129599868236,
|
|
|
- 222819573728193325268644030206737371345667885599602384508424089704440116301,
|
|
|
- 341318259000017461738706238280879290398059773267212529438772847337449455616,
|
|
|
- 1275126645346645395843037504005879519843596923369759718556759844520336145,
|
|
|
- 363528783578153760894082184744116718493621815898909809604883433584616420886,
|
|
|
- 301537311768214106147206781423041990995720118715322906821301413003463484347,
|
|
|
- 83150006264761451992768264969047148434524798781124754530141755679159432208,
|
|
|
- 96387772316726941183358990094337324283641753573556594738287498821253761827,
|
|
|
- 395908154570808692326126405856049827157095768069251211022053821585519235652,
|
|
|
- 87135893730137265929093180553063146337041045646221968026289709394440932141,
|
|
|
- 245333243912241114598596888050489286502591033459250287888834,
|
|
|
- ]
|
|
|
- ),
|
|
|
- 25
|
|
|
- )
|
|
|
- );
|
|
|
+ pyth.update_price_feeds(price_update1_test());
|
|
|
stop_prank(CheatTarget::One(pyth.contract_address));
|
|
|
let new_balance = fee_contract.balanceOf(user);
|
|
|
assert!(balance - new_balance == 1000);
|
|
|
@@ -129,31 +105,7 @@ fn test_governance_set_fee_works() {
|
|
|
pyth.execute_governance_instruction(governance_set_fee());
|
|
|
|
|
|
start_prank(CheatTarget::One(pyth.contract_address), user);
|
|
|
- pyth
|
|
|
- .update_price_feeds(
|
|
|
- ByteArrayImpl::new(
|
|
|
- array_try_into(
|
|
|
- array![
|
|
|
- 141887862745809943100421399774809552050874823427618844548942380383465221086,
|
|
|
- 106893583704677921907497845070624642590618427233243792006390965895909696183,
|
|
|
- 126617671723931969110123875642449115250793288301361049879364132884271078113,
|
|
|
- 3498691308882995183871222184377409432186747119716981166996399082193594993,
|
|
|
- 1390200461185063661704370212555794334034815850290352693418762308,
|
|
|
- 419598057710749587537080281518289024699150505326900462079484531390510117965,
|
|
|
- 341318259000017461738706238280879290398059773267212529438780607147892801536,
|
|
|
- 1437437604754599821041091415535991441313586347841485651963630208563420739,
|
|
|
- 305222830440467078008666830004555943609735125691441831219591213494068931362,
|
|
|
- 358396406696718360717615797531477055540194104082154743994717297650279402646,
|
|
|
- 429270385827211102844129651648706540139690432947840438198166022904666187018,
|
|
|
- 343946166212648899477337159288779715507980257611242783073384876024451565860,
|
|
|
- 67853010773876862913176476530730880916439012004585961528150130218675908823,
|
|
|
- 370855179649505412564259994413632062925303311800103998016489412083011059699,
|
|
|
- 1182295126766215829784496273374889928477877265080355104888778,
|
|
|
- ]
|
|
|
- ),
|
|
|
- 25
|
|
|
- )
|
|
|
- );
|
|
|
+ pyth.update_price_feeds(price_update2_test());
|
|
|
stop_prank(CheatTarget::One(pyth.contract_address));
|
|
|
let new_balance = fee_contract.balanceOf(user);
|
|
|
assert!(balance - new_balance == 4200);
|
|
|
@@ -177,6 +129,69 @@ fn test_rejects_corrupted_governance_instruction(pos: usize, random1: usize, ran
|
|
|
pyth.execute_governance_instruction(input);
|
|
|
}
|
|
|
|
|
|
+#[test]
|
|
|
+fn test_governance_set_data_sources_works() {
|
|
|
+ let owner = 'owner'.try_into().unwrap();
|
|
|
+ let user = 'user'.try_into().unwrap();
|
|
|
+ let wormhole = super::wormhole::deploy_with_test_guardian();
|
|
|
+ let fee_contract = deploy_fee_contract(user);
|
|
|
+ let pyth = deploy_default(owner, wormhole.contract_address, fee_contract.contract_address);
|
|
|
+
|
|
|
+ start_prank(CheatTarget::One(fee_contract.contract_address), user);
|
|
|
+ fee_contract.approve(pyth.contract_address, 10000);
|
|
|
+ stop_prank(CheatTarget::One(fee_contract.contract_address));
|
|
|
+
|
|
|
+ start_prank(CheatTarget::One(pyth.contract_address), user);
|
|
|
+ pyth.update_price_feeds(price_update1_test());
|
|
|
+ stop_prank(CheatTarget::One(pyth.contract_address));
|
|
|
+ let last_price = pyth
|
|
|
+ .get_price_unsafe(0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43)
|
|
|
+ .unwrap_with_felt252();
|
|
|
+ assert!(last_price.price == 6281060000000);
|
|
|
+
|
|
|
+ pyth.execute_governance_instruction(governance_set_data_sources());
|
|
|
+
|
|
|
+ start_prank(CheatTarget::One(pyth.contract_address), user);
|
|
|
+ pyth.update_price_feeds(price_update2_test_alt_emitter());
|
|
|
+ stop_prank(CheatTarget::One(pyth.contract_address));
|
|
|
+ let last_price = pyth
|
|
|
+ .get_price_unsafe(0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43)
|
|
|
+ .unwrap_with_felt252();
|
|
|
+ assert!(last_price.price == 6281522520745);
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+#[should_panic(expected: ('invalid update data source',))]
|
|
|
+fn test_rejects_update_after_data_source_changed() {
|
|
|
+ let owner = 'owner'.try_into().unwrap();
|
|
|
+ let user = 'user'.try_into().unwrap();
|
|
|
+ let wormhole = super::wormhole::deploy_with_test_guardian();
|
|
|
+ let fee_contract = deploy_fee_contract(user);
|
|
|
+ let pyth = deploy_default(owner, wormhole.contract_address, fee_contract.contract_address);
|
|
|
+
|
|
|
+ start_prank(CheatTarget::One(fee_contract.contract_address), user);
|
|
|
+ fee_contract.approve(pyth.contract_address, 10000);
|
|
|
+ stop_prank(CheatTarget::One(fee_contract.contract_address));
|
|
|
+
|
|
|
+ start_prank(CheatTarget::One(pyth.contract_address), user);
|
|
|
+ pyth.update_price_feeds(price_update1_test());
|
|
|
+ stop_prank(CheatTarget::One(pyth.contract_address));
|
|
|
+ let last_price = pyth
|
|
|
+ .get_price_unsafe(0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43)
|
|
|
+ .unwrap_with_felt252();
|
|
|
+ assert!(last_price.price == 6281060000000);
|
|
|
+
|
|
|
+ pyth.execute_governance_instruction(governance_set_data_sources());
|
|
|
+
|
|
|
+ start_prank(CheatTarget::One(pyth.contract_address), user);
|
|
|
+ pyth.update_price_feeds(price_update2_test());
|
|
|
+ stop_prank(CheatTarget::One(pyth.contract_address));
|
|
|
+ let last_price = pyth
|
|
|
+ .get_price_unsafe(0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43)
|
|
|
+ .unwrap_with_felt252();
|
|
|
+ assert!(last_price.price == 6281522520745);
|
|
|
+}
|
|
|
+
|
|
|
fn deploy_default(
|
|
|
owner: ContractAddress, wormhole_address: ContractAddress, fee_contract_address: ContractAddress
|
|
|
) -> IPythDispatcher {
|
|
|
@@ -197,7 +212,6 @@ fn deploy_default(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
fn deploy(
|
|
|
owner: ContractAddress,
|
|
|
wormhole_address: ContractAddress,
|
|
|
@@ -287,6 +301,7 @@ fn good_update1() -> ByteArray {
|
|
|
ByteArrayImpl::new(array_try_into(bytes), 11)
|
|
|
}
|
|
|
|
|
|
+// Generated with `../../tools/test_vaas/src/bin/generate_wormhole_vaas.rs`
|
|
|
fn governance_set_fee() -> ByteArray {
|
|
|
ByteArrayImpl::new(
|
|
|
array_try_into(
|
|
|
@@ -301,3 +316,100 @@ fn governance_set_fee() -> ByteArray {
|
|
|
23
|
|
|
)
|
|
|
}
|
|
|
+
|
|
|
+// Generated with `../../tools/test_vaas/src/bin/generate_wormhole_vaas.rs`
|
|
|
+fn governance_set_data_sources() -> ByteArray {
|
|
|
+ ByteArrayImpl::new(
|
|
|
+ array_try_into(
|
|
|
+ array![
|
|
|
+ 1766847064779993795984967344618836356750759980724568847727566676204733945,
|
|
|
+ 319252252405206634291073190903653114488682078063415369176250618646860635118,
|
|
|
+ 427774687951454487776318063357824898404188691225649546174530713404617785344,
|
|
|
+ 49565958604199796163020368,
|
|
|
+ 148907253454411774545738931219166892876160512393929267898119961543514185585,
|
|
|
+ 223938022913800988696085410923418445187967252047785407181969631814277398528,
|
|
|
+ 301,
|
|
|
+ ]
|
|
|
+ ),
|
|
|
+ 14
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+// Generated with `../../tools/test_vaas/src/bin/re_sign_price_updates.rs`
|
|
|
+fn price_update1_test() -> ByteArray {
|
|
|
+ ByteArrayImpl::new(
|
|
|
+ array_try_into(
|
|
|
+ array![
|
|
|
+ 141887862745809943100421399774809552050876420277163116849842965275903806689,
|
|
|
+ 210740906737592158039211995620336526131859667363627655742687286503264782608,
|
|
|
+ 437230063624699337579360546580839669896712252828825008570863758867641146081,
|
|
|
+ 3498691308882995183871222184377409432186747119716981166996399082193594993,
|
|
|
+ 1390200166945919815453709407753165121175395927094647129599868236,
|
|
|
+ 222819573728193325268644030206737371345667885599602384508424089704440116301,
|
|
|
+ 341318259000017461738706238280879290398059773267212529438772847337449455616,
|
|
|
+ 1275126645346645395843037504005879519843596923369759718556759844520336145,
|
|
|
+ 363528783578153760894082184744116718493621815898909809604883433584616420886,
|
|
|
+ 301537311768214106147206781423041990995720118715322906821301413003463484347,
|
|
|
+ 83150006264761451992768264969047148434524798781124754530141755679159432208,
|
|
|
+ 96387772316726941183358990094337324283641753573556594738287498821253761827,
|
|
|
+ 395908154570808692326126405856049827157095768069251211022053821585519235652,
|
|
|
+ 87135893730137265929093180553063146337041045646221968026289709394440932141,
|
|
|
+ 245333243912241114598596888050489286502591033459250287888834,
|
|
|
+ ]
|
|
|
+ ),
|
|
|
+ 25
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+// Generated with `../../tools/test_vaas/src/bin/re_sign_price_updates.rs`
|
|
|
+fn price_update2_test() -> ByteArray {
|
|
|
+ ByteArrayImpl::new(
|
|
|
+ array_try_into(
|
|
|
+ array![
|
|
|
+ 141887862745809943100421399774809552050874823427618844548942380383465221086,
|
|
|
+ 106893583704677921907497845070624642590618427233243792006390965895909696183,
|
|
|
+ 126617671723931969110123875642449115250793288301361049879364132884271078113,
|
|
|
+ 3498691308882995183871222184377409432186747119716981166996399082193594993,
|
|
|
+ 1390200461185063661704370212555794334034815850290352693418762308,
|
|
|
+ 419598057710749587537080281518289024699150505326900462079484531390510117965,
|
|
|
+ 341318259000017461738706238280879290398059773267212529438780607147892801536,
|
|
|
+ 1437437604754599821041091415535991441313586347841485651963630208563420739,
|
|
|
+ 305222830440467078008666830004555943609735125691441831219591213494068931362,
|
|
|
+ 358396406696718360717615797531477055540194104082154743994717297650279402646,
|
|
|
+ 429270385827211102844129651648706540139690432947840438198166022904666187018,
|
|
|
+ 343946166212648899477337159288779715507980257611242783073384876024451565860,
|
|
|
+ 67853010773876862913176476530730880916439012004585961528150130218675908823,
|
|
|
+ 370855179649505412564259994413632062925303311800103998016489412083011059699,
|
|
|
+ 1182295126766215829784496273374889928477877265080355104888778,
|
|
|
+ ]
|
|
|
+ ),
|
|
|
+ 25
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+// Generated with `../../tools/test_vaas/src/bin/re_sign_price_updates.rs`
|
|
|
+// (same as `price_update2_test()` but with a different emitter)
|
|
|
+fn price_update2_test_alt_emitter() -> ByteArray {
|
|
|
+ ByteArrayImpl::new(
|
|
|
+ array_try_into(
|
|
|
+ array![
|
|
|
+ 141887862745809943100421399774809552050876183715022494587482285730295850458,
|
|
|
+ 359963320496358929787450247990998878269668655936959553372924597144593948268,
|
|
|
+ 168294065609209340478050191639515428002729901421915929480902120205187023616,
|
|
|
+ 301,
|
|
|
+ 1390200461185063661704370212555794334034815850290352693418762308,
|
|
|
+ 419598057710749587537080281518289024699150505326900462079484531390510117965,
|
|
|
+ 341318259000017461738706238280879290398059773267212529438780607147892801536,
|
|
|
+ 1437437604754599821041091415535991441313586347841485651963630208563420739,
|
|
|
+ 305222830440467078008666830004555943609735125691441831219591213494068931362,
|
|
|
+ 358396406696718360717615797531477055540194104082154743994717297650279402646,
|
|
|
+ 429270385827211102844129651648706540139690432947840438198166022904666187018,
|
|
|
+ 343946166212648899477337159288779715507980257611242783073384876024451565860,
|
|
|
+ 67853010773876862913176476530730880916439012004585961528150130218675908823,
|
|
|
+ 370855179649505412564259994413632062925303311800103998016489412083011059699,
|
|
|
+ 1182295126766215829784496273374889928477877265080355104888778,
|
|
|
+ ]
|
|
|
+ ),
|
|
|
+ 25
|
|
|
+ )
|
|
|
+}
|