From 26fcf05a738e68ef8c9c18fcc0997ccf931d6f41 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 11 Apr 2024 14:02:28 -0700 Subject: [PATCH] Forbid etching below rune activation height (#3523) Don't allow etching if the etching reveal height is below the runes activation height, otherwise the user would waste funds on an ineffective etching. --- src/subcommand/wallet/batch_command.rs | 7 +++++ tests/wallet/batch_command.rs | 42 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/subcommand/wallet/batch_command.rs b/src/subcommand/wallet/batch_command.rs index 1655585333..b5fd837499 100644 --- a/src/subcommand/wallet/batch_command.rs +++ b/src/subcommand/wallet/batch_command.rs @@ -122,6 +122,13 @@ impl Batch { let reveal_height = current_height + u32::from(Runestone::COMMIT_CONFIRMATIONS); + let first_rune_height = Rune::first_rune_height(wallet.chain().into()); + + ensure!( + reveal_height >= first_rune_height, + "rune reveal height below rune activation height: {reveal_height} < {first_rune_height}", + ); + if let Some(terms) = etching.terms { if let Some((start, end)) = terms.offset.and_then(|range| range.start.zip(range.end)) { ensure!( diff --git a/tests/wallet/batch_command.rs b/tests/wallet/batch_command.rs index 7418b57e18..2197eec2d8 100644 --- a/tests/wallet/batch_command.rs +++ b/tests/wallet/batch_command.rs @@ -2699,3 +2699,45 @@ fn batch_inscribe_errors_if_pending_etchings() { ) .run_and_extract_stdout(); } + +#[test] +fn forbid_etching_below_rune_activation_height() { + let core = mockcore::builder().build(); + + let ord = TestServer::spawn_with_server_args(&core, &["--index-runes"], &[]); + + create_wallet(&core, &ord); + + core.mine_blocks(1); + + CommandBuilder::new("--index-runes wallet batch --fee-rate 0 --batch batch.yaml") + .write("inscription.txt", "foo") + .write( + "batch.yaml", + serde_yaml::to_string(&batch::File { + etching: Some(batch::Etching { + divisibility: 0, + rune: SpacedRune { + rune: Rune(RUNE), + spacers: 0, + }, + supply: "1".parse().unwrap(), + premine: "1".parse().unwrap(), + symbol: 'ยข', + terms: None, + turbo: false, + }), + inscriptions: vec![batch::Entry { + file: Some("inscription.txt".into()), + ..default() + }], + ..default() + }) + .unwrap(), + ) + .core(&core) + .ord(&ord) + .expected_stderr("error: rune reveal height below rune activation height: 7 < 840000\n") + .expected_exit_code(1) + .run_and_extract_stdout(); +}