Move Bank-based tests into unit-tests
This commit is contained in:
@ -158,6 +158,17 @@ mod test {
|
||||
(bank, mint_keypair)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_budget_payment() {
|
||||
let (bank, mint_keypair) = create_bank(10_000);
|
||||
let alice_client = BankClient::new(&bank, mint_keypair);
|
||||
let alice_pubkey = alice_client.pubkey();
|
||||
let bob_pubkey = Keypair::new().pubkey();
|
||||
let script = BudgetInstruction::new_payment_script(&alice_pubkey, &bob_pubkey, 100);
|
||||
alice_client.process_script(script).unwrap();
|
||||
assert_eq!(bank.get_balance(&bob_pubkey), 100);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unsigned_witness_key() {
|
||||
let (bank, mint_keypair) = create_bank(10_000);
|
@ -1,6 +1,6 @@
|
||||
mod budget_program;
|
||||
mod budget_processor;
|
||||
|
||||
use crate::budget_program::process_instruction;
|
||||
use crate::budget_processor::process_instruction;
|
||||
use log::*;
|
||||
use solana_sdk::account::KeyedAccount;
|
||||
use solana_sdk::native_program::ProgramError;
|
||||
|
@ -5,6 +5,7 @@ use bincode::serialized_size;
|
||||
use chrono::prelude::{DateTime, Utc};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_instruction::SystemInstruction;
|
||||
use solana_sdk::transaction::{Instruction, Script};
|
||||
|
||||
@ -53,6 +54,13 @@ impl BudgetInstruction {
|
||||
]
|
||||
}
|
||||
|
||||
/// Create a new payment script.
|
||||
pub fn new_payment_script(from: &Pubkey, to: &Pubkey, lamports: u64) -> Script {
|
||||
let contract = Keypair::new().pubkey();
|
||||
let expr = BudgetExpr::new_payment(lamports, to);
|
||||
Self::new_initialize_account_script(from, &contract, lamports, expr)
|
||||
}
|
||||
|
||||
/// Create a postdated payment script.
|
||||
pub fn new_on_date_script(
|
||||
from: &Pubkey,
|
||||
|
@ -1,10 +1,7 @@
|
||||
//! The `budget_transaction` module provides functionality for creating Budget transactions.
|
||||
|
||||
use crate::budget_expr::BudgetExpr;
|
||||
use crate::budget_instruction::BudgetInstruction;
|
||||
use crate::budget_state::BudgetState;
|
||||
use crate::id;
|
||||
use bincode::{deserialize, serialized_size};
|
||||
use bincode::deserialize;
|
||||
use chrono::prelude::*;
|
||||
use solana_sdk::hash::Hash;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
@ -15,27 +12,6 @@ use solana_sdk::transaction::{Script, Transaction};
|
||||
pub struct BudgetTransaction {}
|
||||
|
||||
impl BudgetTransaction {
|
||||
/// Create and sign a new Transaction. Used for unit-testing.
|
||||
#[allow(clippy::new_ret_no_self)]
|
||||
fn new(
|
||||
from_keypair: &Keypair,
|
||||
contract: &Pubkey,
|
||||
expr: BudgetExpr,
|
||||
lamports: u64,
|
||||
recent_blockhash: Hash,
|
||||
fee: u64,
|
||||
) -> Transaction {
|
||||
let from = from_keypair.pubkey();
|
||||
let space = serialized_size(&BudgetState::new(expr.clone())).unwrap();
|
||||
let create_ix =
|
||||
SystemInstruction::new_program_account(&from, contract, lamports, space, &id());
|
||||
let init_ix = BudgetInstruction::new_initialize_account(contract, expr);
|
||||
let mut tx = Transaction::new(vec![create_ix, init_ix]);
|
||||
tx.fee = fee;
|
||||
tx.sign(&[from_keypair], recent_blockhash);
|
||||
tx
|
||||
}
|
||||
|
||||
fn new_signed(
|
||||
from_keypair: &Keypair,
|
||||
script: Script,
|
||||
@ -56,16 +32,8 @@ impl BudgetTransaction {
|
||||
recent_blockhash: Hash,
|
||||
fee: u64,
|
||||
) -> Transaction {
|
||||
let contract = Keypair::new().pubkey();
|
||||
let expr = BudgetExpr::new_payment(lamports, to);
|
||||
Self::new(
|
||||
from_keypair,
|
||||
&contract,
|
||||
expr,
|
||||
lamports,
|
||||
recent_blockhash,
|
||||
fee,
|
||||
)
|
||||
let script = BudgetInstruction::new_payment_script(&from_keypair.pubkey(), to, lamports);
|
||||
Self::new_signed(from_keypair, script, recent_blockhash, fee)
|
||||
}
|
||||
|
||||
/// Create and sign a new Witness Timestamp. Used for unit-testing.
|
||||
|
Reference in New Issue
Block a user