Skip to content

Commit

Permalink
add sepolia issue
Browse files Browse the repository at this point in the history
  • Loading branch information
byteZorvin committed Sep 26, 2024
1 parent c674a6a commit a5a6e18
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io"

##### STARKNET SETTLEMENT TEST #####
STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86
ACCOUNT_CONTRACT_ADDRESS=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1
STARKNET_PUBLIC_KEY=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1
STARKNET_RPC_URL=http://localhost:9944
5 changes: 2 additions & 3 deletions crates/settlement-clients/ethereum/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::str::FromStr;

use serde::{Deserialize, Serialize};
use settlement_client_interface::SettlementConfig;
use url::Url;
use utils::settings::Settings;

Expand All @@ -15,8 +14,8 @@ pub struct EthereumSettlementConfig {
pub core_contract_address: String,
}

impl SettlementConfig for EthereumSettlementConfig {
fn new_with_settings(settings: &impl Settings) -> Self {
impl EthereumSettlementConfig {
pub fn new_with_settings(settings: &impl Settings) -> Self {
let rpc_url = settings.get_settings_or_panic(SETTLEMENT_RPC_URL);
let rpc_url = Url::from_str(&rpc_url).unwrap_or_else(|_| panic!("Failed to parse {}", SETTLEMENT_RPC_URL));
let core_contract_address = settings.get_settings_or_panic(ENV_CORE_CONTRACT_ADDRESS);
Expand Down
4 changes: 2 additions & 2 deletions crates/settlement-clients/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ use mockall::{automock, predicate::*};

use alloy::providers::ProviderBuilder;
use conversion::{get_input_data_for_eip_4844, prepare_sidecar};
#[cfg(feature = "testing")]
use settlement_client_interface::{SettlementClient, SettlementConfig, SettlementVerificationStatus};
#[cfg(not(feature = "testing"))]
use settlement_client_interface::{SettlementClient, SettlementConfig, SettlementVerificationStatus};
#[cfg(feature = "testing")]
use settlement_client_interface::{SettlementClient, SettlementVerificationStatus};
#[cfg(feature = "testing")]
use url::Url;
use utils::env_utils::get_env_var_or_panic;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use async_trait::async_trait;
use color_eyre::eyre::Result;
use mockall::automock;
use mockall::predicate::*;
use utils::settings::Settings;

pub const SETTLEMENT_SETTINGS_NAME: &str = "settlement_settings";

Expand Down Expand Up @@ -49,9 +48,3 @@ pub trait SettlementClient: Send + Sync {
/// Should retrieve the latest transaction count to be used as nonce.
async fn get_nonce(&self) -> Result<u64>;
}

/// Trait for every new SettlementConfig to implement
pub trait SettlementConfig {
/// Should create a new instance of the SettlementConfig from the environment variables
fn new_with_settings(settings: &impl Settings) -> Self;
}
1 change: 0 additions & 1 deletion crates/settlement-clients/starknet/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::str::FromStr;

use serde::{Deserialize, Serialize};
use settlement_client_interface::SettlementConfig;
use url::Url;
use utils::env_utils::get_env_var_or_default;
use utils::settings::Settings;
Expand Down
2 changes: 1 addition & 1 deletion crates/settlement-clients/starknet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use starknet::{
use tokio::time::{sleep, Duration};

use appchain_core_contract_client::clients::StarknetCoreContractClient;
use settlement_client_interface::{SettlementClient, SettlementConfig, SettlementVerificationStatus};
use settlement_client_interface::{SettlementClient, SettlementVerificationStatus};
use utils::settings::Settings;

use crate::config::StarknetSettlementConfig;
Expand Down
57 changes: 27 additions & 30 deletions crates/settlement-clients/starknet/src/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ use starknet::{
contract::ContractFactory,
core::types::{
contract::{CompiledClass, SierraClass},
BlockId, BlockTag, Felt,
BlockId, BlockTag, DeclareTransactionResult, Felt,
},
macros::felt,
providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Url,
},
providers::{jsonrpc::HttpTransport, JsonRpcClient, Provider, Url},
signers::{LocalWallet, SigningKey},
};
use std::env;
Expand All @@ -22,6 +19,7 @@ use std::sync::Arc;
use utils::settings::env::EnvSettingsProvider;
use utils::settings::Settings;

#[allow(unused)]
pub async fn spin_up_madara() -> MadaraCmd {
env::set_current_dir(PathBuf::from("/Users/bytezorvin/work/karnot/madara/"))
.expect("Failed to set working directory");
Expand Down Expand Up @@ -61,22 +59,30 @@ pub async fn spin_up_madara() -> MadaraCmd {
async fn setup() -> SingleOwnerAccount<JsonRpcClient<HttpTransport>, LocalWallet> {
// let madara_process = spin_up_madara().await;
// println!("RPC url {:?}", madara_process.rpc_url);
dotenvy::from_filename_override(".env").expect("Failed to load the .env file");

let env_settings = EnvSettingsProvider::default();
let rpc_url = Url::parse(&env_settings.get_settings_or_panic("STARKNET_RPC_URL")).unwrap();
println!("RPC url {:?}", rpc_url);
// let endpoint = madara_process.rpc_url.join("/health").unwrap();
// let endpoint = rpc_url.join("/health").unwrap();
// let response = reqwest::get(endpoint.clone()).await.expect("Failed to connect to Provider");
// assert!(response.status().is_success(), "Failed to connect to Provider");

// let provider = JsonRpcClient::new(HttpTransport::new(Url::parse("http://localhost:9944").unwrap()));
let provider = JsonRpcClient::new(HttpTransport::new(rpc_url));
let provider: JsonRpcClient<HttpTransport> = JsonRpcClient::new(HttpTransport::new(rpc_url));
let signer = LocalWallet::from(SigningKey::from_secret_scalar(
Felt::from_hex(&env_settings.get_settings_or_panic("STARKNET_PRIVATE_KEY")).unwrap(),
Felt::from_hex(&env_settings.get_settings_or_panic("STARKNET_PRIVATE_KEY")).expect("Invalid private key"),
));
let address = Felt::from_hex(&env_settings.get_settings_or_panic("ACCOUNT_CONTRACT_ADDRESS")).unwrap();
let address = Felt::from_hex(&env_settings.get_settings_or_panic("STARKNET_PUBLIC_KEY")).unwrap();

let chain_id = provider.chain_id().await.unwrap();
println!("address {:?}", env_settings.get_settings_or_panic("STARKNET_PUBLIC_KEY"));
let mut account = SingleOwnerAccount::new(
provider,
signer,
address,
Felt::from_hex("0x4d41444152415f54455354").unwrap(), // chain id = MADARA_TEST
chain_id,
ExecutionEncoding::New,
);

Expand All @@ -91,15 +97,9 @@ async fn setup() -> SingleOwnerAccount<JsonRpcClient<HttpTransport>, LocalWallet
#[tokio::test]
// async fn test_deployment(#[future] setup: (SingleOwnerAccount<JsonRpcClient<HttpTransport>, LocalWallet>, MadaraCmd)) {
async fn test_deployment(#[future] setup: SingleOwnerAccount<JsonRpcClient<HttpTransport>, LocalWallet>) {
dotenvy::from_filename(".env.test").expect("Failed to load the .env file");
// let (account, madara_process) = setup.await;
let account = setup.await;

// let endpoint = madara_process.rpc_url.join("/health").unwrap();
let endpoint = Url::parse("http://localhost:9944").unwrap().join("/health").unwrap();
let response = reqwest::get(endpoint.clone()).await.unwrap();
println!("Response from health: {:?}", response);

// println!("the db being used is {:?}", madara_process.tempdir);
let account = Arc::new(account);

Expand Down Expand Up @@ -137,39 +137,36 @@ async fn test_settle(#[future] setup: SingleOwnerAccount<JsonRpcClient<HttpTrans
// let (account, madara_process) = setup.await;
let account = setup.await;

// let endpoint = madara_process.rpc_url.join("/health").unwrap();
let endpoint = Url::parse("http://localhost:9944").unwrap().join("/health").unwrap();
let response = reqwest::get(endpoint.clone()).await.unwrap();
println!("Response from health: {:?}", response);

// println!("the db being used is {:?}", madara_process.tempdir);
let account = Arc::new(account);

// NOTE: you will need to declare this class first
let sierra_class: SierraClass = serde_json::from_reader(
std::fs::File::open("/Users/bytezorvin/work/karnot/madara-orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev/mock_contracts_Piltover.contract_class.json").unwrap(),
std::fs::File::open("/Users/bytezorvin/work/karnot/orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev/mock_contracts_Piltover.contract_class.json").unwrap(),
)
.unwrap();

let compiled_class: CompiledClass = serde_json::from_reader(
std::fs::File::open("/Users/bytezorvin/work/karnot/madara-orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev/mock_contracts_Piltover.compiled_contract_class.json").unwrap(),
std::fs::File::open("/Users/bytezorvin/work/karnot/orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev/mock_contracts_Piltover.compiled_contract_class.json").unwrap(),
)
.unwrap();

let flattened_class = sierra_class.clone().flatten().unwrap();
let compiled_class_hash = compiled_class.class_hash().unwrap();
let class_hash = flattened_class.class_hash();
account.declare_v2(Arc::new(flattened_class), compiled_class_hash).send().await.unwrap();
let DeclareTransactionResult { transaction_hash: _, class_hash } =
account.declare_v2(Arc::new(flattened_class), compiled_class_hash).send().await.unwrap();

// This done since madara currently does not increment nonce for pending transactions
// This is done, since currently madara does not increment nonce for pending transactions
tokio::time::sleep(tokio::time::Duration::from_secs(4)).await;

let contract_factory = ContractFactory::new(class_hash, account);
contract_factory
.deploy_v1(vec![felt!("123456")], felt!("1122"), false)
.send()
.await
.expect("Unable to deploy contract");
let deploy_v1 = contract_factory.deploy_v1(vec![felt!("123456")], felt!("1122"), false);
let deployed_address = deploy_v1.deployed_address();
env::set_var("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", deployed_address.to_hex_string());
deploy_v1.send().await.expect("Unable to deploy contract");

// This is done, since currently madara does not increment nonce for pending transactions
tokio::time::sleep(tokio::time::Duration::from_secs(4)).await;

let env_settings = EnvSettingsProvider {};
let settlement_client = StarknetSettlementClient::new_with_settings(&env_settings).await;
Expand Down

0 comments on commit a5a6e18

Please sign in to comment.