Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph committed Mar 16, 2024
1 parent 697712c commit 83cf72c
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/runes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use {

pub use {edict::Edict, rune::Rune, rune_id::RuneId, runestone::Runestone};

pub(crate) use {etching::Etching, mint::Mint, pile::Pile, spaced_rune::SpacedRune};
pub use {etching::Etching, mint::Mint, pile::Pile, spaced_rune::SpacedRune};

pub const MAX_DIVISIBILITY: u8 = 38;
pub(crate) const MAX_LIMIT: u128 = 1 << 64;
pub const MAX_LIMIT: u128 = 1 << 64;
const RESERVED: u128 = 6402364363415443603228541259936211926;

mod edict;
Expand Down
5 changes: 3 additions & 2 deletions src/runes/mint.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::*;

// This is for etching
#[derive(Default, Serialize, Debug, PartialEq, Copy, Clone)]
pub struct Mint {
pub deadline: Option<u32>, // unix timestamp
pub limit: Option<u128>, // absolute block height
pub term: Option<u32>, // relative to etch height
pub limit: Option<u128>, // max amount mintable per tx
pub term: Option<u32>, // relative to mint height
}
2 changes: 1 addition & 1 deletion src/runes/runestone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl Runestone {
}))
}

pub(crate) fn encipher(&self) -> ScriptBuf {
pub fn encipher(&self) -> ScriptBuf {
let mut payload = Vec::new();

if let Some(etching) = self.etching {
Expand Down
11 changes: 8 additions & 3 deletions src/subcommand/wallet/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pub(crate) struct Mint {
#[derive(Serialize, Deserialize, Debug)]
pub struct Output {
pub rune: SpacedRune,
// pub amount: Pile,
pub transaction: Txid,
pub pile: Pile,
pub txid: Txid,
}

impl Mint {
Expand Down Expand Up @@ -107,7 +107,12 @@ impl Mint {

Ok(Some(Box::new(Output {
rune: self.rune,
transaction,
pile: Pile {
amount: mint.limit.unwrap_or(crate::runes::MAX_LIMIT),
divisibility: rune_entry.divisibility,
symbol: rune_entry.symbol,
},
txid: transaction,
})))
}
}
1 change: 1 addition & 0 deletions tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod create;
mod dump;
mod inscribe;
mod inscriptions;
mod mint;
mod outputs;
mod receive;
mod restore;
Expand Down
101 changes: 101 additions & 0 deletions tests/wallet/mint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
use {
super::*,
bitcoin::Witness,
ord::{
runes::{Etching, Mint},
subcommand::wallet::mint::Output,
},
};

#[test]
fn minting_rune_works() {
let bitcoin_rpc_server = test_bitcoincore_rpc::builder()
.network(Network::Regtest)
.build();

let ord_rpc_server =
TestServer::spawn_with_server_args(&bitcoin_rpc_server, &["--index-runes", "--regtest"], &[]);

bitcoin_rpc_server.mine_blocks(1);

create_wallet(&bitcoin_rpc_server, &ord_rpc_server);

CommandBuilder::new(format!(
"--chain regtest --index-runes wallet mint --fee-rate 1 --rune {}",
Rune(RUNE)
))
.bitcoin_rpc_server(&bitcoin_rpc_server)
.ord_rpc_server(&ord_rpc_server)
.expected_exit_code(1)
.expected_stderr("error: Rune AAAAAAAAAAAAA does not exist\n")
.run_and_extract_stdout();

bitcoin_rpc_server.broadcast_tx(TransactionTemplate {
inputs: &[(1, 0, 0, Witness::new())],
op_return: Some(
Runestone {
etching: Some(Etching {
rune: Some(Rune(RUNE)),
mint: Some(Mint {
limit: Some(1111),
term: Some(2),
..Default::default()
}),
..Default::default()
}),
..Default::default()
}
.encipher(),
),
..Default::default()
});

bitcoin_rpc_server.mine_blocks(1);

let output = CommandBuilder::new(format!(
"--chain regtest --index-runes wallet mint --fee-rate 1 --rune {}",
Rune(RUNE)
))
.bitcoin_rpc_server(&bitcoin_rpc_server)
.ord_rpc_server(&ord_rpc_server)
.run_and_deserialize_output::<mint::Output>();

bitcoin_rpc_server.mine_blocks(1);

let balances = CommandBuilder::new("--regtest --index-runes balances")
.bitcoin_rpc_server(&bitcoin_rpc_server)
.ord_rpc_server(&ord_rpc_server)
.run_and_deserialize_output::<ord::subcommand::balances::Output>();

assert_eq!(
balances,
ord::subcommand::balances::Output {
runes: vec![(
Rune(RUNE),
vec![(
OutPoint {
txid: output.txid,
vout: 1
},
1111
)]
.into_iter()
.collect()
),]
.into_iter()
.collect(),
}
);

bitcoin_rpc_server.mine_blocks(1);

CommandBuilder::new(format!(
"--chain regtest --index-runes wallet mint --fee-rate 1 --rune {}",
Rune(RUNE)
))
.bitcoin_rpc_server(&bitcoin_rpc_server)
.ord_rpc_server(&ord_rpc_server)
.expected_exit_code(1)
.expected_stderr("error: Mint block height end of 4 for rune AAAAAAAAAAAAA has passed\n")
.run_and_extract_stdout();
}
74 changes: 37 additions & 37 deletions tests/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,43 @@ fn send_btc_does_not_send_locked_utxos() {
.run_and_extract_stdout();
}

#[test]
fn send_dry_run() {
let bitcoin_rpc_server = test_bitcoincore_rpc::spawn();

let ord_rpc_server = TestServer::spawn_with_server_args(&bitcoin_rpc_server, &[], &[]);

create_wallet(&bitcoin_rpc_server, &ord_rpc_server);

bitcoin_rpc_server.mine_blocks(1);

let (inscription, _) = inscribe(&bitcoin_rpc_server, &ord_rpc_server);

bitcoin_rpc_server.mine_blocks(1);

let output = CommandBuilder::new(format!(
"wallet send --fee-rate 1 bc1qcqgs2pps4u4yedfyl5pysdjjncs8et5utseepv {inscription} --dry-run",
))
.bitcoin_rpc_server(&bitcoin_rpc_server)
.ord_rpc_server(&ord_rpc_server)
.run_and_deserialize_output::<send::Output>();

assert!(bitcoin_rpc_server.mempool().is_empty());
assert_eq!(
Psbt::deserialize(
&base64::engine::general_purpose::STANDARD
.decode(output.psbt)
.unwrap()
)
.unwrap()
.fee()
.unwrap()
.to_sat(),
output.fee
);
assert_eq!(output.outgoing, Outgoing::InscriptionId(inscription));
}

#[test]
fn sending_rune_that_has_not_been_etched_is_an_error() {
let bitcoin_rpc_server = test_bitcoincore_rpc::builder()
Expand Down Expand Up @@ -1083,40 +1120,3 @@ fn sending_rune_does_not_send_inscription() {
.stderr_regex("error:.*")
.run_and_extract_stdout();
}

#[test]
fn send_dry_run() {
let bitcoin_rpc_server = test_bitcoincore_rpc::spawn();

let ord_rpc_server = TestServer::spawn_with_server_args(&bitcoin_rpc_server, &[], &[]);

create_wallet(&bitcoin_rpc_server, &ord_rpc_server);

bitcoin_rpc_server.mine_blocks(1);

let (inscription, _) = inscribe(&bitcoin_rpc_server, &ord_rpc_server);

bitcoin_rpc_server.mine_blocks(1);

let output = CommandBuilder::new(format!(
"wallet send --fee-rate 1 bc1qcqgs2pps4u4yedfyl5pysdjjncs8et5utseepv {inscription} --dry-run",
))
.bitcoin_rpc_server(&bitcoin_rpc_server)
.ord_rpc_server(&ord_rpc_server)
.run_and_deserialize_output::<send::Output>();

assert!(bitcoin_rpc_server.mempool().is_empty());
assert_eq!(
Psbt::deserialize(
&base64::engine::general_purpose::STANDARD
.decode(output.psbt)
.unwrap()
)
.unwrap()
.fee()
.unwrap()
.to_sat(),
output.fee
);
assert_eq!(output.outgoing, Outgoing::InscriptionId(inscription));
}

0 comments on commit 83cf72c

Please sign in to comment.