Skip to content

Commit 8a44ece

Browse files
committed
chore: test local hint-replicas override
1 parent 6794642 commit 8a44ece

File tree

1 file changed

+120
-1
lines changed

1 file changed

+120
-1
lines changed

stackslib/src/net/stackerdb/tests/config.rs

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ fn test_valid_and_invalid_stackerdb_configs() {
528528
ContractName::try_from(format!("test-{}", i)).unwrap(),
529529
);
530530
peer.with_db_state(|sortdb, chainstate, _, _| {
531-
match StackerDBConfig::from_smart_contract(chainstate, sortdb, &contract_id, 32) {
531+
match StackerDBConfig::from_smart_contract(chainstate, sortdb, &contract_id, 32, None) {
532532
Ok(config) => {
533533
let expected = result
534534
.clone()
@@ -551,3 +551,122 @@ fn test_valid_and_invalid_stackerdb_configs() {
551551
.unwrap();
552552
}
553553
}
554+
555+
#[test]
556+
fn test_hint_replicas_override() {
557+
let AUTO_UNLOCK_HEIGHT = 12;
558+
let EXPECTED_FIRST_V2_CYCLE = 8;
559+
// the sim environment produces 25 empty sortitions before
560+
// tenures start being tracked.
561+
let EMPTY_SORTITIONS = 25;
562+
563+
let mut burnchain = Burnchain::default_unittest(
564+
0,
565+
&BurnchainHeaderHash::from_hex(BITCOIN_REGTEST_FIRST_BLOCK_HASH).unwrap(),
566+
);
567+
burnchain.pox_constants.reward_cycle_length = 5;
568+
burnchain.pox_constants.prepare_length = 2;
569+
burnchain.pox_constants.anchor_threshold = 1;
570+
burnchain.pox_constants.v1_unlock_height = AUTO_UNLOCK_HEIGHT + EMPTY_SORTITIONS;
571+
572+
let first_v2_cycle = burnchain
573+
.block_height_to_reward_cycle(burnchain.pox_constants.v1_unlock_height as u64)
574+
.unwrap()
575+
+ 1;
576+
577+
assert_eq!(first_v2_cycle, EXPECTED_FIRST_V2_CYCLE);
578+
579+
let epochs = StacksEpoch::all(0, 0, EMPTY_SORTITIONS as u64 + 10);
580+
581+
let observer = TestEventObserver::new();
582+
583+
let (mut peer, mut keys) = instantiate_pox_peer_with_epoch(
584+
&burnchain,
585+
"test_valid_and_invalid_stackerdb_configs",
586+
Some(epochs.clone()),
587+
Some(&observer),
588+
);
589+
590+
let contract_owner = keys.pop().unwrap();
591+
let contract_id = QualifiedContractIdentifier::new(
592+
StacksAddress::from_public_keys(
593+
26,
594+
&AddressHashMode::SerializeP2PKH,
595+
1,
596+
&vec![StacksPublicKey::from_private(&contract_owner)],
597+
)
598+
.unwrap()
599+
.into(),
600+
ContractName::try_from("test-0").unwrap(),
601+
);
602+
603+
peer.config.check_pox_invariants =
604+
Some((EXPECTED_FIRST_V2_CYCLE, EXPECTED_FIRST_V2_CYCLE + 10));
605+
606+
let override_replica = NeighborAddress {
607+
addrbytes: PeerAddress([2u8; 16]),
608+
port: 123,
609+
public_key_hash: Hash160([3u8; 20]),
610+
};
611+
612+
let mut coinbase_nonce = 0;
613+
let mut txs = vec![];
614+
615+
let config_contract = r#"
616+
(define-public (stackerdb-get-signer-slots)
617+
(ok (list { signer: 'ST2TFVBMRPS5SSNP98DQKQ5JNB2B6NZM91C4K3P7B, num-slots: u3 })))
618+
619+
(define-public (stackerdb-get-config)
620+
(ok {
621+
chunk-size: u123,
622+
write-freq: u4,
623+
max-writes: u56,
624+
max-neighbors: u7,
625+
hint-replicas: (list
626+
{
627+
addr: (list u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u255 u255 u142 u150 u80 u100),
628+
port: u8901,
629+
public-key-hash: 0x0123456789abcdef0123456789abcdef01234567
630+
})
631+
}))
632+
"#;
633+
634+
let expected_config = StackerDBConfig {
635+
chunk_size: 123,
636+
signers: vec![(
637+
StacksAddress {
638+
version: 26,
639+
bytes: Hash160::from_hex("b4fdae98b64b9cd6c9436f3b965558966afe890b").unwrap(),
640+
},
641+
3,
642+
)],
643+
write_freq: 4,
644+
max_writes: 56,
645+
hint_replicas: vec![override_replica.clone()],
646+
max_neighbors: 7,
647+
};
648+
649+
let tx = make_smart_contract("test-0", &config_contract, &contract_owner, 0, 10000);
650+
txs.push(tx);
651+
652+
peer.tenure_with_txs(&txs, &mut coinbase_nonce);
653+
654+
peer.with_db_state(|sortdb, chainstate, _, _| {
655+
match StackerDBConfig::from_smart_contract(
656+
chainstate,
657+
sortdb,
658+
&contract_id,
659+
32,
660+
Some(vec![override_replica.clone()]),
661+
) {
662+
Ok(config) => {
663+
assert_eq!(config, expected_config);
664+
}
665+
Err(e) => {
666+
panic!("Unexpected error: {:?}", &e);
667+
}
668+
}
669+
Ok(())
670+
})
671+
.unwrap();
672+
}

0 commit comments

Comments
 (0)