Skip to content

Commit

Permalink
Fixed broken tests after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
carllin committed Jul 29, 2018
1 parent 93fad15 commit ffad72e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
41 changes: 32 additions & 9 deletions src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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];
Expand All @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/thin_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ffad72e

Please sign in to comment.