|
| 1 | +use std::collections::HashSet; |
| 2 | + |
1 | 3 | use crate::{ |
2 | 4 | config::{ |
3 | 5 | Config, |
@@ -643,6 +645,7 @@ fn get_sorted_out_tx1_2_3() { |
643 | 645 | max_gas: u64::MAX, |
644 | 646 | maximum_txs: u16::MAX, |
645 | 647 | maximum_block_size: u32::MAX, |
| 648 | + excluded_contracts: Default::default(), |
646 | 649 | }); |
647 | 650 |
|
648 | 651 | // Then |
@@ -700,6 +703,7 @@ fn get_sorted_out_tx_same_tips() { |
700 | 703 | max_gas: u64::MAX, |
701 | 704 | maximum_txs: u16::MAX, |
702 | 705 | maximum_block_size: u32::MAX, |
| 706 | + excluded_contracts: Default::default(), |
703 | 707 | }); |
704 | 708 |
|
705 | 709 | // Then |
@@ -757,6 +761,7 @@ fn get_sorted_out_zero_tip() { |
757 | 761 | max_gas: u64::MAX, |
758 | 762 | maximum_txs: u16::MAX, |
759 | 763 | maximum_block_size: u32::MAX, |
| 764 | + excluded_contracts: Default::default(), |
760 | 765 | }); |
761 | 766 |
|
762 | 767 | // Then |
@@ -814,6 +819,7 @@ fn get_sorted_out_tx_profitable_ratios() { |
814 | 819 | max_gas: u64::MAX, |
815 | 820 | maximum_txs: u16::MAX, |
816 | 821 | maximum_block_size: u32::MAX, |
| 822 | + excluded_contracts: Default::default(), |
817 | 823 | }); |
818 | 824 |
|
819 | 825 | // Then |
@@ -853,6 +859,7 @@ fn get_sorted_out_tx_by_creation_instant() { |
853 | 859 | max_gas: u64::MAX, |
854 | 860 | maximum_txs: u16::MAX, |
855 | 861 | maximum_block_size: u32::MAX, |
| 862 | + excluded_contracts: Default::default(), |
856 | 863 | }); |
857 | 864 |
|
858 | 865 | // Then |
@@ -1292,6 +1299,7 @@ fn verify_and_insert__when_dependent_tx_is_extracted_new_tx_still_accepted() { |
1292 | 1299 | max_gas: u64::MAX, |
1293 | 1300 | maximum_txs: u16::MAX, |
1294 | 1301 | maximum_block_size: u32::MAX, |
| 1302 | + excluded_contracts: Default::default(), |
1295 | 1303 | }); |
1296 | 1304 | assert_eq!(txs.len(), 1); |
1297 | 1305 | assert_eq!(pool_dependency_tx.id(), txs[0].id()); |
@@ -1405,3 +1413,74 @@ fn insert__tx_upgrade_with_invalid_wasm() { |
1405 | 1413 | )); |
1406 | 1414 | universe.assert_pool_integrity(&[]); |
1407 | 1415 | } |
| 1416 | + |
| 1417 | +#[test] |
| 1418 | +fn extract__tx_with_excluded_contract() { |
| 1419 | + let mut universe = TestPoolUniverse::default().config(Config { |
| 1420 | + utxo_validation: false, |
| 1421 | + ..Default::default() |
| 1422 | + }); |
| 1423 | + universe.build_pool(); |
| 1424 | + |
| 1425 | + // Given |
| 1426 | + let (create_tx_1, excluded_contract) = |
| 1427 | + universe.build_create_contract_transaction(vec![1, 2, 3]); |
| 1428 | + let (create_tx_2, authorized_contract) = |
| 1429 | + universe.build_create_contract_transaction(vec![4, 5, 6]); |
| 1430 | + let tx1 = universe.build_script_transaction( |
| 1431 | + Some(vec![Input::contract( |
| 1432 | + Default::default(), |
| 1433 | + Default::default(), |
| 1434 | + Default::default(), |
| 1435 | + Default::default(), |
| 1436 | + excluded_contract, |
| 1437 | + )]), |
| 1438 | + Some(vec![Output::contract( |
| 1439 | + 0, |
| 1440 | + Default::default(), |
| 1441 | + Default::default(), |
| 1442 | + )]), |
| 1443 | + 0, |
| 1444 | + ); |
| 1445 | + let tx2 = universe.build_script_transaction( |
| 1446 | + Some(vec![Input::contract( |
| 1447 | + Default::default(), |
| 1448 | + Default::default(), |
| 1449 | + Default::default(), |
| 1450 | + Default::default(), |
| 1451 | + authorized_contract, |
| 1452 | + )]), |
| 1453 | + Some(vec![Output::contract( |
| 1454 | + 0, |
| 1455 | + Default::default(), |
| 1456 | + Default::default(), |
| 1457 | + )]), |
| 1458 | + 0, |
| 1459 | + ); |
| 1460 | + let mut excluded_contracts = HashSet::default(); |
| 1461 | + excluded_contracts.insert(excluded_contract); |
| 1462 | + |
| 1463 | + let tx2_id = tx2.id(&ChainId::default()); |
| 1464 | + |
| 1465 | + universe.verify_and_insert(create_tx_1).unwrap(); |
| 1466 | + universe.verify_and_insert(create_tx_2).unwrap(); |
| 1467 | + let tx1 = universe.verify_and_insert(tx1).unwrap(); |
| 1468 | + universe.verify_and_insert(tx2).unwrap(); |
| 1469 | + |
| 1470 | + // When |
| 1471 | + let txs = universe |
| 1472 | + .get_pool() |
| 1473 | + .write() |
| 1474 | + .extract_transactions_for_block(Constraints { |
| 1475 | + minimal_gas_price: 0, |
| 1476 | + max_gas: u64::MAX, |
| 1477 | + maximum_txs: u16::MAX, |
| 1478 | + maximum_block_size: u32::MAX, |
| 1479 | + excluded_contracts, |
| 1480 | + }); |
| 1481 | + |
| 1482 | + // Then |
| 1483 | + assert_eq!(txs.len(), 3, "Should have 1 txs"); |
| 1484 | + assert_eq!(txs[2].id(), tx2_id, "First should be tx2"); |
| 1485 | + universe.assert_pool_integrity(&[tx1]); |
| 1486 | +} |
0 commit comments