/__w/smoldot/smoldot/repo/lib/src/transactions/pool/tests.rs
Line | Count | Source |
1 | | // Smoldot |
2 | | // Copyright (C) 2023 Pierre Krieger |
3 | | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 |
4 | | |
5 | | // This program is free software: you can redistribute it and/or modify |
6 | | // it under the terms of the GNU General Public License as published by |
7 | | // the Free Software Foundation, either version 3 of the License, or |
8 | | // (at your option) any later version. |
9 | | |
10 | | // This program is distributed in the hope that it will be useful, |
11 | | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | // GNU General Public License for more details. |
14 | | |
15 | | // You should have received a copy of the GNU General Public License |
16 | | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | | |
18 | | #![cfg(test)] |
19 | | |
20 | | use core::num::NonZeroU64; |
21 | | |
22 | | use super::{Config, Pool, ValidTransaction}; |
23 | | |
24 | | #[test] |
25 | 1 | fn basic_includable() { |
26 | 1 | let mut pool = Pool::new(Config { |
27 | 1 | capacity: 16, |
28 | 1 | finalized_block_height: 0, |
29 | 1 | randomness_seed: [0; 16], |
30 | 1 | }); |
31 | 1 | |
32 | 1 | let tx_id = pool.add_unvalidated(vec![], ()); |
33 | 1 | |
34 | 1 | pool.append_empty_block(); |
35 | 1 | assert!(pool.best_block_includable_transactions().next().is_none()); |
36 | | |
37 | 1 | pool.set_validation_result( |
38 | 1 | tx_id, |
39 | 1 | 1, |
40 | 1 | ValidTransaction { |
41 | 1 | longevity: NonZeroU64::new(16).unwrap(), |
42 | 1 | priority: 0, |
43 | 1 | propagate: true, |
44 | 1 | provides: Vec::new(), |
45 | 1 | requires: Vec::new(), |
46 | 1 | }, |
47 | 1 | ); |
48 | 1 | |
49 | 1 | pool.append_empty_block(); |
50 | 1 | assert_eq!( |
51 | 1 | pool.best_block_includable_transactions().next(), |
52 | 1 | Some((tx_id, &())) |
53 | 1 | ); |
54 | | |
55 | 1 | pool.best_block_add_transaction_by_id(tx_id); |
56 | 1 | assert!(pool.best_block_includable_transactions().next().is_none()); |
57 | 1 | } |
58 | | |
59 | | // TODO: more tests |