|
|
@@ -9,6 +9,7 @@ use pyth::byte_array::{ByteArray, ByteArrayImpl};
|
|
|
use pyth::util::{array_try_into, UnwrapWithFelt252};
|
|
|
use core::starknet::ContractAddress;
|
|
|
use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait};
|
|
|
+use super::wormhole::corrupted_vm;
|
|
|
|
|
|
fn decode_event(event: @Event) -> PythEvent {
|
|
|
if *event.keys.at(0) == event_name_hash('PriceFeedUpdate') {
|
|
|
@@ -78,28 +79,102 @@ fn update_price_feeds_works() {
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
-#[should_panic(expected: ('todo',))]
|
|
|
-fn test_governance_instruction() {
|
|
|
+fn test_governance_set_fee_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('fee_minter'.try_into().unwrap());
|
|
|
+ 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));
|
|
|
+
|
|
|
+ let mut balance = fee_contract.balanceOf(user);
|
|
|
+ start_prank(CheatTarget::One(pyth.contract_address), user);
|
|
|
pyth
|
|
|
- .execute_governance_instruction(
|
|
|
+ .update_price_feeds(
|
|
|
ByteArrayImpl::new(
|
|
|
array_try_into(
|
|
|
array![
|
|
|
- 1766847064779996587365624568667043246291590523274145657502751050464410443,
|
|
|
- 182147492092754791035110789954683447734750444021289139488583154515468770101,
|
|
|
- 260016405939643347307460729490551925646487038190069904485177441375406260224,
|
|
|
- 49565958604199796163020368,
|
|
|
- 8072278384728444780182694421117884443886221966887092232,
|
|
|
+ 141887862745809943100421399774809552050876420277163116849842965275903806689,
|
|
|
+ 210740906737592158039211995620336526131859667363627655742687286503264782608,
|
|
|
+ 437230063624699337579360546580839669896712252828825008570863758867641146081,
|
|
|
+ 3498691308882995183871222184377409432186747119716981166996399082193594993,
|
|
|
+ 1390200166945919815453709407753165121175395927094647129599868236,
|
|
|
+ 222819573728193325268644030206737371345667885599602384508424089704440116301,
|
|
|
+ 341318259000017461738706238280879290398059773267212529438772847337449455616,
|
|
|
+ 1275126645346645395843037504005879519843596923369759718556759844520336145,
|
|
|
+ 363528783578153760894082184744116718493621815898909809604883433584616420886,
|
|
|
+ 301537311768214106147206781423041990995720118715322906821301413003463484347,
|
|
|
+ 83150006264761451992768264969047148434524798781124754530141755679159432208,
|
|
|
+ 96387772316726941183358990094337324283641753573556594738287498821253761827,
|
|
|
+ 395908154570808692326126405856049827157095768069251211022053821585519235652,
|
|
|
+ 87135893730137265929093180553063146337041045646221968026289709394440932141,
|
|
|
+ 245333243912241114598596888050489286502591033459250287888834,
|
|
|
]
|
|
|
),
|
|
|
- 23
|
|
|
+ 25
|
|
|
)
|
|
|
);
|
|
|
+ stop_prank(CheatTarget::One(pyth.contract_address));
|
|
|
+ let new_balance = fee_contract.balanceOf(user);
|
|
|
+ assert!(balance - new_balance == 1000);
|
|
|
+ balance = new_balance;
|
|
|
+ let last_price = pyth
|
|
|
+ .get_price_unsafe(0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43)
|
|
|
+ .unwrap_with_felt252();
|
|
|
+ assert!(last_price.price == 6281060000000);
|
|
|
+
|
|
|
+ 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
|
|
|
+ )
|
|
|
+ );
|
|
|
+ stop_prank(CheatTarget::One(pyth.contract_address));
|
|
|
+ let new_balance = fee_contract.balanceOf(user);
|
|
|
+ assert!(balance - new_balance == 4200);
|
|
|
+ let last_price = pyth
|
|
|
+ .get_price_unsafe(0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43)
|
|
|
+ .unwrap_with_felt252();
|
|
|
+ assert!(last_price.price == 6281522520745);
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+#[fuzzer(runs: 100, seed: 0)]
|
|
|
+#[should_panic]
|
|
|
+fn test_rejects_corrupted_governance_instruction(pos: usize, random1: usize, random2: usize) {
|
|
|
+ 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);
|
|
|
+
|
|
|
+ let input = corrupted_vm(governance_set_fee(), pos, random1, random2);
|
|
|
+ pyth.execute_governance_instruction(input);
|
|
|
}
|
|
|
|
|
|
fn deploy_default(
|
|
|
@@ -211,3 +286,18 @@ fn good_update1() -> ByteArray {
|
|
|
];
|
|
|
ByteArrayImpl::new(array_try_into(bytes), 11)
|
|
|
}
|
|
|
+
|
|
|
+fn governance_set_fee() -> ByteArray {
|
|
|
+ ByteArrayImpl::new(
|
|
|
+ array_try_into(
|
|
|
+ array![
|
|
|
+ 1766847064779993955862540543984267022910717161432209540262366788014689913,
|
|
|
+ 322968519187498395396360816568387642032723484530650782503164941848016432477,
|
|
|
+ 407975527128964115747680681091773270935844489133353741223501742992990928896,
|
|
|
+ 49565958604199796163020368,
|
|
|
+ 8072278384728444780182694421117884443886221966887092226,
|
|
|
+ ]
|
|
|
+ ),
|
|
|
+ 23
|
|
|
+ )
|
|
|
+}
|