Skip to content

Commit 6dd461b

Browse files
authored
Merge pull request #271 from neotheprogramist/add/new-executable-acc
Executable account fix
2 parents 0741ae5 + 3f4bdca commit 6dd461b

File tree

14 files changed

+376
-129
lines changed

14 files changed

+376
-129
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ clap = { version = "4.5.16", features = ["derive", "env"] }
3030
clap_derive = "4.5.13"
3131
colored = "2.1.0"
3232
crypto-bigint = "0.5.5"
33-
crypto-utils = { path = "./crypto-utils" }
33+
crypto-utils = { git = "https://github.com/neotheprogramist/starknet-rpc-tests.git", rev = "824a4c294d5040f73fd576d0ed17ba85439fc593" }
3434
indexmap = "2.2.5"
3535
lambdaworks-math = { version = "0.7.0", default-features = false }
3636
num-bigint = { version = "0.4", features = ["serde"], default-features = false }

contracts/src/exec_acc.cairo

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// SPDX-License-Identifier: MIT
2+
// Compatible with OpenZeppelin Contracts for Cairo ^0.20.0
3+
4+
#[starknet::contract(account)]
5+
mod MyAccountExec {
6+
use openzeppelin::account::AccountComponent;
7+
use openzeppelin::account::extensions::SRC9Component;
8+
use openzeppelin::introspection::src5::SRC5Component;
9+
10+
component!(path: AccountComponent, storage: account, event: AccountEvent);
11+
component!(path: SRC5Component, storage: src5, event: SRC5Event);
12+
component!(path: SRC9Component, storage: src9, event: SRC9Event);
13+
14+
// External
15+
#[abi(embed_v0)]
16+
impl SRC6Impl = AccountComponent::SRC6Impl<ContractState>;
17+
#[abi(embed_v0)]
18+
impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl<ContractState>;
19+
#[abi(embed_v0)]
20+
impl DeclarerImpl = AccountComponent::DeclarerImpl<ContractState>;
21+
#[abi(embed_v0)]
22+
impl DeployableImpl = AccountComponent::DeployableImpl<ContractState>;
23+
#[abi(embed_v0)]
24+
impl SRC5Impl = SRC5Component::SRC5Impl<ContractState>;
25+
#[abi(embed_v0)]
26+
impl OutsideExecutionV2Impl = SRC9Component::OutsideExecutionV2Impl<ContractState>;
27+
28+
// Internal
29+
impl AccountInternalImpl = AccountComponent::InternalImpl<ContractState>;
30+
impl OutsideExecutionInternalImpl = SRC9Component::InternalImpl<ContractState>;
31+
32+
#[storage]
33+
struct Storage {
34+
#[substorage(v0)]
35+
account: AccountComponent::Storage,
36+
#[substorage(v0)]
37+
src5: SRC5Component::Storage,
38+
#[substorage(v0)]
39+
src9: SRC9Component::Storage,
40+
}
41+
42+
#[event]
43+
#[derive(Drop, starknet::Event)]
44+
enum Event {
45+
#[flat]
46+
AccountEvent: AccountComponent::Event,
47+
#[flat]
48+
SRC5Event: SRC5Component::Event,
49+
#[flat]
50+
SRC9Event: SRC9Component::Event,
51+
}
52+
53+
#[constructor]
54+
fn constructor(ref self: ContractState, public_key: felt252) {
55+
self.account.initializer(public_key);
56+
self.src9.initializer();
57+
}
58+
}

contracts/src/lib.cairo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ mod smpl16;
2626
mod smpl17;
2727
mod smpl18;
2828
mod smpl19;
29+
mod exec_acc;
2930

3031
/// Paymaster implementation.
3132
mod paymaster {

openrpc-testgen/src/suite_openrpc/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub struct TestSuiteOpenRpc {
9090
pub random_paymaster_account: RandomSingleOwnerAccount,
9191
pub paymaster_private_key: Felt,
9292
pub random_executable_account: RandomSingleOwnerAccount,
93+
pub executable_private_key: Felt,
9394
pub account_class_hash: Felt,
9495
pub udc_address: Felt,
9596
}
@@ -109,9 +110,9 @@ impl SetupableTrait for TestSuiteOpenRpc {
109110
async fn setup(setup_input: &Self::Input) -> Result<Self, OpenRpcTestGenError> {
110111
let (executable_account_flattened_sierra_class, executable_account_compiled_class_hash) =
111112
get_compiled_contract(
112-
PathBuf::from_str("target/dev/contracts_ExecutableAccount.contract_class.json")?,
113+
PathBuf::from_str("target/dev/contracts_MyAccountExec.contract_class.json")?,
113114
PathBuf::from_str(
114-
"target/dev/contracts_ExecutableAccount.compiled_contract_class.json",
115+
"target/dev/contracts_MyAccountExec.compiled_contract_class.json",
115116
)?,
116117
)
117118
.await?;
@@ -255,6 +256,7 @@ impl SetupableTrait for TestSuiteOpenRpc {
255256
accounts: paymaster_accounts,
256257
},
257258
paymaster_private_key: setup_input.paymaster_private_key,
259+
executable_private_key: executable_account_data.signing_key.secret_scalar(),
258260
account_class_hash: setup_input.account_class_hash,
259261
udc_address: setup_input.udc_address,
260262
})

openrpc-testgen/src/suite_openrpc/suite_deploy/suite_contract_calls/test_estimate_message_fee.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ impl RunnableTrait for TestCase {
3737
assert_result!(result);
3838

3939
let estimate = estimate?;
40-
println!("estimate: {estimate:#?}");
4140

4241
let expected_price_unit = PriceUnit::Wei;
4342
assert_result!(

openrpc-testgen/src/suite_openrpc/test_deploy_account_outside_execution.rs

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
use crate::{
22
assert_matches_result,
3-
utils::v7::{
4-
accounts::{
5-
account::{Account, ConnectedAccount},
6-
call::Call,
7-
creation::create::{create_account, AccountType},
3+
utils::{
4+
outside_execution::{get_current_timestamp, prepare_outside_execution, OutsideExecution},
5+
v7::{
6+
accounts::{
7+
account::{Account, ConnectedAccount},
8+
call::Call,
9+
creation::create::{create_account, AccountType},
10+
},
11+
endpoints::{
12+
errors::OpenRpcTestGenError,
13+
utils::{get_selector_from_name, wait_for_sent_transaction},
14+
},
15+
providers::provider::Provider,
816
},
9-
endpoints::{
10-
endpoints_functions::OutsideExecution,
11-
errors::OpenRpcTestGenError,
12-
utils::{get_selector_from_name, wait_for_sent_transaction},
13-
},
14-
providers::provider::Provider,
1517
},
1618
RandomizableAccountsTrait, RunnableTrait,
1719
};
18-
use cainome_cairo_serde::CairoSerde;
19-
use starknet::core::crypto::ecdsa_sign;
20-
use starknet_types_core::{
21-
felt::Felt,
22-
hash::{Poseidon, StarkHash},
23-
};
20+
21+
use starknet_types_core::felt::Felt;
22+
2423
use starknet_types_rpc::{BlockId, BlockTag, InvokeTxn, MaybePendingBlockWithTxs, Txn};
2524

2625
#[derive(Clone, Debug)]
@@ -38,6 +37,15 @@ impl RunnableTrait for TestCase {
3837
)
3938
.await?;
4039

40+
let nonce = test_input
41+
.random_paymaster_account
42+
.provider()
43+
.get_nonce(
44+
BlockId::Tag(BlockTag::Latest),
45+
test_input.random_paymaster_account.address(),
46+
)
47+
.await?;
48+
4149
let udc_call = Call {
4250
to: Felt::from_hex_unchecked(
4351
"0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
@@ -52,31 +60,37 @@ impl RunnableTrait for TestCase {
5260
],
5361
};
5462

63+
let timestamp =
64+
get_current_timestamp(&test_input.random_paymaster_account.provider()).await?;
65+
5566
let outside_execution = OutsideExecution {
5667
caller: test_input.random_paymaster_account.address(),
57-
nonce: Felt::ZERO,
68+
execute_before: timestamp + 500,
69+
execute_after: timestamp - 500,
70+
nonce: nonce + Felt::ONE,
5871
calls: vec![udc_call],
5972
};
6073

61-
let outside_execution_cairo_serialized =
62-
&OutsideExecution::cairo_serialize(&outside_execution);
63-
64-
let hash = Poseidon::hash_array(outside_execution_cairo_serialized);
65-
66-
let starknet::core::crypto::ExtendedSignature { r, s, v: _ } =
67-
ecdsa_sign(&test_input.paymaster_private_key, &hash).unwrap();
68-
69-
let mut calldata_to_executable_account_call = outside_execution_cairo_serialized.clone();
70-
calldata_to_executable_account_call.push(Felt::from_dec_str("2")?);
71-
calldata_to_executable_account_call.push(r);
72-
calldata_to_executable_account_call.push(s);
73-
74+
let calldata_to_executable_account_call = prepare_outside_execution(
75+
&outside_execution,
76+
test_input
77+
.random_executable_account
78+
.random_accounts()?
79+
.address(),
80+
test_input.executable_private_key,
81+
test_input
82+
.random_paymaster_account
83+
.provider()
84+
.chain_id()
85+
.await?,
86+
)
87+
.await?;
7488
let call_to_executable_account = Call {
7589
to: test_input
7690
.random_executable_account
7791
.random_accounts()?
7892
.address(),
79-
selector: get_selector_from_name("execute_from_outside")?,
93+
selector: get_selector_from_name("execute_from_outside_v2")?,
8094
calldata: calldata_to_executable_account_call,
8195
};
8296

openrpc-testgen/src/suite_openrpc/test_erc20_transfer_outside_execution.rs

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{
33
utils::{
44
conversions::felts_to_biguint::felts_slice_to_biguint,
55
get_balance::get_balance,
6+
outside_execution::{get_current_timestamp, prepare_outside_execution, OutsideExecution},
67
v7::{
78
accounts::{
89
account::{Account, AccountError, ConnectedAccount},
@@ -14,7 +15,6 @@ use crate::{
1415
extract_class_hash_from_error, get_compiled_contract,
1516
parse_class_hash_from_error, RunnerError,
1617
},
17-
endpoints_functions::OutsideExecution,
1818
errors::{CallError, OpenRpcTestGenError},
1919
utils::{get_selector_from_name, wait_for_sent_transaction},
2020
},
@@ -23,13 +23,9 @@ use crate::{
2323
},
2424
RandomizableAccountsTrait, RunnableTrait,
2525
};
26-
use cainome_cairo_serde::CairoSerde;
2726
use rand::{rngs::StdRng, RngCore, SeedableRng};
28-
use starknet::core::crypto::ecdsa_sign;
29-
use starknet_types_core::{
30-
felt::Felt,
31-
hash::{Poseidon, StarkHash},
32-
};
27+
use starknet_types_core::felt::Felt;
28+
3329
use starknet_types_rpc::{BlockId, BlockTag, TxnReceipt};
3430
use std::path::PathBuf;
3531
use std::str::FromStr;
@@ -188,34 +184,47 @@ impl RunnableTrait for TestCase {
188184
],
189185
};
190186

191-
let outside_execution = OutsideExecution {
192-
caller: test_input
193-
.random_paymaster_account
194-
.random_accounts()?
195-
.address(),
196-
nonce: Felt::ONE,
197-
calls: vec![erc20_transfer_call],
198-
};
199-
200-
let outside_execution_cairo_serialized =
201-
&OutsideExecution::cairo_serialize(&outside_execution);
187+
let timestamp =
188+
get_current_timestamp(test_input.random_paymaster_account.provider()).await?;
202189

203-
let hash = Poseidon::hash_array(outside_execution_cairo_serialized);
190+
let nonce = test_input
191+
.random_paymaster_account
192+
.provider()
193+
.get_nonce(
194+
BlockId::Tag(BlockTag::Latest),
195+
test_input.random_paymaster_account.address(),
196+
)
197+
.await?;
204198

205-
let starknet::core::crypto::ExtendedSignature { r, s, v: _ } =
206-
ecdsa_sign(&test_input.paymaster_private_key, &hash).unwrap();
199+
let outside_execution = OutsideExecution {
200+
caller: test_input.random_paymaster_account.address(),
201+
execute_before: timestamp + 500,
202+
execute_after: timestamp - 500,
203+
nonce: nonce + Felt::ONE,
204+
calls: vec![erc20_transfer_call.clone()],
205+
};
207206

208-
let mut calldata_to_executable_account_call = outside_execution_cairo_serialized.clone();
209-
calldata_to_executable_account_call.push(Felt::from_dec_str("2")?);
210-
calldata_to_executable_account_call.push(r);
211-
calldata_to_executable_account_call.push(s);
207+
let calldata_to_executable_account_call = prepare_outside_execution(
208+
&outside_execution,
209+
test_input
210+
.random_executable_account
211+
.random_accounts()?
212+
.address(),
213+
test_input.executable_private_key,
214+
test_input
215+
.random_paymaster_account
216+
.provider()
217+
.chain_id()
218+
.await?,
219+
)
220+
.await?;
212221

213222
let call_to_executable_account = Call {
214223
to: test_input
215224
.random_executable_account
216225
.random_accounts()?
217226
.address(),
218-
selector: get_selector_from_name("execute_from_outside")?,
227+
selector: get_selector_from_name("execute_from_outside_v2")?,
219228
calldata: calldata_to_executable_account_call,
220229
};
221230

openrpc-testgen/src/utils/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod conversions;
22
pub mod get_balance;
33
pub mod get_deployed_contract_address;
4+
pub mod outside_execution;
45
pub mod random_single_owner_account;
56
pub mod starknet_hive;
67
pub mod v7;

0 commit comments

Comments
 (0)