Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Fix query version bit flag being unsupported in versions other than 0 (
Browse files Browse the repository at this point in the history
…#825)

* Add all supported version with flag set

* Added tests

* Fix versions in some tests
  • Loading branch information
xqft authored Jul 17, 2023
1 parent a66205b commit 4b90ba8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
10 changes: 8 additions & 2 deletions src/definitions/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ pub(crate) const N_STEPS_FEE_WEIGHT: f64 = 0.01;
pub(crate) const L1_HANDLER_VERSION: u64 = 0;

lazy_static! {
pub static ref SUPPORTED_VERSIONS: [Felt252; 4] =
[0.into(), 1.into(), 2.into(), QUERY_VERSION_BASE.clone()];
pub static ref SUPPORTED_VERSIONS: [Felt252; 6] = [
0.into(),
1.into(),
2.into(),
&0.into() | &QUERY_VERSION_BASE.clone(),
&1.into() | &QUERY_VERSION_BASE.clone(),
&2.into() | &QUERY_VERSION_BASE.clone(),
];
}

lazy_static! {
Expand Down
4 changes: 2 additions & 2 deletions src/transaction/declare_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,13 @@ mod tests {
let path;
#[cfg(not(feature = "cairo_1_tests"))]
{
version = QUERY_VERSION_BASE.clone();
version = &2.into() | &QUERY_VERSION_BASE.clone();
path = PathBuf::from("starknet_programs/cairo2/fibonacci.sierra");
}

#[cfg(feature = "cairo_1_tests")]
{
version = QUERY_VERSION_BASE.clone();
version = &1.into() | &QUERY_VERSION_BASE.clone();
path = PathBuf::from("starknet_programs/cairo1/fibonacci.sierra");
}

Expand Down
6 changes: 3 additions & 3 deletions src/transaction/invoke_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1055,16 +1055,16 @@ mod tests {
}

#[test]
fn invoke_version_one_with_no_nonce_with_query_base() {
fn invoke_version_one_with_no_nonce_with_query_base_should_fail() {
let expected_error = preprocess_invoke_function_fields(
Felt252::from_str_radix(
"112e35f48499939272000bd72eb840e502ca4c3aefa8800992e8defb746e0c9",
16,
)
.unwrap(),
None,
QUERY_VERSION_BASE.clone(),
&1.into() | &QUERY_VERSION_BASE.clone(),
);
assert!(expected_error.is_ok());
assert!(expected_error.is_err());
}
}
34 changes: 33 additions & 1 deletion src/transaction/verify_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ pub fn verify_version(

#[cfg(test)]
mod test {
use crate::transaction::error::TransactionError;
// TODO: fixture tests would be better here
use crate::{definitions::constants::QUERY_VERSION_BASE, transaction::error::TransactionError};

use super::verify_version;

Expand Down Expand Up @@ -104,4 +105,35 @@ mod test {
let result = verify_version(&version, max_fee, &nonce, &signature).unwrap_err();
assert_matches!(result, TransactionError::InvalidSignature);
}

#[test]
fn version_0_with_max_fee_0_nonce_0_and_empty_signature_and_query_version_set_should_return_ok()
{
let version = &0.into() | &QUERY_VERSION_BASE.clone();
let max_fee = 0;
let nonce = 0.into();
let signature = vec![];
let result = verify_version(&version, max_fee, &nonce, &signature);
assert!(result.is_ok());
}

#[test]
fn version_1_with_query_version_set_should_return_ok() {
let version = &1.into() | &QUERY_VERSION_BASE.clone();
let max_fee = 2;
let nonce = 3.into();
let signature = vec![5.into()];
let result = verify_version(&version, max_fee, &nonce, &signature);
assert!(result.is_ok());
}

#[test]
fn version_2_with_query_version_set_should_return_ok() {
let version = &2.into() | &QUERY_VERSION_BASE.clone();
let max_fee = 43;
let nonce = 4.into();
let signature = vec![6.into()];
let result = verify_version(&version, max_fee, &nonce, &signature);
assert!(result.is_ok());
}
}

0 comments on commit 4b90ba8

Please sign in to comment.