|
1 |
| -This patch is applied to the downloaded corelib, to remove tests for unimplemented libfuncs. |
2 |
| -This patch allows us to not need to add the full corelib to the repository. |
3 |
| - |
4 | 1 | diff --git a/cairo2/corelib/src/test.cairo b/cairo2/corelib/src/test.cairo
|
5 |
| -index 39072873c..3ae171a6f 100644 |
| 2 | +index 91d974b79..0df271b1b 100644 |
6 | 3 | --- a/cairo2/corelib/src/test.cairo
|
7 | 4 | +++ b/cairo2/corelib/src/test.cairo
|
8 |
| -@@ -22,7 +22,6 @@ mod num_test; |
9 |
| - mod option_test; |
10 |
| - mod plugins_test; |
11 |
| - mod print_test; |
12 |
| --mod qm31_test; |
13 |
| - mod range_test; |
14 |
| - mod result_test; |
15 |
| - mod secp256k1_test; |
16 |
| -diff --git a/cairo2/corelib/src/test/dict_test.cairo b/cairo2/corelib/src/test/dict_test.cairo |
17 |
| -index 6fe7ea306..b5d5604ff 100644 |
18 |
| ---- a/cairo2/corelib/src/test/dict_test.cairo |
19 |
| -+++ b/cairo2/corelib/src/test/dict_test.cairo |
20 |
| -@@ -176,11 +176,3 @@ fn test_dict_from_collect_with_duplicate_keys() { |
21 |
| - let mut dict = array![(0, 1_u32), (0, 2_u32)].into_iter().collect::<Felt252Dict<_>>(); |
22 |
| - assert_eq!(dict[0], 2); |
23 |
| - } |
24 |
| -- |
25 |
| --#[test] |
26 |
| --fn test_array_from_squash_dict() { |
27 |
| -- let mut dict: Felt252Dict<u32> = (0..5_u32).into_iter().map(|x| (x.into(), x)).collect(); |
28 |
| -- assert_eq!( |
29 |
| -- dict.squash().into_entries(), array![(0, 0, 0), (1, 0, 1), (2, 0, 2), (3, 0, 3), (4, 0, 4)], |
30 |
| -- ); |
31 |
| --} |
32 |
| -diff --git a/cairo2/corelib/src/test/hash_test.cairo b/cairo2/corelib/src/test/hash_test.cairo |
33 |
| -index 64dca71a6..17bf43e13 100644 |
34 |
| ---- a/cairo2/corelib/src/test/hash_test.cairo |
35 |
| -+++ b/cairo2/corelib/src/test/hash_test.cairo |
36 |
| -@@ -1,4 +1,3 @@ |
37 |
| --use crate::blake::{blake2s_compress, blake2s_finalize}; |
38 |
| - use crate::hash::{HashStateExTrait, HashStateTrait}; |
39 |
| - use crate::poseidon::PoseidonTrait; |
40 |
| - use crate::test::test_utils::assert_eq; |
41 |
| -@@ -86,30 +85,3 @@ fn test_user_defined_hash() { |
42 |
| - 'Bad hash of StructForHash', |
43 |
| - ); |
44 |
| - } |
45 |
| -- |
46 |
| -- |
47 |
| --#[test] |
48 |
| --fn test_blake2s() { |
49 |
| -- let state = BoxTrait::new([0_u32; 8]); |
50 |
| -- let msg = BoxTrait::new([0_u32; 16]); |
51 |
| -- let byte_count = 64_u32; |
52 |
| -- |
53 |
| -- let res = blake2s_compress(state, byte_count, msg).unbox(); |
54 |
| -- |
55 |
| -- assert_eq!( |
56 |
| -- res, |
57 |
| -- [ |
58 |
| -- 3893814314, 2107143640, 4255525973, 2730947657, 3397056017, 3710875177, 3168346915, |
59 |
| -- 365144891, |
60 |
| -- ], |
61 |
| -- ); |
62 |
| -- |
63 |
| -- let res = blake2s_finalize(state, byte_count, msg).unbox(); |
64 |
| -- assert_eq!( |
65 |
| -- res, |
66 |
| -- [ |
67 |
| -- 128291589, 1454945417, 3191583614, 1491889056, 794023379, 651000200, 3725903680, |
68 |
| -- 1044330286, |
69 |
| -- ], |
70 |
| -- ); |
71 |
| --} |
72 |
| -diff --git a/cairo2/corelib/src/test/qm31_test.cairo b/cairo2/corelib/src/test/qm31_test.cairo |
| 5 | +@@ -12,7 +12,6 @@ mod dict_test; |
| 6 | + mod ec_test; |
| 7 | + mod felt_test; |
| 8 | + mod fmt_test; |
| 9 | +-mod gas_reserve_test; |
| 10 | + mod hash_test; |
| 11 | + mod integer_test; |
| 12 | + mod iter_test; |
| 13 | +diff --git a/cairo2/corelib/src/test/gas_reserve_test.cairo b/cairo2/corelib/src/test/gas_reserve_test.cairo |
73 | 14 | deleted file mode 100644
|
74 |
| -index ef64d5c51..000000000 |
75 |
| ---- a/cairo2/corelib/src/test/qm31_test.cairo |
| 15 | +index df99b0774..000000000 |
| 16 | +--- a/cairo2/corelib/src/test/gas_reserve_test.cairo |
76 | 17 | +++ /dev/null
|
77 |
| -@@ -1,67 +0,0 @@ |
78 |
| --use core::qm31::{QM31Trait, m31, qm31, qm31_const}; |
| 18 | +@@ -1,29 +0,0 @@ |
| 19 | +-use core::gas::{GasReserve, gas_reserve_create, gas_reserve_utilize}; |
79 | 20 | -
|
80 |
| --#[test] |
81 |
| --fn test_qm31_add_and_sub() { |
82 |
| -- let a = qm31_const::<0x544b2fba, 0x673cff77, 0x60713d44, 0x499602d2>(); |
83 |
| -- let b = qm31_const::<0x499602d2, 0x544b2fba, 0x673cff77, 0x60713d44>(); |
84 |
| -- let c = qm31_const::<0x1de1328d, 0x3b882f32, 0x47ae3cbc, 0x2a074017>(); |
85 |
| -- assert!(a + b == c); |
86 |
| -- assert!(b + a == c); |
87 |
| -- assert!(c - a == b); |
88 |
| -- assert!(c - b == a); |
89 |
| --} |
| 21 | +-// Allow implicitly dropping GasReserve instances. |
| 22 | +-impl GasReserveDrop of Drop<GasReserve> {} |
90 | 23 | -
|
91 | 24 | -#[test]
|
92 |
| --fn test_qm31_mul_and_div() { |
93 |
| -- let a = qm31_const::<0x544b2fba, 0x673cff77, 0x60713d44, 0x499602d2>(); |
94 |
| -- let b = qm31_const::<0x4b18de99, 0x55f6fb62, 0x6e2290d9, 0x7cd851b9>(); |
95 |
| -- let c = qm31_const::<0x38810ab4, 0x5a0fd30a, 0x2527b81e, 0x4b1ed1cd>(); |
96 |
| -- assert!(a * b == c); |
97 |
| -- assert!(b * a == c); |
98 |
| -- assert!(c / a == b); |
99 |
| -- assert!(c / b == a); |
100 |
| --} |
| 25 | +-fn test_create_and_utilize_gas_reserve() { |
| 26 | +- let gas0 = crate::testing::get_available_gas(); |
101 | 27 | -
|
102 |
| --#[test] |
103 |
| --fn test_qm31_inverse() { |
104 |
| -- let one = qm31_const::<1, 0, 0, 0>(); |
105 |
| -- let a = qm31_const::<0x4b18de99, 0x55f6fb62, 0x6e2290d9, 0x7cd851b9>(); |
106 |
| -- assert!((one / a) * a == one); |
107 |
| -- let a = qm31_const::<1, 2, 3, 4>(); |
108 |
| -- assert!((one / a) * a == one); |
109 |
| -- let a = qm31_const::<0x6849959f, 0x31bf5a51, 0x730c2120, 0x7b0430a5>(); |
110 |
| -- assert!((one / a) * a == one); |
111 |
| --} |
| 28 | +- // Buy and redeposit a GasReserve. |
| 29 | +- let reserve1 = gas_reserve_create(1000).unwrap(); |
| 30 | +- let gas1 = crate::testing::get_available_gas(); |
| 31 | +- gas_reserve_utilize(reserve1); |
| 32 | +- let gas2 = crate::testing::get_available_gas(); |
112 | 33 | -
|
113 |
| --#[test] |
114 |
| --fn test_pack() { |
115 |
| -- assert!(QM31Trait::new(1, 2, 3, 4) == qm31_const::<1, 2, 3, 4>()); |
116 |
| -- assert!(QM31Trait::new(2, 3, 4, 1) == qm31_const::<2, 3, 4, 1>()); |
117 |
| -- assert!(QM31Trait::new(3, 4, 1, 2) == qm31_const::<3, 4, 1, 2>()); |
118 |
| -- assert!(QM31Trait::new(4, 1, 2, 3) == qm31_const::<4, 1, 2, 3>()); |
119 |
| --} |
| 34 | +- // Buy the rest of the available gas. |
| 35 | +- let reserve2 = gas_reserve_create(gas2).unwrap(); |
| 36 | +- let gas3 = crate::testing::get_available_gas(); |
120 | 37 | -
|
121 |
| --#[test] |
122 |
| --fn test_unpack() { |
123 |
| -- assert_eq!(qm31_const::<1, 2, 3, 4>().unpack(), [1, 2, 3, 4]); |
124 |
| -- assert_eq!(qm31_const::<2, 3, 4, 1>().unpack(), [2, 3, 4, 1]); |
125 |
| -- assert_eq!(qm31_const::<3, 4, 1, 2>().unpack(), [3, 4, 1, 2]); |
126 |
| -- assert_eq!(qm31_const::<4, 1, 2, 3>().unpack(), [4, 1, 2, 3]); |
127 |
| --} |
| 38 | +- // Try to buy another reserve. This should fail. |
| 39 | +- let reserve3_opt = gas_reserve_create(1); |
128 | 40 | -
|
129 |
| --#[test] |
130 |
| --fn test_m31_into_qm31() { |
131 |
| -- assert_eq!(Into::<m31, qm31>::into(1).unpack(), [1, 0, 0, 0]); |
132 |
| -- assert_eq!(Into::<m31, qm31>::into(2).unpack(), [2, 0, 0, 0]); |
133 |
| -- assert_eq!(Into::<m31, qm31>::into(3).unpack(), [3, 0, 0, 0]); |
134 |
| -- assert_eq!(Into::<m31, qm31>::into(4).unpack(), [4, 0, 0, 0]); |
135 |
| --} |
136 |
| --use core::qm31::m31_ops; |
| 41 | +- gas_reserve_utilize(reserve2); |
| 42 | +- assert!(reserve3_opt.is_none()); |
137 | 43 | -
|
138 |
| --#[test] |
139 |
| --fn test_m31_ops() { |
140 |
| -- assert_eq!(m31_ops::add(0x544b2fba, 0x4b18de99), 0x1f640e54); |
141 |
| -- assert_eq!(m31_ops::sub(0x4b18de99, 0x544b2fba), 0x76cdaede); |
142 |
| -- assert_eq!(m31_ops::mul(0x544b2fba, 0x4b18de99), 0x3d3740d1); |
143 |
| -- assert_eq!(m31_ops::div(0x544b2fba, 0x4b18de99), 0x4b887296); |
| 44 | +- assert_eq!(gas1, gas0 - 1000); |
| 45 | +- assert_eq!(gas2, gas0); |
| 46 | +- assert_eq!(gas3, 0); |
144 | 47 | -}
|
145 |
| -diff --git a/cairo2/corelib/src/test/testing_test.cairo b/cairo2/corelib/src/test/testing_test.cairo |
146 |
| -index 52df78e78..ede469abe 100644 |
147 |
| ---- a/cairo2/corelib/src/test/testing_test.cairo |
148 |
| -+++ b/cairo2/corelib/src/test/testing_test.cairo |
149 |
| -@@ -135,19 +135,6 @@ fn identity<T>(t: T) -> T { |
150 |
| - t |
151 |
| - } |
152 |
| - |
153 |
| --#[test] |
154 |
| --fn test_get_unspent_gas() { |
155 |
| -- let one = identity(1); |
156 |
| -- let two = identity(2); |
157 |
| -- let prev = crate::testing::get_unspent_gas(); |
158 |
| -- let _three = identity(one + two); |
159 |
| -- let after = crate::testing::get_unspent_gas(); |
160 |
| -- let expected_cost = 100 // `one + two`. |
161 |
| -- + 300 // `identity(...)`. |
162 |
| -- + 2300; // `get_unspent_gas()`. |
163 |
| -- assert_eq!(prev - after, expected_cost); |
164 |
| --} |
165 |
| -- |
166 |
| - #[derive(Drop, Debug, PartialEq)] |
167 |
| - struct NoCopy { |
168 |
| - value: u8, |
0 commit comments