From 4f3e0362fc5041da023a69c096aced65d2e6de86 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 22 Apr 2024 16:47:34 -0700 Subject: [PATCH] Allow minting if mint begins next block (#3659) Make `ord wallet mint` check whether the rune to be minted is mintable in the next block, since that's the block in which our mint transaction might actually be mined. --- src/subcommand/wallet/mint.rs | 2 +- tests/wallet/mint.rs | 87 +++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/src/subcommand/wallet/mint.rs b/src/subcommand/wallet/mint.rs index 1dd70a0efb..281bdf5fe6 100644 --- a/src/subcommand/wallet/mint.rs +++ b/src/subcommand/wallet/mint.rs @@ -42,7 +42,7 @@ impl Mint { let postage = self.postage.unwrap_or(TARGET_POSTAGE); let amount = rune_entry - .mintable(block_height) + .mintable(block_height + 1) .map_err(|err| anyhow!("rune {rune} {err}"))?; let chain = wallet.chain(); diff --git a/tests/wallet/mint.rs b/tests/wallet/mint.rs index 40f148c83d..b3541613cd 100644 --- a/tests/wallet/mint.rs +++ b/tests/wallet/mint.rs @@ -489,3 +489,90 @@ fn minting_rune_with_postage_dust() { .expected_stderr("error: postage below dust limit of 330sat\n") .run_and_extract_stdout(); } + +#[test] +fn minting_is_allowed_when_mint_begins_next_block() { + let core = mockcore::builder().network(Network::Regtest).build(); + + let ord = TestServer::spawn_with_server_args(&core, &["--index-runes", "--regtest"], &[]); + + core.mine_blocks(1); + + create_wallet(&core, &ord); + + batch( + &core, + &ord, + batch::File { + etching: Some(batch::Etching { + divisibility: 1, + rune: SpacedRune { + rune: Rune(RUNE), + spacers: 0, + }, + premine: "0".parse().unwrap(), + symbol: '¢', + supply: "111.1".parse().unwrap(), + terms: Some(batch::Terms { + cap: 1, + offset: Some(batch::Range { + end: None, + start: Some(1), + }), + amount: "111.1".parse().unwrap(), + height: None, + }), + turbo: false, + }), + inscriptions: vec![batch::Entry { + file: Some("inscription.jpeg".into()), + ..default() + }], + ..default() + }, + ); + + let output = CommandBuilder::new(format!( + "--chain regtest --index-runes wallet mint --fee-rate 1 --rune {}", + Rune(RUNE) + )) + .core(&core) + .ord(&ord) + .run_and_deserialize_output::(); + + core.mine_blocks(1); + + let balances = CommandBuilder::new("--regtest --index-runes balances") + .core(&core) + .ord(&ord) + .run_and_deserialize_output::(); + + pretty_assert_eq!( + output.pile, + Pile { + amount: 1111, + divisibility: 1, + symbol: Some('¢'), + } + ); + + pretty_assert_eq!( + balances, + ord::subcommand::balances::Output { + runes: vec![( + output.rune, + vec![( + OutPoint { + txid: output.mint, + vout: 1 + }, + output.pile, + )] + .into_iter() + .collect() + ),] + .into_iter() + .collect(), + } + ); +}