Skip to content

Commit

Permalink
Merge branch 'feat-2.0' into new-execution-engine
Browse files Browse the repository at this point in the history
 Conflicts:
	types/src/transaction/deploy/error.rs
	types/src/transaction/transaction_v1/errors_v1.rs
  • Loading branch information
mpapierski committed Jul 23, 2024
2 parents 882cc77 + 32c973b commit 78756d0
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 12 deletions.
8 changes: 8 additions & 0 deletions binary_port/src/error_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ pub enum ErrorCode {
/// Invalid transaction kind
#[error("invalid transaction kind")]
InvalidTransactionInvalidTransactionKind = 84,
/// Gas price tolerance too low
#[error("gas price tolerance too low")]
GasPriceToleranceTooLow = 85,
}

impl TryFrom<u16> for ErrorCode {
Expand Down Expand Up @@ -363,6 +366,7 @@ impl TryFrom<u16> for ErrorCode {
82 => Ok(ErrorCode::DeployMissingModuleBytes),
83 => Ok(ErrorCode::InvalidTransactionEntryPointCannotBeCall),
84 => Ok(ErrorCode::InvalidTransactionInvalidTransactionKind),
85 => Ok(ErrorCode::GasPriceToleranceTooLow),
_ => Err(UnknownErrorCode),
}
}
Expand Down Expand Up @@ -433,6 +437,7 @@ impl From<InvalidDeploy> for ErrorCode {
InvalidDeploy::UnableToCalculateGasCost => {
ErrorCode::InvalidDeployUnableToCalculateGasCost
}
InvalidDeploy::GasPriceToleranceTooLow { .. } => ErrorCode::GasPriceToleranceTooLow,
_ => ErrorCode::InvalidDeployUnspecified,
}
}
Expand Down Expand Up @@ -497,6 +502,9 @@ impl From<InvalidTransactionV1> for ErrorCode {
InvalidTransactionV1::InvalidTransactionKind(_) => {
ErrorCode::InvalidTransactionInvalidTransactionKind
}
InvalidTransactionV1::GasPriceToleranceTooLow { .. } => {
ErrorCode::GasPriceToleranceTooLow
}
_ => ErrorCode::InvalidTransactionUnspecified,
}
}
Expand Down
54 changes: 52 additions & 2 deletions node/src/components/transaction_acceptor/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ enum TestScenario {
DeployWithoutTransferAmount,
BalanceCheckForDeploySentByPeer,
InvalidPricingModeForTransactionV1,
TooLowGasPriceToleranceForTransactionV1,
TooLowGasPriceToleranceForDeploy,
}

impl TestScenario {
Expand Down Expand Up @@ -252,7 +254,9 @@ impl TestScenario {
| TestScenario::FromClientSignedByAdmin(_)
| TestScenario::DeployWithEmptySessionModuleBytes
| TestScenario::DeployWithNativeTransferInPayment
| TestScenario::InvalidPricingModeForTransactionV1 => Source::Client,
| TestScenario::InvalidPricingModeForTransactionV1
| TestScenario::TooLowGasPriceToleranceForTransactionV1
| TestScenario::TooLowGasPriceToleranceForDeploy => Source::Client,
}
}

Expand Down Expand Up @@ -566,6 +570,24 @@ impl TestScenario {
.expect("must create classic mode transaction");
Transaction::from(classic_mode_transaction)
}
TestScenario::TooLowGasPriceToleranceForTransactionV1 => {
const TOO_LOW_GAS_PRICE_TOLERANCE: u8 = 0;

let fixed_mode_transaction = TransactionV1Builder::new_random(rng)
.with_pricing_mode(PricingMode::Fixed {
gas_price_tolerance: TOO_LOW_GAS_PRICE_TOLERANCE,
})
.with_chain_name("casper-example")
.build()
.expect("must create fixed mode transaction");
Transaction::from(fixed_mode_transaction)
}
TestScenario::TooLowGasPriceToleranceForDeploy => {
const TOO_LOW_GAS_PRICE_TOLERANCE: u64 = 0;

let deploy = Deploy::random_with_gas_price(rng, TOO_LOW_GAS_PRICE_TOLERANCE);
Transaction::from(deploy)
}
}
}

Expand Down Expand Up @@ -620,6 +642,8 @@ impl TestScenario {
}
}
TestScenario::InvalidPricingModeForTransactionV1 => false,
TestScenario::TooLowGasPriceToleranceForTransactionV1 => false,
TestScenario::TooLowGasPriceToleranceForDeploy => false,
}
}

Expand Down Expand Up @@ -1156,7 +1180,9 @@ async fn run_transaction_acceptor_without_timeout(
| TestScenario::DeployWithoutTransferTarget
| TestScenario::DeployWithoutTransferAmount
| TestScenario::InvalidPricingModeForTransactionV1
| TestScenario::FromClientExpired(_) => {
| TestScenario::FromClientExpired(_)
| TestScenario::TooLowGasPriceToleranceForTransactionV1
| TestScenario::TooLowGasPriceToleranceForDeploy => {
matches!(
event,
Event::TransactionAcceptorAnnouncement(
Expand Down Expand Up @@ -2380,3 +2406,27 @@ async fn should_reject_transaction_v1_with_invalid_pricing_mode() {
)))
))
}

#[tokio::test]
async fn should_reject_transaction_v1_with_too_low_gas_price_tolerance() {
let test_scenario = TestScenario::TooLowGasPriceToleranceForTransactionV1;
let result = run_transaction_acceptor(test_scenario).await;
assert!(matches!(
result,
Err(super::Error::InvalidTransaction(InvalidTransaction::V1(
InvalidTransactionV1::GasPriceToleranceTooLow { .. }
)))
))
}

#[tokio::test]
async fn should_reject_deploy_with_too_low_gas_price_tolerance() {
let test_scenario = TestScenario::TooLowGasPriceToleranceForDeploy;
let result = run_transaction_acceptor(test_scenario).await;
assert!(matches!(
result,
Err(super::Error::InvalidTransaction(
InvalidTransaction::Deploy(InvalidDeploy::GasPriceToleranceTooLow { .. })
))
))
}
Loading

0 comments on commit 78756d0

Please sign in to comment.