diff --git a/src/ledger.rs b/src/ledger.rs index ebced54411cd71..11b0954f6d03c0 100644 --- a/src/ledger.rs +++ b/src/ledger.rs @@ -151,13 +151,18 @@ pub fn next_entries( mod tests { use super::*; use bincode::serialized_size; + use budget::{Budget, Condition}; use chrono::prelude::*; use entry::{next_entry, Entry}; use hash::hash; - use packet::{BlobRecycler, BLOB_DATA_SIZE, PACKET_DATA_SIZE}; + use packet::{BlobRecycler, BLOB_DATA_SIZE}; + use payment_plan::Payment; use signature::{KeyPair, KeyPairUtil}; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; - use transaction::{Transaction, Vote, BASE_TRANSACTION_SIZE, MAX_INSTRUCTION_SIZE}; + use transaction::{ + Contract, Instruction, Plan, Transaction, Vote, BASE_TRANSACTION_SIZE, FEE_PER_INSTRUCTION, + MAX_INSTRUCTION_SIZE, + }; #[test] fn test_verify_slice() { @@ -232,16 +237,34 @@ mod tests { next_id, 2, ); - let tx_large = Transaction::new(&keypair, keypair.pubkey(), 1, next_id); - let tx_small_size = serialized_size(&tx_small).unwrap(); - let tx_large_size = serialized_size(&tx_large).unwrap(); + // Create large transaction + let transfer_value = 1000; + let date_condition = ( + Condition::Timestamp(Utc::now(), keypair.pubkey()), + Payment { + tokens: transfer_value, + to: keypair.pubkey(), + }, + ); + + let budget = Budget::Or(date_condition.clone(), date_condition); + let plan = Plan::Budget(budget); + let contract = Contract::new(transfer_value, plan); + let tx_large = Transaction::new_from_instructions( + &keypair, + vec![Instruction::NewContract(contract)], + next_id, + FEE_PER_INSTRUCTION as i64, + ); + + let tx_small_size = serialized_size(&tx_small).unwrap() as usize; + let tx_large_size = serialized_size(&tx_large).unwrap() as usize; assert!(tx_small_size < tx_large_size); - assert!(tx_large_size < PACKET_DATA_SIZE as u64); + assert!(tx_large_size <= BASE_TRANSACTION_SIZE + MAX_INSTRUCTION_SIZE); - let transaction_size = BASE_TRANSACTION_SIZE + MAX_INSTRUCTION_SIZE; // NOTE: if Entry grows to larger than a transaction, the code below falls over - let threshold = (BLOB_DATA_SIZE / transaction_size) - 1; // 256 is transaction size + let threshold = (BLOB_DATA_SIZE / (tx_small_size as usize)) - 1; // verify no split let transactions = vec![tx_small.clone(); threshold]; @@ -265,7 +288,7 @@ mod tests { transactions.extend(large_transactions); let entries0 = next_entries(&id, 0, transactions.clone()); - assert!(entries0.len() > 2); + assert!(entries0.len() >= 2); assert!(entries0[0].has_more); assert!(!entries0[entries0.len() - 1].has_more); assert!(entries0.verify(&id)); diff --git a/src/thin_client.rs b/src/thin_client.rs index 294ea056558a25..3fcb11725c28d1 100644 --- a/src/thin_client.rs +++ b/src/thin_client.rs @@ -4,7 +4,7 @@ //! unstable and may change in future releases. use bincode::{deserialize, serialize}; -use budget::Condition; +use budget::Condition::Timestamp; use chrono::prelude::Utc; use hash::Hash; use influx_db_client as influxdb; @@ -585,7 +585,7 @@ mod tests { expected_balance += transfer_value; let date_condition = ( - Condition::Timestamp(Utc::now(), alice.pubkey()), + Timestamp(Utc::now(), alice.pubkey()), Payment { tokens: transfer_value, to: bob_pubkey, diff --git a/src/transaction.rs b/src/transaction.rs index a106561fe84b83..ddac8c966bab3c 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -13,7 +13,7 @@ pub const PUB_KEY_OFFSET: usize = 80; pub const MAX_ALLOWED_INSTRUCTIONS: usize = 20; // The biggest current instruction is a Budget with a payment plan of 'Or' with two // datetime 'Condition' branches. This is the serialized size of that instruction -pub const MAX_INSTRUCTION_SIZE: usize = 314; +pub const MAX_INSTRUCTION_SIZE: usize = 352; // Serialized size of everything in the transaction excluding the instructions pub const BASE_TRANSACTION_SIZE: usize = 168; pub const FEE_PER_INSTRUCTION: usize = 0;