Skip to content

Commit 11fea64

Browse files
committed
improved coinbase mint and transfer test
1 parent d38a184 commit 11fea64

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed

stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -771,29 +771,36 @@ pub fn next_block_and_process_new_stacks_block(
771771

772772
/// Mine a bitcoin block, and wait until:
773773
/// number_of_blocks has been processed by the coordinator
774-
pub fn next_block_and_process_new_stacks_blocks(
774+
pub fn next_block_and_process_new_stacks_blocks<F>(
775775
btc_controller: &BitcoinRegtestController,
776-
number_of_blocks: u32,
776+
number_of_blocks: u64,
777777
timeout_secs: u64,
778778
coord_channels: &Arc<Mutex<CoordinatorChannels>>,
779-
) -> Result<(), String> {
780-
for _ in 0..number_of_blocks {
781-
let blocks_processed_before = coord_channels
779+
mut post_block_generation: F,
780+
) -> Result<(), String>
781+
where
782+
F: FnMut() -> Result<(), String>,
783+
{
784+
let blocks_processed_before = coord_channels
785+
.lock()
786+
.expect("Mutex poisoned")
787+
.get_stacks_blocks_processed();
788+
let mut block_processed_current = blocks_processed_before;
789+
next_block_and(btc_controller, timeout_secs, || {
790+
let blocks_processed = coord_channels
782791
.lock()
783792
.expect("Mutex poisoned")
784793
.get_stacks_blocks_processed();
785-
next_block_and(btc_controller, timeout_secs, || {
786-
let blocks_processed = coord_channels
787-
.lock()
788-
.expect("Mutex poisoned")
789-
.get_stacks_blocks_processed();
790-
if blocks_processed > blocks_processed_before {
791-
return Ok(true);
792-
}
793-
Ok(false)
794-
})?;
795-
}
796-
Ok(())
794+
// new block?
795+
if blocks_processed > block_processed_current {
796+
post_block_generation()?;
797+
block_processed_current += 1;
798+
}
799+
if blocks_processed >= blocks_processed_before + number_of_blocks {
800+
return Ok(true);
801+
}
802+
Ok(false)
803+
})
797804
}
798805

799806
/// Mine a bitcoin block, and wait until:
@@ -13002,7 +13009,8 @@ fn test_sip_031_last_phase() {
1300213009
let sender_signer_sk = Secp256k1PrivateKey::random();
1300313010
let sender_signer_addr = tests::to_addr(&sender_signer_sk);
1300413011
let mut signers = TestSigners::new(vec![sender_signer_sk]);
13005-
let tenure_count = 5;
13012+
// let's assume funds for 200 tenures
13013+
let tenure_count = 200;
1300613014
let inter_blocks_per_tenure = 9;
1300713015
// setup sender + recipient for some test stx transfers
1300813016
// these are necessary for the interim blocks to get mined at all
@@ -13150,6 +13158,9 @@ fn test_sip_031_last_phase() {
1315013158
)
1315113159
.unwrap();
1315213160

13161+
let http_origin = format!("http://{}", &naka_conf.node.rpc_bind);
13162+
13163+
let mut sender_nonce = 0;
1315313164
// 50 more tenures (each one with 3 stacks blocks)
1315413165
for _ in 0..50 {
1315513166
let commits_before = commits_submitted.load(Ordering::SeqCst);
@@ -13158,6 +13169,19 @@ fn test_sip_031_last_phase() {
1315813169
3,
1315913170
60,
1316013171
&coord_channel,
13172+
|| {
13173+
let transfer_tx = make_stacks_transfer_serialized(
13174+
&sender_sk,
13175+
sender_nonce,
13176+
send_fee,
13177+
naka_conf.burnchain.chain_id,
13178+
&PrincipalData::from(sender_signer_addr),
13179+
send_amt,
13180+
);
13181+
submit_tx(&http_origin, &transfer_tx);
13182+
sender_nonce += 1;
13183+
Ok(())
13184+
},
1316113185
)
1316213186
.unwrap();
1316313187
wait_for(20, || {
@@ -13214,8 +13238,8 @@ fn test_sip_031_last_phase() {
1321413238
}
1321513239
}
1321613240

13217-
// (100_000 + 200_000 + 300_000) * 5
13218-
assert_eq!(total_minted_and_transferred, 3_000_000);
13241+
// (100_000 + 200_000 + 300_000) * 10
13242+
assert_eq!(total_minted_and_transferred, 6_000_000);
1321913243

1322013244
let latest_stacks_block_id = get_latest_block_proposal(&naka_conf, &sortdb)
1322113245
.unwrap()

0 commit comments

Comments
 (0)