diff --git a/node/src/reactor/main_reactor/tests/transactions.rs b/node/src/reactor/main_reactor/tests/transactions.rs index b3f28589c2..b60d7ac3db 100644 --- a/node/src/reactor/main_reactor/tests/transactions.rs +++ b/node/src/reactor/main_reactor/tests/transactions.rs @@ -32,7 +32,7 @@ static CHARLIE_SECRET_KEY: Lazy> = Lazy::new(|| { static CHARLIE_PUBLIC_KEY: Lazy = Lazy::new(|| PublicKey::from(&*CHARLIE_SECRET_KEY.clone())); -const MIN_GAS_PRICE: u8 = 5; +const MIN_GAS_PRICE: u8 = 1; const CHAIN_NAME: &str = "single-transaction-test-net"; async fn transfer_to_account>( @@ -1023,8 +1023,6 @@ impl SingleTransactionTestCase { ConfigsOverride::default() .with_minimum_era_height(5) // make the era longer so that the transaction doesn't land in the switch block. .with_balance_hold_interval(TimeDiff::from_seconds(5)) - .with_min_gas_price(MIN_GAS_PRICE) - .with_max_gas_price(MIN_GAS_PRICE) .with_chain_name("single-transaction-test-net".to_string()) } @@ -3045,25 +3043,27 @@ async fn insufficient_funds_transfer_from_account() { let transfer_amount = U512::max_value(); - let mut txn = Transaction::from( + let txn_v1 = TransactionV1Builder::new_transfer(transfer_amount, None, ALICE_PUBLIC_KEY.clone(), None) .unwrap() .with_chain_name(CHAIN_NAME) .with_initiator_addr(PublicKey::from(&**BOB_SECRET_KEY)) .build() - .unwrap(), - ); + .unwrap(); + let price = txn_v1 + .payment_amount() + .expect("must have payment amount as txns are using classic"); + let mut txn = Transaction::from(txn_v1); txn.sign(&BOB_SECRET_KEY); let (_txn_hash, _block_height, exec_result) = test.send_transaction(txn).await; let ExecutionResult::V2(result) = exec_result else { panic!("Expected ExecutionResult::V2 but got {:?}", exec_result); }; - let transfer_cost: U512 = - U512::from(test.chainspec().system_costs_config.mint_costs().transfer) * MIN_GAS_PRICE; + let expected_cost: U512 = U512::from(price) * MIN_GAS_PRICE; assert_eq!(result.error_message.as_deref(), Some("Insufficient funds")); - assert_eq!(result.cost, transfer_cost); + assert_eq!(result.cost, expected_cost); } #[tokio::test] @@ -3089,22 +3089,22 @@ async fn insufficient_funds_add_bid() { let (_, bob_initial_balance, _) = test.get_balances(None); let bid_amount = bob_initial_balance.total; - let mut txn = Transaction::from( + let txn = TransactionV1Builder::new_add_bid(BOB_PUBLIC_KEY.clone(), 0, bid_amount, None, None, None) .unwrap() .with_chain_name(CHAIN_NAME) .with_initiator_addr(PublicKey::from(&**BOB_SECRET_KEY)) .build() - .unwrap(), - ); + .unwrap(); + let price = txn.payment_amount().expect("must get payment amount"); + let mut txn = Transaction::from(txn); txn.sign(&BOB_SECRET_KEY); let (_txn_hash, _block_height, exec_result) = test.send_transaction(txn).await; let ExecutionResult::V2(result) = exec_result else { panic!("Expected ExecutionResult::V2 but got {:?}", exec_result); }; - let bid_cost: U512 = - U512::from(test.chainspec().system_costs_config.auction_costs().add_bid) * MIN_GAS_PRICE; + let bid_cost: U512 = U512::from(price) * MIN_GAS_PRICE; assert_eq!( result.error_message.as_deref(), @@ -3175,27 +3175,26 @@ async fn insufficient_funds_transfer_from_purse() { // now we try to transfer from the purse we just created let transfer_amount = U512::max_value(); - let mut txn = Transaction::from( - TransactionV1Builder::new_transfer( - transfer_amount, - Some(uref), - ALICE_PUBLIC_KEY.clone(), - None, - ) - .unwrap() - .with_chain_name(CHAIN_NAME) - .with_initiator_addr(PublicKey::from(&**BOB_SECRET_KEY)) - .build() - .unwrap(), - ); + let txn = TransactionV1Builder::new_transfer( + transfer_amount, + Some(uref), + ALICE_PUBLIC_KEY.clone(), + None, + ) + .unwrap() + .with_chain_name(CHAIN_NAME) + .with_initiator_addr(PublicKey::from(&**BOB_SECRET_KEY)) + .build() + .unwrap(); + let price = txn.payment_amount().expect("must get payment amount"); + let mut txn = Transaction::from(txn); txn.sign(&BOB_SECRET_KEY); let (_txn_hash, _block_height, exec_result) = test.send_transaction(txn).await; let ExecutionResult::V2(result) = exec_result else { panic!("Expected ExecutionResult::V2 but got {:?}", exec_result); }; - let transfer_cost: U512 = - U512::from(test.chainspec().system_costs_config.mint_costs().transfer) * MIN_GAS_PRICE; + let transfer_cost: U512 = U512::from(price) * MIN_GAS_PRICE; assert_eq!(result.error_message.as_deref(), Some("Insufficient funds")); assert_eq!(result.cost, transfer_cost); @@ -3223,22 +3222,22 @@ async fn insufficient_funds_when_caller_lacks_minimum_balance() { let (_, bob_initial_balance, _) = test.get_balances(None); let transfer_amount = bob_initial_balance.total - U512::one(); - let mut txn = Transaction::from( + let txn = TransactionV1Builder::new_transfer(transfer_amount, None, ALICE_PUBLIC_KEY.clone(), None) .unwrap() .with_chain_name(CHAIN_NAME) .with_initiator_addr(PublicKey::from(&**BOB_SECRET_KEY)) .build() - .unwrap(), - ); + .unwrap(); + let price = txn.payment_amount().expect("must get payment amount"); + let mut txn = Transaction::from(txn); txn.sign(&BOB_SECRET_KEY); let (_txn_hash, _block_height, exec_result) = test.send_transaction(txn).await; let ExecutionResult::V2(result) = exec_result else { panic!("Expected ExecutionResult::V2 but got {:?}", exec_result); }; - let transfer_cost: U512 = - U512::from(test.chainspec().system_costs_config.mint_costs().transfer) * MIN_GAS_PRICE; + let transfer_cost: U512 = U512::from(price) * MIN_GAS_PRICE; assert_eq!(result.error_message.as_deref(), Some("Insufficient funds")); assert_eq!(result.cost, transfer_cost); diff --git a/node/src/types/transaction/transaction_v1_builder.rs b/node/src/types/transaction/transaction_v1_builder.rs index df8ef856d0..e793319d3f 100644 --- a/node/src/types/transaction/transaction_v1_builder.rs +++ b/node/src/types/transaction/transaction_v1_builder.rs @@ -108,7 +108,7 @@ impl<'a> TransactionV1Builder<'a> { 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::PaymentLimited { - payment_amount: 2_500_000_000, + payment_amount: 10_000_000_000, gas_price_tolerance: 3, standard_payment: true, }; diff --git a/types/src/transaction/transaction_v1.rs b/types/src/transaction/transaction_v1.rs index 47c28fa4d7..9508fb9eb0 100644 --- a/types/src/transaction/transaction_v1.rs +++ b/types/src/transaction/transaction_v1.rs @@ -281,6 +281,16 @@ impl TransactionV1 { self.approvals.extend(approvals); } + /// Returns the payment amount if the txn is using classic mode. + #[cfg(any(all(feature = "std", feature = "testing"), test))] + pub fn payment_amount(&self) -> Option { + if let PricingMode::PaymentLimited { payment_amount, .. } = self.pricing_mode() { + Some(*payment_amount) + } else { + None + } + } + /// Returns a random, valid but possibly expired transaction. #[cfg(any(all(feature = "std", feature = "testing"), test))] pub fn random(rng: &mut TestRng) -> Self {