Skip to content

Commit e225595

Browse files
authored
Enable governance by master authority (#308)
* Update master key to be able to perform all admin actions * Update tests * Update error for unauthorized publisher * Fix CI
1 parent f285596 commit e225595

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

program/rust/src/accounts/permission.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl PermissionAccount {
4545
pub fn is_authorized(&self, key: &Pubkey, command: OracleCommand) -> bool {
4646
#[allow(clippy::match_like_matches_macro)]
4747
match (*key, command) {
48-
(pubkey, OracleCommand::InitMapping) if pubkey == self.master_authority => true,
48+
(pubkey, _) if pubkey == self.master_authority => true,
4949
_ => false,
5050
}
5151
}

program/rust/src/processor/upd_price.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub fn upd_price(
9696
}
9797
pyth_assert(
9898
publisher_index < try_convert::<u32, usize>(price_data.num_)?,
99-
ProgramError::InvalidArgument,
99+
OracleError::PermissionViolation.into(),
100100
)?;
101101

102102

program/rust/src/tests/test_permission_migration.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ fn test_permission_migration() {
8282
&[
8383
attacker_account.clone(),
8484
mapping_account.clone(),
85-
next_mapping_account.clone(),
8685
permissions_account.clone()
8786
],
88-
bytes_of::<CommandHeader>(&AddMapping.into())
87+
bytes_of::<CommandHeader>(&InitMapping.into())
8988
),
9089
Err(OracleError::PermissionViolation.into())
9190
);
@@ -106,7 +105,7 @@ fn test_permission_migration() {
106105
process_instruction(
107106
&program_id,
108107
&[
109-
funding_account.clone(),
108+
attacker_account.clone(),
110109
mapping_account.clone(),
111110
next_mapping_account.clone(),
112111
permissions_account.clone()
@@ -120,7 +119,7 @@ fn test_permission_migration() {
120119
process_instruction(
121120
&program_id,
122121
&[
123-
funding_account.clone(),
122+
attacker_account.clone(),
124123
mapping_account.clone(),
125124
product_account.clone(),
126125
permissions_account.clone()
@@ -134,7 +133,7 @@ fn test_permission_migration() {
134133
process_instruction(
135134
&program_id,
136135
&[
137-
funding_account.clone(),
136+
attacker_account.clone(),
138137
product_account.clone(),
139138
permissions_account.clone()
140139
],
@@ -147,7 +146,7 @@ fn test_permission_migration() {
147146
process_instruction(
148147
&program_id,
149148
&[
150-
funding_account.clone(),
149+
attacker_account.clone(),
151150
product_account.clone(),
152151
price_account.clone(),
153152
permissions_account.clone()
@@ -165,7 +164,7 @@ fn test_permission_migration() {
165164
process_instruction(
166165
&program_id,
167166
&[
168-
funding_account.clone(),
167+
attacker_account.clone(),
169168
price_account.clone(),
170169
permissions_account.clone()
171170
],
@@ -182,7 +181,7 @@ fn test_permission_migration() {
182181
process_instruction(
183182
&program_id,
184183
&[
185-
funding_account.clone(),
184+
attacker_account.clone(),
186185
price_account.clone(),
187186
permissions_account.clone()
188187
],
@@ -198,7 +197,7 @@ fn test_permission_migration() {
198197
process_instruction(
199198
&program_id,
200199
&[
201-
funding_account.clone(),
200+
attacker_account.clone(),
202201
price_account.clone(),
203202
permissions_account.clone()
204203
],
@@ -214,7 +213,7 @@ fn test_permission_migration() {
214213
process_instruction(
215214
&program_id,
216215
&[
217-
funding_account.clone(),
216+
attacker_account.clone(),
218217
price_account.clone(),
219218
permissions_account.clone()
220219
],
@@ -231,7 +230,7 @@ fn test_permission_migration() {
231230
process_instruction(
232231
&program_id,
233232
&[
234-
funding_account.clone(),
233+
attacker_account.clone(),
235234
price_account.clone(),
236235
price_account.clone(), // Mock system program
237236
permissions_account.clone()
@@ -245,7 +244,7 @@ fn test_permission_migration() {
245244
process_instruction(
246245
&program_id,
247246
&[
248-
funding_account.clone(),
247+
attacker_account.clone(),
249248
product_account.clone(),
250249
price_account.clone(),
251250
permissions_account.clone()
@@ -259,7 +258,7 @@ fn test_permission_migration() {
259258
process_instruction(
260259
&program_id,
261260
&[
262-
funding_account.clone(),
261+
attacker_account.clone(),
263262
mapping_account.clone(),
264263
product_account.clone(),
265264
permissions_account.clone()

program/rust/src/tests/test_upd_price_no_fail_on_error.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use {
1313
load_checked,
1414
load_mut,
1515
},
16+
error::OracleError,
1617
instruction::{
1718
OracleCommand,
1819
UpdPriceArgs,
@@ -65,7 +66,7 @@ fn test_upd_price_no_fail_on_error_no_fail_on_error() {
6566
],
6667
&instruction_data
6768
),
68-
Err(ProgramError::InvalidArgument)
69+
Err(OracleError::PermissionViolation.into())
6970
);
7071

7172

0 commit comments

Comments
 (0)