Skip to content

Commit

Permalink
mine_empty_stacks* should return Result
Browse files Browse the repository at this point in the history
  • Loading branch information
brady.ouren committed Jul 22, 2024
1 parent 973b5f3 commit c9c2b0d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
12 changes: 6 additions & 6 deletions components/clarinet-sdk-wasm/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,20 +930,20 @@ impl SDK {
self.mine_empty_burn_blocks(count)
}
#[wasm_bindgen(js_name=mineEmptyStacksBlock)]
pub fn mine_empty_stacks_block(&mut self) -> u32 {
pub fn mine_empty_stacks_block(&mut self) -> Result<u32, String> {
let session = self.get_session_mut();
match session.advance_stacks_chaintip(1) {
Ok(new_height) => new_height,
Err(msg) => panic!("{}", msg),
Ok(new_height) => Ok(new_height),
Err(msg) => Err(msg),
}
}

#[wasm_bindgen(js_name=mineEmptyStacksBlocks)]
pub fn mine_empty_stacks_blocks(&mut self, count: Option<u32>) -> u32 {
pub fn mine_empty_stacks_blocks(&mut self, count: Option<u32>) -> Result<u32, String> {
let session = self.get_session_mut();
match session.advance_stacks_chaintip(count.unwrap_or(1)) {
Ok(new_height) => new_height,
Err(msg) => panic!("{}", msg),
Ok(new_height) => Ok(new_height),
Err(msg) => Err(msg),
}
}

Expand Down
26 changes: 13 additions & 13 deletions components/clarinet-sdk/node/tests/simnet-usage-epoch3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function deleteExistingDeploymentPlan() {

beforeEach(async () => {
deleteExistingDeploymentPlan();
await fs.copyFileSync(customDeploymentPlanPath, deploymentPlanPath);
fs.copyFileSync(customDeploymentPlanPath, deploymentPlanPath);
simnet = await initSimnet("tests/fixtures/Clarinet.toml");
});

Expand All @@ -39,16 +39,16 @@ describe("basic simnet interactions", () => {
expect(simnet.blockHeight).toBe(1);
});

// it("can mine empty blocks", () => {
// const blockHeight = simnet.stacksBlockHeight;
// const burnBlockHeight = simnet.burnBlockHeight;
// simnet.mineEmptyStacksBlock();
// expect(simnet.stacksBlockHeight).toBe(blockHeight + 1);
// expect(simnet.burnBlockHeight).toBe(burnBlockHeight);
// simnet.mineEmptyStacksBlocks(4);
// expect(simnet.stacksBlockHeight).toBe(blockHeight + 5);
// simnet.mineEmptyBurnBlocks(4);
// expect(simnet.burnBlockHeight).toBe(burnBlockHeight + 4);
// expect(simnet.stacksBlockHeight).toBe(blockHeight + 9);
// })
it("can mine empty blocks", () => {
const blockHeight = simnet.stacksBlockHeight;
const burnBlockHeight = simnet.burnBlockHeight;
simnet.mineEmptyStacksBlock();
expect(simnet.stacksBlockHeight).toBe(blockHeight + 1);
expect(simnet.burnBlockHeight).toBe(burnBlockHeight);
simnet.mineEmptyStacksBlocks(4);
expect(simnet.stacksBlockHeight).toBe(blockHeight + 5);
simnet.mineEmptyBurnBlocks(4);
expect(simnet.burnBlockHeight).toBe(burnBlockHeight + 4);
expect(simnet.stacksBlockHeight).toBe(blockHeight + 9);
})
})
3 changes: 3 additions & 0 deletions components/clarinet-sdk/node/tests/simnet-usage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ describe("basic simnet interactions", () => {
simnet.mineEmptyBlocks(4);
expect(simnet.blockHeight).toBe(blockHeight + 5);
});
it("can not mine empty stacks block in pre-3.0", () => {
expect(() => simnet.mineEmptyStacksBlock()).toThrowError("stacks block height can't be advanced in 2.4");
})

it("exposes devnet stacks accounts", () => {
const accounts = simnet.getAccounts();
Expand Down
2 changes: 1 addition & 1 deletion components/clarity-repl/src/repl/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct BlockInfo {
consensus_hash: ConsensusHash,
vrf_seed: VRFSeed,
burn_block_time: u64,
pub burn_block_height: u32,
burn_block_height: u32,
miner: StacksAddress,
burnchain_tokens_spent_for_block: u128,
get_burnchain_tokens_spent_for_winning_block: u128,
Expand Down

0 comments on commit c9c2b0d

Please sign in to comment.