Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions openrpc-testgen/src/suite_openrpc/suite_deploy/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::path::PathBuf;

use starknet_types_core::felt::Felt;
use starknet_types_rpc::{BlockId, ClassAndTxnHash, DeclareTxn, EventFilterWithPageRequest, Txn};
use starknet_types_rpc::{
BlockId, BlockTag, ClassAndTxnHash, DeclareTxn, EventFilterWithPageRequest, Txn,
};
use tracing::info;

use super::RandomSingleOwnerAccount;
Expand Down Expand Up @@ -102,18 +104,14 @@ impl SetupableTrait for TestSuiteDeploy {

let filter = EventFilterWithPageRequest {
address: None,
from_block: Some(BlockId::Number(322421)),
to_block: Some(BlockId::Number(322421)),
from_block: Some(BlockId::Number(1)),
to_block: Some(BlockId::Tag(BlockTag::Latest)),
keys: Some(vec![vec![]]),
chunk_size: 100,
continuation_token: None,
};

let provider = setup_input.random_paymaster_account.provider();
let random_account_address = setup_input
.random_paymaster_account
.random_accounts()?
.address();

let mut continuation_token = None;
let mut found_txn_hash = None;
Expand All @@ -125,17 +123,14 @@ impl SetupableTrait for TestSuiteDeploy {
let events_chunk = provider.get_events(current_filter).await?;

for event in events_chunk.events {
if event.event.data.contains(&random_account_address) {
let txn_hash = event.transaction_hash;
let txn_hash = event.transaction_hash;

let txn_details =
provider.get_transaction_by_hash(txn_hash).await?;
let txn_details = provider.get_transaction_by_hash(txn_hash).await?;

if let Txn::Declare(DeclareTxn::V3(declare_txn)) = txn_details {
if declare_txn.class_hash == class_hash {
found_txn_hash = Some(txn_hash);
break;
}
if let Txn::Declare(DeclareTxn::V3(declare_txn)) = txn_details {
if declare_txn.class_hash == class_hash {
found_txn_hash = Some(txn_hash);
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
};

pub mod test_call_contract;
pub mod test_call_invalid_selector;
// pub mod test_call_invalid_selector;
pub mod test_estimate_message_fee;
pub mod test_get_storage_at;
pub mod test_get_storage_at_map;
Expand Down
67 changes: 56 additions & 11 deletions openrpc-testgen/src/suite_openrpc/suite_deploy/test_get_class_at.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::path::PathBuf;
use std::str::FromStr;

use crate::utils::v7::accounts::account::{Account, ConnectedAccount};
use crate::utils::v7::accounts::account::{Account, AccountError, ConnectedAccount};
use crate::utils::v7::contract::factory::ContractFactory;
use crate::utils::v7::endpoints::declare_contract::get_compiled_contract;
use crate::utils::v7::endpoints::declare_contract::{
extract_class_hash_from_error, get_compiled_contract, parse_class_hash_from_error, RunnerError,
};
use crate::utils::v7::endpoints::errors::CallError;
use crate::utils::v7::endpoints::utils::wait_for_sent_transaction;
use crate::utils::v7::providers::provider::Provider;
use crate::utils::v7::providers::provider::{Provider, ProviderError};
use crate::{assert_result, RandomizableAccountsTrait};
use crate::{utils::v7::endpoints::errors::OpenRpcTestGenError, RunnableTrait};
use rand::rngs::StdRng;
Expand All @@ -32,20 +34,63 @@ impl RunnableTrait for TestCase {
)
.await?;

let declaration_result = test_input
let declaration_result = match test_input
.random_paymaster_account
.declare_v3(flattened_sierra_class.clone(), compiled_class_hash)
.send()
.await?;
.await
{
Ok(result) => {
wait_for_sent_transaction(
result.transaction_hash,
&test_input.random_paymaster_account.random_accounts()?,
)
.await?;

Ok(result.class_hash)
}
Err(AccountError::Signing(sign_error)) => {
if sign_error.to_string().contains("is already declared") {
Ok(parse_class_hash_from_error(&sign_error.to_string())?)
} else {
Err(OpenRpcTestGenError::RunnerError(
RunnerError::AccountFailure(format!(
"Transaction execution error: {}",
sign_error
)),
))
}
}

wait_for_sent_transaction(
declaration_result.transaction_hash,
&test_input.random_paymaster_account.random_accounts()?,
)
.await?;
Err(AccountError::Provider(ProviderError::Other(starkneterror))) => {
if starkneterror.to_string().contains("is already declared") {
Ok(parse_class_hash_from_error(&starkneterror.to_string())?)
} else {
Err(OpenRpcTestGenError::RunnerError(
RunnerError::AccountFailure(format!(
"Transaction execution error: {}",
starkneterror
)),
))
}
}
Err(e) => {
let full_error_message = format!("{:?}", e);

if full_error_message.contains("is already declared") {
Ok(extract_class_hash_from_error(&full_error_message)?)
} else {
let full_error_message = format!("{:?}", e);

return Err(OpenRpcTestGenError::AccountError(AccountError::Other(
full_error_message,
)));
}
}
}?;

let factory = ContractFactory::new(
declaration_result.class_hash,
declaration_result,
test_input.random_paymaster_account.random_accounts()?,
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::path::PathBuf;
use std::str::FromStr;

use crate::utils::v7::accounts::account::{Account, ConnectedAccount};
use crate::utils::v7::accounts::account::{Account, AccountError, ConnectedAccount};
use crate::utils::v7::contract::factory::ContractFactory;
use crate::utils::v7::endpoints::declare_contract::get_compiled_contract;
use crate::utils::v7::endpoints::declare_contract::{
extract_class_hash_from_error, get_compiled_contract, parse_class_hash_from_error, RunnerError,
};
use crate::utils::v7::endpoints::errors::CallError;
use crate::utils::v7::endpoints::utils::wait_for_sent_transaction;
use crate::utils::v7::providers::provider::Provider;
use crate::utils::v7::providers::provider::{Provider, ProviderError};
use crate::{assert_result, RandomizableAccountsTrait};
use crate::{utils::v7::endpoints::errors::OpenRpcTestGenError, RunnableTrait};
use rand::rngs::StdRng;
Expand All @@ -31,20 +33,63 @@ impl RunnableTrait for TestCase {
)
.await?;

let declaration_result = test_input
let declaration_result = match test_input
.random_paymaster_account
.declare_v3(flattened_sierra_class.clone(), compiled_class_hash)
.send()
.await?;
.await
{
Ok(result) => {
wait_for_sent_transaction(
result.transaction_hash,
&test_input.random_paymaster_account.random_accounts()?,
)
.await?;

Ok(result.class_hash)
}
Err(AccountError::Signing(sign_error)) => {
if sign_error.to_string().contains("is already declared") {
Ok(parse_class_hash_from_error(&sign_error.to_string())?)
} else {
Err(OpenRpcTestGenError::RunnerError(
RunnerError::AccountFailure(format!(
"Transaction execution error: {}",
sign_error
)),
))
}
}

wait_for_sent_transaction(
declaration_result.transaction_hash,
&test_input.random_paymaster_account.random_accounts()?,
)
.await?;
Err(AccountError::Provider(ProviderError::Other(starkneterror))) => {
if starkneterror.to_string().contains("is already declared") {
Ok(parse_class_hash_from_error(&starkneterror.to_string())?)
} else {
Err(OpenRpcTestGenError::RunnerError(
RunnerError::AccountFailure(format!(
"Transaction execution error: {}",
starkneterror
)),
))
}
}
Err(e) => {
let full_error_message = format!("{:?}", e);

if full_error_message.contains("is already declared") {
Ok(extract_class_hash_from_error(&full_error_message)?)
} else {
let full_error_message = format!("{:?}", e);

return Err(OpenRpcTestGenError::AccountError(AccountError::Other(
full_error_message,
)));
}
}
}?;

let factory = ContractFactory::new(
declaration_result.class_hash,
declaration_result,
test_input.random_paymaster_account.random_accounts()?,
);

Expand Down Expand Up @@ -105,10 +150,10 @@ impl RunnableTrait for TestCase {
let contract_class_hash = contract_class_hash?;

assert_result!(
contract_class_hash == declaration_result.class_hash,
contract_class_hash == declaration_result,
format!(
"Class hash mismatch: expected {}, got {}",
declaration_result.class_hash, contract_class_hash
declaration_result, contract_class_hash
)
);

Expand Down
71 changes: 58 additions & 13 deletions openrpc-testgen/src/suite_openrpc/test_get_block_txn_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ use crate::{
assert_result,
utils::v7::{
accounts::{
account::{Account, ConnectedAccount},
account::{Account, AccountError, ConnectedAccount},
call::Call,
},
contract::factory::ContractFactory,
endpoints::{
declare_contract::get_compiled_contract,
declare_contract::{
extract_class_hash_from_error, get_compiled_contract, parse_class_hash_from_error,
RunnerError,
},
errors::{CallError, OpenRpcTestGenError},
utils::{get_selector_from_name, wait_for_sent_transaction},
},
providers::provider::Provider,
providers::provider::{Provider, ProviderError},
},
RandomizableAccountsTrait, RunnableTrait,
};
Expand Down Expand Up @@ -46,23 +49,65 @@ impl RunnableTrait for TestCase {
)
.await?;

let declaration_result = test_input
let declaration_result = match test_input
.random_paymaster_account
.declare_v3(flattened_sierra_class, compiled_class_hash)
.declare_v3(flattened_sierra_class.clone(), compiled_class_hash)
.send()
.await?;
.await
{
Ok(result) => {
wait_for_sent_transaction(
result.transaction_hash,
&test_input.random_paymaster_account.random_accounts()?,
)
.await?;

wait_for_sent_transaction(
declaration_result.transaction_hash,
&test_input.random_paymaster_account.random_accounts()?,
)
.await?;
Ok(result.class_hash)
}
Err(AccountError::Signing(sign_error)) => {
if sign_error.to_string().contains("is already declared") {
Ok(parse_class_hash_from_error(&sign_error.to_string())?)
} else {
Err(OpenRpcTestGenError::RunnerError(
RunnerError::AccountFailure(format!(
"Transaction execution error: {}",
sign_error
)),
))
}
}

Err(AccountError::Provider(ProviderError::Other(starkneterror))) => {
if starkneterror.to_string().contains("is already declared") {
Ok(parse_class_hash_from_error(&starkneterror.to_string())?)
} else {
Err(OpenRpcTestGenError::RunnerError(
RunnerError::AccountFailure(format!(
"Transaction execution error: {}",
starkneterror
)),
))
}
}
Err(e) => {
let full_error_message = format!("{:?}", e);

if full_error_message.contains("is already declared") {
Ok(extract_class_hash_from_error(&full_error_message)?)
} else {
let full_error_message = format!("{:?}", e);

return Err(OpenRpcTestGenError::AccountError(AccountError::Other(
full_error_message,
)));
}
}
}?;

// Step 2: Deploy the declared contract
let paymaster_account = test_input.random_paymaster_account.random_accounts()?;

let factory =
ContractFactory::new(declaration_result.class_hash, paymaster_account.clone());
let factory = ContractFactory::new(declaration_result, paymaster_account.clone());

let mut salt_buffer = [0u8; 32];
let mut rng = StdRng::from_entropy();
Expand Down
Loading
Loading