fixup! s/contract/program
This commit is contained in:
parent
9bfead2e01
commit
c0e7e43e96
|
@ -107,7 +107,7 @@ Returns all information associated with the account of provided Pubkey
|
||||||
The result field will be a JSON object with the following sub fields:
|
The result field will be a JSON object with the following sub fields:
|
||||||
|
|
||||||
* `tokens`, number of tokens assigned to this account, as a signed 64-bit integer
|
* `tokens`, number of tokens assigned to this account, as a signed 64-bit integer
|
||||||
* `contract_id`, array of 32 bytes representing the program this account has been assigned to
|
* `program_id`, array of 32 bytes representing the program this account has been assigned to
|
||||||
* `userdata`, array of bytes representing any userdata associated with the account
|
* `userdata`, array of bytes representing any userdata associated with the account
|
||||||
|
|
||||||
##### Example:
|
##### Example:
|
||||||
|
@ -116,7 +116,7 @@ The result field will be a JSON object with the following sub fields:
|
||||||
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, "method":"getAccountInfo", "params":["FVxxngPx368XvMCoeskdd6U8cZJFsfa1BEtGWqyAxRj4"]}' http://localhost:8899
|
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, "method":"getAccountInfo", "params":["FVxxngPx368XvMCoeskdd6U8cZJFsfa1BEtGWqyAxRj4"]}' http://localhost:8899
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
{"jsonrpc":"2.0","result":{"contract_id":[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tokens":1,"userdata":[3,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,20,0,0,0,0,0,0,0,50,48,53,48,45,48,49,45,48,49,84,48,48,58,48,48,58,48,48,90,252,10,7,28,246,140,88,177,98,82,10,227,89,81,18,30,194,101,199,16,11,73,133,20,246,62,114,39,20,113,189,32,50,0,0,0,0,0,0,0,247,15,36,102,167,83,225,42,133,127,82,34,36,224,207,130,109,230,224,188,163,33,213,13,5,117,211,251,65,159,197,51,0,0,0,0,0,0]},"id":1}
|
{"jsonrpc":"2.0","result":{"program_id":[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tokens":1,"userdata":[3,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,20,0,0,0,0,0,0,0,50,48,53,48,45,48,49,45,48,49,84,48,48,58,48,48,58,48,48,90,252,10,7,28,246,140,88,177,98,82,10,227,89,81,18,30,194,101,199,16,11,73,133,20,246,62,114,39,20,113,189,32,50,0,0,0,0,0,0,0,247,15,36,102,167,83,225,42,133,127,82,34,36,224,207,130,109,230,224,188,163,33,213,13,5,117,211,251,65,159,197,51,0,0,0,0,0,0]},"id":1}
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
12
src/bank.rs
12
src/bank.rs
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
use bincode::deserialize;
|
use bincode::deserialize;
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
use budget_program::BudgetProgram;
|
use budget_program::BudgetState;
|
||||||
use counter::Counter;
|
use counter::Counter;
|
||||||
use entry::Entry;
|
use entry::Entry;
|
||||||
use hash::{hash, Hash};
|
use hash::{hash, Hash};
|
||||||
|
@ -284,7 +284,7 @@ impl Bank {
|
||||||
} else {
|
} else {
|
||||||
error_counters.account_not_found_leader += 1;
|
error_counters.account_not_found_leader += 1;
|
||||||
}
|
}
|
||||||
if BudgetProgram::check_id(&tx.program_id) {
|
if BudgetState::check_id(&tx.program_id) {
|
||||||
use instruction::Instruction;
|
use instruction::Instruction;
|
||||||
if let Some(Instruction::NewVote(_vote)) = tx.instruction() {
|
if let Some(Instruction::NewVote(_vote)) = tx.instruction() {
|
||||||
error_counters.account_not_found_vote += 1;
|
error_counters.account_not_found_vote += 1;
|
||||||
|
@ -355,10 +355,10 @@ impl Bank {
|
||||||
// It's up to the contract to implement its own rules on moving funds
|
// It's up to the contract to implement its own rules on moving funds
|
||||||
if SystemProgram::check_id(&tx.program_id) {
|
if SystemProgram::check_id(&tx.program_id) {
|
||||||
SystemProgram::process_transaction(&tx, accounts)
|
SystemProgram::process_transaction(&tx, accounts)
|
||||||
} else if BudgetProgram::check_id(&tx.program_id) {
|
} else if BudgetState::check_id(&tx.program_id) {
|
||||||
// TODO: the runtime should be checking read/write access to memory
|
// TODO: the runtime should be checking read/write access to memory
|
||||||
// we are trusting the hard coded contracts not to clobber or allocate
|
// we are trusting the hard coded contracts not to clobber or allocate
|
||||||
BudgetProgram::process_transaction(&tx, accounts)
|
BudgetState::process_transaction(&tx, accounts)
|
||||||
} else {
|
} else {
|
||||||
return Err(BankError::UnknownContractId(tx.program_id));
|
return Err(BankError::UnknownContractId(tx.program_id));
|
||||||
}
|
}
|
||||||
|
@ -609,8 +609,8 @@ impl Bank {
|
||||||
pub fn read_balance(account: &Account) -> i64 {
|
pub fn read_balance(account: &Account) -> i64 {
|
||||||
if SystemProgram::check_id(&account.program_id) {
|
if SystemProgram::check_id(&account.program_id) {
|
||||||
SystemProgram::get_balance(account)
|
SystemProgram::get_balance(account)
|
||||||
} else if BudgetProgram::check_id(&account.program_id) {
|
} else if BudgetState::check_id(&account.program_id) {
|
||||||
BudgetProgram::get_balance(account)
|
BudgetState::get_balance(account)
|
||||||
} else {
|
} else {
|
||||||
account.tokens
|
account.tokens
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ pub enum BudgetError {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
|
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
|
||||||
pub struct BudgetProgram {
|
pub struct BudgetState {
|
||||||
pub initialized: bool,
|
pub initialized: bool,
|
||||||
pub pending_budget: Option<Budget>,
|
pub pending_budget: Option<Budget>,
|
||||||
pub last_error: Option<BudgetError>,
|
pub last_error: Option<BudgetError>,
|
||||||
|
@ -32,7 +32,7 @@ pub struct BudgetProgram {
|
||||||
pub const BUDGET_PROGRAM_ID: [u8; 32] = [
|
pub const BUDGET_PROGRAM_ID: [u8; 32] = [
|
||||||
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
];
|
];
|
||||||
impl BudgetProgram {
|
impl BudgetState {
|
||||||
fn is_pending(&self) -> bool {
|
fn is_pending(&self) -> bool {
|
||||||
self.pending_budget != None
|
self.pending_budget != None
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ impl BudgetProgram {
|
||||||
trace!("contract already exists");
|
trace!("contract already exists");
|
||||||
Err(BudgetError::ContractAlreadyExists(tx.keys[1]))
|
Err(BudgetError::ContractAlreadyExists(tx.keys[1]))
|
||||||
} else {
|
} else {
|
||||||
let mut state = BudgetProgram::default();
|
let mut state = BudgetState::default();
|
||||||
state.pending_budget = Some(budget);
|
state.pending_budget = Some(budget);
|
||||||
accounts[1].tokens += contract.tokens;
|
accounts[1].tokens += contract.tokens;
|
||||||
state.initialized = true;
|
state.initialized = true;
|
||||||
|
@ -231,7 +231,7 @@ impl BudgetProgram {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_error_to_budget_state(e: BudgetError, accounts: &mut [Account]) -> () {
|
fn save_error_to_budget_state(e: BudgetError, accounts: &mut [Account]) -> () {
|
||||||
if let Ok(mut state) = BudgetProgram::deserialize(&accounts[1].userdata) {
|
if let Ok(mut state) = BudgetState::deserialize(&accounts[1].userdata) {
|
||||||
trace!("saved error {:?}", e);
|
trace!("saved error {:?}", e);
|
||||||
state.last_error = Some(e);
|
state.last_error = Some(e);
|
||||||
state.serialize(&mut accounts[1].userdata).unwrap();
|
state.serialize(&mut accounts[1].userdata).unwrap();
|
||||||
|
@ -262,7 +262,7 @@ impl BudgetProgram {
|
||||||
//TODO the contract needs to provide a "get_balance" introspection call of the userdata
|
//TODO the contract needs to provide a "get_balance" introspection call of the userdata
|
||||||
pub fn get_balance(account: &Account) -> i64 {
|
pub fn get_balance(account: &Account) -> i64 {
|
||||||
if let Ok(state) = deserialize(&account.userdata) {
|
if let Ok(state) = deserialize(&account.userdata) {
|
||||||
let state: BudgetProgram = state;
|
let state: BudgetState = state;
|
||||||
if state.is_pending() {
|
if state.is_pending() {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
|
@ -277,26 +277,26 @@ impl BudgetProgram {
|
||||||
mod test {
|
mod test {
|
||||||
use bank::Account;
|
use bank::Account;
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
use budget_program::{BudgetError, BudgetProgram};
|
use budget_program::{BudgetError, BudgetState};
|
||||||
use chrono::prelude::{DateTime, NaiveDate, Utc};
|
use chrono::prelude::{DateTime, NaiveDate, Utc};
|
||||||
use hash::Hash;
|
use hash::Hash;
|
||||||
use signature::{GenKeys, Keypair, KeypairUtil, Pubkey};
|
use signature::{GenKeys, Keypair, KeypairUtil, Pubkey};
|
||||||
use transaction::Transaction;
|
use transaction::Transaction;
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serializer() {
|
fn test_serializer() {
|
||||||
let mut a = Account::new(0, 512, BudgetProgram::id());
|
let mut a = Account::new(0, 512, BudgetState::id());
|
||||||
let b = BudgetProgram::default();
|
let b = BudgetState::default();
|
||||||
b.serialize(&mut a.userdata).unwrap();
|
b.serialize(&mut a.userdata).unwrap();
|
||||||
let buf = serialize(&b).unwrap();
|
let buf = serialize(&b).unwrap();
|
||||||
assert_eq!(a.userdata[8..8 + buf.len()], buf[0..]);
|
assert_eq!(a.userdata[8..8 + buf.len()], buf[0..]);
|
||||||
let c = BudgetProgram::deserialize(&a.userdata).unwrap();
|
let c = BudgetState::deserialize(&a.userdata).unwrap();
|
||||||
assert_eq!(b, c);
|
assert_eq!(b, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serializer_userdata_too_small() {
|
fn test_serializer_userdata_too_small() {
|
||||||
let mut a = Account::new(0, 1, BudgetContract::id());
|
let mut a = Account::new(0, 1, BudgetState::id());
|
||||||
let b = BudgetContract::default();
|
let b = BudgetState::default();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
b.serialize(&mut a.userdata),
|
b.serialize(&mut a.userdata),
|
||||||
Err(BudgetError::UserdataTooSmall)
|
Err(BudgetError::UserdataTooSmall)
|
||||||
|
@ -305,8 +305,8 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_invalid_instruction() {
|
fn test_invalid_instruction() {
|
||||||
let mut accounts = vec![
|
let mut accounts = vec![
|
||||||
Account::new(1, 0, BudgetContract::id()),
|
Account::new(1, 0, BudgetState::id()),
|
||||||
Account::new(0, 512, BudgetContract::id()),
|
Account::new(0, 512, BudgetState::id()),
|
||||||
];
|
];
|
||||||
let from = Keypair::new();
|
let from = Keypair::new();
|
||||||
let contract = Keypair::new();
|
let contract = Keypair::new();
|
||||||
|
@ -314,12 +314,12 @@ mod test {
|
||||||
let tx = Transaction::new_with_userdata(
|
let tx = Transaction::new_with_userdata(
|
||||||
&from,
|
&from,
|
||||||
&[contract.pubkey()],
|
&[contract.pubkey()],
|
||||||
BudgetContract::id(),
|
BudgetState::id(),
|
||||||
vec![1, 2, 3], // <== garbage instruction
|
vec![1, 2, 3], // <== garbage instruction
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
BudgetContract::process_transaction(&tx, &mut accounts);
|
BudgetState::process_transaction(&tx, &mut accounts);
|
||||||
|
|
||||||
// Success if there was no panic...
|
// Success if there was no panic...
|
||||||
}
|
}
|
||||||
|
@ -327,9 +327,9 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transfer_on_date() {
|
fn test_transfer_on_date() {
|
||||||
let mut accounts = vec![
|
let mut accounts = vec![
|
||||||
Account::new(1, 0, BudgetProgram::id()),
|
Account::new(1, 0, BudgetState::id()),
|
||||||
Account::new(0, 512, BudgetProgram::id()),
|
Account::new(0, 512, BudgetState::id()),
|
||||||
Account::new(0, 0, BudgetProgram::id()),
|
Account::new(0, 0, BudgetState::id()),
|
||||||
];
|
];
|
||||||
let from_account = 0;
|
let from_account = 0;
|
||||||
let contract_account = 1;
|
let contract_account = 1;
|
||||||
|
@ -347,10 +347,10 @@ mod test {
|
||||||
1,
|
1,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
BudgetProgram::process_transaction(&tx, &mut accounts);
|
BudgetState::process_transaction(&tx, &mut accounts);
|
||||||
assert_eq!(accounts[from_account].tokens, 0);
|
assert_eq!(accounts[from_account].tokens, 0);
|
||||||
assert_eq!(accounts[contract_account].tokens, 1);
|
assert_eq!(accounts[contract_account].tokens, 1);
|
||||||
let state = BudgetProgram::deserialize(&accounts[contract_account].userdata).unwrap();
|
let state = BudgetState::deserialize(&accounts[contract_account].userdata).unwrap();
|
||||||
assert_eq!(state.last_error, None);
|
assert_eq!(state.last_error, None);
|
||||||
assert!(state.is_pending());
|
assert!(state.is_pending());
|
||||||
|
|
||||||
|
@ -362,12 +362,12 @@ mod test {
|
||||||
dt,
|
dt,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
BudgetProgram::process_transaction(&tx, &mut accounts);
|
BudgetState::process_transaction(&tx, &mut accounts);
|
||||||
assert_eq!(accounts[from_account].tokens, 0);
|
assert_eq!(accounts[from_account].tokens, 0);
|
||||||
assert_eq!(accounts[contract_account].tokens, 1);
|
assert_eq!(accounts[contract_account].tokens, 1);
|
||||||
assert_eq!(accounts[to_account].tokens, 0);
|
assert_eq!(accounts[to_account].tokens, 0);
|
||||||
|
|
||||||
let state = BudgetProgram::deserialize(&accounts[contract_account].userdata).unwrap();
|
let state = BudgetState::deserialize(&accounts[contract_account].userdata).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
state.last_error,
|
state.last_error,
|
||||||
Some(BudgetError::DestinationMissing(to.pubkey()))
|
Some(BudgetError::DestinationMissing(to.pubkey()))
|
||||||
|
@ -383,20 +383,20 @@ mod test {
|
||||||
dt,
|
dt,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
BudgetProgram::process_transaction(&tx, &mut accounts);
|
BudgetState::process_transaction(&tx, &mut accounts);
|
||||||
assert_eq!(accounts[from_account].tokens, 0);
|
assert_eq!(accounts[from_account].tokens, 0);
|
||||||
assert_eq!(accounts[contract_account].tokens, 0);
|
assert_eq!(accounts[contract_account].tokens, 0);
|
||||||
assert_eq!(accounts[to_account].tokens, 1);
|
assert_eq!(accounts[to_account].tokens, 1);
|
||||||
|
|
||||||
let state = BudgetProgram::deserialize(&accounts[contract_account].userdata).unwrap();
|
let state = BudgetState::deserialize(&accounts[contract_account].userdata).unwrap();
|
||||||
assert!(!state.is_pending());
|
assert!(!state.is_pending());
|
||||||
|
|
||||||
// try to replay the timestamp contract
|
// try to replay the timestamp contract
|
||||||
BudgetProgram::process_transaction(&tx, &mut accounts);
|
BudgetState::process_transaction(&tx, &mut accounts);
|
||||||
assert_eq!(accounts[from_account].tokens, 0);
|
assert_eq!(accounts[from_account].tokens, 0);
|
||||||
assert_eq!(accounts[contract_account].tokens, 0);
|
assert_eq!(accounts[contract_account].tokens, 0);
|
||||||
assert_eq!(accounts[to_account].tokens, 1);
|
assert_eq!(accounts[to_account].tokens, 1);
|
||||||
let state = BudgetProgram::deserialize(&accounts[contract_account].userdata).unwrap();
|
let state = BudgetState::deserialize(&accounts[contract_account].userdata).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
state.last_error,
|
state.last_error,
|
||||||
Some(BudgetError::ContractNotPending(contract.pubkey()))
|
Some(BudgetError::ContractNotPending(contract.pubkey()))
|
||||||
|
@ -405,9 +405,9 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cancel_transfer() {
|
fn test_cancel_transfer() {
|
||||||
let mut accounts = vec![
|
let mut accounts = vec![
|
||||||
Account::new(1, 0, BudgetProgram::id()),
|
Account::new(1, 0, BudgetState::id()),
|
||||||
Account::new(0, 512, BudgetProgram::id()),
|
Account::new(0, 512, BudgetState::id()),
|
||||||
Account::new(0, 0, BudgetProgram::id()),
|
Account::new(0, 0, BudgetState::id()),
|
||||||
];
|
];
|
||||||
let from_account = 0;
|
let from_account = 0;
|
||||||
let contract_account = 1;
|
let contract_account = 1;
|
||||||
|
@ -424,10 +424,10 @@ mod test {
|
||||||
1,
|
1,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
BudgetProgram::process_transaction(&tx, &mut accounts);
|
BudgetState::process_transaction(&tx, &mut accounts);
|
||||||
assert_eq!(accounts[from_account].tokens, 0);
|
assert_eq!(accounts[from_account].tokens, 0);
|
||||||
assert_eq!(accounts[contract_account].tokens, 1);
|
assert_eq!(accounts[contract_account].tokens, 1);
|
||||||
let state = BudgetProgram::deserialize(&accounts[contract_account].userdata).unwrap();
|
let state = BudgetState::deserialize(&accounts[contract_account].userdata).unwrap();
|
||||||
assert_eq!(state.last_error, None);
|
assert_eq!(state.last_error, None);
|
||||||
assert!(state.is_pending());
|
assert!(state.is_pending());
|
||||||
|
|
||||||
|
@ -436,7 +436,7 @@ mod test {
|
||||||
Transaction::budget_new_signature(&to, contract.pubkey(), to.pubkey(), Hash::default());
|
Transaction::budget_new_signature(&to, contract.pubkey(), to.pubkey(), Hash::default());
|
||||||
// unit test hack, the `from account` is passed instead of the `to` account to avoid
|
// unit test hack, the `from account` is passed instead of the `to` account to avoid
|
||||||
// creating more account vectors
|
// creating more account vectors
|
||||||
BudgetProgram::process_transaction(&tx, &mut accounts);
|
BudgetState::process_transaction(&tx, &mut accounts);
|
||||||
// nothing should be changed because apply witness didn't finalize a payment
|
// nothing should be changed because apply witness didn't finalize a payment
|
||||||
assert_eq!(accounts[from_account].tokens, 0);
|
assert_eq!(accounts[from_account].tokens, 0);
|
||||||
assert_eq!(accounts[contract_account].tokens, 1);
|
assert_eq!(accounts[contract_account].tokens, 1);
|
||||||
|
@ -450,7 +450,7 @@ mod test {
|
||||||
from.pubkey(),
|
from.pubkey(),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
BudgetProgram::process_transaction(&tx, &mut accounts);
|
BudgetState::process_transaction(&tx, &mut accounts);
|
||||||
assert_eq!(accounts[from_account].tokens, 0);
|
assert_eq!(accounts[from_account].tokens, 0);
|
||||||
assert_eq!(accounts[contract_account].tokens, 0);
|
assert_eq!(accounts[contract_account].tokens, 0);
|
||||||
assert_eq!(accounts[pay_account].tokens, 1);
|
assert_eq!(accounts[pay_account].tokens, 1);
|
||||||
|
@ -462,12 +462,12 @@ mod test {
|
||||||
from.pubkey(),
|
from.pubkey(),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
BudgetProgram::process_transaction(&tx, &mut accounts);
|
BudgetState::process_transaction(&tx, &mut accounts);
|
||||||
assert_eq!(accounts[from_account].tokens, 0);
|
assert_eq!(accounts[from_account].tokens, 0);
|
||||||
assert_eq!(accounts[contract_account].tokens, 0);
|
assert_eq!(accounts[contract_account].tokens, 0);
|
||||||
assert_eq!(accounts[pay_account].tokens, 1);
|
assert_eq!(accounts[pay_account].tokens, 1);
|
||||||
|
|
||||||
let state = BudgetProgram::deserialize(&accounts[contract_account].userdata).unwrap();
|
let state = BudgetState::deserialize(&accounts[contract_account].userdata).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
state.last_error,
|
state.last_error,
|
||||||
Some(BudgetError::ContractNotPending(contract.pubkey()))
|
Some(BudgetError::ContractNotPending(contract.pubkey()))
|
||||||
|
@ -477,9 +477,9 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_userdata_too_small() {
|
fn test_userdata_too_small() {
|
||||||
let mut accounts = vec![
|
let mut accounts = vec![
|
||||||
Account::new(1, 0, BudgetContract::id()),
|
Account::new(1, 0, BudgetState::id()),
|
||||||
Account::new(1, 0, BudgetContract::id()), // <== userdata is 0, which is not enough
|
Account::new(1, 0, BudgetState::id()), // <== userdata is 0, which is not enough
|
||||||
Account::new(1, 0, BudgetContract::id()),
|
Account::new(1, 0, BudgetState::id()),
|
||||||
];
|
];
|
||||||
let from = Keypair::new();
|
let from = Keypair::new();
|
||||||
let contract = Keypair::new();
|
let contract = Keypair::new();
|
||||||
|
@ -493,8 +493,8 @@ mod test {
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
|
|
||||||
BudgetContract::process_transaction(&tx, &mut accounts);
|
BudgetState::process_transaction(&tx, &mut accounts);
|
||||||
assert!(BudgetContract::deserialize(&accounts[1].userdata).is_err());
|
assert!(BudgetState::deserialize(&accounts[1].userdata).is_err());
|
||||||
|
|
||||||
let tx = Transaction::budget_new_timestamp(
|
let tx = Transaction::budget_new_timestamp(
|
||||||
&from,
|
&from,
|
||||||
|
@ -503,8 +503,8 @@ mod test {
|
||||||
Utc::now(),
|
Utc::now(),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
BudgetContract::process_transaction(&tx, &mut accounts);
|
BudgetState::process_transaction(&tx, &mut accounts);
|
||||||
assert!(BudgetContract::deserialize(&accounts[1].userdata).is_err());
|
assert!(BudgetState::deserialize(&accounts[1].userdata).is_err());
|
||||||
|
|
||||||
// Success if there was no panic...
|
// Success if there was no panic...
|
||||||
}
|
}
|
||||||
|
|
|
@ -298,7 +298,7 @@ mod tests {
|
||||||
let expected = r#"{
|
let expected = r#"{
|
||||||
"jsonrpc":"2.0",
|
"jsonrpc":"2.0",
|
||||||
"result":{
|
"result":{
|
||||||
"contract_id": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
|
"program_id": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
|
||||||
"tokens": 20,
|
"tokens": 20,
|
||||||
"userdata": []
|
"userdata": []
|
||||||
},
|
},
|
||||||
|
|
|
@ -74,6 +74,7 @@ impl SystemProgram {
|
||||||
accounts[0].tokens -= tokens;
|
accounts[0].tokens -= tokens;
|
||||||
accounts[1].tokens += tokens;
|
accounts[1].tokens += tokens;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
info!("Invalid transaction userdata: {:?}", tx.userdata);
|
info!("Invalid transaction userdata: {:?}", tx.userdata);
|
||||||
}
|
}
|
||||||
|
@ -126,7 +127,7 @@ mod test {
|
||||||
let mut accounts = vec![Account::default(), Account::default()];
|
let mut accounts = vec![Account::default(), Account::default()];
|
||||||
let tx =
|
let tx =
|
||||||
Transaction::system_create(&from, to.pubkey(), Hash::default(), 0, 1, to.pubkey(), 0);
|
Transaction::system_create(&from, to.pubkey(), Hash::default(), 0, 1, to.pubkey(), 0);
|
||||||
SystemContract::process_transaction(&tx, &mut accounts);
|
SystemProgram::process_transaction(&tx, &mut accounts);
|
||||||
assert!(accounts[0].userdata.is_empty());
|
assert!(accounts[0].userdata.is_empty());
|
||||||
assert_eq!(accounts[1].userdata.len(), 1);
|
assert_eq!(accounts[1].userdata.len(), 1);
|
||||||
assert_eq!(accounts[1].program_id, to.pubkey());
|
assert_eq!(accounts[1].program_id, to.pubkey());
|
||||||
|
@ -136,7 +137,7 @@ mod test {
|
||||||
let from = Keypair::new();
|
let from = Keypair::new();
|
||||||
let to = Keypair::new();
|
let to = Keypair::new();
|
||||||
let mut accounts = vec![Account::default(), Account::default()];
|
let mut accounts = vec![Account::default(), Account::default()];
|
||||||
accounts[1].contract_id = to.pubkey();
|
accounts[1].program_id = to.pubkey();
|
||||||
let tx = Transaction::system_create(
|
let tx = Transaction::system_create(
|
||||||
&from,
|
&from,
|
||||||
to.pubkey(),
|
to.pubkey(),
|
||||||
|
@ -146,7 +147,7 @@ mod test {
|
||||||
Pubkey::default(),
|
Pubkey::default(),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
SystemContract::process_transaction(&tx, &mut accounts);
|
SystemProgram::process_transaction(&tx, &mut accounts);
|
||||||
assert!(accounts[1].userdata.is_empty());
|
assert!(accounts[1].userdata.is_empty());
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -164,7 +165,7 @@ mod test {
|
||||||
Pubkey::default(),
|
Pubkey::default(),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
SystemContract::process_transaction(&tx, &mut accounts);
|
SystemProgram::process_transaction(&tx, &mut accounts);
|
||||||
assert!(accounts[1].userdata.is_empty());
|
assert!(accounts[1].userdata.is_empty());
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -182,7 +183,7 @@ mod test {
|
||||||
Pubkey::default(),
|
Pubkey::default(),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
SystemContract::process_transaction(&tx, &mut accounts);
|
SystemProgram::process_transaction(&tx, &mut accounts);
|
||||||
assert_eq!(accounts[1].userdata.len(), 3);
|
assert_eq!(accounts[1].userdata.len(), 3);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use bincode::{deserialize, serialize};
|
use bincode::{deserialize, serialize};
|
||||||
use budget::{Budget, Condition};
|
use budget::{Budget, Condition};
|
||||||
use budget_program::BudgetProgram;
|
use budget_program::BudgetState;
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use hash::Hash;
|
use hash::Hash;
|
||||||
use instruction::{Contract, Instruction, Vote};
|
use instruction::{Contract, Instruction, Vote};
|
||||||
|
@ -89,7 +89,7 @@ impl Transaction {
|
||||||
Self::new_with_userdata(
|
Self::new_with_userdata(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
&[to],
|
&[to],
|
||||||
BudgetProgram::id(),
|
BudgetState::id(),
|
||||||
userdata,
|
userdata,
|
||||||
last_id,
|
last_id,
|
||||||
fee,
|
fee,
|
||||||
|
@ -114,7 +114,7 @@ impl Transaction {
|
||||||
Self::new_with_userdata(
|
Self::new_with_userdata(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
&[contract, to],
|
&[contract, to],
|
||||||
BudgetProgram::id(),
|
BudgetState::id(),
|
||||||
userdata,
|
userdata,
|
||||||
last_id,
|
last_id,
|
||||||
0,
|
0,
|
||||||
|
@ -133,7 +133,7 @@ impl Transaction {
|
||||||
Self::new_with_userdata(
|
Self::new_with_userdata(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
&[contract, to],
|
&[contract, to],
|
||||||
BudgetProgram::id(),
|
BudgetState::id(),
|
||||||
userdata,
|
userdata,
|
||||||
last_id,
|
last_id,
|
||||||
0,
|
0,
|
||||||
|
@ -146,7 +146,7 @@ impl Transaction {
|
||||||
Self::new_with_userdata(
|
Self::new_with_userdata(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
&[],
|
&[],
|
||||||
BudgetProgram::id(),
|
BudgetState::id(),
|
||||||
userdata,
|
userdata,
|
||||||
last_id,
|
last_id,
|
||||||
fee,
|
fee,
|
||||||
|
@ -172,7 +172,7 @@ impl Transaction {
|
||||||
Self::new_with_userdata(
|
Self::new_with_userdata(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
&[contract],
|
&[contract],
|
||||||
BudgetProgram::id(),
|
BudgetState::id(),
|
||||||
userdata,
|
userdata,
|
||||||
last_id,
|
last_id,
|
||||||
0,
|
0,
|
||||||
|
|
Loading…
Reference in New Issue