-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add basic test for change_authorized_agent
- Loading branch information
1 parent
cbfdf97
commit 0734a76
Showing
2 changed files
with
140 additions
and
2 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
programs/voter-stake-registry/tests/change_authorized_agent.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
use anchor_spl::token::TokenAccount; | ||
use mplx_staking_states::state::{LockupKind, LockupPeriod}; | ||
use program_test::*; | ||
use solana_program_test::*; | ||
use solana_sdk::{signature::Keypair, signer::Signer, transport::TransportError}; | ||
|
||
mod program_test; | ||
|
||
#[tokio::test] | ||
async fn stake_with_delegate() -> Result<(), TransportError> { | ||
let context = TestContext::new().await; | ||
|
||
let payer = &context.users[0].key; | ||
let realm_authority = Keypair::new(); | ||
let realm = context | ||
.governance | ||
.create_realm( | ||
"testrealm", | ||
realm_authority.pubkey(), | ||
&context.mints[0], | ||
payer, | ||
&context.addin.program_id, | ||
) | ||
.await; | ||
|
||
let voter_authority = &context.users[1].key; | ||
let token_owner_record = realm | ||
.create_token_owner_record(voter_authority.pubkey(), payer) | ||
.await; | ||
|
||
let fill_authority = Keypair::from_bytes(&context.users[3].key.to_bytes()).unwrap(); | ||
let distribution_authority = Keypair::new(); | ||
let (registrar, rewards_pool) = context | ||
.addin | ||
.create_registrar( | ||
&realm, | ||
&realm_authority, | ||
payer, | ||
&fill_authority.pubkey(), | ||
&distribution_authority.pubkey(), | ||
&context.rewards.program_id, | ||
) | ||
.await; | ||
context | ||
.addin | ||
.configure_voting_mint( | ||
®istrar, | ||
&realm_authority, | ||
payer, | ||
0, | ||
&context.mints[0], | ||
None, | ||
None, | ||
) | ||
.await; | ||
let _mngo_voting_mint = context | ||
.addin | ||
.configure_voting_mint( | ||
®istrar, | ||
&realm_authority, | ||
payer, | ||
0, | ||
&context.mints[0], | ||
None, | ||
None, | ||
) | ||
.await; | ||
|
||
let (deposit_mining, _) = find_deposit_mining_addr( | ||
&context.rewards.program_id, | ||
&voter_authority.pubkey(), | ||
&rewards_pool, | ||
); | ||
|
||
let voter = context | ||
.addin | ||
.create_voter( | ||
®istrar, | ||
&token_owner_record, | ||
voter_authority, | ||
payer, | ||
&rewards_pool, | ||
&deposit_mining, | ||
&context.rewards.program_id, | ||
) | ||
.await; | ||
|
||
let voter_account = voter.get_voter(&context.solana).await; | ||
assert_eq!(voter_account.authorized_agent, voter.authority.pubkey()); | ||
|
||
// CREATE AGENT | ||
let authorized_agent = Keypair::new(); | ||
|
||
context | ||
.addin | ||
.change_authorized_agent(®istrar, &voter, authorized_agent.pubkey()) | ||
.await?; | ||
|
||
let voter_account = voter.get_voter(&context.solana).await; | ||
assert_eq!(voter_account.authorized_agent, authorized_agent.pubkey()); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters