Skip to content

Commit

Permalink
Fix generation of test transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
darthsiroftardis committed Dec 6, 2024
1 parent c1b3f4c commit 9b97f5e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
21 changes: 14 additions & 7 deletions node/src/components/transaction_acceptor/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ use casper_types::{
global_state::TrieMerkleProof,
testing::TestRng,
Block, BlockV2, CLValue, Chainspec, ChainspecRawBytes, Contract, Deploy, EraId, HashAddr,
InvalidDeploy, InvalidTransaction, InvalidTransactionV1, Package, PricingMode, ProtocolVersion,
PublicKey, SecretKey, StoredValue, TestBlockBuilder, TimeDiff, Timestamp, Transaction,
TransactionConfig, TransactionRuntime, TransactionV1, URef, U512,
InvalidDeploy, InvalidTransaction, InvalidTransactionV1, Package, PricingHandling, PricingMode,
ProtocolVersion, PublicKey, SecretKey, StoredValue, TestBlockBuilder, TimeDiff, Timestamp,
Transaction, TransactionConfig, TransactionRuntime, TransactionV1, URef, U512,
};

use super::*;
Expand Down Expand Up @@ -595,10 +595,9 @@ impl TestScenario {
}
TestScenario::InvalidPricingModeForTransactionV1 => {
let classic_mode_transaction = TransactionV1Builder::new_random(rng)
.with_pricing_mode(PricingMode::PaymentLimited {
payment_amount: 10000u64,
gas_price_tolerance: 1u8,
standard_payment: true,
.with_pricing_mode(PricingMode::Fixed {
gas_price_tolerance: 5,
additional_computation_factor: 0,
})
.with_chain_name("casper-example")
.build()
Expand Down Expand Up @@ -1152,6 +1151,14 @@ async fn run_transaction_acceptor_without_timeout(
let admin = SecretKey::random(rng);
let (mut chainspec, chainspec_raw_bytes) =
<(Chainspec, ChainspecRawBytes)>::from_resources("local");
let mut chainspec = if let TestScenario::TooLowGasPriceToleranceForTransactionV1 = test_scenario
{
chainspec.with_pricing_handling(PricingHandling::Fixed);
chainspec
} else {
chainspec
};

chainspec.core_config.administrators = iter::once(PublicKey::from(&admin)).collect();

let chainspec = Arc::new(chainspec);
Expand Down
21 changes: 12 additions & 9 deletions node/src/types/transaction/transaction_v1_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ impl<'a> TransactionV1Builder<'a> {
/// The default time-to-live for transactions, i.e. 30 minutes.
pub const DEFAULT_TTL: TimeDiff = TimeDiff::from_millis(30 * 60 * 1_000);
/// The default pricing mode for v1 transactions, ie FIXED cost.
pub const DEFAULT_PRICING_MODE: PricingMode = PricingMode::Fixed {
gas_price_tolerance: 5,
additional_computation_factor: 0,
pub const DEFAULT_PRICING_MODE: PricingMode = PricingMode::PaymentLimited {
payment_amount: 2_500_000_000,
gas_price_tolerance: 3,
standard_payment: true,
};
/// The default scheduling for transactions, i.e. `Standard`.
pub const DEFAULT_SCHEDULING: TransactionScheduling = TransactionScheduling::Standard;
Expand Down Expand Up @@ -384,9 +385,10 @@ impl<'a> TransactionV1Builder<'a> {
target: fields.target,
entry_point: fields.entry_point,
scheduling: fields.scheduling,
pricing_mode: PricingMode::Fixed {
gas_price_tolerance: 5,
additional_computation_factor: 0,
pricing_mode: PricingMode::PaymentLimited {
payment_amount: 2_500_000_000,
gas_price_tolerance: 3,
standard_payment: true,
},
initiator_addr: Some(InitiatorAddr::PublicKey(PublicKey::from(&secret_key))),
secret_key: Some(secret_key),
Expand Down Expand Up @@ -423,9 +425,10 @@ impl<'a> TransactionV1Builder<'a> {
target,
entry_point,
scheduling,
pricing_mode: PricingMode::Fixed {
gas_price_tolerance: 5,
additional_computation_factor: 0,
pricing_mode: PricingMode::PaymentLimited {
payment_amount: 2_500_000_000,
gas_price_tolerance: 3,
standard_payment: true,
},
initiator_addr: Some(InitiatorAddr::PublicKey(PublicKey::from(&secret_key))),
secret_key: Some(secret_key),
Expand Down

0 comments on commit 9b97f5e

Please sign in to comment.