Skip to content

Commit

Permalink
Mandatory fee rate for inscribe (#1897)
Browse files Browse the repository at this point in the history
Co-authored-by: Greg Martin <[email protected]>
Co-authored-by: raphjaph <[email protected]>
  • Loading branch information
3 people authored Mar 27, 2023
1 parent a314534 commit 92157e5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 40 deletions.
2 changes: 1 addition & 1 deletion docs/src/guides/inscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Creating Inscriptions
To create an inscription with the contents of `FILE`, run:

```
ord wallet inscribe FILE
ord wallet inscribe --fee-rate FEE_RATE FILE
```

Ord will output two transactions IDs, one for the commit transaction, and one
Expand Down
6 changes: 1 addition & 5 deletions src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ struct Output {
pub(crate) struct Inscribe {
#[clap(long, help = "Inscribe <SATPOINT>")]
pub(crate) satpoint: Option<SatPoint>,
#[clap(
long,
default_value = "1.0",
help = "Use fee rate of <FEE_RATE> sats/vB"
)]
#[clap(long, help = "Use fee rate of <FEE_RATE> sats/vB")]
pub(crate) fee_rate: FeeRate,
#[clap(
long,
Expand Down
2 changes: 1 addition & 1 deletion tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct Inscribe {
fn inscribe(rpc_server: &test_bitcoincore_rpc::Handle) -> Inscribe {
rpc_server.mine_blocks(1);

let output = CommandBuilder::new("wallet inscribe foo.txt")
let output = CommandBuilder::new("wallet inscribe --fee-rate 1 foo.txt")
.write("foo.txt", "FOO")
.rpc_server(rpc_server)
.output();
Expand Down
72 changes: 39 additions & 33 deletions tests/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn inscribe_works_with_huge_expensive_inscriptions() {
fn inscribe_fails_if_bitcoin_core_is_too_old() {
let rpc_server = test_bitcoincore_rpc::builder().version(230000).build();

CommandBuilder::new("wallet inscribe hello.txt")
CommandBuilder::new("wallet inscribe hello.txt --fee-rate 1")
.write("hello.txt", "HELLOWORLD")
.expected_exit_code(1)
.expected_stderr("error: Bitcoin Core 24.0.0 or newer required, current version is 23.0.0\n")
Expand All @@ -58,7 +58,7 @@ fn inscribe_no_backup() {
create_wallet(&rpc_server);
assert_eq!(rpc_server.descriptors().len(), 2);

CommandBuilder::new("wallet inscribe hello.txt --no-backup")
CommandBuilder::new("wallet inscribe hello.txt --no-backup --fee-rate 1")
.write("hello.txt", "HELLOWORLD")
.rpc_server(&rpc_server)
.output::<Inscribe>();
Expand All @@ -72,7 +72,7 @@ fn inscribe_unknown_file_extension() {
create_wallet(&rpc_server);
rpc_server.mine_blocks(1);

CommandBuilder::new("wallet inscribe pepe.xyz")
CommandBuilder::new("wallet inscribe pepe.xyz --fee-rate 1")
.write("pepe.xyz", [1; 520])
.rpc_server(&rpc_server)
.expected_exit_code(1)
Expand All @@ -88,7 +88,7 @@ fn inscribe_exceeds_chain_limit() {
create_wallet(&rpc_server);
rpc_server.mine_blocks(1);

CommandBuilder::new("--chain signet wallet inscribe degenerate.png")
CommandBuilder::new("--chain signet wallet inscribe degenerate.png --fee-rate 1")
.write("degenerate.png", [1; 1025])
.rpc_server(&rpc_server)
.expected_exit_code(1)
Expand All @@ -106,7 +106,7 @@ fn regtest_has_no_content_size_limit() {
create_wallet(&rpc_server);
rpc_server.mine_blocks(1);

CommandBuilder::new("--chain regtest wallet inscribe degenerate.png")
CommandBuilder::new("--chain regtest wallet inscribe degenerate.png --fee-rate 1")
.write("degenerate.png", [1; 1025])
.rpc_server(&rpc_server)
.stdout_regex(".*")
Expand All @@ -121,7 +121,7 @@ fn mainnet_has_no_content_size_limit() {
create_wallet(&rpc_server);
rpc_server.mine_blocks(1);

CommandBuilder::new("wallet inscribe degenerate.png")
CommandBuilder::new("wallet inscribe degenerate.png --fee-rate 1")
.write("degenerate.png", [1; 1025])
.rpc_server(&rpc_server)
.stdout_regex(".*")
Expand All @@ -136,7 +136,7 @@ fn inscribe_does_not_use_inscribed_sats_as_cardinal_utxos() {
rpc_server.mine_blocks_with_subsidy(1, 100);

CommandBuilder::new(
"wallet inscribe degenerate.png"
"wallet inscribe degenerate.png --fee-rate 1"
)
.rpc_server(&rpc_server)
.write("degenerate.png", [1; 100])
Expand All @@ -156,12 +156,14 @@ fn refuse_to_reinscribe_sats() {

rpc_server.mine_blocks_with_subsidy(1, 100);

CommandBuilder::new(format!("wallet inscribe --satpoint {reveal}:0:0 hello.txt"))
.write("hello.txt", "HELLOWORLD")
.rpc_server(&rpc_server)
.expected_exit_code(1)
.expected_stderr(format!("error: sat at {reveal}:0:0 already inscribed\n"))
.run();
CommandBuilder::new(format!(
"wallet inscribe --satpoint {reveal}:0:0 hello.txt --fee-rate 1"
))
.write("hello.txt", "HELLOWORLD")
.rpc_server(&rpc_server)
.expected_exit_code(1)
.expected_stderr(format!("error: sat at {reveal}:0:0 already inscribed\n"))
.run();
}

#[test]
Expand All @@ -181,7 +183,7 @@ fn refuse_to_inscribe_already_inscribed_utxo() {
};

CommandBuilder::new(format!(
"wallet inscribe --satpoint {output}:55555 hello.txt"
"wallet inscribe --satpoint {output}:55555 hello.txt --fee-rate 1"
))
.write("hello.txt", "HELLOWORLD")
.rpc_server(&rpc_server)
Expand All @@ -198,11 +200,12 @@ fn inscribe_with_optional_satpoint_arg() {
create_wallet(&rpc_server);
let txid = rpc_server.mine_blocks(1)[0].txdata[0].txid();

let Inscribe { inscription, .. } =
CommandBuilder::new(format!("wallet inscribe foo.txt --satpoint {txid}:0:0"))
.write("foo.txt", "FOO")
.rpc_server(&rpc_server)
.output();
let Inscribe { inscription, .. } = CommandBuilder::new(format!(
"wallet inscribe foo.txt --satpoint {txid}:0:0 --fee-rate 1"
))
.write("foo.txt", "FOO")
.rpc_server(&rpc_server)
.output();

rpc_server.mine_blocks(1);

Expand Down Expand Up @@ -262,10 +265,12 @@ fn inscribe_with_commit_fee_rate() {
create_wallet(&rpc_server);
rpc_server.mine_blocks(1);

CommandBuilder::new("--index-sats wallet inscribe degenerate.png --commit-fee-rate 2.0")
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.output::<Inscribe>();
CommandBuilder::new(
"--index-sats wallet inscribe degenerate.png --commit-fee-rate 2.0 --fee-rate 1",
)
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.output::<Inscribe>();

let tx1 = &rpc_server.mempool()[0];
let mut fee = 0;
Expand Down Expand Up @@ -307,7 +312,7 @@ fn inscribe_with_wallet_named_foo() {

rpc_server.mine_blocks(1);

CommandBuilder::new("--wallet foo wallet inscribe degenerate.png")
CommandBuilder::new("--wallet foo wallet inscribe degenerate.png --fee-rate 1")
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.output::<Inscribe>();
Expand All @@ -319,14 +324,14 @@ fn inscribe_with_dry_run_flag() {
create_wallet(&rpc_server);
rpc_server.mine_blocks(1);

CommandBuilder::new("wallet inscribe --dry-run degenerate.png")
CommandBuilder::new("wallet inscribe --dry-run degenerate.png --fee-rate 1")
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.output::<Inscribe>();

assert!(rpc_server.mempool().is_empty());

CommandBuilder::new("wallet inscribe degenerate.png")
CommandBuilder::new("wallet inscribe degenerate.png --fee-rate 1")
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.output::<Inscribe>();
Expand All @@ -340,11 +345,12 @@ fn inscribe_with_dry_run_flag_fees_inscrease() {
create_wallet(&rpc_server);
rpc_server.mine_blocks(1);

let total_fee_dry_run = CommandBuilder::new("wallet inscribe --dry-run degenerate.png")
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.output::<Inscribe>()
.fees;
let total_fee_dry_run =
CommandBuilder::new("wallet inscribe --dry-run degenerate.png --fee-rate 1")
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.output::<Inscribe>()
.fees;

let total_fee_normal =
CommandBuilder::new("wallet inscribe --dry-run degenerate.png --fee-rate 1.1")
Expand All @@ -368,7 +374,7 @@ fn inscribe_to_specific_destination() {
.address;

let txid = CommandBuilder::new(format!(
"wallet inscribe --destination {destination} degenerate.png"
"wallet inscribe --destination {destination} degenerate.png --fee-rate 1"
))
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
Expand All @@ -390,7 +396,7 @@ fn inscribe_with_no_limit() {
rpc_server.mine_blocks(1);

let four_megger = std::iter::repeat(0).take(4_000_000).collect::<Vec<u8>>();
CommandBuilder::new("wallet inscribe --no-limit degenerate.png")
CommandBuilder::new("wallet inscribe --no-limit degenerate.png --fee-rate 1")
.write("degenerate.png", four_megger)
.rpc_server(&rpc_server);
}

0 comments on commit 92157e5

Please sign in to comment.