Skip to content

Commit

Permalink
WIP: initial stab at getting peer node to work for scenario 5
Browse files Browse the repository at this point in the history
Signed-off-by: Jacinta Ferrant <[email protected]>
  • Loading branch information
jferrant committed Mar 25, 2024
1 parent 575cf58 commit f2e6c05
Show file tree
Hide file tree
Showing 5 changed files with 690 additions and 10 deletions.
39 changes: 39 additions & 0 deletions stackslib/src/chainstate/nakamoto/coordinator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use crate::chainstate::nakamoto::tests::get_account;
use crate::chainstate::nakamoto::tests::node::TestStacker;
use crate::chainstate::nakamoto::{NakamotoBlock, NakamotoChainState};
use crate::chainstate::stacks::address::PoxAddress;
use crate::chainstate::stacks::boot::pox_4_tests::{get_stacking_minimum, get_tip};
use crate::chainstate::stacks::boot::signers_tests::{readonly_call, readonly_call_with_sortdb};
use crate::chainstate::stacks::boot::test::{
key_to_stacks_addr, make_pox_4_lockup, make_signer_key_signature,
Expand Down Expand Up @@ -222,6 +223,44 @@ pub fn make_all_signers_vote_for_aggregate_key(
.collect()
}

// Create a peer configured for for testing Nakamoto functionality
pub fn nakamoto_peer<'a>(
test_name: &str,
mut initial_balances: Vec<(PrincipalData, u64)>,
test_signers: &mut TestSigners,
observer: Option<&'a TestEventObserver>,
) -> TestPeer<'a> {
let aggregate_public_key = test_signers.aggregate_public_key.clone();
let mut peer_config = TestPeerConfig::new(test_name, 0, 0);
let private_key = peer_config.private_key.clone();
let addr = StacksAddress::from_public_keys(
C32_ADDRESS_VERSION_TESTNET_SINGLESIG,
&AddressHashMode::SerializeP2PKH,
1,
&vec![StacksPublicKey::from_private(&private_key)],
)
.unwrap();

// reward cycles are 5 blocks long
// first 25 blocks are boot-up
// reward cycle 6 instantiates pox-3
// we stack in reward cycle 7 so pox-3 is evaluated to find reward set participation
peer_config.aggregate_public_key = Some(aggregate_public_key.clone());
peer_config
.stacker_dbs
.push(boot_code_id(MINERS_NAME, false));
peer_config.epochs = Some(StacksEpoch::unit_test_3_0_only(37));
peer_config.initial_balances = vec![(addr.to_account_principal(), 1_000_000_000_000_000_000)];

peer_config.initial_balances.append(&mut initial_balances);
peer_config.burnchain.pox_constants.v2_unlock_height = 21;
peer_config.burnchain.pox_constants.pox_3_activation_height = 26;
peer_config.burnchain.pox_constants.v3_unlock_height = 27;
peer_config.burnchain.pox_constants.pox_4_activation_height = 31;
peer_config.test_signers = Some(test_signers.clone());
TestPeer::new_with_observer(peer_config, observer)
}

/// Make a peer and transition it into the Nakamoto epoch.
/// The node needs to be stacking and it needs to vote for an aggregate key;
/// otherwise, Nakamoto can't activate.
Expand Down
57 changes: 57 additions & 0 deletions stackslib/src/chainstate/stacks/boot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,63 @@ pub mod test {
}
}

pub fn get_stacker_info_pox_4(
peer: &mut TestPeer,
addr: &PrincipalData,
) -> Option<(PoxAddress, u128, u128, Vec<u128>)> {
let value_opt = eval_at_tip(
peer,
"pox-4",
&format!("(get-stacker-info '{})", addr.to_string()),
);
let data = if let Some(d) = value_opt.expect_optional().unwrap() {
d
} else {
return None;
};
// { pox-addr: pox-addr,
// first-reward-cycle: first-reward-cycle,
// reward-set-indexes: (list),
// lock-period: lock-period,
// delegated-to: (some tx-sender) }

let data = data.expect_tuple().unwrap();
let pox_addr = tuple_to_pox_addr(
data.get("pox-addr")
.unwrap()
.to_owned()
.expect_tuple()
.unwrap(),
);
let first_reward_cycle = data
.get("first-reward-cycle")
.unwrap()
.to_owned()
.expect_u128()
.unwrap();
let lock_period = data
.get("lock-period")
.unwrap()
.to_owned()
.expect_u128()
.unwrap();
let reward_set_indices = data
.get("reward-set-indexes")
.unwrap()
.to_owned()
.expect_list()
.unwrap()
.iter()
.map(|v| v.to_owned().expect_u128().unwrap())
.collect();
Some((
pox_addr,
first_reward_cycle,
lock_period,
reward_set_indices,
))
}

pub fn get_stacker_info(
peer: &mut TestPeer,
addr: &PrincipalData,
Expand Down
Loading

0 comments on commit f2e6c05

Please sign in to comment.