Skip to content

Commit

Permalink
solana: remove initialize
Browse files Browse the repository at this point in the history
Signed-off-by: bingyuyap <[email protected]>
  • Loading branch information
bingyuyap committed Oct 8, 2024
1 parent 5e9ba22 commit a5c2f03
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 138 deletions.
44 changes: 0 additions & 44 deletions svm/programs/router/src/instructions/initialize.rs

This file was deleted.

2 changes: 0 additions & 2 deletions svm/programs/router/src/instructions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
pub mod initialize;
pub mod initialize_integrator_chain_transceivers;
pub mod initialize_integrator_config;
pub mod register_transceiver;

pub use initialize::*;
pub use initialize_integrator_chain_transceivers::*;
pub use initialize_integrator_config::*;
pub use register_transceiver::*;
9 changes: 0 additions & 9 deletions svm/programs/router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ declare_id!("7qtLhNMdb9dNAWwFvNBMok64EJrS1toY9TQoedVhU1xp");
pub mod router {
use super::*;

/// Initializes the GMP Router
///
/// # Arguments
///
/// * `ctx` - The context of the instruction
pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
instructions::initialize::initialize(ctx)
}

/// Initializes the integrator config
///
/// # Arguments
Expand Down
64 changes: 6 additions & 58 deletions svm/programs/router/tests/common/setup.rs
Original file line number Diff line number Diff line change
@@ -1,81 +1,29 @@
use anchor_lang::{
prelude::*, solana_program::instruction::Instruction, system_program, InstructionData,
};
use router::{id, state::Config};
use anchor_lang::prelude::*;
use router::id;
use solana_program_test::ProgramTest;
use solana_sdk::{
account::AccountSharedData,
hash::Hash,
signature::{Keypair, Signer},
};
use solana_sdk::{hash::Hash, signature::Keypair};

pub struct TestContext {
pub banks_client: solana_program_test::BanksClient,
pub payer: Keypair,
pub last_blockhash: Hash,
}

pub struct Initialize {
pub payer: Pubkey,
pub config: Pubkey,
}

pub async fn setup() -> (TestContext, Pubkey) {
pub async fn setup() -> TestContext {
// Set up the program test environment
let program_id = id();
let program_test = ProgramTest::new("router", program_id, None);

// Start the test context
let mut ctx = program_test.start_with_context().await;

// Derive the config PDA
let (config_pda, _bump) = Pubkey::find_program_address(&[Config::SEED_PREFIX], &program_id);

// Initialize the program
initialize_program(&mut ctx, config_pda).await;
let ctx = program_test.start_with_context().await;

let test_context = TestContext {
banks_client: ctx.banks_client,
payer: ctx.payer,
last_blockhash: ctx.last_blockhash,
};

(test_context, config_pda)
}

pub fn initialize(accounts: Initialize) -> Instruction {
let accounts = router::accounts::Initialize {
payer: accounts.payer,
config: accounts.config,
system_program: system_program::ID,
};

Instruction {
program_id: id(),
accounts: accounts.to_account_metas(None),
data: router::instruction::Initialize {}.data(),
}
}

async fn initialize_program(ctx: &mut solana_program_test::ProgramTestContext, config_pda: Pubkey) {
let initialize_accounts = Initialize {
payer: ctx.payer.pubkey(),
config: config_pda,
};

let ix = initialize(initialize_accounts);

let transaction = solana_sdk::transaction::Transaction::new_signed_with_payer(
&[ix],
Some(&ctx.payer.pubkey()),
&[&ctx.payer],
ctx.last_blockhash,
);

ctx.banks_client
.process_transaction(transaction)
.await
.unwrap();
test_context
}

pub async fn get_account<T: AccountDeserialize>(
Expand Down
19 changes: 0 additions & 19 deletions svm/programs/router/tests/initialize.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use solana_sdk::{signature::Keypair, signer::Signer};
#[tokio::test]
async fn test_initialize_integrator_chain_transceivers_success() {
// Set up the test environment
let (mut context, config_pda) = setup().await;
let mut context = setup().await;
let payer = context.payer.insecure_clone();
let authority = Keypair::new();
let integrator_program_id = Keypair::new().pubkey();
Expand Down Expand Up @@ -113,7 +113,7 @@ async fn test_initialize_integrator_chain_transceivers_success() {
#[tokio::test]
async fn test_initialize_integrator_chain_transceivers_different_chains() {
// Set up the test environment
let (mut context, config_pda) = setup().await;
let mut context = setup().await;
let payer = context.payer.insecure_clone();
let authority = Keypair::new();
let integrator_program_id = Keypair::new().pubkey();
Expand Down
4 changes: 2 additions & 2 deletions svm/programs/router/tests/initialize_integrator_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use solana_sdk::{signature::Keypair, signer::Signer};
#[tokio::test]
async fn test_initialize_integrator_config_success() {
// Set up the test environment
let (mut context, config_pda) = setup().await;
let mut context = setup().await;
let payer = context.payer.insecure_clone();
let authority = Keypair::new();
let integrator_program_id = Keypair::new().pubkey();
Expand Down Expand Up @@ -91,7 +91,7 @@ async fn test_initialize_integrator_config_success() {
#[tokio::test]
async fn test_initialize_integrator_config_different_programs() {
// Set up the test environment
let (mut context, config_pda) = setup().await;
let mut context = setup().await;
let payer = context.payer.insecure_clone();
let authority = Keypair::new();
let integrator_program_id_1 = Keypair::new().pubkey();
Expand Down
4 changes: 2 additions & 2 deletions svm/programs/router/tests/register_transceiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use solana_sdk::{signature::Keypair, signer::Signer};
#[tokio::test]
async fn test_register_transceiver_success() {
// Set up the test environment
let (mut context, config_pda) = setup().await;
let mut context = setup().await;
let payer = context.payer.insecure_clone();
let authority = Keypair::new();
let integrator_program_id = Keypair::new().pubkey();
Expand Down Expand Up @@ -81,7 +81,7 @@ async fn test_register_transceiver_success() {
#[tokio::test]
async fn test_register_multiple_transceivers() {
// Set up the test environment
let (mut context, config_pda) = setup().await;
let mut context = setup().await;
let payer = context.payer.insecure_clone();
let authority = Keypair::new();
let integrator_program_id = Keypair::new().pubkey();
Expand Down

0 comments on commit a5c2f03

Please sign in to comment.