Skip to content

Commit

Permalink
Merge branch 'main' into 1364_cargo-udeps
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy authored Jan 11, 2024
2 parents 7b662a1 + 3fd7f3c commit 89b38d0
Show file tree
Hide file tree
Showing 22 changed files with 337 additions and 102 deletions.
11 changes: 6 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \

RUN apt install -y gh libgmp3-dev

COPY rust-toolchain.toml .
# To allow independent workflow of the container, the rust-toolchain is explicitely given.
RUN echo "1.74.0" > rust_toolchain_version

# Install cargo-binstall
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash

RUN rustup toolchain install $(cat rust-toolchain.toml | grep channel | cut -d\" -f2) && \
rustup default $(cat rust-toolchain.toml | grep channel | cut -d\" -f2) && \
RUN rustup toolchain install $(cat rust_toolchain_version) && \
rustup default $(cat rust_toolchain_version) && \
rustup component add clippy && \
rustup component add rustfmt

Expand All @@ -37,14 +38,14 @@ RUN if [ "$TARGETPLATFORM" = "linux/arm64" ] ; then \
mv hurl-4.1.0-aarch64-unknown-linux-gnu/hurl /usr/local/bin/ && \
rm -r hurl-4.1.0-aarch64-unknown-linux-gnu && \
rm hurl.tar.gz && \
rustup component add llvm-tools-preview --toolchain 1.74.0-aarch64-unknown-linux-gnu; \
rustup component add llvm-tools-preview --toolchain $(cat rust_toolchain_version)-aarch64-unknown-linux-gnu; \
elif [ "$TARGETPLATFORM" = "linux/amd64" ] ; then \
curl -L https://github.com/Orange-OpenSource/hurl/releases/download/4.1.0/hurl-4.1.0-x86_64-unknown-linux-gnu.tar.gz -o hurl.tar.gz && \
tar -xzf hurl.tar.gz && \
mv hurl-4.1.0-x86_64-unknown-linux-gnu/hurl /usr/local/bin/ && \
rm -r hurl-4.1.0-x86_64-unknown-linux-gnu && \
rm hurl.tar.gz && \
rustup component add llvm-tools-preview --toolchain 1.74.0-x86_64-unknown-linux-gnu && \
rustup component add llvm-tools-preview --toolchain $(cat rust_toolchain_version)-x86_64-unknown-linux-gnu && \
rustup target add x86_64-fortanix-unknown-sgx --toolchain nightly; \
fi

Expand Down
1 change: 0 additions & 1 deletion crates/dojo-world/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ impl Environment {
self.private_key.as_deref()
}

#[allow(dead_code)]
pub fn keystore_path(&self) -> Option<&str> {
self.keystore_path.as_deref()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/katana/core/contracts/messaging/cairo/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ACCOUNT_L2=./account_l2.json
ACCOUNT_L2_ADDR=0x9238c8ca6b3c6ab45a793593b13d98797ccd3bda179d313553e51fee114624
ACCOUNT_L2_ADDR=0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03
L2_PRIVATE_KEY=0x1800000000300000180000000000030000000000003006001800006600

# Build files helpers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"deployment": {
"status": "deployed",
"class_hash": "0x4d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27f0bb5bc5f",
"address": "0x9238c8ca6b3c6ab45a793593b13d98797ccd3bda179d313553e51fee114624"
"address": "0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03"
}
}
2 changes: 1 addition & 1 deletion crates/katana/core/contracts/messaging/solidity/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export $(shell sed 's/=.*//' .env)

# Addresses fixed here for easy testing.
C_MSG_L2_ADDR=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
L2_ACCOUNT=0x9238c8ca6b3c6ab45a793593b13d98797ccd3bda179d313553e51fee114624
L2_ACCOUNT=0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03
L2_CONTRACT_ADDR=0x0429a64d97c1422a37a09fc7406f35c264be59b744aaff5a79d59393eb1bc7e1

deploy_messaging_contracts:
Expand Down
32 changes: 5 additions & 27 deletions crates/katana/core/src/accounts.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::fmt::Display;
use std::sync::Arc;

use anyhow::Result;
use blockifier::execution::contract_class::ContractClass;
use katana_primitives::contract::ContractAddress;
use katana_primitives::FieldElement;
use katana_provider::traits::state::StateWriter;
Expand All @@ -14,9 +12,7 @@ use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet::core::utils::{get_contract_address, get_storage_var_address};
use starknet::signers::SigningKey;

use crate::constants::{
FEE_TOKEN_ADDRESS, OZ_V1_ACCOUNT_CONTRACT_COMPILED, OZ_V1_ACCOUNT_CONTRACT_COMPILED_CLASS_HASH,
};
use crate::constants::{FEE_TOKEN_ADDRESS, OZ_V1_ACCOUNT_CONTRACT_CLASS_HASH};

#[serde_as]
#[derive(Debug, Clone, Serialize)]
Expand All @@ -31,18 +27,11 @@ pub struct Account {
pub address: FieldElement,
#[serde_as(as = "UfeHex")]
pub class_hash: FieldElement,
#[serde(skip_serializing)]
pub contract_class: Arc<ContractClass>,
}

impl Account {
#[must_use]
pub fn new(
private_key: FieldElement,
balance: FieldElement,
class_hash: FieldElement,
contract_class: Arc<ContractClass>,
) -> Self {
pub fn new(private_key: FieldElement, balance: FieldElement, class_hash: FieldElement) -> Self {
let public_key = public_key_from_private_key(private_key);
let address = get_contract_address(
FieldElement::from(666u32),
Expand All @@ -51,7 +40,7 @@ impl Account {
FieldElement::ZERO,
);

Self { address, public_key, balance, class_hash, private_key, contract_class }
Self { address, public_key, balance, class_hash, private_key }
}

// TODO: separate fund logic from this struct - implement FeeToken type
Expand Down Expand Up @@ -104,7 +93,6 @@ pub struct DevAccountGenerator {
pub seed: [u8; 32],
pub balance: FieldElement,
pub class_hash: FieldElement,
pub contract_class: Arc<ContractClass>,
}

impl DevAccountGenerator {
Expand All @@ -114,8 +102,7 @@ impl DevAccountGenerator {
total,
seed: [0u8; 32],
balance: FieldElement::ZERO,
class_hash: (*OZ_V1_ACCOUNT_CONTRACT_COMPILED_CLASS_HASH),
contract_class: Arc::new((*OZ_V1_ACCOUNT_CONTRACT_COMPILED).clone()),
class_hash: (*OZ_V1_ACCOUNT_CONTRACT_CLASS_HASH),
}
}

Expand All @@ -127,10 +114,6 @@ impl DevAccountGenerator {
Self { balance, ..self }
}

pub fn with_class(self, class_hash: FieldElement, contract_class: Arc<ContractClass>) -> Self {
Self { class_hash, contract_class, ..self }
}

/// Generate `total` number of accounts based on the `seed`.
#[must_use]
pub fn generate(&self) -> Vec<Account> {
Expand All @@ -147,12 +130,7 @@ impl DevAccountGenerator {
let private_key = FieldElement::from_bytes_be(&private_key_bytes)
.expect("able to create FieldElement from bytes");

Account::new(
private_key,
self.balance,
self.class_hash,
self.contract_class.clone(),
)
Account::new(private_key, self.balance, self.class_hash)
})
.collect()
}
Expand Down
4 changes: 2 additions & 2 deletions crates/katana/core/src/service/messaging/starknet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ mod tests {
let to_address = selector!("to_address");
let selector = selector!("selector");
let nonce = FieldElement::ONE;
let calldata = vec![from_address, FieldElement::THREE];
let calldata = [from_address, FieldElement::THREE];
let transaction_hash = FieldElement::ZERO;

let event = EmittedEvent {
Expand Down Expand Up @@ -522,7 +522,7 @@ mod tests {
let _to_address = selector!("to_address");
let _selector = selector!("selector");
let _nonce = FieldElement::ONE;
let _calldata = vec![from_address, FieldElement::THREE];
let _calldata = [from_address, FieldElement::THREE];
let transaction_hash = FieldElement::ZERO;

let event = EmittedEvent {
Expand Down
8 changes: 4 additions & 4 deletions crates/katana/core/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ pub(super) fn get_genesis_states_for_testing() -> StateUpdatesWithDeclaredClasse
]);

let declared_sierra_classes = HashMap::from([(
*OZ_V1_ACCOUNT_CONTRACT_COMPILED_CLASS_HASH,
*OZ_V1_ACCOUNT_CONTRACT_CLASS_HASH,
OZ_V1_ACCOUNT_CONTRACT.clone().flatten().unwrap(),
)]);

let declared_compiled_classes = HashMap::from([
(*UDC_COMPILED_CLASS_HASH, (*UDC_CONTRACT).clone()),
(*ERC20_CONTRACT_COMPILED_CLASS_HASH, (*ERC20_CONTRACT).clone()),
(*OZ_V1_ACCOUNT_CONTRACT_COMPILED_CLASS_HASH, (*OZ_V1_ACCOUNT_CONTRACT_COMPILED).clone()),
(*UDC_CLASS_HASH, (*UDC_CONTRACT).clone()),
(*ERC20_CONTRACT_CLASS_HASH, (*ERC20_CONTRACT).clone()),
(*OZ_V1_ACCOUNT_CONTRACT_CLASS_HASH, (*OZ_V1_ACCOUNT_CONTRACT_COMPILED).clone()),
]);

StateUpdatesWithDeclaredClasses {
Expand Down
42 changes: 21 additions & 21 deletions crates/katana/storage/provider/tests/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ use fixtures::{
};
use utils::generate_dummy_blocks_and_receipts;

#[template]
#[rstest::rstest]
#[case::insert_1_block(1)]
#[case::insert_2_block(2)]
#[case::insert_5_block(5)]
#[case::insert_10_block(10)]
fn insert_block_cases(#[case] block_count: u64) {}

#[apply(insert_block_cases)]
fn insert_block_with_in_memory_provider(
#[from(in_memory_provider)] provider: BlockchainProvider<InMemoryProvider>,
Expand Down Expand Up @@ -139,19 +131,6 @@ where
Ok(())
}

#[template]
#[rstest::rstest]
#[case::state_update_at_block_1(1, mock_state_updates()[0].clone())]
#[case::state_update_at_block_2(2, mock_state_updates()[1].clone())]
#[case::state_update_at_block_3(3, StateUpdatesWithDeclaredClasses::default())]
#[case::state_update_at_block_5(5, mock_state_updates()[2].clone())]
fn test_read_state_update<Db>(
#[from(provider_with_states)] provider: BlockchainProvider<Db>,
#[case] block_num: BlockNumber,
#[case] expected_state_update: StateUpdatesWithDeclaredClasses,
) {
}

#[apply(test_read_state_update)]
fn test_read_state_update_with_in_memory_provider(
#[with(in_memory_provider())] provider: BlockchainProvider<InMemoryProvider>,
Expand Down Expand Up @@ -193,3 +172,24 @@ where
assert_eq!(actual_state_update, Some(expected_state_update.state_updates));
Ok(())
}

#[template]
#[rstest::rstest]
#[case::insert_1_block(1)]
#[case::insert_2_block(2)]
#[case::insert_5_block(5)]
#[case::insert_10_block(10)]
fn insert_block_cases(#[case] block_count: u64) {}

#[template]
#[rstest::rstest]
#[case::state_update_at_block_1(1, mock_state_updates()[0].clone())]
#[case::state_update_at_block_2(2, mock_state_updates()[1].clone())]
#[case::state_update_at_block_3(3, StateUpdatesWithDeclaredClasses::default())]
#[case::state_update_at_block_5(5, mock_state_updates()[2].clone())]
fn test_read_state_update<Db>(
#[from(provider_with_states)] provider: BlockchainProvider<Db>,
#[case] block_num: BlockNumber,
#[case] expected_state_update: StateUpdatesWithDeclaredClasses,
) {
}
Loading

0 comments on commit 89b38d0

Please sign in to comment.