Skip to content

Commit 280d1de

Browse files
committed
Ledger/transaction_logic: move tests to integration tests
Moved the transaction_logic tests module from scan_state/transaction_logic/mod.rs (104 lines) to a new integration test file at ledger/tests/transaction_logic_tests.rs. Changes: - Removed inline tests module from mod.rs - Created transaction_logic_tests.rs in tests directory - Updated imports to work from integration test context - All 3 tests pass: test_hash_empty_event, test_cons_receipt_hash_ocaml, test_receipt_hash_update
1 parent 311b34e commit 280d1de

File tree

2 files changed

+132
-131
lines changed

2 files changed

+132
-131
lines changed

ledger/src/scan_state/transaction_logic/mod.rs

Lines changed: 22 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,28 @@ use std::{
3838
fmt::Display,
3939
};
4040

41+
pub mod local_state;
42+
pub mod protocol_state;
43+
pub mod signed_command;
44+
pub mod transaction_applied;
45+
pub mod transaction_partially_applied;
46+
pub mod transaction_union_payload;
47+
pub mod transaction_witness;
48+
pub mod valid;
49+
pub mod verifiable;
50+
pub mod zkapp_command;
51+
pub mod zkapp_statement;
52+
pub use transaction_partially_applied::{
53+
apply_transaction_first_pass, apply_transaction_second_pass, apply_transactions,
54+
apply_user_command, set_with_location, AccountState,
55+
};
56+
pub use transaction_union_payload::{
57+
account_check_timing, add_amount, checked_cons_signed_command_payload,
58+
cons_signed_command_payload, cons_zkapp_command_commitment, get_with_location, sub_amount,
59+
timing_error_to_user_command_status, validate_nonces, validate_timing, Body, Common,
60+
ExistingOrNew, Tag, TimingValidation, TransactionUnion, TransactionUnionPayload,
61+
};
62+
4163
/// <https://github.com/MinaProtocol/mina/blob/2ee6e004ba8c6a0541056076aab22ea162f7eb3a/src/lib/mina_base/transaction_status.ml#L9>
4264
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
4365
pub enum TransactionFailure {
@@ -237,8 +259,6 @@ where
237259
}
238260
}
239261

240-
pub mod valid;
241-
242262
/// <https://github.com/MinaProtocol/mina/blob/2ee6e004ba8c6a0541056076aab22ea162f7eb3a/src/lib/mina_base/fee_transfer.ml#L19>
243263
#[derive(Debug, Clone, PartialEq)]
244264
pub struct SingleFeeTransfer {
@@ -589,13 +609,6 @@ impl Memo {
589609
}
590610
}
591611

592-
pub mod signed_command;
593-
594-
pub mod zkapp_command;
595-
pub mod zkapp_statement;
596-
597-
pub mod verifiable;
598-
599612
#[derive(Clone, Debug, PartialEq)]
600613
pub enum UserCommand {
601614
SignedCommand(Box<signed_command::SignedCommand>),
@@ -1017,24 +1030,6 @@ impl From<&Transaction> for MinaTransactionTransactionStableV2 {
10171030
}
10181031
}
10191032

1020-
pub mod local_state;
1021-
pub mod protocol_state;
1022-
pub mod transaction_applied;
1023-
pub mod transaction_partially_applied;
1024-
pub mod transaction_witness;
1025-
pub use transaction_partially_applied::{
1026-
apply_transaction_first_pass, apply_transaction_second_pass, apply_transactions,
1027-
apply_user_command, set_with_location, AccountState,
1028-
};
1029-
1030-
pub mod transaction_union_payload;
1031-
pub use transaction_union_payload::{
1032-
account_check_timing, add_amount, checked_cons_signed_command_payload,
1033-
cons_signed_command_payload, cons_zkapp_command_commitment, get_with_location, sub_amount,
1034-
timing_error_to_user_command_status, validate_nonces, validate_timing, Body, Common,
1035-
ExistingOrNew, Tag, TimingValidation, TransactionUnion, TransactionUnionPayload,
1036-
};
1037-
10381033
#[cfg(any(test, feature = "fuzzing"))]
10391034
pub mod for_tests {
10401035
use mina_signer::Keypair;
@@ -1319,107 +1314,3 @@ pub mod for_tests {
13191314
}
13201315
}
13211316

1322-
#[cfg(test)]
1323-
mod tests {
1324-
use std::str::FromStr;
1325-
1326-
use o1_utils::FieldHelpers;
1327-
1328-
#[cfg(target_family = "wasm")]
1329-
use wasm_bindgen_test::wasm_bindgen_test as test;
1330-
1331-
use super::{
1332-
signed_command::{Body, Common, PaymentPayload},
1333-
*,
1334-
};
1335-
1336-
fn pub_key(address: &str) -> CompressedPubKey {
1337-
mina_signer::PubKey::from_address(address)
1338-
.unwrap()
1339-
.into_compressed()
1340-
}
1341-
1342-
#[test]
1343-
fn test_hash_empty_event() {
1344-
// Same value than OCaml
1345-
const EXPECTED: &str =
1346-
"6963060754718463299978089777716994949151371320681588566338620419071140958308";
1347-
1348-
let event = zkapp_command::Event::empty();
1349-
assert_eq!(event.hash(), Fp::from_str(EXPECTED).unwrap());
1350-
}
1351-
1352-
/// Test using same values as here:
1353-
/// <https://github.com/MinaProtocol/mina/blob/3a78f0e0c1343d14e2729c8b00205baa2ec70c93/src/lib/mina_base/receipt.ml#L136>
1354-
#[test]
1355-
fn test_cons_receipt_hash_ocaml() {
1356-
let from = pub_key("B62qr71UxuyKpkSKYceCPsjw14nuaeLwWKZdMqaBMPber5AAF6nkowS");
1357-
let to = pub_key("B62qnvGVnU7FXdy8GdkxL7yciZ8KattyCdq5J6mzo5NCxjgQPjL7BTH");
1358-
1359-
let common = Common {
1360-
fee: Fee::from_u64(9758327274353182341),
1361-
fee_payer_pk: from,
1362-
nonce: Nonce::from_u32(1609569868),
1363-
valid_until: Slot::from_u32(2127252111),
1364-
memo: Memo([
1365-
1, 32, 101, 26, 225, 104, 115, 118, 55, 102, 76, 118, 108, 78, 114, 50, 0, 115,
1366-
110, 108, 53, 75, 109, 112, 50, 110, 88, 97, 76, 66, 76, 81, 235, 79,
1367-
]),
1368-
};
1369-
1370-
let body = Body::Payment(PaymentPayload {
1371-
receiver_pk: to,
1372-
amount: Amount::from_u64(1155659205107036493),
1373-
});
1374-
1375-
let tx = SignedCommandPayload { common, body };
1376-
1377-
let prev = "4918218371695029984164006552208340844155171097348169027410983585063546229555";
1378-
let prev_receipt_chain_hash = ReceiptChainHash(Fp::from_str(prev).unwrap());
1379-
1380-
let next = "19078048535981853335308913493724081578728104896524544653528728307378106007337";
1381-
let next_receipt_chain_hash = ReceiptChainHash(Fp::from_str(next).unwrap());
1382-
1383-
let result = cons_signed_command_payload(&tx, prev_receipt_chain_hash);
1384-
assert_eq!(result, next_receipt_chain_hash);
1385-
}
1386-
1387-
#[test]
1388-
fn test_receipt_hash_update() {
1389-
let from = pub_key("B62qmnY6m4c6bdgSPnQGZriSaj9vuSjsfh6qkveGTsFX3yGA5ywRaja");
1390-
let to = pub_key("B62qjVQLxt9nYMWGn45mkgwYfcz8e8jvjNCBo11VKJb7vxDNwv5QLPS");
1391-
1392-
let common = Common {
1393-
fee: Fee::from_u64(14500000),
1394-
fee_payer_pk: from,
1395-
nonce: Nonce::from_u32(15),
1396-
valid_until: Slot::from_u32(-1i32 as u32),
1397-
memo: Memo([
1398-
1, 7, 84, 104, 101, 32, 49, 48, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1399-
0, 0, 0, 0, 0, 0, 0, 0, 0,
1400-
]),
1401-
};
1402-
1403-
let body = Body::Payment(PaymentPayload {
1404-
receiver_pk: to,
1405-
amount: Amount::from_u64(2354000000),
1406-
});
1407-
1408-
let tx = SignedCommandPayload { common, body };
1409-
1410-
let mut prev =
1411-
hex::decode("09ac04c9965b885acfc9c54141dbecfc63b2394a4532ea2c598d086b894bfb14")
1412-
.unwrap();
1413-
prev.reverse();
1414-
let prev_receipt_chain_hash = ReceiptChainHash(Fp::from_bytes(&prev).unwrap());
1415-
1416-
let mut next =
1417-
hex::decode("3ecaa73739df77549a2f92f7decf822562d0593373cff1e480bb24b4c87dc8f0")
1418-
.unwrap();
1419-
next.reverse();
1420-
let next_receipt_chain_hash = ReceiptChainHash(Fp::from_bytes(&next).unwrap());
1421-
1422-
let result = cons_signed_command_payload(&tx, prev_receipt_chain_hash);
1423-
assert_eq!(result, next_receipt_chain_hash);
1424-
}
1425-
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
use std::str::FromStr;
2+
3+
use o1_utils::FieldHelpers;
4+
5+
#[cfg(target_family = "wasm")]
6+
use wasm_bindgen_test::wasm_bindgen_test as test;
7+
8+
use mina_curves::pasta::Fp;
9+
use mina_signer::CompressedPubKey;
10+
use mina_tree::{
11+
scan_state::{
12+
currency::{Amount, Fee, Nonce, Slot},
13+
transaction_logic::{
14+
cons_signed_command_payload,
15+
signed_command::{Body, Common, PaymentPayload, SignedCommandPayload},
16+
zkapp_command, Memo,
17+
},
18+
},
19+
ReceiptChainHash,
20+
};
21+
22+
fn pub_key(address: &str) -> CompressedPubKey {
23+
mina_signer::PubKey::from_address(address)
24+
.unwrap()
25+
.into_compressed()
26+
}
27+
28+
#[test]
29+
fn test_hash_empty_event() {
30+
// Same value than OCaml
31+
const EXPECTED: &str =
32+
"6963060754718463299978089777716994949151371320681588566338620419071140958308";
33+
34+
let event = zkapp_command::Event::empty();
35+
assert_eq!(event.hash(), Fp::from_str(EXPECTED).unwrap());
36+
}
37+
38+
/// Test using same values as here:
39+
/// <https://github.com/MinaProtocol/mina/blob/3a78f0e0c1343d14e2729c8b00205baa2ec70c93/src/lib/mina_base/receipt.ml#L136>
40+
#[test]
41+
fn test_cons_receipt_hash_ocaml() {
42+
let from = pub_key("B62qr71UxuyKpkSKYceCPsjw14nuaeLwWKZdMqaBMPber5AAF6nkowS");
43+
let to = pub_key("B62qnvGVnU7FXdy8GdkxL7yciZ8KattyCdq5J6mzo5NCxjgQPjL7BTH");
44+
45+
let common = Common {
46+
fee: Fee::from_u64(9758327274353182341),
47+
fee_payer_pk: from,
48+
nonce: Nonce::from_u32(1609569868),
49+
valid_until: Slot::from_u32(2127252111),
50+
memo: Memo([
51+
1, 32, 101, 26, 225, 104, 115, 118, 55, 102, 76, 118, 108, 78, 114, 50, 0, 115,
52+
110, 108, 53, 75, 109, 112, 50, 110, 88, 97, 76, 66, 76, 81, 235, 79,
53+
]),
54+
};
55+
56+
let body = Body::Payment(PaymentPayload {
57+
receiver_pk: to,
58+
amount: Amount::from_u64(1155659205107036493),
59+
});
60+
61+
let tx = SignedCommandPayload { common, body };
62+
63+
let prev = "4918218371695029984164006552208340844155171097348169027410983585063546229555";
64+
let prev_receipt_chain_hash = ReceiptChainHash(Fp::from_str(prev).unwrap());
65+
66+
let next = "19078048535981853335308913493724081578728104896524544653528728307378106007337";
67+
let next_receipt_chain_hash = ReceiptChainHash(Fp::from_str(next).unwrap());
68+
69+
let result = cons_signed_command_payload(&tx, prev_receipt_chain_hash);
70+
assert_eq!(result, next_receipt_chain_hash);
71+
}
72+
73+
#[test]
74+
fn test_receipt_hash_update() {
75+
let from = pub_key("B62qmnY6m4c6bdgSPnQGZriSaj9vuSjsfh6qkveGTsFX3yGA5ywRaja");
76+
let to = pub_key("B62qjVQLxt9nYMWGn45mkgwYfcz8e8jvjNCBo11VKJb7vxDNwv5QLPS");
77+
78+
let common = Common {
79+
fee: Fee::from_u64(14500000),
80+
fee_payer_pk: from,
81+
nonce: Nonce::from_u32(15),
82+
valid_until: Slot::from_u32(-1i32 as u32),
83+
memo: Memo([
84+
1, 7, 84, 104, 101, 32, 49, 48, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
85+
0, 0, 0, 0, 0, 0, 0, 0, 0,
86+
]),
87+
};
88+
89+
let body = Body::Payment(PaymentPayload {
90+
receiver_pk: to,
91+
amount: Amount::from_u64(2354000000),
92+
});
93+
94+
let tx = SignedCommandPayload { common, body };
95+
96+
let mut prev =
97+
hex::decode("09ac04c9965b885acfc9c54141dbecfc63b2394a4532ea2c598d086b894bfb14")
98+
.unwrap();
99+
prev.reverse();
100+
let prev_receipt_chain_hash = ReceiptChainHash(Fp::from_bytes(&prev).unwrap());
101+
102+
let mut next =
103+
hex::decode("3ecaa73739df77549a2f92f7decf822562d0593373cff1e480bb24b4c87dc8f0")
104+
.unwrap();
105+
next.reverse();
106+
let next_receipt_chain_hash = ReceiptChainHash(Fp::from_bytes(&next).unwrap());
107+
108+
let result = cons_signed_command_payload(&tx, prev_receipt_chain_hash);
109+
assert_eq!(result, next_receipt_chain_hash);
110+
}

0 commit comments

Comments
 (0)