Skip to content

Commit 3a2333c

Browse files
committed
Use u32 as consensus chain block number in pallet-domains tests
This is used to keep consistent with the production runtime Signed-off-by: linning <[email protected]>
1 parent 6aaee34 commit 3a2333c

File tree

4 files changed

+25
-27
lines changed

4 files changed

+25
-27
lines changed

crates/pallet-domains/src/block_tree.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ mod tests {
692692
);
693693
let mut receipt_of_block_1 = None;
694694
let mut bundle_header_hash_of_block_1 = None;
695-
for block_number in 1..=(block_tree_pruning_depth as u64 + 3) {
695+
for block_number in 1..=(block_tree_pruning_depth + 3) {
696696
// Finilize parent block and initialize block at `block_number`
697697
run_to_block::<Test>(block_number, receipt.consensus_block_hash);
698698

@@ -726,7 +726,7 @@ mod tests {
726726
));
727727
// `bundle_extrinsics_root` should be tracked in `ExecutionInbox`
728728
assert_eq!(
729-
ExecutionInbox::<Test>::get((domain_id, block_number as u32, block_number)),
729+
ExecutionInbox::<Test>::get((domain_id, block_number, block_number)),
730730
vec![BundleDigest {
731731
header_hash: bundle_header_hash,
732732
extrinsics_root: bundle_extrinsics_root,
@@ -739,7 +739,7 @@ mod tests {
739739

740740
// Head receipt number should be updated
741741
let head_receipt_number = HeadReceiptNumber::<Test>::get(domain_id);
742-
assert_eq!(head_receipt_number, block_number as u32 - 1);
742+
assert_eq!(head_receipt_number, block_number - 1);
743743

744744
// As we only extending the block tree there should be no fork
745745
let parent_domain_block_receipt =
@@ -1035,7 +1035,7 @@ mod tests {
10351035
// Construct a future receipt
10361036
let mut future_receipt = next_receipt.clone();
10371037
future_receipt.domain_block_number = head_receipt_number + 2;
1038-
future_receipt.consensus_block_number = head_receipt_number as u64 + 2;
1038+
future_receipt.consensus_block_number = head_receipt_number as u32 + 2;
10391039
ExecutionInbox::<Test>::insert(
10401040
(
10411041
domain_id,
@@ -1127,7 +1127,7 @@ mod tests {
11271127
// Construct a future receipt
11281128
let mut future_receipt = next_receipt.clone();
11291129
future_receipt.domain_block_number = head_receipt_number + 1;
1130-
future_receipt.consensus_block_number = head_receipt_number as u64 + 1;
1130+
future_receipt.consensus_block_number = head_receipt_number as u32 + 1;
11311131

11321132
ExecutionInbox::<Test>::insert(
11331133
(
@@ -1222,7 +1222,7 @@ mod tests {
12221222
#[test]
12231223
fn test_collect_invalid_bundle_author() {
12241224
let creator = 0u128;
1225-
let challenge_period = BlockTreePruningDepth::get() as u64;
1225+
let challenge_period = BlockTreePruningDepth::get();
12261226
let operator_set: Vec<_> = (1..15).collect();
12271227
let mut ext = new_test_ext_with_extensions();
12281228
ext.execute_with(|| {
@@ -1250,7 +1250,7 @@ mod tests {
12501250
let current_block_number = frame_system::Pallet::<Test>::current_block_number();
12511251
let execution_inbox = ExecutionInbox::<Test>::get((
12521252
domain_id,
1253-
current_block_number as u32,
1253+
current_block_number,
12541254
current_block_number,
12551255
));
12561256
let bundles_extrinsics_roots: Vec<_> = execution_inbox
@@ -1289,7 +1289,7 @@ mod tests {
12891289
let next_receipt = extend_block_tree(
12901290
domain_id,
12911291
operator_set[0],
1292-
(current_block_number + challenge_period) as u32 + 1,
1292+
current_block_number + challenge_period + 1u32,
12931293
target_receipt,
12941294
);
12951295
// Confirm `target_receipt`

crates/pallet-domains/src/domain_registry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ mod tests {
401401
#[test]
402402
fn test_domain_instantiation() {
403403
let creator = 1u128;
404-
let created_at = 0u64;
404+
let created_at = 0u32;
405405
// Construct an invalid domain config initially
406406
let mut domain_config_params = DomainConfigParams {
407407
domain_name: String::from_utf8(vec![0; 1024]).unwrap(),
@@ -562,7 +562,7 @@ mod tests {
562562
#[test]
563563
fn test_domain_instantiation_evm_accounts() {
564564
let creator = 1u128;
565-
let created_at = 0u64;
565+
let created_at = 0u32;
566566
// Construct an invalid domain config initially
567567
let mut domain_config_params = DomainConfigParams {
568568
domain_name: "evm-domain".to_owned(),
@@ -729,7 +729,7 @@ mod tests {
729729
#[test]
730730
fn test_domain_instantiation_evm_contract_allow_list() {
731731
let creator = 1u128;
732-
let created_at = 0u64;
732+
let created_at = 0u32;
733733
// Construct a valid default domain config
734734
let mut domain_config_params = DomainConfigParams {
735735
domain_name: "evm-domain".to_owned(),

crates/pallet-domains/src/runtime_registry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ mod tests {
501501
));
502502

503503
ext.execute_with(|| {
504-
frame_system::Pallet::<Test>::set_block_number(100u64);
504+
frame_system::Pallet::<Test>::set_block_number(100u32);
505505
let res = crate::Pallet::<Test>::upgrade_domain_runtime(
506506
RawOrigin::Root.into(),
507507
0,
@@ -514,7 +514,7 @@ mod tests {
514514

515515
// will not be able to override an already scheduled upgrade
516516
ext.execute_with(|| {
517-
frame_system::Pallet::<Test>::set_block_number(100u64);
517+
frame_system::Pallet::<Test>::set_block_number(100u32);
518518
let res = crate::Pallet::<Test>::upgrade_domain_runtime(
519519
RawOrigin::Root.into(),
520520
0,
@@ -562,7 +562,7 @@ mod tests {
562562
})
563563
}
564564

565-
fn go_to_block(block: u64) {
565+
fn go_to_block(block: u32) {
566566
for i in System::block_number() + 1..=block {
567567
let parent_hash = if System::block_number() > 1 {
568568
let header = System::finalize();

crates/pallet-domains/src/tests.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use subspace_runtime_primitives::{
4747
};
4848

4949
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
50-
type Block = frame_system::mocking::MockBlock<Test>;
50+
type Block = frame_system::mocking::MockBlockU32<Test>;
5151
type Balance = u128;
5252

5353
// TODO: Remove when DomainRegistry is usable.
@@ -67,7 +67,7 @@ frame_support::construct_runtime!(
6767
}
6868
);
6969

70-
type BlockNumber = u64;
70+
type BlockNumber = u32;
7171
type Hash = H256;
7272
pub(crate) type AccountId = u128;
7373

@@ -189,7 +189,7 @@ impl BlockSlot<Test> for DummyBlockSlot {
189189
}
190190

191191
fn slot_produced_after(_slot: sp_consensus_slots::Slot) -> Option<BlockNumberFor<Test>> {
192-
Some(0u64)
192+
Some(0u32)
193193
}
194194
}
195195

@@ -513,9 +513,9 @@ pub(crate) fn extend_block_tree(
513513
mut latest_receipt: ExecutionReceiptOf<Test>,
514514
) -> ExecutionReceiptOf<Test> {
515515
let current_block_number = frame_system::Pallet::<Test>::current_block_number();
516-
assert!(current_block_number < to as u64);
516+
assert!(current_block_number < to);
517517

518-
for block_number in (current_block_number + 1)..to as u64 {
518+
for block_number in (current_block_number + 1)..to {
519519
// Finilize parent block and initialize block at `block_number`
520520
run_to_block::<Test>(block_number, latest_receipt.consensus_block_hash);
521521

@@ -547,7 +547,7 @@ pub(crate) fn extend_block_tree(
547547
}
548548

549549
// Finilize parent block and initialize block at `to`
550-
run_to_block::<Test>(to as u64, latest_receipt.consensus_block_hash);
550+
run_to_block::<Test>(to, latest_receipt.consensus_block_hash);
551551

552552
latest_receipt
553553
}
@@ -810,13 +810,11 @@ fn test_basic_fraud_proof_processing() {
810810

811811
// The other data that used to verify ER should not be removed, such that the honest
812812
// operator can re-submit the valid ER
813-
assert!(!ExecutionInbox::<Test>::get((
814-
domain_id,
815-
block_number,
816-
block_number as u64
817-
))
818-
.is_empty());
819-
assert!(ConsensusBlockHash::<Test>::get(domain_id, block_number as u64).is_some());
813+
assert!(
814+
!ExecutionInbox::<Test>::get((domain_id, block_number, block_number))
815+
.is_empty()
816+
);
817+
assert!(ConsensusBlockHash::<Test>::get(domain_id, block_number).is_some());
820818
}
821819

822820
// Re-submit the valid ER

0 commit comments

Comments
 (0)