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

Commit

Permalink
Merge branch 'main' into fix/rpc-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EvolveArt authored Sep 25, 2023
2 parents dde9ec4 + 2244ec1 commit 251c813
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 24 deletions.
40 changes: 24 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,37 @@

## Next release

## v0.3.0

- chore: release v0.3.0
- chore: big transaction type refactoring
- chore: split `primitives` crates into multiple smaller crates
- chore: improve logging about transaction when nonce is too high
- chore: add real class hash values for genesis config
- fix: use specific commit for avail and celestia
- fix: change dep of rustdoc on push
- fix: initial_gas set to max_fee and fixed fee not being charged when max_fee=0
- fix: correct value of compiled_class_hash in RPCTransaction
- fix: std feature import in transactions crate
- fix: replace all calls to `transmute` by calls `from_raw_parts`
- fix: estimate_fee should make sure all transaction have a version being
2^128 + 1 or 2^128+2 depending on the tx type
- feat: modify the hash_bytes functions in `poseidon` and `pedersen` for dynamic
data length
- chore: add real class hash values for genesis config
- feat: print development accounts at node startup
- feat: unification of the DA interface
- feat: use resolver 2 for cargo in the workspace
- upgrade: restructure code for rust latest version
- upgrade: bump rustc nightly version to 1.74 date
- feat: bump starknet-core to 0.6.0 and remove InvokeV0
- fix: estimate_fee should make sure all transaction have a version being
2^128 + 1 or 2^128+2 depending on the tx type
- fix: initial_gas set to max_fee and fixed fee not being charged when max_fee=0
- fix: correct value of compiled_class_hash in RPCTransaction
- ci: scope cache by branch and add cache cleanup
- feat: print development accounts at node startup
- test: add test to check tx signed by OZ account can be signed with Argent pk
- feat: use resolver 2 for cargo in the workspace
- feat: impl tx execution and verification as traits
- perf: reduce the amount of data stored in the runtime and use the Substrate
block to as source of data in the client
- perf: use perfect hash function in calculate_l1_gas_by_vm_usage
- build: restructure code for rust latest version
- build: bump rustc nightly version to 1.74 date
- buid: add rust-analyzer to toolchain components
- ci: scope cache by branch and add cache cleanup
- ci: increase threshold for codecov to 1%
- test: add `starknet-rpc-test` crate to the workspace
- test(rpc): add `get_block_number.rs` tests
- test(rpc): add `get_block_hash_and_number.rs` tests
- test(rpc): add `get_block_transaction_count.rs` tests
- test(rpc): add `chain_id.rs` tests
- feat: print development accounts at node startup
- test: add test to check tx signed by OZ account can be signed with Argent pk
- buid: add rust-analyzer to toolchain components
- ci: increase threshold for codecov to 1%
Expand All @@ -41,6 +47,8 @@
- fix: std feature import in transactions crate
- chore: improve logging about transaction when nonce is too high
- fix: rpc tests and background node run
- test: add tests for simulate tx offset
- test: add tests for tx hashing

## v0.2.0

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ rpath = false # Disables adding rpath to the binary
authors = ["Abdelhamid Bakhta <@abdelhamidbakhta>"]
edition = "2021"
repository = "https://github.com/keep-starknet-strange/madara/"
version = "0.2.0"
version = "0.3.0"

[workspace.dependencies]
# Substrate frame dependencies
Expand Down
105 changes: 98 additions & 7 deletions crates/primitives/transactions/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,21 @@ pub trait GetAccountTransactionContext {
fn get_account_transaction_context(&self, is_query: bool) -> AccountTransactionContext;
}

pub trait SimulateTxVersionOffset {
fn apply_simulate_tx_version_offset(&self) -> TransactionVersion;
}

impl SimulateTxVersionOffset for TransactionVersion {
fn apply_simulate_tx_version_offset(&self) -> TransactionVersion {
Felt252Wrapper(Felt252Wrapper::from(self.0).0 + SIMULATE_TX_VERSION_OFFSET).into()
}
}

impl GetAccountTransactionContext for DeclareTransaction {
fn get_account_transaction_context(&self, is_query: bool) -> AccountTransactionContext {
let mut version = self.tx().version();
if is_query {
version = Felt252Wrapper(Felt252Wrapper::from(version.0).0 + SIMULATE_TX_VERSION_OFFSET).into();
version = version.apply_simulate_tx_version_offset();
}

AccountTransactionContext {
Expand All @@ -76,7 +86,7 @@ impl GetAccountTransactionContext for DeployAccountTransaction {
fn get_account_transaction_context(&self, is_query: bool) -> AccountTransactionContext {
let mut version = self.version();
if is_query {
version = Felt252Wrapper(Felt252Wrapper::from(version.0).0 + SIMULATE_TX_VERSION_OFFSET).into();
version = version.apply_simulate_tx_version_offset();
}

AccountTransactionContext {
Expand All @@ -97,7 +107,7 @@ impl GetAccountTransactionContext for InvokeTransaction {
starknet_api::transaction::InvokeTransaction::V1(_) => TransactionVersion(StarkFelt::from(1u8)),
};
if is_query {
version = Felt252Wrapper(Felt252Wrapper::from(version.0).0 + SIMULATE_TX_VERSION_OFFSET).into();
version = version.apply_simulate_tx_version_offset();
}

let nonce = match &self.tx {
Expand Down Expand Up @@ -125,7 +135,7 @@ impl GetAccountTransactionContext for L1HandlerTransaction {
fn get_account_transaction_context(&self, is_query: bool) -> AccountTransactionContext {
let mut version = self.tx.version;
if is_query {
version = Felt252Wrapper(Felt252Wrapper::from(version.0).0 + SIMULATE_TX_VERSION_OFFSET).into();
version = version.apply_simulate_tx_version_offset();
}

AccountTransactionContext {
Expand Down Expand Up @@ -564,9 +574,11 @@ impl Execute for L1HandlerTransaction {

#[cfg(test)]
mod simulate_tx_offset {
use blockifier::execution::contract_class::ContractClass;
use starknet_ff::FieldElement;

use super::SIMULATE_TX_VERSION_OFFSET;
use super::*;

#[test]
fn offset_is_correct() {
assert_eq!(
Expand All @@ -575,6 +587,85 @@ mod simulate_tx_offset {
);
}

// TODO: add test that check that each get_account_transaction_context impl correctly uses this
// offset
#[test]
fn l1_handler_transaction_correctly_applies_simulate_tx_version_offset() {
let l1_handler_tx = L1HandlerTransaction {
tx: Default::default(),
paid_fee_on_l1: Default::default(),
tx_hash: Default::default(),
};

let original_version = l1_handler_tx.tx.version;
let queried_version = l1_handler_tx.get_account_transaction_context(true).version;

assert_eq!(
queried_version,
Felt252Wrapper(Felt252Wrapper::from(original_version.0).0 + SIMULATE_TX_VERSION_OFFSET).into()
);

let non_queried_version = l1_handler_tx.get_account_transaction_context(false).version;
assert_eq!(non_queried_version, original_version);
}

#[test]
fn deploy_account_transaction_correctly_applies_simulate_tx_version_offset() {
let deploy_account_tx = DeployAccountTransaction {
tx: Default::default(),
tx_hash: Default::default(),
contract_address: Default::default(),
};

let original_version = deploy_account_tx.tx.version;

let queried_version = deploy_account_tx.get_account_transaction_context(true).version;
assert_eq!(
queried_version,
Felt252Wrapper(Felt252Wrapper::from(original_version.0).0 + SIMULATE_TX_VERSION_OFFSET).into()
);

let non_queried_version = deploy_account_tx.get_account_transaction_context(false).version;
assert_eq!(non_queried_version, original_version);
}

#[test]
fn declare_transaction_correctly_applies_simulate_tx_version_offset() {
let declare_tx_v0 = DeclareTransaction::new(
starknet_api::transaction::DeclareTransaction::V0(Default::default()),
Default::default(),
ContractClass::V0(Default::default()),
)
.unwrap();

// gen TxVersion from v0 manually
let original_version_v0 = TransactionVersion(StarkFelt::from(0u8));

let queried_version = declare_tx_v0.get_account_transaction_context(true).version;
assert_eq!(
queried_version,
Felt252Wrapper(Felt252Wrapper::from(original_version_v0.0).0 + SIMULATE_TX_VERSION_OFFSET).into()
);

let non_queried_version = declare_tx_v0.get_account_transaction_context(false).version;
assert_eq!(non_queried_version, original_version_v0);
}

#[test]
fn invoke_transaction_correctly_applies_simulate_tx_version_offset() {
let invoke_tx = InvokeTransaction {
tx: starknet_api::transaction::InvokeTransaction::V0(Default::default()),
tx_hash: Default::default(),
};

// gen TxVersion from v0 manually
let original_version_v0 = TransactionVersion(StarkFelt::from(0u8));

let queried_version = invoke_tx.get_account_transaction_context(true).version;
assert_eq!(
queried_version,
Felt252Wrapper(Felt252Wrapper::from(original_version_v0.0).0 + SIMULATE_TX_VERSION_OFFSET).into()
);

let non_queried_version = invoke_tx.get_account_transaction_context(false).version;
assert_eq!(non_queried_version, original_version_v0);
}
}

0 comments on commit 251c813

Please sign in to comment.