Rename TransactionCompiler to Script and use it to replace the type alias
This commit is contained in:
@ -292,7 +292,7 @@ mod test {
|
||||
dt,
|
||||
);
|
||||
assert_eq!(
|
||||
alice_client.process_script(vec![instruction]).unwrap_err(),
|
||||
alice_client.process_instruction(instruction).unwrap_err(),
|
||||
TransactionError::InstructionError(
|
||||
0,
|
||||
InstructionError::ProgramError(ProgramError::CustomError(
|
||||
@ -312,7 +312,7 @@ mod test {
|
||||
// that pubkey's funds are now available.
|
||||
let instruction =
|
||||
BudgetInstruction::new_apply_timestamp(&alice_pubkey, &budget_pubkey, &bob_pubkey, dt);
|
||||
alice_client.process_script(vec![instruction]).unwrap();
|
||||
alice_client.process_instruction(instruction).unwrap();
|
||||
assert_eq!(bank.get_balance(&alice_pubkey), 1);
|
||||
assert_eq!(bank.get_balance(&budget_pubkey), 0);
|
||||
assert_eq!(bank.get_balance(&bob_pubkey), 1);
|
||||
@ -353,7 +353,7 @@ mod test {
|
||||
|
||||
let instruction =
|
||||
BudgetInstruction::new_apply_signature(&mallory_pubkey, &budget_pubkey, &bob_pubkey);
|
||||
mallory_client.process_script(vec![instruction]).unwrap();
|
||||
mallory_client.process_instruction(instruction).unwrap();
|
||||
// nothing should be changed because apply witness didn't finalize a payment
|
||||
assert_eq!(bank.get_balance(&alice_pubkey), 1);
|
||||
assert_eq!(bank.get_balance(&budget_pubkey), 1);
|
||||
@ -362,7 +362,7 @@ mod test {
|
||||
// Now, cancel the transaction. mint gets her funds back
|
||||
let instruction =
|
||||
BudgetInstruction::new_apply_signature(&alice_pubkey, &budget_pubkey, &alice_pubkey);
|
||||
alice_client.process_script(vec![instruction]).unwrap();
|
||||
alice_client.process_instruction(instruction).unwrap();
|
||||
assert_eq!(bank.get_balance(&alice_pubkey), 2);
|
||||
assert_eq!(bank.get_account(&budget_pubkey), None);
|
||||
assert_eq!(bank.get_account(&bob_pubkey), None);
|
||||
|
@ -5,9 +5,10 @@ use bincode::serialized_size;
|
||||
use chrono::prelude::{DateTime, Utc};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::script::Script;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_instruction::SystemInstruction;
|
||||
use solana_sdk::transaction::{Instruction, Script};
|
||||
use solana_sdk::transaction::Instruction;
|
||||
|
||||
/// A smart contract.
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||
@ -48,10 +49,10 @@ impl BudgetInstruction {
|
||||
expr: BudgetExpr,
|
||||
) -> Script {
|
||||
let space = serialized_size(&BudgetState::new(expr.clone())).unwrap();
|
||||
vec![
|
||||
Script::new(vec![
|
||||
SystemInstruction::new_program_account(&from, contract, lamports, space, &id()),
|
||||
Self::new_initialize_account(contract, expr),
|
||||
]
|
||||
])
|
||||
}
|
||||
|
||||
/// Create a new payment script.
|
||||
|
@ -5,9 +5,10 @@ use bincode::deserialize;
|
||||
use chrono::prelude::*;
|
||||
use solana_sdk::hash::Hash;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::script::Script;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_instruction::SystemInstruction;
|
||||
use solana_sdk::transaction::{Script, Transaction};
|
||||
use solana_sdk::transaction::Transaction;
|
||||
|
||||
pub struct BudgetTransaction {}
|
||||
|
||||
@ -18,7 +19,7 @@ impl BudgetTransaction {
|
||||
recent_blockhash: Hash,
|
||||
fee: u64,
|
||||
) -> Transaction {
|
||||
let mut tx = Transaction::new(script);
|
||||
let mut tx = script.compile();
|
||||
tx.fee = fee;
|
||||
tx.sign(&[from_keypair], recent_blockhash);
|
||||
tx
|
||||
|
@ -55,9 +55,10 @@ mod tests {
|
||||
use solana_runtime::bank::Bank;
|
||||
use solana_runtime::bank_client::BankClient;
|
||||
use solana_sdk::genesis_block::GenesisBlock;
|
||||
use solana_sdk::script::Script;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_instruction::SystemInstruction;
|
||||
use solana_sdk::transaction::{Instruction, Transaction};
|
||||
use solana_sdk::transaction::Instruction;
|
||||
|
||||
#[derive(Serialize, Deserialize, Default, Debug, PartialEq)]
|
||||
struct MyConfig {
|
||||
@ -96,7 +97,7 @@ mod tests {
|
||||
let config_pubkey = config_client.pubkey();
|
||||
|
||||
let instruction = create_account_instruction(&from_pubkey, &config_pubkey);
|
||||
from_client.process_script(vec![instruction]).unwrap();
|
||||
from_client.process_instruction(instruction).unwrap();
|
||||
|
||||
config_client
|
||||
}
|
||||
@ -123,7 +124,7 @@ mod tests {
|
||||
|
||||
let my_config = MyConfig::new(42);
|
||||
let instruction = ConfigInstruction::new_store(&config_pubkey, &my_config);
|
||||
config_client.process_script(vec![instruction]).unwrap();
|
||||
config_client.process_instruction(instruction).unwrap();
|
||||
|
||||
let config_account = bank.get_account(&config_pubkey).unwrap();
|
||||
assert_eq!(
|
||||
@ -143,7 +144,8 @@ mod tests {
|
||||
let instruction = ConfigInstruction::new_store(&config_pubkey, &my_config);
|
||||
|
||||
// Replace instruction data with a vector that's too large
|
||||
let mut transaction = Transaction::new(vec![instruction]);
|
||||
let script = Script::new(vec![instruction]);
|
||||
let mut transaction = script.compile();
|
||||
transaction.instructions[0].data = vec![0; 123];
|
||||
config_client.process_transaction(transaction).unwrap_err();
|
||||
}
|
||||
@ -164,7 +166,8 @@ mod tests {
|
||||
let store_instruction = ConfigInstruction::new_store(&config_pubkey, &my_config);
|
||||
|
||||
// Don't sign the transaction with `config_client`
|
||||
let mut transaction = Transaction::new(vec![move_instruction, store_instruction]);
|
||||
let script = Script::new(vec![move_instruction, store_instruction]);
|
||||
let mut transaction = script.compile();
|
||||
transaction.sign_unchecked(&[&system_keypair], bank.last_blockhash());
|
||||
let system_client = BankClient::new(&bank, system_keypair);
|
||||
system_client.process_transaction(transaction).unwrap_err();
|
||||
|
Reference in New Issue
Block a user