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

chore: add update forester and governance authority test script #849

Merged
merged 1 commit into from
Jun 21, 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
1 change: 1 addition & 0 deletions programs/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ pub mod light_registry {
// increment points in registered relayer account
}

#[derive(Debug)]
#[account]
pub struct LightGovernanceAuthority {
pub authority: Pubkey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![cfg(feature = "test-sbf")]

use std::str::FromStr;

use account_compression::{
self, utils::constants::GROUP_AUTHORITY_SEED, GroupAuthority, RegisteredProgram, ID,
};
Expand All @@ -16,6 +14,7 @@ use solana_sdk::{
signature::{Keypair, Signer},
transaction::Transaction,
};
use std::str::FromStr;

/// Tests:
/// 1. Create group authority
Expand Down
2 changes: 1 addition & 1 deletion test-programs/registry-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ light-utils = {path = "../../utils"}
light-verifier = {path = "../../circuit-lib/verifier"}
solana-cli-output = "1.18.11"
serde_json = "1.0.114"
solana-sdk = "1.18.11"
solana-sdk = "1.18.11"
106 changes: 101 additions & 5 deletions test-programs/registry-test/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,31 @@ use light_registry::{
get_forester_epoch_pda_address,
sdk::{
create_nullify_instruction, create_update_address_merkle_tree_instruction,
CreateNullifyInstructionInputs, UpdateAddressMerkleTreeInstructionInputs,
get_governance_authority_pda, CreateNullifyInstructionInputs,
UpdateAddressMerkleTreeInstructionInputs,
},
RegistryError,
ForesterEpoch, LightGovernanceAuthority, RegistryError,
};
use light_test_utils::{
registry::{
create_rollover_address_merkle_tree_instructions,
create_rollover_state_merkle_tree_instructions, register_test_forester,
update_test_forester,
},
rpc::{errors::assert_rpc_error, rpc_connection::RpcConnection},
test_env::{register_program_with_registry_program, setup_test_programs_with_accounts},
rpc::{errors::assert_rpc_error, rpc_connection::RpcConnection, SolanaRpcConnection},
test_env::{
get_test_env_accounts, register_program_with_registry_program,
setup_test_programs_with_accounts,
},
};
use solana_sdk::{
instruction::Instruction,
native_token::LAMPORTS_PER_SOL,
pubkey::Pubkey,
signature::{read_keypair_file, Keypair},
signer::Signer,
};
use solana_sdk::{instruction::Instruction, signature::Keypair, signer::Signer};
use std::str::FromStr;

#[tokio::test]
async fn test_register_program() {
Expand Down Expand Up @@ -205,3 +216,88 @@ async fn failing_test_forester() {
assert_rpc_error(result, 2, expected_error_code).unwrap();
}
}

// cargo test-sbf -p registry-test -- --test update_registry_governance_on_testnet update_forester_on_testnet --ignored --nocapture
#[ignore]
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn update_forester_on_testnet() {
let testnet_url = "https://zk-testnet.helius.dev:8899";
let env_accounts = get_test_env_accounts();

let mut rpc = SolanaRpcConnection::new_with_url(testnet_url, None);
rpc.airdrop_lamports(&env_accounts.forester.pubkey(), LAMPORTS_PER_SOL * 100)
.await
.unwrap();
let forester_epoch_account =
Pubkey::from_str("8KEKiyAMugpKq9XCGzx81UtTBuytByW8arm9EaBVpD5k").unwrap();
let forester_epoch = rpc
.get_anchor_account::<ForesterEpoch>(&env_accounts.registered_forester_epoch_pda)
.await;
println!("ForesterEpoch: {:?}", forester_epoch_account);
assert_eq!(forester_epoch.authority, env_accounts.forester.pubkey());

let updated_keypair = read_keypair_file("../../target/forester-keypair.json").unwrap();
println!("updated keypair: {:?}", updated_keypair.pubkey());
update_test_forester(&mut rpc, &env_accounts.forester, &updated_keypair.pubkey())
.await
.unwrap();
let forester_epoch = rpc
.get_anchor_account::<ForesterEpoch>(&env_accounts.registered_forester_epoch_pda)
.await;
println!("ForesterEpoch: {:?}", forester_epoch_account);
assert_eq!(forester_epoch.authority, updated_keypair.pubkey());
}

#[ignore]
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn update_registry_governance_on_testnet() {
let testnet_url = "https://zk-testnet.helius.dev:8899";
let env_accounts = get_test_env_accounts();

let mut rpc = SolanaRpcConnection::new_with_url(testnet_url, None);
rpc.airdrop_lamports(
&&env_accounts.governance_authority.pubkey(),
LAMPORTS_PER_SOL * 100,
)
.await
.unwrap();
let governance_authority = rpc
.get_anchor_account::<LightGovernanceAuthority>(&env_accounts.governance_authority_pda)
.await;
println!("GroupAuthority: {:?}", governance_authority);
assert_eq!(
governance_authority.authority,
env_accounts.governance_authority.pubkey()
);

let updated_keypair =
read_keypair_file("../../target/governance-authority-keypair.json").unwrap();
println!("updated keypair: {:?}", updated_keypair.pubkey());
let (_, bump) = get_governance_authority_pda();
let instruction = light_registry::instruction::UpdateGovernanceAuthority {
new_authority: updated_keypair.pubkey(),
bump,
};
let accounts = light_registry::accounts::UpdateAuthority {
authority_pda: env_accounts.governance_authority_pda,
authority: env_accounts.governance_authority.pubkey(),
};
let ix = Instruction {
program_id: light_registry::ID,
accounts: accounts.to_account_metas(Some(true)),
data: instruction.data(),
};
let signature = rpc
.create_and_send_transaction(
&[ix],
&env_accounts.governance_authority.pubkey(),
&[&env_accounts.governance_authority],
)
.await
.unwrap();
println!("signature: {:?}", signature);
let governance_authority = rpc
.get_anchor_account::<LightGovernanceAuthority>(&env_accounts.governance_authority_pda)
.await;
assert_eq!(governance_authority.authority, updated_keypair.pubkey());
}