Skip to content

Commit

Permalink
Fixing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Zajkowski committed Oct 1, 2024
1 parent 156f834 commit 43b8bcf
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 68 deletions.
8 changes: 4 additions & 4 deletions node/src/components/transaction_buffer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,9 @@ fn block_fully_saturated() {

// Ensure that only 'total_allowed' transactions are proposed.
let timestamp = Timestamp::now();
let expiry = timestamp.saturating_add(TimeDiff::from_seconds(1));
let expiry = timestamp.saturating_add(TimeDiff::from_seconds(60));
let appendable_block = transaction_buffer.appendable_block(Timestamp::now(), ERA_ONE, expiry);

assert_eq!(
appendable_block.transaction_hashes().len(),
total_allowed as usize
Expand All @@ -584,15 +585,14 @@ fn block_fully_saturated() {
proposed_standards += 1;
}
});

let mut has_hit_any_limit = false;
if proposed_transfers == max_transfers {
has_hit_any_limit = true;
}
if proposed_stakings == max_staking {
has_hit_any_limit = true;
}
if proposed_install_upgrades as u64 == max_install_upgrade {
if proposed_install_upgrades == max_install_upgrade {
has_hit_any_limit = true;
}
if proposed_standards == max_standard {
Expand Down Expand Up @@ -1326,7 +1326,7 @@ fn should_have_diverse_proposable_blocks_with_stocked_buffer() {
// using this strategy, it should be very unlikely...the below brute forces a check for this
let expected_eq_tolerance = 1;
let mut actual_eq_count = 0;
let expiry = last_timestamp.saturating_add(TimeDiff::from_seconds(120));
let expiry = last_timestamp.saturating_add(TimeDiff::from_seconds(240));
for _ in 0..10 {
let appendable1 = transaction_buffer.appendable_block(last_timestamp, ERA_ONE, expiry);
let appendable2 = transaction_buffer.appendable_block(last_timestamp, ERA_ONE, expiry);
Expand Down
15 changes: 13 additions & 2 deletions node/src/reactor/main_reactor/tests/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@ async fn send_wasm_transaction(
) -> (TransactionHash, u64, ExecutionResult) {
let chain_name = fixture.chainspec.network_config.name.clone();

//These bytes are intentionally so large - this way they fall into "WASM_LARGE" category in the
// local chainspec Alternatively we could change the chainspec to have a different limits
// for the wasm categories, but that would require aligning all tests that use local
// chainspec
let module_bytes = Bytes::from(vec![1; 172_033]);
let mut txn = Transaction::from(
TransactionV1Builder::new_session(false, Bytes::from(vec![1]))
TransactionV1Builder::new_session(false, module_bytes)
.with_chain_name(chain_name)
.with_pricing_mode(pricing)
.with_initiator_addr(PublicKey::from(from))
Expand Down Expand Up @@ -845,6 +850,7 @@ async fn native_operations_fees_are_not_refunded() {

#[tokio::test]
async fn wasm_transaction_fees_are_refunded() {
std::env::set_var("CL_TEST_SEED", "84188df5d5f7a1e736c13623fb9721f6");
let initial_stakes = InitialStakes::FromVec(vec![u128::MAX, 1]); // Node 0 is effectively guaranteed to be the proposer.

let refund_ratio = Ratio::new(1, 2);
Expand Down Expand Up @@ -2357,8 +2363,13 @@ fn transfer_txn<A: Into<U512>>(
}

fn invalid_wasm_txn(initiator: Arc<SecretKey>, pricing_mode: PricingMode) -> Transaction {
//These bytes are intentionally so large - this way they fall into "WASM_LARGE" category in the
// local chainspec Alternatively we could change the chainspec to have a different limits
// for the wasm categories, but that would require aligning all tests that use local
// chainspec
let module_bytes = Bytes::from(vec![1; 172_033]);
let mut txn = Transaction::from(
TransactionV1Builder::new_session(false, Bytes::from(vec![1]))
TransactionV1Builder::new_session(false, module_bytes)
.with_chain_name(CHAIN_NAME)
.with_pricing_mode(pricing_mode)
.with_initiator_addr(PublicKey::from(&*initiator))
Expand Down
10 changes: 5 additions & 5 deletions node/src/types/appendable_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ impl AppendableBlock {
if expires < self.timestamp {
return Err(AddError::Expired);
}
let category = footprint.lane_id;
let lane_id = footprint.lane_id;
let limit = self
.transaction_config
.transaction_v1_config
.get_max_transaction_count(category);
.get_max_transaction_count(lane_id);
// check total count by category
let count = self
.transactions
.iter()
.filter(|(_, item)| item.lane_id == category)
.filter(|(_, item)| item.lane_id == lane_id)
.count();
if count.checked_add(1).ok_or(AddError::Count(category))? > limit as usize {
return Err(AddError::Count(category));
if count.checked_add(1).ok_or(AddError::Count(lane_id))? > limit as usize {
return Err(AddError::Count(lane_id));
}
// check total gas
let gas_limit: U512 = self
Expand Down
4 changes: 2 additions & 2 deletions node/src/types/transaction/meta_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,12 @@ impl Display for MetaTransaction {
#[cfg(test)]
mod proptests {
use super::*;
use casper_types::gens::transaction_arb;
use casper_types::gens::legal_transaction_arb;
use proptest::prelude::*;

proptest! {
#[test]
fn construction_roundtrip(transaction in transaction_arb()) {
fn construction_roundtrip(transaction in legal_transaction_arb()) {
let maybe_transaction = MetaTransaction::from(&transaction, &TransactionConfig::default());
assert!(maybe_transaction.is_ok());
}
Expand Down
93 changes: 47 additions & 46 deletions resources/test/sse_data_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1588,31 +1588,25 @@
"fields",
"initiator_addr",
"pricing_mode",
"serialization_version",
"timestamp",
"ttl"
],
"properties": {
"serialization_version": {
"type": "integer",
"format": "uint8",
"minimum": 0.0
},
"chain_name": {
"type": "string"
"initiator_addr": {
"$ref": "#/definitions/InitiatorAddr"
},
"timestamp": {
"$ref": "#/definitions/Timestamp"
},
"ttl": {
"$ref": "#/definitions/TimeDiff"
},
"chain_name": {
"type": "string"
},
"pricing_mode": {
"$ref": "#/definitions/PricingMode"
},
"initiator_addr": {
"$ref": "#/definitions/InitiatorAddr"
},
"fields": {
"type": "object",
"additionalProperties": {
Expand All @@ -1622,6 +1616,41 @@
},
"additionalProperties": false
},
"InitiatorAddr": {
"description": "The address of the initiator of a TransactionV1.",
"oneOf": [
{
"description": "The public key of the initiator.",
"type": "object",
"required": [
"PublicKey"
],
"properties": {
"PublicKey": {
"$ref": "#/definitions/PublicKey"
}
},
"additionalProperties": false
},
{
"description": "The account hash derived from the public key of the initiator.",
"type": "object",
"required": [
"AccountHash"
],
"properties": {
"AccountHash": {
"$ref": "#/definitions/AccountHash"
}
},
"additionalProperties": false
}
]
},
"AccountHash": {
"description": "Account hash as a formatted string.",
"type": "string"
},
"PricingMode": {
"description": "Pricing mode of a Transaction.",
"oneOf": [
Expand Down Expand Up @@ -1672,9 +1701,16 @@
"Fixed": {
"type": "object",
"required": [
"additional_computation_factor",
"gas_price_tolerance"
],
"properties": {
"additional_computation_factor": {
"description": "User-specified additional computation factor (minimum 0). If \"0\" is provided, no additional logic is applied to the computation limit. Each value above \"0\" tells the node that it needs to treat the transaction as if it uses more gas than it's serialized size indicates. Each \"1\" will increase the \"wasm lane\" size bucket for this transaction by 1. So if the size of the transaction indicates bucket \"0\" and \"additional_computation_factor = 2\", the transaction will be treated as a \"2\".",
"type": "integer",
"format": "uint8",
"minimum": 0.0
},
"gas_price_tolerance": {
"description": "User-specified gas_price tolerance (minimum 1). This is interpreted to mean \"do not include this transaction in a block if the current gas price is greater than this number\"",
"type": "integer",
Expand Down Expand Up @@ -1716,41 +1752,6 @@
}
]
},
"InitiatorAddr": {
"description": "The address of the initiator of a TransactionV1.",
"oneOf": [
{
"description": "The public key of the initiator.",
"type": "object",
"required": [
"PublicKey"
],
"properties": {
"PublicKey": {
"$ref": "#/definitions/PublicKey"
}
},
"additionalProperties": false
},
{
"description": "The account hash derived from the public key of the initiator.",
"type": "object",
"required": [
"AccountHash"
],
"properties": {
"AccountHash": {
"$ref": "#/definitions/AccountHash"
}
},
"additionalProperties": false
}
]
},
"AccountHash": {
"description": "Account hash as a formatted string.",
"type": "string"
},
"ExecutionResult": {
"description": "The versioned result of executing a single deploy.",
"oneOf": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ impl TransactionV1Config {
self.native_auction_lane.max_transaction_count = auction_count;
}
if let Some(install_upgrade) = install {
self.native_auction_lane.max_transaction_count = install_upgrade;
self.install_upgrade_lane.max_transaction_count = install_upgrade;
}
if let Some(large_limit) = large {
for lane in self.wasm_lanes.iter_mut() {
Expand Down
Loading

0 comments on commit 43b8bcf

Please sign in to comment.