Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Solana] governance tests #1265

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions target_chains/solana/programs/pyth-solana-receiver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ pub mod pyth_solana_receiver {
Ok(())
}

pub fn authorize_governance_authority_transfer(
ctx: Context<AuthorizeGovernanceAuthorityTransfer>,
pub fn accept_governance_authority_transfer(
ctx: Context<AcceptGovernanceAuthorityTransfer>,
) -> Result<()> {
let config = &mut ctx.accounts.config;
config.governance_authority = config.target_governance_authority.ok_or(error!(
Expand Down Expand Up @@ -244,13 +244,13 @@ pub struct Governance<'info> {
}

#[derive(Accounts)]
pub struct AuthorizeGovernanceAuthorityTransfer<'info> {
pub struct AcceptGovernanceAuthorityTransfer<'info> {
#[account(constraint =
payer.key() == config.target_governance_authority.ok_or(error!(ReceiverError::NonexistentGovernanceAuthorityTransferRequest))? @
ReceiverError::TargetGovernanceAuthorityMismatch
)]
pub payer: Signer<'info>,
#[account(seeds = [CONFIG_SEED.as_ref()], bump)]
#[account(mut, seeds = [CONFIG_SEED.as_ref()], bump)]
pub config: Account<'info, Config>,
}

Expand Down
57 changes: 57 additions & 0 deletions target_chains/solana/programs/pyth-solana-receiver/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ impl accounts::Governance {
}
}

impl accounts::AcceptGovernanceAuthorityTransfer {
pub fn populate(payer: Pubkey) -> Self {
let config = get_config_address();
accounts::AcceptGovernanceAuthorityTransfer { payer, config }
}
}

impl instruction::Initialize {
pub fn populate(payer: &Pubkey, initial_config: Config) -> Instruction {
Instruction {
Expand Down Expand Up @@ -173,6 +180,56 @@ impl instruction::SetFee {
}


impl instruction::SetWormholeAddress {
pub fn populate(payer: Pubkey, wormhole: Pubkey) -> Instruction {
let governance_accounts = accounts::Governance::populate(payer).to_account_metas(None);
Instruction {
program_id: ID,
accounts: governance_accounts,
data: instruction::SetWormholeAddress { wormhole }.data(),
}
}
}


impl instruction::SetMinimumSignatures {
pub fn populate(payer: Pubkey, minimum_signatures: u8) -> Instruction {
let governance_accounts = accounts::Governance::populate(payer).to_account_metas(None);
Instruction {
program_id: ID,
accounts: governance_accounts,
data: instruction::SetMinimumSignatures { minimum_signatures }.data(),
}
}
}

impl instruction::RequestGovernanceAuthorityTransfer {
pub fn populate(payer: Pubkey, target_governance_authority: Pubkey) -> Instruction {
let governance_accounts = accounts::Governance::populate(payer).to_account_metas(None);
Instruction {
program_id: ID,
accounts: governance_accounts,
data: instruction::RequestGovernanceAuthorityTransfer {
target_governance_authority,
}
.data(),
}
}
}

impl instruction::AcceptGovernanceAuthorityTransfer {
pub fn populate(payer: Pubkey) -> Instruction {
let governance_accounts =
accounts::AcceptGovernanceAuthorityTransfer::populate(payer).to_account_metas(None);
Instruction {
program_id: ID,
accounts: governance_accounts,
data: instruction::AcceptGovernanceAuthorityTransfer {}.data(),
}
}
}


pub fn get_treasury_address() -> Pubkey {
Pubkey::find_program_address(&[TREASURY_SEED.as_ref()], &ID).0
}
Expand Down
Loading
Loading