diff --git a/Cargo.lock b/Cargo.lock index c17773926c..2ad6bf0aa9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2076,6 +2076,7 @@ dependencies = [ "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "solana-budget-api 0.12.0", "solana-logger 0.12.0", + "solana-runtime 0.12.0", "solana-sdk 0.12.0", ] diff --git a/programs/budget/Cargo.toml b/programs/budget/Cargo.toml index 0949e32e7f..f444c29ecb 100644 --- a/programs/budget/Cargo.toml +++ b/programs/budget/Cargo.toml @@ -18,6 +18,9 @@ solana-budget-api = { path = "../budget_api", version = "0.12.0" } solana-logger = { path = "../../logger", version = "0.12.0" } solana-sdk = { path = "../../sdk", version = "0.12.0" } +[dev-dependencies] +solana-runtime = { path = "../../runtime", version = "0.12.0" } + [lib] name = "solana_budget_program" crate-type = ["cdylib"] diff --git a/programs/budget/tests/budget.rs b/programs/budget/tests/budget.rs new file mode 100644 index 0000000000..62c9f1d6fb --- /dev/null +++ b/programs/budget/tests/budget.rs @@ -0,0 +1,32 @@ +use solana_budget_api::budget_transaction::BudgetTransaction; +use solana_runtime::bank::{Bank, Result}; +use solana_sdk::genesis_block::GenesisBlock; +use solana_sdk::pubkey::Pubkey; +use solana_sdk::signature::{Keypair, KeypairUtil}; + +struct BudgetBank<'a> { + bank: &'a Bank, +} + +impl<'a> BudgetBank<'a> { + fn new(bank: &'a Bank) -> Self { + bank.add_native_program("solana_budget_program", &solana_budget_api::id()); + Self { bank } + } + + fn pay(&self, from_keypair: &Keypair, to_id: Pubkey, lamports: u64) -> Result<()> { + let blockhash = self.bank.last_blockhash(); + let tx = BudgetTransaction::new_payment(from_keypair, to_id, lamports, blockhash, 0); + self.bank.process_transaction(&tx) + } +} + +#[test] +fn test_budget_payment_via_bank() { + let (genesis_block, from_keypair) = GenesisBlock::new(10_000); + let bank = Bank::new(&genesis_block); + let budget_bank = BudgetBank::new(&bank); + let to_id = Keypair::new().pubkey(); + budget_bank.pay(&from_keypair, to_id, 100).unwrap(); + assert_eq!(bank.get_balance(&to_id), 100); +}