Skip to content

Commit

Permalink
Feat/write operations (#741)
Browse files Browse the repository at this point in the history
* feat: integrate dna in docker compose

* call and estimate gas

* add fee_history

* add send_raw_transaction

* refactory and delete unused code

* mock mongo using testcontainers crate

* fix some tests

* clean after rebase

* refactor estimate gas

* add setup fixture for logging + test estimate gas

* cleaning

* alchemy api testing

* update makefile

* answer comments

* fix makefile

* clean makefile + add tests

---------

Co-authored-by: Elias Tazartes <elias.tazartes@gmail.com>
  • Loading branch information
greged93 and Eikix authored Feb 1, 2024
1 parent bcadfc9 commit cc34b48
Show file tree
Hide file tree
Showing 79 changed files with 1,230 additions and 3,715 deletions.
69 changes: 28 additions & 41 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ anyhow = { version = "1.0.68", default-features = false }
async-trait = { version = "0.1.58", default-features = false }
auto_impl = { version = "1.1.0", default-features = false }
bytes = { version = "1", default-features = false }
ctor = { version = "0.2.4", default-features = false }
dotenv = { version = "0.15.0", default-features = false }
env_logger = { version = "0.10.0", default-features = false }
eyre = { version = "0.6.8", default-features = false }
Expand All @@ -54,14 +53,14 @@ futures = { version = "0.3.26", default-features = false }
hex = { version = "0.4", default-features = false }
lazy_static = { version = "1.4.0", default-features = false }
log = { version = "0.4.17", default-features = false }
mockall = { version = "0.12.1", default-features = false }
mongodb = { version = "2.8.0", default-features = false, features = [
"tokio-runtime",
] }
reqwest = { version = "0.11.13", default-features = false }
ruint = { version = "1.9.0", default-features = false }
rstest = { version = "0.18.1", default-features = false }

testcontainers = { version = "0.15.0", default-features = false, optional = true }
thiserror = { version = "1.0.38", default-features = false }
tokio = { version = "1.21.2", features = ["macros"] }
tower = { version = "0.4.12", default-features = false }
Expand Down Expand Up @@ -90,3 +89,6 @@ cairo-vm = { git = "https://github.com/dojoengine/cairo-rs.git", rev = "262b7eb4
dojo-test-utils = { git = 'https://github.com/dojoengine/dojo', rev = "be16762" }
rstest = { version = "0.18.1", default-features = false }
toml = { version = "0.7.5", default-features = false }

[features]
testing = ["testcontainers"]
24 changes: 17 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
HURL_FILES = $(shell find ./rpc-call-examples/ -name '*.hurl')

-include .env
export

ifndef STARKNET_NETWORK
override STARKNET_NETWORK = katana
endif

DECLARATIONS=./lib/kakarot/deployments/$(STARKNET_NETWORK)/declarations.json
DEPLOYMENTS=./lib/kakarot/deployments/$(STARKNET_NETWORK)/deployments.json

setup: .gitmodules
chmod +x ./scripts/extract_abi.sh
git submodule update --init --recursive
Expand All @@ -16,8 +17,14 @@ setup: .gitmodules
deploy-kakarot:
cd lib/kakarot && STARKNET_NETWORK=$(STARKNET_NETWORK) poetry run python ./scripts/deploy_kakarot.py && cd ..

run-dev:
PROXY_ACCOUNT_CLASS_HASH=$(shell jq -r '.proxy' ./lib/kakarot/deployments/$(STARKNET_NETWORK)/declarations.json) CONTRACT_ACCOUNT_CLASS_HASH=$(shell jq -r '.contract_account' ./lib/kakarot/deployments/$(STARKNET_NETWORK)/declarations.json) EXTERNALLY_OWNED_ACCOUNT_CLASS_HASH=$(shell jq -r '.externally_owned_account' ./lib/kakarot/deployments/$(STARKNET_NETWORK)/declarations.json) KAKAROT_ADDRESS=$(shell jq -r '.kakarot.address' ./lib/kakarot/deployments/$(STARKNET_NETWORK)/deployments.json) RUST_LOG=trace cargo run --bin kakarot-rpc
load-env:
$(eval PROXY_ACCOUNT_CLASS_HASH=$(shell jq -r '.proxy' $(DECLARATIONS)))
$(eval CONTRACT_ACCOUNT_CLASS_HASH=$(shell jq -r '.contract_account' $(DECLARATIONS)))
$(eval EXTERNALLY_OWNED_ACCOUNT_CLASS_HASH=$(shell jq -r '.externally_owned_account' $(DECLARATIONS)))
$(eval KAKAROT_ADDRESS=$(shell jq -r '.kakarot.address' $(DEPLOYMENTS)))

run-dev: load-env
RUST_LOG=trace cargo run --bin kakarot-rpc

# Run Katana, Deploy Kakarot, Run Kakarot RPC
katana-rpc-up:
Expand All @@ -42,16 +49,19 @@ kill-katana:

dump-katana: run-katana deploy-kakarot kill-katana

test: dump-katana
cargo test --all
test: dump-katana load-env
cargo test --all --features testing

test-coverage:
test-coverage: load-env
cargo llvm-cov nextest --all-features --workspace --lcov --output-path lcov.info

# Make sure to have a Kakarot RPC running and the correct port set in your .env and an underlying Starknet client running.
benchmark-madara:
cd benchmarks && bun i && bun run benchmark-madara

test-target: load-env
cargo test --tests --features testing $(TARGET) -- --nocapture

benchmark-katana:
cd benchmarks && bun i && bun run benchmark-katana

Expand Down
39 changes: 15 additions & 24 deletions src/starknet_client/config.rs → src/config.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
use eyre::Result;
use eyre::eyre;
use starknet::core::types::FieldElement;
use starknet::providers::jsonrpc::{HttpTransport, JsonRpcTransport};
use starknet::providers::{JsonRpcClient, SequencerGatewayProvider};
use std::env::var;
use url::Url;

use super::constants::{KATANA_RPC_URL, MADARA_RPC_URL};
use super::errors::ConfigError;
fn env_var_to_field_element(var_name: &str) -> Result<FieldElement, eyre::Error> {
let env_var = var(var_name)?;

pub fn env_var(name: &str) -> Result<String, ConfigError> {
std::env::var(name).map_err(|_| ConfigError::EnvironmentVariableMissing(name.into()))
}

fn env_var_to_field_element(var_name: &str) -> Result<FieldElement, ConfigError> {
let env_var = env_var(var_name)?;

FieldElement::from_hex_be(&env_var)
.map_err(|err| ConfigError::EnvironmentVariableSetWrong(var_name.into(), err.to_string()))
Ok(FieldElement::from_hex_be(&env_var)?)
}

#[derive(Default, Clone, Debug)]
Expand All @@ -31,26 +24,24 @@ pub enum Network {
}

impl Network {
pub fn gateway_url(&self) -> Result<Url, ConfigError> {
pub fn gateway_url(&self) -> Result<Url, eyre::Error> {
match self {
Self::MainnetGateway => Ok(Url::parse("https://alpha-mainnet.starknet.io/feeder_gateway/")?),
Self::Goerli1Gateway => Ok(Url::parse("https://alpha4.starknet.io/feeder_gateway/")?),
Self::Goerli2Gateway => Ok(Url::parse("https://alpha4-2.starknet.io/feeder_gateway/")?),
_ => Err(ConfigError::InvalidNetwork(format!("Network {:?} is not supported for gateway url", self))),
_ => Err(eyre!("Network {:?} is not supported for gateway url", self)),
}
}

pub fn provider_url(&self) -> Result<Url, ConfigError> {
pub fn provider_url(&self) -> Result<Url, eyre::Error> {
match self {
Self::Katana => Ok(Url::parse(KATANA_RPC_URL)?),
Self::Madara => Ok(Url::parse(MADARA_RPC_URL)?),
Self::Katana => Ok(Url::parse("http://0.0.0.0:5050")?),
Self::Madara => Ok(Url::parse("http://127.0.0.1:9944")?),
Self::Sharingan => Ok(Url::parse(
std::env::var("SHARINGAN_RPC_URL")
.map_err(|_| ConfigError::EnvironmentVariableMissing("SHARINGAN_RPC_URL".to_string()))?
.as_str(),
var("SHARINGAN_RPC_URL").map_err(|_| eyre!("Missing env var SHARINGAN_RPC_URL".to_string()))?.as_str(),
)?),
Self::JsonRpcProvider(url) => Ok(url.clone()),
_ => Err(ConfigError::InvalidNetwork(format!("Network {:?} is not supported for provider url", self))),
_ => Err(eyre!("Network {:?} is not supported for provider url", self)),
}
}
}
Expand Down Expand Up @@ -91,8 +82,8 @@ impl KakarotRpcConfig {
/// When using non-standard providers (i.e. not "katana", "madara", "mainnet"), the
/// `STARKNET_NETWORK` environment variable should be set the URL of a JsonRpc
/// starknet provider, e.g. https://starknet-goerli.g.alchemy.com/v2/some_key.
pub fn from_env() -> Result<Self, ConfigError> {
let network = env_var("STARKNET_NETWORK")?;
pub fn from_env() -> Result<Self, eyre::Error> {
let network = var("STARKNET_NETWORK")?;
let network = match network.to_lowercase().as_str() {
"katana" => Network::Katana,
"madara" => Network::Madara,
Expand Down Expand Up @@ -159,7 +150,7 @@ impl JsonRpcClientBuilder<HttpTransport> {
/// let starknet_provider: JsonRpcClient<HttpTransport> =
/// JsonRpcClientBuilder::with_http(&config).unwrap().build();
/// ```
pub fn with_http(config: &KakarotRpcConfig) -> Result<Self> {
pub fn with_http(config: &KakarotRpcConfig) -> Result<Self, eyre::Error> {
let url = config.network.provider_url()?;
let transport = HttpTransport::new(url);
Ok(Self::new(transport))
Expand Down
88 changes: 0 additions & 88 deletions src/contracts/erc20.rs

This file was deleted.

Loading

0 comments on commit cc34b48

Please sign in to comment.