-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathlib.rs
More file actions
1195 lines (1154 loc) · 40.2 KB
/
lib.rs
File metadata and controls
1195 lines (1154 loc) · 40.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#![allow(clippy::unwrap_used)]
#[cfg(test)]
mod precision_test;
use std::cmp::max;
use std::collections::{BTreeMap, HashMap};
use std::env;
use std::hash::Hash;
use std::net::SocketAddr;
use std::num::{NonZeroU32, NonZeroU64};
use std::ops::{Deref, Index};
use std::sync::Arc;
use cairo_lang_casm::hints::{CoreHint, CoreHintBase, Hint};
use cairo_lang_casm::operand::{
BinOpOperand,
CellRef,
DerefOrImmediate,
Operation,
Register,
ResOperand,
};
use cairo_lang_starknet_classes::casm_contract_class::{
CasmContractClass,
CasmContractEntryPoint,
CasmContractEntryPoints,
};
use cairo_lang_starknet_classes::NestedIntList;
use cairo_lang_utils::bigint::BigUintAsHex;
use indexmap::IndexMap;
use num_bigint::BigUint;
use primitive_types::H160;
use prometheus_parse::Value;
use rand::{Rng, RngCore, SeedableRng};
use rand_chacha::ChaCha8Rng;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use starknet_api::block::{
Block,
BlockBody,
BlockHash,
BlockHeader,
BlockHeaderWithoutHash,
BlockNumber,
BlockSignature,
BlockStatus,
BlockTimestamp,
GasPrice,
GasPricePerToken,
StarknetVersion,
};
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{
ClassHash,
CompiledClassHash,
ContractAddress,
EntryPointSelector,
EthAddress,
EventCommitment,
GlobalRoot,
Nonce,
ReceiptCommitment,
SequencerContractAddress,
StateDiffCommitment,
TransactionCommitment,
};
use starknet_api::crypto::utils::Signature;
use starknet_api::data_availability::{DataAvailabilityMode, L1DataAvailabilityMode};
use starknet_api::deprecated_contract_class::{
ConstructorType,
ContractClass as DeprecatedContractClass,
ContractClassAbiEntry,
EntryPointOffset,
EntryPointV0 as DeprecatedEntryPoint,
EventAbiEntry,
EventType,
FunctionAbiEntry,
FunctionStateMutability,
FunctionType,
L1HandlerType,
Program,
StructAbiEntry,
StructMember,
StructType,
TypedParameter,
};
use starknet_api::execution_resources::{Builtin, ExecutionResources, GasAmount, GasVector};
use starknet_api::hash::{PoseidonHash, StarkHash};
use starknet_api::rpc_transaction::{
DeployAccountTransactionV3WithAddress,
EntryPointByType as RpcEntryPointByType,
EntryPointByType,
InternalRpcDeclareTransactionV3,
InternalRpcTransaction,
InternalRpcTransactionWithoutTxHash,
RpcDeclareTransaction,
RpcDeclareTransactionV3,
RpcDeployAccountTransaction,
RpcDeployAccountTransactionV3,
RpcInvokeTransaction,
RpcInvokeTransactionV3,
RpcTransaction,
};
use starknet_api::state::{
EntryPoint,
FunctionIndex,
SierraContractClass,
StateDiff,
StorageKey,
ThinStateDiff,
};
use starknet_api::test_utils::read_json_file;
use starknet_api::transaction::fields::{
AccountDeploymentData,
AllResourceBounds,
Calldata,
ContractAddressSalt,
Fee,
PaymasterData,
Resource,
ResourceBounds,
Tip,
TransactionSignature,
ValidResourceBounds,
};
use starknet_api::transaction::{
DeclareTransaction,
DeclareTransactionOutput,
DeclareTransactionV0V1,
DeclareTransactionV2,
DeclareTransactionV3,
DeployAccountTransaction,
DeployAccountTransactionOutput,
DeployAccountTransactionV1,
DeployAccountTransactionV3,
DeployTransaction,
DeployTransactionOutput,
Event,
EventContent,
EventData,
EventIndexInTransactionOutput,
EventKey,
InvokeTransaction,
InvokeTransactionOutput,
InvokeTransactionV0,
InvokeTransactionV1,
InvokeTransactionV3,
L1HandlerTransaction,
L1HandlerTransactionOutput,
L1ToL2Payload,
L2ToL1Payload,
MessageToL1,
MessageToL2,
RevertedTransactionExecutionStatus,
Transaction,
TransactionExecutionStatus,
TransactionHash,
TransactionOffsetInBlock,
TransactionOutput,
TransactionVersion,
};
use starknet_api::{class_hash, tx_hash};
use starknet_types_core::felt::Felt;
//////////////////////////////////////////////////////////////////////////
// GENERIC TEST UTIL FUNCTIONS
//////////////////////////////////////////////////////////////////////////
pub async fn send_request(
address: SocketAddr,
method: &str,
params: &str,
version: &str,
) -> serde_json::Value {
let client = Client::new();
let res_str = client
.post(format!("http://{address:?}/rpc/{version}"))
.header("Content-Type", "application/json")
.body(format!(r#"{{"jsonrpc":"2.0","id":"1","method":"{method}","params":[{params}]}}"#))
.send()
.await
.unwrap()
.text()
.await
.unwrap();
serde_json::from_str(&res_str).unwrap()
}
pub fn validate_load_and_dump<T: Serialize + for<'a> Deserialize<'a>>(path_in_resource_dir: &str) {
let json_value = read_json_file(path_in_resource_dir);
let load_result = serde_json::from_value::<T>(json_value.clone());
assert!(load_result.is_ok(), "error: {:?}", load_result.err());
let dump_result = serde_json::to_value(load_result.unwrap());
assert!(dump_result.is_ok(), "error: {:?}", dump_result.err());
assert_eq!(json_value, dump_result.unwrap());
}
/// Used in random test to create a random generator, see for example storage_serde_test.
/// Randomness can be seeded by setting and env variable `SEED` or by the OS (the rust default).
pub fn get_rng() -> ChaCha8Rng {
let seed: u64 = match env::var("SEED") {
Ok(seed_str) => seed_str.parse().unwrap(),
_ => rand::thread_rng().gen(),
};
// Will be printed if the test failed.
println!("Testing with seed: {seed:?}");
// Create a new PRNG using a u64 seed. This is a convenience-wrapper around from_seed.
// It is designed such that low Hamming Weight numbers like 0 and 1 can be used and
// should still result in good, independent seeds to the returned PRNG.
// This is not suitable for cryptography purposes.
ChaCha8Rng::seed_from_u64(seed)
}
/// Use to get the value of a metric by name and labels.
// If the data contains a metric with metric_name and labels returns its value else None.
pub fn prometheus_is_contained(
data: String,
metric_name: &str,
labels: &[(&str, &str)],
) -> Option<Value> {
// Converts labels to HashMap<String, String>.
let labels: HashMap<String, String> =
labels.iter().map(|(k, v)| (k.to_string(), v.to_string())).collect();
let lines: Vec<_> = data.lines().map(|s| Ok(s.to_owned())).collect();
let metrics = prometheus_parse::Scrape::parse(lines.into_iter()).unwrap();
for s in metrics.samples {
if s.metric == metric_name && s.labels.deref() == &labels {
return Some(s.value);
}
}
None
}
//////////////////////////////////////////////////////////////////////////
// INTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////
/// Returns a test block with a variable number of transactions and events.
fn get_rand_test_block_with_events(
rng: &mut ChaCha8Rng,
transaction_count: usize,
events_per_tx: usize,
from_addresses: Option<Vec<ContractAddress>>,
keys: Option<Vec<Vec<EventKey>>>,
) -> Block {
Block {
header: BlockHeader::default(),
body: get_rand_test_body_with_events(
rng,
transaction_count,
events_per_tx,
from_addresses,
keys,
),
}
}
// TODO(Dan, 01/11/2023): Remove this util once v3 tests are ready and transaction generation is
// using randomness more stably.
fn is_v3_transaction(transaction: &Transaction) -> bool {
matches!(
transaction,
Transaction::Declare(DeclareTransaction::V3(_))
| Transaction::DeployAccount(DeployAccountTransaction::V3(_))
| Transaction::Invoke(InvokeTransaction::V3(_))
)
}
/// Returns a test block body with a variable number of transactions and events.
fn get_rand_test_body_with_events(
rng: &mut ChaCha8Rng,
transaction_count: usize,
events_per_tx: usize,
from_addresses: Option<Vec<ContractAddress>>,
keys: Option<Vec<Vec<EventKey>>>,
) -> BlockBody {
let mut transactions = vec![];
let mut transaction_outputs = vec![];
let mut transaction_hashes = vec![];
let mut transaction_execution_statuses = vec![];
for i in 0..transaction_count {
let mut transaction = Transaction::get_test_instance(rng);
while is_v3_transaction(&transaction) {
transaction = Transaction::get_test_instance(rng);
}
transaction_hashes.push(tx_hash!(i));
let transaction_output = get_test_transaction_output(&transaction);
transactions.push(transaction);
transaction_outputs.push(transaction_output);
transaction_execution_statuses.push(TransactionExecutionStatus::default());
}
let mut body = BlockBody { transactions, transaction_outputs, transaction_hashes };
for tx_output in &mut body.transaction_outputs {
let mut events = vec![];
for _ in 0..events_per_tx {
let from_address = if let Some(ref options) = from_addresses {
*options.index(rng.gen_range(0..options.len()))
} else {
ContractAddress::default()
};
let final_keys = if let Some(ref options) = keys {
let mut chosen_keys = vec![];
for options_per_i in options {
let key = options_per_i.index(rng.gen_range(0..options_per_i.len())).clone();
chosen_keys.push(key);
}
chosen_keys
} else {
vec![EventKey::default()]
};
events.push(Event {
from_address,
content: EventContent { keys: final_keys, data: EventData::default() },
});
}
set_events(tx_output, events);
}
body
}
fn get_test_transaction_output(transaction: &Transaction) -> TransactionOutput {
let mut rng = get_rng();
let execution_resources = ExecutionResources::get_test_instance(&mut rng);
let execution_status = TransactionExecutionStatus::get_test_instance(&mut rng);
match transaction {
Transaction::Declare(_) => TransactionOutput::Declare(DeclareTransactionOutput {
execution_resources,
execution_status,
..Default::default()
}),
Transaction::Deploy(_) => TransactionOutput::Deploy(DeployTransactionOutput {
execution_resources,
execution_status,
..Default::default()
}),
Transaction::DeployAccount(_) => {
TransactionOutput::DeployAccount(DeployAccountTransactionOutput {
execution_resources,
execution_status,
..Default::default()
})
}
Transaction::Invoke(_) => TransactionOutput::Invoke(InvokeTransactionOutput {
execution_resources,
execution_status,
..Default::default()
}),
Transaction::L1Handler(_) => TransactionOutput::L1Handler(L1HandlerTransactionOutput {
execution_resources,
execution_status,
..Default::default()
}),
}
}
fn set_events(tx: &mut TransactionOutput, events: Vec<Event>) {
match tx {
TransactionOutput::Declare(tx) => tx.events = events,
TransactionOutput::Deploy(tx) => tx.events = events,
TransactionOutput::DeployAccount(tx) => tx.events = events,
TransactionOutput::Invoke(tx) => tx.events = events,
TransactionOutput::L1Handler(tx) => tx.events = events,
}
}
//////////////////////////////////////////////////////////////////////////
// EXTERNAL FUNCTIONS - REMOVE DUPLICATIONS
//////////////////////////////////////////////////////////////////////////
// Returns a test block with a variable number of transactions and events.
pub fn get_test_block(
transaction_count: usize,
// TODO(shahak): remove unused event-related arguments.
events_per_tx: Option<usize>,
from_addresses: Option<Vec<ContractAddress>>,
keys: Option<Vec<Vec<EventKey>>>,
) -> Block {
let mut rng = get_rng();
let events_per_tx = events_per_tx.unwrap_or_default();
get_rand_test_block_with_events(
&mut rng,
transaction_count,
events_per_tx,
from_addresses,
keys,
)
}
// Returns a test block body with a variable number of transactions.
pub fn get_test_body(
transaction_count: usize,
events_per_tx: Option<usize>,
from_addresses: Option<Vec<ContractAddress>>,
keys: Option<Vec<Vec<EventKey>>>,
) -> BlockBody {
let mut rng = get_rng();
let events_per_tx = events_per_tx.unwrap_or_default();
get_rand_test_body_with_events(&mut rng, transaction_count, events_per_tx, from_addresses, keys)
}
// Returns a state diff with one item in each IndexMap.
// For a random test state diff call StateDiff::get_test_instance.
pub fn get_test_state_diff() -> StateDiff {
let mut rng = get_rng();
let mut res = StateDiff::get_test_instance(&mut rng);
// TODO(anatg): fix StateDiff::get_test_instance so the declared_classes will have different
// hashes than the deprecated_contract_classes.
let (_, data) = res.declared_classes.pop().unwrap();
res.declared_classes.insert(class_hash!("0x001"), data);
// TODO(yair): Find a way to create replaced classes in a test instance of StateDiff.
res.replaced_classes.clear();
res
}
////////////////////////////////////////////////////////////////////////
// Implementation of GetTestInstance
////////////////////////////////////////////////////////////////////////
pub trait GetTestInstance: Sized {
fn get_test_instance(rng: &mut ChaCha8Rng) -> Self;
}
auto_impl_get_test_instance! {
pub struct AccountDeploymentData(pub Vec<Felt>);
pub struct AllResourceBounds {
pub l1_gas: ResourceBounds,
pub l2_gas: ResourceBounds,
pub l1_data_gas: ResourceBounds,
}
pub struct BlockHash(pub StarkHash);
pub struct BlockHeader {
pub block_hash: BlockHash,
pub block_header_without_hash: BlockHeaderWithoutHash,
pub state_diff_commitment: Option<StateDiffCommitment>,
pub transaction_commitment: Option<TransactionCommitment>,
pub event_commitment: Option<EventCommitment>,
pub receipt_commitment: Option<ReceiptCommitment>,
pub state_diff_length: Option<usize>,
pub n_transactions: usize,
pub n_events: usize,
}
pub struct BlockHeaderWithoutHash {
pub parent_hash: BlockHash,
pub block_number: BlockNumber,
pub l1_gas_price: GasPricePerToken,
pub l1_data_gas_price: GasPricePerToken,
pub l2_gas_price: GasPricePerToken,
pub state_root: GlobalRoot,
pub sequencer: SequencerContractAddress,
pub timestamp: BlockTimestamp,
pub l1_da_mode: L1DataAvailabilityMode,
pub starknet_version: StarknetVersion,
}
pub struct BlockNumber(pub u64);
pub struct BlockSignature(pub Signature);
pub enum BlockStatus {
Pending = 0,
AcceptedOnL2 = 1,
AcceptedOnL1 = 2,
Rejected = 3,
}
pub struct BlockTimestamp(pub u64);
pub enum Builtin {
RangeCheck = 0,
Pedersen = 1,
Poseidon = 2,
EcOp = 3,
Ecdsa = 4,
Bitwise = 5,
Keccak = 6,
SegmentArena = 7,
AddMod = 8,
MulMod = 9,
RangeCheck96 = 10,
}
pub enum StarknetVersion {
V0_9_1 = 0,
V0_10_0 = 1,
V0_10_1 = 2,
V0_10_2 = 3,
V0_10_3 = 4,
V0_11_0 = 5,
V0_11_0_2 = 6,
V0_11_1 = 7,
V0_11_2 = 8,
V0_12_0 = 9,
V0_12_1 = 10,
V0_12_2 = 11,
V0_12_3 = 12,
V0_13_0 = 13,
V0_13_1 = 14,
V0_13_1_1 = 15,
V0_13_2 = 16,
V0_13_2_1 = 17,
V0_13_3 = 18,
V0_13_4 = 19,
}
pub struct Calldata(pub Arc<Vec<Felt>>);
pub struct ClassHash(pub StarkHash);
pub struct CompiledClassHash(pub StarkHash);
pub struct ContractAddressSalt(pub StarkHash);
pub struct SierraContractClass {
pub sierra_program: Vec<Felt>,
pub contract_class_version: String,
pub entry_points_by_type: EntryPointByType,
pub abi: String,
}
pub struct DeprecatedContractClass {
pub abi: Option<Vec<ContractClassAbiEntry>>,
pub program: Program,
pub entry_points_by_type: HashMap<EntryPointType, Vec<DeprecatedEntryPoint>>,
}
pub enum ContractClassAbiEntry {
Event(EventAbiEntry) = 0,
Function(FunctionAbiEntry<FunctionType>) = 1,
Constructor(FunctionAbiEntry<ConstructorType>) = 2,
L1Handler(FunctionAbiEntry<L1HandlerType>) = 3,
Struct(StructAbiEntry) = 4,
}
pub enum DataAvailabilityMode {
L1 = 0,
L2 = 1,
}
pub enum DeclareTransaction {
V0(DeclareTransactionV0V1) = 0,
V1(DeclareTransactionV0V1) = 1,
V2(DeclareTransactionV2) = 2,
V3(DeclareTransactionV3) = 3,
}
pub struct DeclareTransactionOutput {
pub actual_fee: Fee,
pub messages_sent: Vec<MessageToL1>,
pub events: Vec<Event>,
pub execution_status: TransactionExecutionStatus,
pub execution_resources: ExecutionResources,
}
pub struct DeclareTransactionV0V1 {
pub max_fee: Fee,
pub signature: TransactionSignature,
pub nonce: Nonce,
pub class_hash: ClassHash,
pub sender_address: ContractAddress,
}
pub struct DeclareTransactionV2 {
pub max_fee: Fee,
pub signature: TransactionSignature,
pub nonce: Nonce,
pub class_hash: ClassHash,
pub compiled_class_hash: CompiledClassHash,
pub sender_address: ContractAddress,
}
pub struct DeclareTransactionV3 {
pub resource_bounds: ValidResourceBounds,
pub tip: Tip,
pub signature: TransactionSignature,
pub nonce: Nonce,
pub class_hash: ClassHash,
pub compiled_class_hash: CompiledClassHash,
pub sender_address: ContractAddress,
pub nonce_data_availability_mode: DataAvailabilityMode,
pub fee_data_availability_mode: DataAvailabilityMode,
pub paymaster_data: PaymasterData,
pub account_deployment_data: AccountDeploymentData,
}
pub enum DeployAccountTransaction {
V1(DeployAccountTransactionV1) = 0,
V3(DeployAccountTransactionV3) = 1,
}
pub struct DeployAccountTransactionOutput {
pub actual_fee: Fee,
pub messages_sent: Vec<MessageToL1>,
pub events: Vec<Event>,
pub contract_address: ContractAddress,
pub execution_status: TransactionExecutionStatus,
pub execution_resources: ExecutionResources,
}
pub struct DeployAccountTransactionV1 {
pub max_fee: Fee,
pub signature: TransactionSignature,
pub nonce: Nonce,
pub class_hash: ClassHash,
pub contract_address_salt: ContractAddressSalt,
pub constructor_calldata: Calldata,
}
pub struct DeployAccountTransactionV3 {
pub resource_bounds: ValidResourceBounds,
pub tip: Tip,
pub signature: TransactionSignature,
pub nonce: Nonce,
pub class_hash: ClassHash,
pub contract_address_salt: ContractAddressSalt,
pub constructor_calldata: Calldata,
pub nonce_data_availability_mode: DataAvailabilityMode,
pub fee_data_availability_mode: DataAvailabilityMode,
pub paymaster_data: PaymasterData,
}
pub struct DeployTransaction {
pub version: TransactionVersion,
pub class_hash: ClassHash,
pub contract_address_salt: ContractAddressSalt,
pub constructor_calldata: Calldata,
}
pub struct DeployTransactionOutput {
pub actual_fee: Fee,
pub messages_sent: Vec<MessageToL1>,
pub events: Vec<Event>,
pub contract_address: ContractAddress,
pub execution_status: TransactionExecutionStatus,
pub execution_resources: ExecutionResources,
}
pub struct DeprecatedEntryPoint {
pub selector: EntryPointSelector,
pub offset: EntryPointOffset,
}
pub struct EntryPoint {
pub function_idx: FunctionIndex,
pub selector: EntryPointSelector,
}
pub struct Event {
pub from_address: ContractAddress,
pub content: EventContent,
}
pub struct EventCommitment(pub StarkHash);
pub struct FunctionIndex(pub usize);
pub struct EntryPointOffset(pub usize);
pub struct EntryPointSelector(pub StarkHash);
pub enum EntryPointType {
Constructor = 0,
External = 1,
L1Handler = 2,
}
pub struct EventAbiEntry {
pub name: String,
pub keys: Vec<TypedParameter>,
pub data: Vec<TypedParameter>,
pub r#type: EventType,
}
pub struct EventContent {
pub keys: Vec<EventKey>,
pub data: EventData,
}
pub struct EventData(pub Vec<Felt>);
pub struct EventIndexInTransactionOutput(pub usize);
pub struct EventKey(pub Felt);
pub enum EventType {
Event = 0,
}
pub struct Fee(pub u128);
pub enum FunctionStateMutability {
View = 0,
}
pub enum FunctionType {
Function = 0,
}
pub struct GasAmount(pub u64);
pub struct GasPrice(pub u128);
pub struct GasPricePerToken {
pub price_in_fri: GasPrice,
pub price_in_wei: GasPrice,
}
pub struct GlobalRoot(pub StarkHash);
pub enum InvokeTransaction {
V0(InvokeTransactionV0) = 0,
V1(InvokeTransactionV1) = 1,
V3(InvokeTransactionV3) = 2,
}
pub struct InvokeTransactionOutput {
pub actual_fee: Fee,
pub messages_sent: Vec<MessageToL1>,
pub events: Vec<Event>,
pub execution_status: TransactionExecutionStatus,
pub execution_resources: ExecutionResources,
}
pub struct InvokeTransactionV0 {
pub max_fee: Fee,
pub signature: TransactionSignature,
pub contract_address: ContractAddress,
pub entry_point_selector: EntryPointSelector,
pub calldata: Calldata,
}
pub struct InvokeTransactionV1 {
pub max_fee: Fee,
pub signature: TransactionSignature,
pub nonce: Nonce,
pub sender_address: ContractAddress,
pub calldata: Calldata,
}
pub struct InvokeTransactionV3 {
pub resource_bounds: ValidResourceBounds,
pub tip: Tip,
pub signature: TransactionSignature,
pub nonce: Nonce,
pub sender_address: ContractAddress,
pub calldata: Calldata,
pub nonce_data_availability_mode: DataAvailabilityMode,
pub fee_data_availability_mode: DataAvailabilityMode,
pub paymaster_data: PaymasterData,
pub account_deployment_data: AccountDeploymentData,
}
pub enum L1DataAvailabilityMode {
Calldata = 0,
Blob = 1,
}
pub struct L1HandlerTransaction {
pub version: TransactionVersion,
pub nonce: Nonce,
pub contract_address: ContractAddress,
pub entry_point_selector: EntryPointSelector,
pub calldata: Calldata,
}
pub struct L1HandlerTransactionOutput {
pub actual_fee: Fee,
pub messages_sent: Vec<MessageToL1>,
pub events: Vec<Event>,
pub execution_status: TransactionExecutionStatus,
pub execution_resources: ExecutionResources,
}
pub struct L1ToL2Payload(pub Vec<Felt>);
pub struct L2ToL1Payload(pub Vec<Felt>);
pub struct MessageToL1 {
pub to_address: EthAddress,
pub payload: L2ToL1Payload,
pub from_address: ContractAddress,
}
pub struct MessageToL2 {
pub from_address: EthAddress,
pub payload: L1ToL2Payload,
}
pub struct Nonce(pub Felt);
pub struct TransactionCommitment(pub StarkHash);
pub struct PaymasterData(pub Vec<Felt>);
pub struct PoseidonHash(pub Felt);
pub struct Program {
pub attributes: serde_json::Value,
pub builtins: serde_json::Value,
pub compiler_version: serde_json::Value,
pub data: serde_json::Value,
pub debug_info: serde_json::Value,
pub hints: serde_json::Value,
pub identifiers: serde_json::Value,
pub main_scope: serde_json::Value,
pub prime: serde_json::Value,
pub reference_manager: serde_json::Value,
}
pub struct ReceiptCommitment(pub StarkHash);
pub enum Resource {
L1Gas = 0,
L2Gas = 1,
}
pub struct ResourceBounds {
pub max_amount: GasAmount,
pub max_price_per_unit: GasPrice,
}
pub struct InternalRpcTransaction {
pub tx: InternalRpcTransactionWithoutTxHash,
pub tx_hash: TransactionHash,
}
pub enum InternalRpcTransactionWithoutTxHash {
Declare(InternalRpcDeclareTransactionV3) = 0,
Invoke(RpcInvokeTransaction) = 1,
DeployAccount(DeployAccountTransactionV3WithAddress) = 2,
}
pub struct InternalRpcDeclareTransactionV3 {
pub sender_address: ContractAddress,
pub compiled_class_hash: CompiledClassHash,
pub signature: TransactionSignature,
pub nonce: Nonce,
pub class_hash: ClassHash,
pub resource_bounds: AllResourceBounds,
pub tip: Tip,
pub paymaster_data: PaymasterData,
pub account_deployment_data: AccountDeploymentData,
pub nonce_data_availability_mode: DataAvailabilityMode,
pub fee_data_availability_mode: DataAvailabilityMode,
}
pub struct DeployAccountTransactionV3WithAddress {
pub tx: RpcDeployAccountTransaction,
pub contract_address: ContractAddress,
}
pub enum RpcTransaction {
Declare(RpcDeclareTransaction) = 0,
DeployAccount(RpcDeployAccountTransaction) = 1,
Invoke(RpcInvokeTransaction) = 2,
}
pub enum RpcDeclareTransaction {
V3(RpcDeclareTransactionV3) = 0,
}
pub struct RpcDeclareTransactionV3 {
pub resource_bounds: AllResourceBounds,
pub tip: Tip,
pub signature: TransactionSignature,
pub nonce: Nonce,
pub contract_class: SierraContractClass,
pub compiled_class_hash: CompiledClassHash,
pub sender_address: ContractAddress,
pub nonce_data_availability_mode: DataAvailabilityMode,
pub fee_data_availability_mode: DataAvailabilityMode,
pub paymaster_data: PaymasterData,
pub account_deployment_data: AccountDeploymentData,
}
pub enum RpcDeployAccountTransaction {
V3(RpcDeployAccountTransactionV3) = 0,
}
pub struct RpcDeployAccountTransactionV3 {
pub resource_bounds: AllResourceBounds,
pub tip: Tip,
pub signature: TransactionSignature,
pub nonce: Nonce,
pub class_hash: ClassHash,
pub contract_address_salt: ContractAddressSalt,
pub constructor_calldata: Calldata,
pub nonce_data_availability_mode: DataAvailabilityMode,
pub fee_data_availability_mode: DataAvailabilityMode,
pub paymaster_data: PaymasterData,
}
pub struct RpcEntryPointByType {
pub constructor: Vec<EntryPoint>,
pub external: Vec<EntryPoint>,
pub l1handler: Vec<EntryPoint>,
}
pub enum RpcInvokeTransaction {
V3(RpcInvokeTransactionV3) = 0,
}
pub struct RpcInvokeTransactionV3 {
pub resource_bounds: AllResourceBounds,
pub tip: Tip,
pub signature: TransactionSignature,
pub nonce: Nonce,
pub sender_address: ContractAddress,
pub calldata: Calldata,
pub nonce_data_availability_mode: DataAvailabilityMode,
pub fee_data_availability_mode: DataAvailabilityMode,
pub paymaster_data: PaymasterData,
pub account_deployment_data: AccountDeploymentData,
}
pub struct SequencerContractAddress(pub ContractAddress);
pub struct Signature {
pub r: Felt,
pub s: Felt,
}
pub struct StateDiff {
pub deployed_contracts: IndexMap<ContractAddress, ClassHash>,
pub storage_diffs: IndexMap<ContractAddress, IndexMap<StorageKey, Felt>>,
pub declared_classes: IndexMap<ClassHash, (CompiledClassHash, SierraContractClass)>,
pub deprecated_declared_classes: IndexMap<ClassHash, DeprecatedContractClass>,
pub nonces: IndexMap<ContractAddress, Nonce>,
pub replaced_classes: IndexMap<ContractAddress, ClassHash>,
}
pub struct StateDiffCommitment(pub PoseidonHash);
pub struct StructMember {
pub name: String,
pub offset: usize,
pub r#type: String,
}
pub enum StructType {
Struct = 0,
}
pub struct ThinStateDiff {
pub deployed_contracts: IndexMap<ContractAddress, ClassHash>,
pub storage_diffs: IndexMap<ContractAddress, IndexMap<StorageKey, Felt>>,
pub declared_classes: IndexMap<ClassHash, CompiledClassHash>,
pub deprecated_declared_classes: Vec<ClassHash>,
pub nonces: IndexMap<ContractAddress, Nonce>,
pub replaced_classes: IndexMap<ContractAddress, ClassHash>,
}
pub struct Tip(pub u64);
pub enum Transaction {
Declare(DeclareTransaction) = 0,
Deploy(DeployTransaction) = 1,
DeployAccount(DeployAccountTransaction) = 2,
Invoke(InvokeTransaction) = 3,
L1Handler(L1HandlerTransaction) = 4,
}
pub enum TransactionExecutionStatus {
Succeeded = 0,
Reverted(RevertedTransactionExecutionStatus) = 1,
}
pub struct RevertedTransactionExecutionStatus {
pub revert_reason: String,
}
pub struct TransactionHash(pub StarkHash);
pub struct TransactionOffsetInBlock(pub usize);
pub enum TransactionOutput {
Declare(DeclareTransactionOutput) = 0,
Deploy(DeployTransactionOutput) = 1,
DeployAccount(DeployAccountTransactionOutput) = 2,
Invoke(InvokeTransactionOutput) = 3,
L1Handler(L1HandlerTransactionOutput) = 4,
}
pub struct TransactionSignature(pub Vec<Felt>);
pub struct TransactionVersion(pub Felt);
pub struct TypedParameter {
pub name: String,
pub r#type: String,
}
pub enum ValidResourceBounds {
L1Gas(ResourceBounds) = 0,
AllResources(AllResourceBounds) = 1,
}
pub struct CasmContractClass {
pub prime: BigUint,
pub compiler_version: String,
pub bytecode: Vec<BigUintAsHex>,
pub bytecode_segment_lengths: Option<NestedIntList>,
pub hints: Vec<(usize, Vec<Hint>)>,
pub pythonic_hints: Option<Vec<(usize, Vec<String>)>>,
pub entry_points_by_type: CasmContractEntryPoints,
}
pub struct CasmContractEntryPoints {
pub external: Vec<CasmContractEntryPoint>,
pub l1_handler: Vec<CasmContractEntryPoint>,
pub constructor: Vec<CasmContractEntryPoint>,
}
pub struct CasmContractEntryPoint {
pub selector: BigUint,
pub offset: usize,
pub builtins: Vec<String>,
}
pub struct BigUintAsHex {
pub value: BigUint,
}
pub enum NestedIntList {
Leaf(usize) = 0,
Node(Vec<NestedIntList>) = 1,
}
binary(bool);
binary(EthAddress);
binary(u8);
binary(u32);
binary(u64);
binary(u128);
binary(usize);
(BlockNumber, TransactionOffsetInBlock);
(BlockHash, ClassHash);
(ContractAddress, BlockHash);
(ContractAddress, BlockNumber);
(ContractAddress, Nonce);
(ContractAddress, StorageKey, BlockHash);
(ContractAddress, StorageKey, BlockNumber);
(CompiledClassHash, SierraContractClass);
(usize, Vec<Hint>);
(usize, Vec<String>);
}
#[macro_export]
macro_rules! auto_impl_get_test_instance {
() => {};
// Tuple structs (no names associated with fields) - one field.
($(pub)? struct $name:ident($(pub)? $ty:ty); $($rest:tt)*) => {
impl GetTestInstance for $name {
fn get_test_instance(rng: &mut rand_chacha::ChaCha8Rng) -> Self {
Self(<$ty>::get_test_instance(rng))
}
}
auto_impl_get_test_instance!($($rest)*);
};
// Tuple structs (no names associated with fields) - two fields.
($(pub)? struct $name:ident($(pub)? $ty0:ty, $(pub)? $ty1:ty) ; $($rest:tt)*) => {
impl GetTestInstance for $name {
fn get_test_instance(rng: &mut rand_chacha::ChaCha8Rng) -> Self {
Self(<$ty0>::get_test_instance(rng), <$ty1>::get_test_instance(rng))
}
}
auto_impl_get_test_instance!($($rest)*);
};
// Structs with public fields.
($(pub)? struct $name:ident { $(pub $field:ident : $ty:ty ,)* } $($rest:tt)*) => {
impl GetTestInstance for $name {
fn get_test_instance(rng: &mut rand_chacha::ChaCha8Rng) -> Self {
Self {
$(
$field: <$ty>::get_test_instance(rng),
)*
}
}
}
auto_impl_get_test_instance!($($rest)*);
};
// Tuples - two elements.
(($ty0:ty, $ty1:ty) ; $($rest:tt)*) => {
impl GetTestInstance for ($ty0, $ty1) {
fn get_test_instance(rng: &mut rand_chacha::ChaCha8Rng) -> Self {
(
<$ty0>::get_test_instance(rng),
<$ty1>::get_test_instance(rng),
)
}
}
auto_impl_get_test_instance!($($rest)*);
};
// Tuples - three elements.