diff --git a/CHANGELOG.md b/CHANGELOG.md index 4afb5d5560..b1cee17cb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### Added - `--l1-gas`, `--l1-gas-price`, `--l2-gas`, `--l2-gas-price`, `--l1-data-gas`, `--l1-data-gas-price` flags +- methods for fee settings creation, in `FeeSettingsTrait`: `max_fee()`, `resource_bounds()` and `estimate()` (in `sncast_std`) #### Changed @@ -20,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### Removed - `--max-gas` and `--max-gas-unit-price` flags +- `max_gas`, `max_gas_unit_price` fields in `FeeSettings` (in `sncast_std`) ## [0.39.0] - 2025-03-19 diff --git a/crates/sncast/src/helpers/fee.rs b/crates/sncast/src/helpers/fee.rs index 89591af205..d3229af51f 100644 --- a/crates/sncast/src/helpers/fee.rs +++ b/crates/sncast/src/helpers/fee.rs @@ -84,7 +84,6 @@ impl FeeArgs { } } -// TODO(#3102): Refactor to be enum with max fee and triplet variants /// Struct used in `sncast script` for deserializing from cairo, `FeeSettings` can't be /// used as it missing `max_fee` #[derive(Debug, PartialEq, CairoDeserialize)] diff --git a/crates/sncast/tests/data/scripts/declare/src/fee_settings.cairo b/crates/sncast/tests/data/scripts/declare/src/fee_settings.cairo index f07edb3ea5..b2f88afa18 100644 --- a/crates/sncast/tests/data/scripts/declare/src/fee_settings.cairo +++ b/crates/sncast/tests/data/scripts/declare/src/fee_settings.cairo @@ -1,18 +1,13 @@ use sncast_std::{ - get_nonce, declare, DeclareResult, ScriptCommandError, ProviderError, StarknetError, FeeSettings + get_nonce, declare, DeclareResult, ScriptCommandError, ProviderError, StarknetError, + FeeSettingsTrait }; fn main() { + let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, 10000000000000, 1000000000, 100000000000000000000, 100000, 10000000000000, + ); let declare_nonce = get_nonce('latest'); - declare( - "Mapa", - FeeSettings { - max_gas: Option::Some(99999), - max_gas_unit_price: Option::Some(999999999999), - max_fee: Option::None - }, - Option::Some(declare_nonce) - ) - .expect('declare failed'); + declare("Mapa", fee_settings, Option::Some(declare_nonce)).expect('declare failed'); println!("success"); } diff --git a/crates/sncast/tests/data/scripts/declare/src/insufficient_account_balance.cairo b/crates/sncast/tests/data/scripts/declare/src/insufficient_account_balance.cairo index cc873516b0..7a771e77a8 100644 --- a/crates/sncast/tests/data/scripts/declare/src/insufficient_account_balance.cairo +++ b/crates/sncast/tests/data/scripts/declare/src/insufficient_account_balance.cairo @@ -1,20 +1,19 @@ use sncast_std::{ get_nonce, declare, DeclareResult, ScriptCommandError, ProviderError, StarknetError, - FeeSettings, + FeeSettingsTrait, }; fn main() { + let fee_settings = FeeSettingsTrait::resource_bounds( + 9999999999999999999, + 99999999999999999999999999999999999999, + 9999999999999999999, + 99999999999999999999999999999999999999, + 9999999999999999999, + 99999999999999999999999999999999999999 + ); let declare_nonce = get_nonce('latest'); - let declare_result = declare( - "Mapa", - FeeSettings { - max_fee: Option::None, - max_gas: Option::Some(9999999999999999999), - max_gas_unit_price: Option::Some(99999999999999999999999999999999999999) - }, - Option::Some(declare_nonce) - ) - .unwrap_err(); + let declare_result = declare("Mapa", fee_settings, Option::Some(declare_nonce)).unwrap_err(); println!("{:?}", declare_result); assert( diff --git a/crates/sncast/tests/data/scripts/declare/src/no_contract.cairo b/crates/sncast/tests/data/scripts/declare/src/no_contract.cairo index 839444184f..57993fcc70 100644 --- a/crates/sncast/tests/data/scripts/declare/src/no_contract.cairo +++ b/crates/sncast/tests/data/scripts/declare/src/no_contract.cairo @@ -1,16 +1,10 @@ use sncast_std::{ - declare, DeclareResult, ScriptCommandError, ProviderError, StarknetError, FeeSettings, + declare, DeclareResult, ScriptCommandError, ProviderError, StarknetError, FeeSettingsTrait, }; fn main() { - let declare_result = declare( - "Mapaaaa", - FeeSettings { - max_fee: Option::None, max_gas: Option::None, max_gas_unit_price: Option::None - }, - Option::None - ) - .unwrap_err(); + let fee_settings = FeeSettingsTrait::estimate(); + let declare_result = declare("Mapaaaa", fee_settings, Option::None).unwrap_err(); println!("{:?}", declare_result); } diff --git a/crates/sncast/tests/data/scripts/declare/src/same_contract_twice.cairo b/crates/sncast/tests/data/scripts/declare/src/same_contract_twice.cairo index 8f1bb83319..1a29cfe148 100644 --- a/crates/sncast/tests/data/scripts/declare/src/same_contract_twice.cairo +++ b/crates/sncast/tests/data/scripts/declare/src/same_contract_twice.cairo @@ -1,19 +1,14 @@ use sncast_std::{ get_nonce, declare, DeclareResult, DeclareResultTrait, ScriptCommandError, ProviderError, - StarknetError, FeeSettings + StarknetError, FeeSettingsTrait }; fn main() { + let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, 10000000000000, 1000000000, 100000000000000000000, 100000, 10000000000000, + ); let declare_nonce = get_nonce('latest'); - let first_declare_result = declare( - "Mapa", - FeeSettings { - max_fee: Option::None, - max_gas: Option::Some(999999), - max_gas_unit_price: Option::Some(100000000000) - }, - Option::Some(declare_nonce) - ) + let first_declare_result = declare("Mapa", fee_settings, Option::Some(declare_nonce)) .expect('declare failed'); println!("success"); @@ -27,15 +22,7 @@ fn main() { assert(*first_declare_result.class_hash() == class_hash, 'Class hashes must be equal'); let declare_nonce = get_nonce('latest'); - let second_declare_result = declare( - "Mapa", - FeeSettings { - max_fee: Option::None, - max_gas: Option::Some(999999), - max_gas_unit_price: Option::Some(100000000000) - }, - Option::Some(declare_nonce) - ) + let second_declare_result = declare("Mapa", fee_settings, Option::Some(declare_nonce)) .expect('second declare failed'); // Check if already declared contract was handled correctly diff --git a/crates/sncast/tests/data/scripts/declare/src/time_out.cairo b/crates/sncast/tests/data/scripts/declare/src/time_out.cairo index db8a3b0ee6..ab548a4e1a 100644 --- a/crates/sncast/tests/data/scripts/declare/src/time_out.cairo +++ b/crates/sncast/tests/data/scripts/declare/src/time_out.cairo @@ -1,19 +1,14 @@ use sncast_std::{ - get_nonce, declare, DeclareResult, ScriptCommandError, ProviderError, StarknetError, FeeSettings + get_nonce, declare, DeclareResult, ScriptCommandError, ProviderError, StarknetError, + FeeSettingsTrait }; fn main() { - let max_fee = 99999999999999999; - + let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, 10000000000000, 1000000000, 100000000000000000000, 100000, 10000000000000, + ); let declare_nonce = get_nonce('latest'); - let declare_result = declare( - "Mapa", - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, - Option::Some(declare_nonce) - ) - .unwrap_err(); + let declare_result = declare("Mapa", fee_settings, Option::Some(declare_nonce)).unwrap_err(); println!("{:?}", declare_result); } diff --git a/crates/sncast/tests/data/scripts/declare/src/with_invalid_max_fee.cairo b/crates/sncast/tests/data/scripts/declare/src/with_invalid_max_fee.cairo index c7f4d487cc..821490ea4d 100644 --- a/crates/sncast/tests/data/scripts/declare/src/with_invalid_max_fee.cairo +++ b/crates/sncast/tests/data/scripts/declare/src/with_invalid_max_fee.cairo @@ -1,22 +1,17 @@ use sncast_std::{ - get_nonce, declare, DeclareResult, ScriptCommandError, ProviderError, StarknetError, FeeSettings + get_nonce, declare, DeclareResult, ScriptCommandError, ProviderError, StarknetError, + FeeSettingsTrait }; fn main() { + let fee_settings = FeeSettingsTrait::resource_bounds(1, 1, 1, 1, 1, 1,); let declare_nonce = get_nonce('latest'); - let declare_result = declare( - "Mapa", - FeeSettings { - max_fee: Option::None, max_gas: Option::Some(1), max_gas_unit_price: Option::Some(1) - }, - Option::Some(declare_nonce) - ) - .unwrap_err(); + let declare_result = declare("Mapa", fee_settings, Option::Some(declare_nonce)).unwrap_err(); println!("{:?}", declare_result); assert( ScriptCommandError::ProviderError( - ProviderError::StarknetError(StarknetError::InsufficientMaxFee) + ProviderError::StarknetError(StarknetError::InsufficientResourcesForValidate) ) == declare_result, 'ohno' ) diff --git a/crates/sncast/tests/data/scripts/declare/src/with_invalid_nonce.cairo b/crates/sncast/tests/data/scripts/declare/src/with_invalid_nonce.cairo index e431c2b338..e6900c2f09 100644 --- a/crates/sncast/tests/data/scripts/declare/src/with_invalid_nonce.cairo +++ b/crates/sncast/tests/data/scripts/declare/src/with_invalid_nonce.cairo @@ -1,19 +1,14 @@ use sncast_std::{ - get_nonce, declare, DeclareResult, ScriptCommandError, ProviderError, StarknetError, FeeSettings + get_nonce, declare, DeclareResult, ScriptCommandError, ProviderError, StarknetError, + FeeSettingsTrait }; fn main() { - let max_fee = 99999999999999999; - + let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, 10000000000000, 1000000000, 100000000000000000000, 100000, 10000000000000, + ); let declare_nonce = get_nonce('pending') + 100; - let declare_result = declare( - "Mapa", - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, - Option::Some(declare_nonce) - ) - .unwrap_err(); + let declare_result = declare("Mapa", fee_settings, Option::Some(declare_nonce)).unwrap_err(); println!("{:?}", declare_result); assert( diff --git a/crates/sncast/tests/data/scripts/deploy/src/fee_settings.cairo b/crates/sncast/tests/data/scripts/deploy/src/fee_settings.cairo index ca5fee1272..ccecc6e716 100644 --- a/crates/sncast/tests/data/scripts/deploy/src/fee_settings.cairo +++ b/crates/sncast/tests/data/scripts/deploy/src/fee_settings.cairo @@ -1,24 +1,18 @@ -use sncast_std::{deploy, DeployResult, FeeSettings}; +use sncast_std::{deploy, DeployResult, FeeSettingsTrait}; use starknet::{ClassHash, Felt252TryIntoClassHash}; use traits::Into; fn main() { + let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, 10000000000000, 1000000000, 100000000000000000000, 100000, 10000000000000, + ); let salt = 0x3; let class_hash: ClassHash = 0x059426c817fb8103edebdbf1712fa084c6744b2829db9c62d1ea4dce14ee6ded .try_into() .expect('Invalid class hash value'); let deploy_result = deploy( - class_hash, - array![0x2, 0x2, 0x0], - Option::Some(salt), - true, - FeeSettings { - max_gas: Option::Some(999), - max_gas_unit_price: Option::Some(999999999999), - max_fee: Option::None - }, - Option::None + class_hash, array![0x2, 0x2, 0x0], Option::Some(salt), true, fee_settings, Option::None ) .expect('deploy failed'); diff --git a/crates/sncast/tests/data/scripts/deploy/src/invalid_calldata.cairo b/crates/sncast/tests/data/scripts/deploy/src/invalid_calldata.cairo index d73c1f880f..c419ca3b08 100644 --- a/crates/sncast/tests/data/scripts/deploy/src/invalid_calldata.cairo +++ b/crates/sncast/tests/data/scripts/deploy/src/invalid_calldata.cairo @@ -1,11 +1,14 @@ use sncast_std::{ - get_nonce, deploy, DeployResult, ScriptCommandError, ProviderError, StarknetError, FeeSettings, + get_nonce, deploy, DeployResult, ScriptCommandError, ProviderError, StarknetError, + FeeSettingsTrait, }; use starknet::{ClassHash, Felt252TryIntoClassHash}; use traits::Into; fn main() { - let max_fee = 99999999999999999; + let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, 10000000000000, 1000000000, 100000000000000000000, 100000, 10000000000000, + ); let salt = 0x3; let class_hash: ClassHash = 0x059426c817fb8103edebdbf1712fa084c6744b2829db9c62d1ea4dce14ee6ded @@ -14,14 +17,7 @@ fn main() { let deploy_nonce = get_nonce('pending'); let deploy_result = deploy( - class_hash, - array![0x2], - Option::Some(salt), - true, - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, - Option::Some(deploy_nonce) + class_hash, array![0x2], Option::Some(salt), true, fee_settings, Option::Some(deploy_nonce) ) .unwrap_err(); diff --git a/crates/sncast/tests/data/scripts/deploy/src/invalid_class_hash.cairo b/crates/sncast/tests/data/scripts/deploy/src/invalid_class_hash.cairo index 799679b1ef..b2009b857e 100644 --- a/crates/sncast/tests/data/scripts/deploy/src/invalid_class_hash.cairo +++ b/crates/sncast/tests/data/scripts/deploy/src/invalid_class_hash.cairo @@ -1,11 +1,14 @@ use sncast_std::{ - get_nonce, deploy, DeployResult, ScriptCommandError, ProviderError, StarknetError, FeeSettings, + get_nonce, deploy, DeployResult, ScriptCommandError, ProviderError, StarknetError, + FeeSettingsTrait, }; use starknet::{ClassHash, Felt252TryIntoClassHash}; use traits::Into; fn main() { - let max_fee = 99999999999999999; + let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, 10000000000000, 1000000000, 100000000000000000000, 100000, 10000000000000, + ); let salt = 0x3; let class_hash: ClassHash = 0xdddd.try_into().expect('Invalid class hash value'); @@ -16,9 +19,7 @@ fn main() { array![0x2, 0x2, 0x0], Option::Some(salt), true, - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, + fee_settings, Option::Some(deploy_nonce) ) .unwrap_err(); diff --git a/crates/sncast/tests/data/scripts/deploy/src/invalid_nonce.cairo b/crates/sncast/tests/data/scripts/deploy/src/invalid_nonce.cairo index 3e58c05326..c7ffd978cd 100644 --- a/crates/sncast/tests/data/scripts/deploy/src/invalid_nonce.cairo +++ b/crates/sncast/tests/data/scripts/deploy/src/invalid_nonce.cairo @@ -1,13 +1,15 @@ use sncast_std::{ - get_nonce, deploy, DeployResult, ScriptCommandError, ProviderError, StarknetError, FeeSettings, - TransactionExecutionErrorData + get_nonce, deploy, DeployResult, ScriptCommandError, ProviderError, StarknetError, + FeeSettingsTrait, TransactionExecutionErrorData }; use starknet::{ClassHash, Felt252TryIntoClassHash}; use traits::Into; fn main() { - let max_fee = 99999999999999999; + let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, 10000000000000, 1000000000, 100000000000000000000, 100000, 10000000000000, + ); let salt = 0x3; let class_hash: ClassHash = 0x059426c817fb8103edebdbf1712fa084c6744b2829db9c62d1ea4dce14ee6ded @@ -20,9 +22,7 @@ fn main() { array![0x2, 0x2, 0x0], Option::Some(salt), true, - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, + fee_settings, Option::Some(deploy_nonce) ) .unwrap_err(); diff --git a/crates/sncast/tests/data/scripts/deploy/src/same_class_hash_and_salt.cairo b/crates/sncast/tests/data/scripts/deploy/src/same_class_hash_and_salt.cairo index f22274cd8f..7bfa9a77c4 100644 --- a/crates/sncast/tests/data/scripts/deploy/src/same_class_hash_and_salt.cairo +++ b/crates/sncast/tests/data/scripts/deploy/src/same_class_hash_and_salt.cairo @@ -1,11 +1,14 @@ use sncast_std::{ - get_nonce, deploy, DeployResult, ScriptCommandError, ProviderError, StarknetError, FeeSettings, + get_nonce, deploy, DeployResult, ScriptCommandError, ProviderError, StarknetError, + FeeSettingsTrait, }; use starknet::{ClassHash, Felt252TryIntoClassHash}; use traits::Into; fn main() { - let max_fee = 99999999999999999; + let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, 10000000000000, 1000000000, 100000000000000000000, 100000, 10000000000000, + ); let salt = 0x34542; let class_hash: ClassHash = 0x059426c817fb8103edebdbf1712fa084c6744b2829db9c62d1ea4dce14ee6ded @@ -18,9 +21,7 @@ fn main() { array![0x2, 0x2, 0x0], Option::Some(salt), true, - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, + fee_settings, Option::Some(deploy_nonce) ) .expect('1st deploy failed'); @@ -35,9 +36,7 @@ fn main() { array![0x2, 0x2, 0x0], Option::Some(salt), true, - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, + fee_settings, Option::Some(deploy_nonce) ) .unwrap_err(); diff --git a/crates/sncast/tests/data/scripts/deploy/src/with_calldata.cairo b/crates/sncast/tests/data/scripts/deploy/src/with_calldata.cairo index a7b131dc7f..7e7a85bcc9 100644 --- a/crates/sncast/tests/data/scripts/deploy/src/with_calldata.cairo +++ b/crates/sncast/tests/data/scripts/deploy/src/with_calldata.cairo @@ -1,23 +1,18 @@ -use sncast_std::{deploy, DeployResult, FeeSettings}; +use sncast_std::{deploy, DeployResult, FeeSettingsTrait}; use starknet::{ClassHash, Felt252TryIntoClassHash}; use traits::Into; fn main() { - let max_fee = 99999999999999999; + let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, 10000000000000, 1000000000, 100000000000000000000, 100000, 10000000000000, + ); let salt = 0x3; let class_hash: ClassHash = 0x059426c817fb8103edebdbf1712fa084c6744b2829db9c62d1ea4dce14ee6ded .try_into() .expect('Invalid class hash value'); let deploy_result = deploy( - class_hash, - array![0x2, 0x2, 0x0], - Option::Some(salt), - true, - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, - Option::None + class_hash, array![0x2, 0x2, 0x0], Option::Some(salt), true, fee_settings, Option::None ) .expect('deploy failed'); diff --git a/crates/sncast/tests/data/scripts/invoke/src/contract_does_not_exist.cairo b/crates/sncast/tests/data/scripts/invoke/src/contract_does_not_exist.cairo index 23318f9298..18c6704408 100644 --- a/crates/sncast/tests/data/scripts/invoke/src/contract_does_not_exist.cairo +++ b/crates/sncast/tests/data/scripts/invoke/src/contract_does_not_exist.cairo @@ -1,20 +1,16 @@ use sncast_std::{ - invoke, InvokeResult, ScriptCommandError, ProviderError, StarknetError, FeeSettings, + invoke, InvokeResult, ScriptCommandError, ProviderError, StarknetError, FeeSettingsTrait, }; use starknet::{ContractAddress, Felt252TryIntoContractAddress}; use traits::Into; fn main() { let map_contract_address = 0x123.try_into().expect('Invalid contract address value'); - + let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, 10000000000000, 1000000000, 100000000000000000000, 100000, 10000000000000, + ); let invoke_result = invoke( - map_contract_address, - selector!("put"), - array![0x10, 0x1], - FeeSettings { - max_fee: Option::None, max_gas: Option::None, max_gas_unit_price: Option::None - }, - Option::None + map_contract_address, selector!("put"), array![0x10, 0x1], fee_settings, Option::None ) .unwrap_err(); println!("{:?}", invoke_result); diff --git a/crates/sncast/tests/data/scripts/invoke/src/max_fee_too_low.cairo b/crates/sncast/tests/data/scripts/invoke/src/max_fee_too_low.cairo index 9d9a48ca79..4eedb4954d 100644 --- a/crates/sncast/tests/data/scripts/invoke/src/max_fee_too_low.cairo +++ b/crates/sncast/tests/data/scripts/invoke/src/max_fee_too_low.cairo @@ -1,5 +1,5 @@ use sncast_std::{ - invoke, InvokeResult, ScriptCommandError, ProviderError, StarknetError, FeeSettings, + invoke, InvokeResult, ScriptCommandError, ProviderError, StarknetError, FeeSettingsTrait }; use starknet::{ContractAddress, Felt252TryIntoContractAddress}; use traits::Into; @@ -8,15 +8,10 @@ fn main() { let map_contract_address = 0x07537a17e169c96cf2b0392508b3a66cbc50c9a811a8a7896529004c5e93fdf6 .try_into() .expect('Invalid contract address value'); + let fee_settings = FeeSettingsTrait::resource_bounds(1, 1, 1, 1, 1, 1,); let invoke_result = invoke( - map_contract_address, - selector!("put"), - array![0x10, 0x1], - FeeSettings { - max_fee: Option::None, max_gas: Option::Some(1), max_gas_unit_price: Option::Some(1) - }, - Option::None + map_contract_address, selector!("put"), array![0x10, 0x1], fee_settings, Option::None ) .unwrap_err(); println!("{:?}", invoke_result); diff --git a/crates/sncast/tests/data/scripts/invoke/src/wrong_calldata.cairo b/crates/sncast/tests/data/scripts/invoke/src/wrong_calldata.cairo index fde516960f..4a9ace6fba 100644 --- a/crates/sncast/tests/data/scripts/invoke/src/wrong_calldata.cairo +++ b/crates/sncast/tests/data/scripts/invoke/src/wrong_calldata.cairo @@ -1,5 +1,5 @@ use sncast_std::{ - invoke, InvokeResult, ScriptCommandError, ProviderError, StarknetError, FeeSettings, + invoke, InvokeResult, ScriptCommandError, ProviderError, StarknetError, FeeSettingsTrait, }; use starknet::{ContractAddress, Felt252TryIntoContractAddress}; use traits::Into; @@ -8,15 +8,10 @@ fn main() { let map_contract_address = 0xcd8f9ab31324bb93251837e4efb4223ee195454f6304fcfcb277e277653008 .try_into() .expect('Invalid contract address value'); + let fee_settings = FeeSettingsTrait::estimate(); let invoke_result = invoke( - map_contract_address, - selector!("put"), - array![0x10], - FeeSettings { - max_fee: Option::None, max_gas: Option::None, max_gas_unit_price: Option::None - }, - Option::None + map_contract_address, selector!("put"), array![0x10], fee_settings, Option::None ) .unwrap_err(); println!("{:?}", invoke_result); diff --git a/crates/sncast/tests/data/scripts/invoke/src/wrong_function_name.cairo b/crates/sncast/tests/data/scripts/invoke/src/wrong_function_name.cairo index 089f3347d5..13ab32ab8c 100644 --- a/crates/sncast/tests/data/scripts/invoke/src/wrong_function_name.cairo +++ b/crates/sncast/tests/data/scripts/invoke/src/wrong_function_name.cairo @@ -1,5 +1,5 @@ use sncast_std::{ - invoke, InvokeResult, ScriptCommandError, ProviderError, StarknetError, FeeSettings, + invoke, InvokeResult, ScriptCommandError, ProviderError, StarknetError, FeeSettingsTrait }; use starknet::{ContractAddress, Felt252TryIntoContractAddress}; use traits::Into; @@ -8,15 +8,10 @@ fn main() { let map_contract_address = 0xcd8f9ab31324bb93251837e4efb4223ee195454f6304fcfcb277e277653008 .try_into() .expect('Invalid contract address value'); + let fee_settings = FeeSettingsTrait::estimate(); let invoke_result = invoke( - map_contract_address, - selector!("mariusz"), - array![0x10, 0x1], - FeeSettings { - max_fee: Option::None, max_gas: Option::None, max_gas_unit_price: Option::None - }, - Option::None + map_contract_address, selector!("mariusz"), array![0x10, 0x1], fee_settings, Option::None ) .unwrap_err(); println!("{:?}", invoke_result); diff --git a/crates/sncast/tests/data/scripts/map_script/scripts/src/display_debug_traits_for_subcommand_responses.cairo b/crates/sncast/tests/data/scripts/map_script/scripts/src/display_debug_traits_for_subcommand_responses.cairo index 83a911d59b..86d9c20354 100644 --- a/crates/sncast/tests/data/scripts/map_script/scripts/src/display_debug_traits_for_subcommand_responses.cairo +++ b/crates/sncast/tests/data/scripts/map_script/scripts/src/display_debug_traits_for_subcommand_responses.cairo @@ -1,7 +1,4 @@ -use sncast_std::{ - declare, deploy, invoke, call, DeclareResult, DeclareResultTrait, DeployResult, InvokeResult, - CallResult, get_nonce, FeeSettings -}; +use sncast_std::{declare, deploy, invoke, call, DeclareResultTrait, get_nonce, FeeSettingsTrait}; fn main() { println!("test"); @@ -11,15 +8,11 @@ fn main() { println!("declare_nonce: {}", declare_nonce); println!("debug declare_nonce: {:?}", declare_nonce); - let declare_result = declare( - "Mapa", - FeeSettings { - max_fee: Option::None, - max_gas: Option::Some(999999), - max_gas_unit_price: Option::Some(100000000000) - }, - Option::Some(declare_nonce) - ) + let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, 10000000000000, 1000000000, 100000000000000000000, 100000, 10000000000000, + ); + + let declare_result = declare("Mapa", fee_settings, Option::Some(declare_nonce)) .expect('declare failed'); println!("declare_result: {}", declare_result); println!("debug declare_result: {:?}", declare_result); @@ -31,11 +24,7 @@ fn main() { ArrayTrait::new(), Option::Some(salt), true, - FeeSettings { - max_fee: Option::None, - max_gas: Option::Some(999999), - max_gas_unit_price: Option::Some(100000000000) - }, + fee_settings, Option::Some(deploy_nonce) ) .expect('deploy failed'); @@ -49,11 +38,7 @@ fn main() { deploy_result.contract_address, selector!("put"), array![0x1, 0x2], - FeeSettings { - max_fee: Option::None, - max_gas: Option::Some(999999), - max_gas_unit_price: Option::Some(100000000000) - }, + fee_settings, Option::Some(invoke_nonce) ) .expect('invoke failed'); diff --git a/crates/sncast/tests/data/scripts/map_script/scripts/src/map_script.cairo b/crates/sncast/tests/data/scripts/map_script/scripts/src/map_script.cairo index c35a4ee5ba..2c10d9a49c 100644 --- a/crates/sncast/tests/data/scripts/map_script/scripts/src/map_script.cairo +++ b/crates/sncast/tests/data/scripts/map_script/scripts/src/map_script.cairo @@ -1,16 +1,11 @@ -use sncast_std::{ - declare, deploy, invoke, call, DeclareResult, DeployResult, DeclareResultTrait, InvokeResult, - CallResult, get_nonce, FeeSettings -}; +use sncast_std::{declare, deploy, invoke, call, DeclareResultTrait, get_nonce, FeeSettingsTrait}; fn second_contract() { - let declare_result = declare( - "Mapa2", - FeeSettings { - max_fee: Option::None, max_gas: Option::None, max_gas_unit_price: Option::None - }, - Option::None - ) + let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, 10000000000000, 1000000000, 100000000000000000000, 100000, 10000000000000, + ); + + let declare_result = declare("Mapa2", fee_settings, Option::None) .expect('mapa2 declare failed'); let deploy_result = deploy( @@ -18,9 +13,7 @@ fn second_contract() { ArrayTrait::new(), Option::None, false, - FeeSettings { - max_fee: Option::None, max_gas: Option::None, max_gas_unit_price: Option::None - }, + fee_settings, Option::None ) .expect('mapa deploy failed'); @@ -30,9 +23,7 @@ fn second_contract() { deploy_result.contract_address, selector!("put"), array![0x1, 0x3], - FeeSettings { - max_fee: Option::None, max_gas: Option::None, max_gas_unit_price: Option::None - }, + fee_settings, Option::None ) .expect('mapa2 invoke failed'); @@ -44,17 +35,13 @@ fn second_contract() { } fn main() { - let max_fee = 99999999999999999; + let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, 10000000000000, 1000000000, 100000000000000000000, 100000, 10000000000000, + ); let salt = 0x3; let declare_nonce = get_nonce('latest'); - let declare_result = declare( - "Mapa", - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, - Option::Some(declare_nonce) - ) + let declare_result = declare("Mapa", fee_settings, Option::Some(declare_nonce)) .expect('mapa declare failed'); let class_hash = declare_result.class_hash(); @@ -64,9 +51,7 @@ fn main() { ArrayTrait::new(), Option::Some(salt), true, - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, + fee_settings, Option::Some(deploy_nonce) ) .expect('mapa deploy failed'); @@ -77,9 +62,7 @@ fn main() { deploy_result.contract_address, selector!("put"), array![0x1, 0x2], - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, + fee_settings, Option::Some(invoke_nonce) ) .expect('mapa invoke failed'); diff --git a/crates/sncast/tests/data/scripts/misc/src/call_fail.cairo b/crates/sncast/tests/data/scripts/misc/src/call_fail.cairo index bec1527a23..bcaec5ec01 100644 --- a/crates/sncast/tests/data/scripts/misc/src/call_fail.cairo +++ b/crates/sncast/tests/data/scripts/misc/src/call_fail.cairo @@ -1,7 +1,7 @@ use sncast_std::{call, CallResult}; fn main() { - let eth = 0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7; - let call_result = call(eth.try_into().unwrap(), selector!("gimme_money"), array![]); + let strk = 0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d; + let call_result = call(strk.try_into().unwrap(), selector!("gimme_money"), array![]); call_result.expect('call failed'); } diff --git a/crates/sncast/tests/data/scripts/state_file/src/all_tx_fail.cairo b/crates/sncast/tests/data/scripts/state_file/src/all_tx_fail.cairo index 2dcc2c125f..69e2778023 100644 --- a/crates/sncast/tests/data/scripts/state_file/src/all_tx_fail.cairo +++ b/crates/sncast/tests/data/scripts/state_file/src/all_tx_fail.cairo @@ -1,11 +1,10 @@ -use sncast_std::{ - declare, deploy, invoke, call, DeclareResult, DeployResult, InvokeResult, CallResult, get_nonce, - FeeSettings -}; +use sncast_std::{declare, deploy, invoke, get_nonce, FeeSettingsTrait}; use starknet::{ClassHash, ContractAddress}; fn main() { - let max_fee = 99999999999999999; + let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, 10000000000000, 1000000000, 100000000000000000000, 100000, 10000000000000, + ); let salt = 0x3; let nonexistent_class_hash: ClassHash = 0x10101.try_into().expect('Invalid class hash value'); @@ -15,15 +14,7 @@ fn main() { .expect('Invalid contract address value'); let declare_nonce = get_nonce('latest'); - declare( - "Not_this_time", - FeeSettings { - max_fee: Option::None, - max_gas: Option::Some(999999), - max_gas_unit_price: Option::Some(100000000000) - }, - Option::Some(declare_nonce) - ) + declare("Not_this_time", fee_settings, Option::Some(declare_nonce)) .expect_err('error expected declare'); let deploy_nonce = get_nonce('pending'); @@ -32,11 +23,7 @@ fn main() { ArrayTrait::new(), Option::Some(salt), true, - FeeSettings { - max_fee: Option::None, - max_gas: Option::Some(999999), - max_gas_unit_price: Option::Some(100000000000) - }, + fee_settings, Option::Some(deploy_nonce) ) .expect_err('error expected deploy'); @@ -46,11 +33,7 @@ fn main() { map_contract_address, selector!("put"), array![0x1, 0x2], - FeeSettings { - max_fee: Option::None, - max_gas: Option::Some(999999), - max_gas_unit_price: Option::Some(100000000000) - }, + fee_settings, Option::Some(invoke_nonce) ) .expect_err('error expected invoke'); diff --git a/crates/sncast/tests/data/scripts/state_file/src/rerun_failed_tx.cairo b/crates/sncast/tests/data/scripts/state_file/src/rerun_failed_tx.cairo index 1a7547008c..84f30fefc2 100644 --- a/crates/sncast/tests/data/scripts/state_file/src/rerun_failed_tx.cairo +++ b/crates/sncast/tests/data/scripts/state_file/src/rerun_failed_tx.cairo @@ -1,21 +1,13 @@ -use sncast_std::{ - declare, deploy, invoke, call, DeclareResult, DeployResult, InvokeResult, CallResult, get_nonce, - FeeSettings -}; +use sncast_std::{invoke, FeeSettingsTrait}; fn main() { + let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, 10000000000000, 1000000000, 100000000000000000000, 100000, 10000000000000, + ); let map_contract_address = 0xcd8f9ab31324bb93251837e4efb4223ee195454f6304fcfcb277e277653008 .try_into() .expect('Invalid contract address value'); - invoke( - map_contract_address, - selector!("put"), - array![0x10, 0x1], - FeeSettings { - max_fee: Option::None, max_gas: Option::None, max_gas_unit_price: Option::None - }, - Option::None - ) + invoke(map_contract_address, selector!("put"), array![0x10, 0x1], fee_settings, Option::None) .unwrap(); } diff --git a/crates/sncast/tests/data/scripts/state_script/scripts/src/state_script.cairo b/crates/sncast/tests/data/scripts/state_script/scripts/src/state_script.cairo index 9c1b1cb2da..2559886f99 100644 --- a/crates/sncast/tests/data/scripts/state_script/scripts/src/state_script.cairo +++ b/crates/sncast/tests/data/scripts/state_script/scripts/src/state_script.cairo @@ -1,20 +1,13 @@ -use sncast_std::{ - declare, deploy, invoke, call, DeclareResult, DeclareResultTrait, DeployResult, InvokeResult, - CallResult, get_nonce, FeeSettings -}; +use sncast_std::{declare, deploy, invoke, call, DeclareResultTrait, get_nonce, FeeSettingsTrait}; fn main() { - let max_fee = 99999999999999999; + let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, 10000000000000, 1000000000, 100000000000000000000, 100000, 10000000000000, + ); let salt = 0x5; let declare_nonce = get_nonce('latest'); - let declare_result = declare( - "State", - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, - Option::Some(declare_nonce) - ) + let declare_result = declare("State", fee_settings, Option::Some(declare_nonce)) .expect('state declare failed'); let class_hash = declare_result.class_hash(); @@ -24,9 +17,7 @@ fn main() { ArrayTrait::new(), Option::Some(salt), true, - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, + fee_settings, Option::Some(deploy_nonce) ) .expect('state deploy failed'); @@ -37,9 +28,7 @@ fn main() { deploy_result.contract_address, selector!("put"), array![0x1, 0x2], - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, + fee_settings, Option::Some(invoke_nonce) ) .expect('state invoke failed'); diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 2e572bed52..4e8485d33a 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -1,5 +1,6 @@ use std::fs; +use crate::helpers::fee::apply_test_resource_bounds_flags; use crate::helpers::fixtures::copy_directory_to_tempdir; use crate::helpers::runner::runner; use camino::Utf8PathBuf; @@ -64,6 +65,15 @@ fn test_docs_snippets() { } } + // TODO(#3100) + // We need to add the resource bounds flags to the args, because auto-estimate from devnet doesn't cover tx costs + if args + .iter() + .any(|&arg| arg == "declare" || arg == "deploy" || arg == "invoke") + { + args = apply_test_resource_bounds_flags(args); + } + let snapbox = runner(&args).current_dir(tempdir.path()); let output = snapbox.assert().success(); diff --git a/crates/sncast/tests/e2e/script/call.rs b/crates/sncast/tests/e2e/script/call.rs index 2f4f518b01..bf1b632686 100644 --- a/crates/sncast/tests/e2e/script/call.rs +++ b/crates/sncast/tests/e2e/script/call.rs @@ -56,11 +56,11 @@ async fn test_call_invalid_entry_point() { assert_stdout_contains( output, - indoc! {r#" - ScriptCommandError::ProviderError(ProviderError::StarknetError(StarknetError::ContractError(ErrorData { msg: "Entry point EntryPointSelector([..]) not found in contract." }))) + indoc! {r" + ScriptCommandError::ProviderError(ProviderError::StarknetError(StarknetError::EntryPointNotFound(()))) command: script run status: success - "#}, + "}, ); } @@ -86,6 +86,7 @@ async fn test_call_invalid_address() { } #[tokio::test] +#[ignore = "TODO(#3120)"] async fn test_call_invalid_calldata() { let tempdir = copy_script_directory_to_tempdir(SCRIPTS_DIR.to_owned() + "/call", Vec::::new()); diff --git a/crates/sncast/tests/e2e/script/declare.rs b/crates/sncast/tests/e2e/script/declare.rs index cf2111831b..4251c06ee1 100644 --- a/crates/sncast/tests/e2e/script/declare.rs +++ b/crates/sncast/tests/e2e/script/declare.rs @@ -9,8 +9,9 @@ use test_case::test_case; #[test_case("oz_cairo_0"; "cairo_0_account")] #[test_case("oz_cairo_1"; "cairo_1_account")] #[test_case("oz"; "oz_account")] -#[test_case("argent"; "argent_account")] -#[test_case("braavos"; "braavos_account")] +// TODO(#3089) +// #[test_case("argent"; "argent_account")] +// #[test_case("braavos"; "braavos_account")] #[tokio::test] async fn test_wrong_contract_name(account: &str) { let contract_dir = duplicate_contract_directory_with_salt( @@ -119,7 +120,7 @@ async fn test_with_invalid_max_fee() { let snapbox = runner(&args).current_dir(script_dir.path()); snapbox.assert().success().stdout_matches(indoc! {r" ... - ScriptCommandError::ProviderError(ProviderError::StarknetError(StarknetError::InsufficientMaxFee(()))) + ScriptCommandError::ProviderError(ProviderError::StarknetError(StarknetError::InsufficientResourcesForValidate(()))) command: script run status: success "}); @@ -161,6 +162,7 @@ async fn test_with_invalid_nonce() { } #[tokio::test] +#[ignore = "TODO(#3091) Devnet response does not match te spec"] async fn test_insufficient_account_balance() { let contract_dir = duplicate_contract_directory_with_salt( SCRIPTS_DIR.to_owned() + "/map_script/contracts/", diff --git a/crates/sncast/tests/e2e/script/deploy.rs b/crates/sncast/tests/e2e/script/deploy.rs index 850c940911..cda2d8a85b 100644 --- a/crates/sncast/tests/e2e/script/deploy.rs +++ b/crates/sncast/tests/e2e/script/deploy.rs @@ -8,8 +8,9 @@ use test_case::test_case; #[test_case("oz_cairo_0"; "cairo_0_account")] #[test_case("oz_cairo_1"; "cairo_1_account")] #[test_case("oz"; "oz_account")] -#[test_case("argent"; "argent_account")] -#[test_case("braavos"; "braavos_account")] +// TODO(#3089) +// #[test_case("argent"; "argent_account")] +// #[test_case("braavos"; "braavos_account")] #[tokio::test] async fn test_with_calldata(account: &str) { let tempdir = @@ -101,7 +102,7 @@ async fn test_same_salt_and_class_hash_deployed_twice() { ScriptCommandError::WaitForTransactionError(WaitForTransactionError::TransactionError(TransactionError::Reverted(ErrorData { msg: "Transaction execution has failed: [..] [..]: Error in the contract class constructor ([..]): - Requested ContractAddress(PatriciaKey([..])) is unavailable for deployment. + Deployment failed: contract already deployed at address [..] " }))) command: script run status: success @@ -175,7 +176,9 @@ async fn test_invalid_call_data() { ScriptCommandError::WaitForTransactionError(WaitForTransactionError::TransactionError(TransactionError::Reverted(ErrorData { msg: "Transaction execution has failed: [..] [..]: Error in the contract class constructor ([..]): - Execution failed. Failure reason: [..] ('Failed to deserialize param #2'). + Execution failed. Failure reason: + Error in contract [..]: + 0x4661696c656420746f20646573657269616c697a6520706172616d202332 ('Failed to deserialize param #2'). " }))) command: script run status: success diff --git a/crates/sncast/tests/e2e/script/general.rs b/crates/sncast/tests/e2e/script/general.rs index 2c613248c0..9da5a4f7bd 100644 --- a/crates/sncast/tests/e2e/script/general.rs +++ b/crates/sncast/tests/e2e/script/general.rs @@ -16,8 +16,9 @@ use test_case::test_case; #[test_case("oz_cairo_0"; "cairo_0_account")] #[test_case("oz_cairo_1"; "cairo_1_account")] #[test_case("oz"; "oz_account")] -#[test_case("argent"; "argent_account")] -#[test_case("braavos"; "braavos_account")] +// TODO(#3089) +// #[test_case("argent"; "argent_account")] +// #[test_case("braavos"; "braavos_account")] #[tokio::test] async fn test_happy_case(account: &str) { let contract_dir = duplicate_contract_directory_with_salt( diff --git a/crates/sncast/tests/e2e/script/invoke.rs b/crates/sncast/tests/e2e/script/invoke.rs index ad4f63944a..953fc6fa3f 100644 --- a/crates/sncast/tests/e2e/script/invoke.rs +++ b/crates/sncast/tests/e2e/script/invoke.rs @@ -8,10 +8,11 @@ use test_case::test_case; #[test_case("oz_cairo_0"; "cairo_0_account")] #[test_case("oz_cairo_1"; "cairo_1_account")] #[test_case("oz"; "oz_account")] -#[test_case("argent"; "argent_account")] -#[test_case("braavos"; "braavos_account")] +// TODO(#3089) +// #[test_case("argent"; "argent_account")] +// #[test_case("braavos"; "braavos_account")] #[tokio::test] -async fn test_max_fee_too_low(account: &str) { +async fn test_insufficient_resource_for_validate(account: &str) { let script_dir = copy_script_directory_to_tempdir(SCRIPTS_DIR.to_owned() + "/invoke", Vec::::new()); let accounts_json_path = get_accounts_path(ACCOUNT_FILE_PATH); @@ -35,7 +36,7 @@ async fn test_max_fee_too_low(account: &str) { assert_stdout_contains( output, indoc! {r" - ScriptCommandError::ProviderError(ProviderError::StarknetError(StarknetError::InsufficientMaxFee(()))) + ScriptCommandError::ProviderError(ProviderError::StarknetError(StarknetError::InsufficientResourcesForValidate(()))) command: script run status: success "}, @@ -68,7 +69,7 @@ async fn test_contract_does_not_exist() { output, indoc! {r#" [..] - ScriptCommandError::ProviderError(ProviderError::StarknetError(StarknetError::TransactionExecutionError(TransactionExecutionErrorData { transaction_index: 0, execution_error: "Transaction execution has failed: + ScriptCommandError::WaitForTransactionError(WaitForTransactionError::TransactionError(TransactionError::Reverted(ErrorData { msg: "Transaction execution has failed: [..] [..]: Error in the called contract ([..]): Requested contract address [..] is not deployed. @@ -80,6 +81,7 @@ async fn test_contract_does_not_exist() { } #[test] +#[ignore = "TODO(#3120)"] fn test_wrong_function_name() { let script_dir = copy_script_directory_to_tempdir(SCRIPTS_DIR.to_owned() + "/invoke", Vec::::new()); @@ -120,6 +122,7 @@ fn test_wrong_function_name() { } #[test] +#[ignore = "TODO(#3120)"] fn test_wrong_calldata() { let script_dir = copy_script_directory_to_tempdir(SCRIPTS_DIR.to_owned() + "/invoke", Vec::::new()); diff --git a/docs/listings/declare/src/lib.cairo b/docs/listings/declare/src/lib.cairo index 7534d0771a..fa307755a2 100644 --- a/docs/listings/declare/src/lib.cairo +++ b/docs/listings/declare/src/lib.cairo @@ -1,16 +1,9 @@ -use sncast_std::{declare, FeeSettings}; +use sncast_std::{declare, FeeSettingsTrait}; fn main() { - let max_fee = 9999999; + let fee_settings = FeeSettingsTrait::max_fee(9999999); - let result = declare( - "HelloStarknet", - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, - Option::None - ) - .expect('declare failed'); + let result = declare("HelloStarknet", fee_settings, Option::None).expect('declare failed'); println!("declare result: {}", result); println!("debug declare result: {:?}", result); diff --git a/docs/listings/deploy/src/lib.cairo b/docs/listings/deploy/src/lib.cairo index 9d85b01d7e..3ab684cc97 100644 --- a/docs/listings/deploy/src/lib.cairo +++ b/docs/listings/deploy/src/lib.cairo @@ -1,8 +1,8 @@ use starknet::ClassHash; -use sncast_std::{deploy, FeeSettings}; +use sncast_std::{deploy, FeeSettingsTrait}; fn main() { - let max_fee = 9999999; + let fee_settings = FeeSettingsTrait::max_fee(9999999); let salt = 0x1; let nonce = 0x1; @@ -11,14 +11,7 @@ fn main() { .expect('Invalid class hash value'); let result = deploy( - class_hash, - ArrayTrait::new(), - Option::Some(salt), - true, - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, - Option::Some(nonce) + class_hash, ArrayTrait::new(), Option::Some(salt), true, fee_settings, Option::Some(nonce) ) .expect('deploy failed'); diff --git a/docs/listings/full_example/src/full_example.cairo b/docs/listings/full_example/src/full_example.cairo index 34fce3ae2c..b82ce456d8 100644 --- a/docs/listings/full_example/src/full_example.cairo +++ b/docs/listings/full_example/src/full_example.cairo @@ -1,18 +1,12 @@ -use sncast_std::{declare, deploy, invoke, call, DeclareResultTrait, get_nonce, FeeSettings}; +use sncast_std::{declare, deploy, invoke, call, DeclareResultTrait, get_nonce, FeeSettingsTrait}; fn main() { - let max_fee = 999999999999999; + let fee_settings = FeeSettingsTrait::max_fee(999999999999999); let salt = 0x3; let declare_nonce = get_nonce('latest'); - let declare_result = declare( - "MapContract", - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, - Option::Some(declare_nonce) - ) + let declare_result = declare("MapContract", fee_settings, Option::Some(declare_nonce)) .expect('map declare failed'); let class_hash = declare_result.class_hash(); @@ -23,9 +17,7 @@ fn main() { ArrayTrait::new(), Option::Some(salt), true, - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, + fee_settings, Option::Some(deploy_nonce) ) .expect('map deploy failed'); @@ -38,9 +30,7 @@ fn main() { deploy_result.contract_address, selector!("put"), array![0x1, 0x2], - FeeSettings { - max_fee: Option::Some(max_fee), max_gas: Option::None, max_gas_unit_price: Option::None - }, + fee_settings, Option::Some(invoke_nonce) ) .expect('map invoke failed'); diff --git a/docs/listings/invoke/src/lib.cairo b/docs/listings/invoke/src/lib.cairo index c5f3f7b3f7..c62b450e57 100644 --- a/docs/listings/invoke/src/lib.cairo +++ b/docs/listings/invoke/src/lib.cairo @@ -1,20 +1,15 @@ use starknet::ContractAddress; -use sncast_std::{invoke, FeeSettings}; +use sncast_std::{invoke, FeeSettingsTrait}; fn main() { let contract_address: ContractAddress = 0x1e52f6ebc3e594d2a6dc2a0d7d193cb50144cfdfb7fdd9519135c29b67e427 .try_into() .expect('Invalid contract address value'); + let fee_settings = FeeSettingsTrait::estimate(); let result = invoke( - contract_address, - selector!("put"), - array![0x1, 0x2], - FeeSettings { - max_fee: Option::None, max_gas: Option::None, max_gas_unit_price: Option::None - }, - Option::None + contract_address, selector!("put"), array![0x1, 0x2], fee_settings, Option::None ) .expect('invoke failed'); diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 4dd248406f..5a9383b379 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -144,6 +144,7 @@ * [get_nonce](appendix/sncast-library/get_nonce.md) * [tx_status](appendix/sncast-library/tx_status.md) * [errors](appendix/sncast-library/errors.md) + * [`FeeSettingsTrait`](appendix/sncast-library/fee_settings_trait.md) * [`snfoundry.toml` Reference](appendix/snfoundry-toml.md) * [`Scarb.toml` Reference](appendix/scarb-toml.md) * [Starknet Foundry Github Action](appendix/starknet-foundry-github-action.md) diff --git a/docs/src/appendix/sncast-library/declare.md b/docs/src/appendix/sncast-library/declare.md index 8b2e21facc..598652e83a 100644 --- a/docs/src/appendix/sncast-library/declare.md +++ b/docs/src/appendix/sncast-library/declare.md @@ -5,7 +5,7 @@ Declares a contract and returns `DeclareResult`. - `contract_name` - name of a contract as Cairo string. It is a name of the contract (part after `mod` keyword) e.g. `"HelloStarknet"`. -- `fee_settings` - fee settings for the transaction. +- `fee_settings` - fee settings for the transaction, see [`FeeSettingsTrait](./fee_settings_trait.md). - `nonce` - nonce for declare transaction. If not provided, nonce will be set automatically. ```rust @@ -46,14 +46,4 @@ pub struct DeclareTransactionResult { pub struct AlreadyDeclaredResult { pub class_hash: ClassHash, } -#[derive(Drop, Copy, Debug, Serde, PartialEq)] -pub struct FeeSettings { - pub max_fee: Option, - pub l1_gas: Option, - pub l1_gas_price: Option, - pub l2_gas: Option, - pub l2_gas_price: Option, - pub l1_data_gas: Option, - pub l1_data_gas_price: Option, -} -``` +``` \ No newline at end of file diff --git a/docs/src/appendix/sncast-library/deploy.md b/docs/src/appendix/sncast-library/deploy.md index 1650ec6ed4..e2866d5aee 100644 --- a/docs/src/appendix/sncast-library/deploy.md +++ b/docs/src/appendix/sncast-library/deploy.md @@ -17,24 +17,13 @@ pub struct DeployResult { pub contract_address: ContractAddress, pub transaction_hash: felt252, } - -#[derive(Drop, Copy, Debug, Serde, PartialEq)] -pub struct FeeSettings { - pub max_fee: Option, - pub l1_gas: Option, - pub l1_gas_price: Option, - pub l2_gas: Option, - pub l2_gas_price: Option, - pub l1_data_gas: Option, - pub l1_data_gas_price: Option, -} ``` - `class_hash` - class hash of a contract to deploy. - `constructor_calldata` - calldata for the contract constructor. - `salt` - salt for the contract address. - `unique` - determines if salt should be further modified with the account address. -- `fee_settings` - fee settings for the transaction. +- `fee_settings` - fee settings for the transaction, see [`FeeSettingsTrait](./fee_settings_trait.md). - `nonce` - nonce for declare transaction. If not provided, nonce will be set automatically. ```rust diff --git a/docs/src/appendix/sncast-library/fee_settings_trait.md b/docs/src/appendix/sncast-library/fee_settings_trait.md new file mode 100644 index 0000000000..72e6a4ba4b --- /dev/null +++ b/docs/src/appendix/sncast-library/fee_settings_trait.md @@ -0,0 +1,22 @@ +# `FeeSettingsTrait` + +```rust +#[generate_trait] +pub trait FeeSettingsTrait { + /// Sets transaction resource bounds with specified gas values. + fn resource_bounds( + l1_gas: u64, + l1_gas_price: u128, + l2_gas: u64, + l2_gas_price: u128, + l1_data_gas: u64, + l1_data_gas_price: u128 + ) -> FeeSettings; + + /// Ensures that total resource bounds of transaction execution won't exceed the given value. + fn max_fee(max_fee: felt252) -> FeeSettings; + + /// Performs an automatic estimation of the resource bounds. + fn estimate() -> FeeSettings; +} +``` \ No newline at end of file diff --git a/docs/src/appendix/sncast-library/invoke.md b/docs/src/appendix/sncast-library/invoke.md index bd7f795a0d..fe7028bbb7 100644 --- a/docs/src/appendix/sncast-library/invoke.md +++ b/docs/src/appendix/sncast-library/invoke.md @@ -13,7 +13,7 @@ Invokes a contract and returns `InvokeResult`. - `contract_address` - address of the contract to invoke. - `entry_point_selector` - the selector of the function to invoke. - `calldata` - inputs to the function to be invoked. -- `fee_settings` - fee settings for the transaction. +- `fee_settings` - fee settings for the transaction, see [`FeeSettingsTrait](./fee_settings_trait.md). - `nonce` - nonce for declare transaction. If not provided, nonce will be set automatically. ```rust @@ -27,15 +27,4 @@ Structures used by the command: pub struct InvokeResult { pub transaction_hash: felt252, } - -#[derive(Drop, Copy, Debug, Serde, PartialEq)] -pub struct FeeSettings { - pub max_fee: Option, - pub l1_gas: Option, - pub l1_gas_price: Option, - pub l2_gas: Option, - pub l2_gas_price: Option, - pub l1_data_gas: Option, - pub l1_data_gas_price: Option, -} ``` diff --git a/docs/src/starknet/script.md b/docs/src/starknet/script.md index e8a7178c67..048c3aad09 100644 --- a/docs/src/starknet/script.md +++ b/docs/src/starknet/script.md @@ -23,13 +23,10 @@ contracts from within Cairo, its interface, internals and feature set can change > Example: > > ```rust +> let fee_settings = FeeSettingsTrait::estimate(); > let declare_result = declare( > "Map", -> FeeSettings { -> max_fee: Option::None, -> max_gas: Option::Some(999999), -> max_gas_unit_price: Option::Some(100000000000) -> }, +> fee_settings, > Option::Some(nonce) > ) > .expect('declare failed'); @@ -414,6 +411,35 @@ status: script panicked
+### Fee settings + +Passing fee settings is possible in a few different ways: + +### Using auto estimation: + +```rust +let fee_settings = FeeSettingsTrait::estimate(); +``` + +### Manually setting the resource bounds (denoted in FRI): + +```rust +let fee_settings = FeeSettingsTrait::resource_bounds( + 100000, // l1 gas + 10000000000000, // l1 gas price + 1000000000, // l2 gas + 100000000000000000000, // l2 gas price + 100000, // l1 data gas + 10000000000000, // l1 data gas price +); +``` + +### Specifying the maximum fee (denoted in FRI): + +```rust +let fee_settings = FeeSettingsTrait::max_fee(100000000000000000000); +``` + ## Error handling Each of `declare`, `deploy`, `invoke`, `call` functions return `Result`, where `T` is a corresponding response struct. diff --git a/sncast_std/src/lib.cairo b/sncast_std/src/lib.cairo index 2de0c3bb52..2703d3a4f7 100644 --- a/sncast_std/src/lib.cairo +++ b/sncast_std/src/lib.cairo @@ -11,6 +11,7 @@ pub struct ErrorData { #[derive(Drop, PartialEq, Serde, Debug)] pub struct TransactionExecutionErrorData { pub transaction_index: felt252, + // TODO(#3120): Implement `ContractExecutionError` and update below field type pub execution_error: ByteArray, } @@ -20,6 +21,8 @@ pub enum StarknetError { FailedToReceiveTransaction, /// Contract not found ContractNotFound, + /// Requested entrypoint does not exist in the contract + EntryPointNotFound, /// Block not found BlockNotFound, /// Invalid transaction index in a block @@ -36,8 +39,8 @@ pub enum StarknetError { ClassAlreadyDeclared, /// Invalid transaction nonce InvalidTransactionNonce, - /// Max fee is smaller than the minimal transaction cost (validation plus fee transfer) - InsufficientMaxFee, + /// The transaction's resources don't cover validation or the minimal transaction fee + InsufficientResourcesForValidate, /// Account balance is smaller than the transaction's max_fee InsufficientAccountBalance, /// Account validation failed @@ -223,12 +226,61 @@ impl DisplayDeployResult of Display { } } -// TODO(#3102): Refactor to be enum with max fee and triplet variants #[derive(Drop, Copy, Debug, Serde, PartialEq)] pub struct FeeSettings { - pub max_fee: Option, - pub max_gas: Option, - pub max_gas_unit_price: Option, + max_fee: Option, + l1_gas: Option, + l1_gas_price: Option, + l2_gas: Option, + l2_gas_price: Option, + l1_data_gas: Option, + l1_data_gas_price: Option, +} + +#[generate_trait] +pub impl FeeSettingsImpl of FeeSettingsTrait { + fn resource_bounds( + l1_gas: u64, + l1_gas_price: u128, + l2_gas: u64, + l2_gas_price: u128, + l1_data_gas: u64, + l1_data_gas_price: u128 + ) -> FeeSettings { + FeeSettings { + max_fee: Option::None, + l1_gas: Option::Some(l1_gas), + l1_gas_price: Option::Some(l1_gas_price), + l2_gas: Option::Some(l2_gas), + l2_gas_price: Option::Some(l2_gas_price), + l1_data_gas: Option::Some(l1_data_gas), + l1_data_gas_price: Option::Some(l1_data_gas_price), + } + } + + fn max_fee(max_fee: felt252) -> FeeSettings { + FeeSettings { + max_fee: Option::Some(max_fee), + l1_gas: Option::None, + l1_gas_price: Option::None, + l2_gas: Option::None, + l2_gas_price: Option::None, + l1_data_gas: Option::None, + l1_data_gas_price: Option::None, + } + } + + fn estimate() -> FeeSettings { + FeeSettings { + max_fee: Option::None, + l1_gas: Option::None, + l1_gas_price: Option::None, + l2_gas: Option::None, + l2_gas_price: Option::None, + l1_data_gas: Option::None, + l1_data_gas_price: Option::None, + } + } } pub fn deploy(