Skip to content

Commit

Permalink
Test that change didn't brake existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph committed Jan 10, 2025
1 parent 2ccac83 commit cf63074
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 11 deletions.
14 changes: 9 additions & 5 deletions crates/mockcore/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub struct State {
pub txid_to_block_height: BTreeMap<Txid, u32>,
pub utxos: BTreeMap<OutPoint, Amount>,
pub version: usize,
pub receive_addresses: Vec<Address>,
pub change_addresses: Vec<Address>,
pub receive_addresses: BTreeSet<Address>,
pub change_addresses: BTreeSet<Address>,
pub wallets: BTreeSet<String>,
pub wallet: Wallet,
}
Expand All @@ -33,7 +33,7 @@ impl State {

Self {
blocks,
change_addresses: Vec::new(),
change_addresses: BTreeSet::new(),
descriptors: Vec::new(),
fail_lock_unspent,
hashes,
Expand All @@ -42,7 +42,7 @@ impl State {
mempool: Vec::new(),
network,
nonce: 0,
receive_addresses: Vec::new(),
receive_addresses: BTreeSet::new(),
transactions: BTreeMap::new(),
txid_to_block_height: BTreeMap::new(),
utxos: BTreeMap::new(),
Expand All @@ -52,6 +52,10 @@ impl State {
}
}

pub fn remove_wallet_address(&mut self, address: Address) {
assert!(self.receive_addresses.remove(&address) || self.change_addresses.remove(&address));
}

pub(crate) fn new_address(&mut self, change: bool) -> Address {
let address = self.wallet.new_address();

Expand All @@ -60,7 +64,7 @@ impl State {
} else {
&mut self.receive_addresses
}
.push(address.clone());
.insert(address.clone());

address
}
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/wallet/offer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;

mod accept;
pub mod accept;
pub mod create;

#[derive(Debug, Parser)]
Expand Down
13 changes: 9 additions & 4 deletions src/subcommand/wallet/offer/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;

#[derive(Debug, Serialize, Deserialize)]
pub struct Output {
pub psbt: String,
pub txid: Txid,
}

Expand Down Expand Up @@ -75,14 +76,18 @@ impl Accept {
.wallet_process_psbt(&base64_encode(&psbt.serialize()), Some(true), None, None)?
.psbt;

let signed_tx = wallet
.bitcoin_client()
.finalize_psbt(&psbt, None)?
let finalized = wallet.bitcoin_client().finalize_psbt(&psbt, None)?;

let signed_tx = finalized
.hex
.ok_or_else(|| anyhow!("unable to sign transaction"))?;

let psbt = finalized
.psbt
.ok_or_else(|| anyhow!("unable to sign transaction"))?;

let txid = wallet.send_raw_transaction(&signed_tx, None)?;

Ok(Some(Box::new(Output { txid })))
Ok(Some(Box::new(Output { psbt, txid })))
}
}
2 changes: 1 addition & 1 deletion tests/wallet/batch_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ inscriptions:
".*
<dt>address</dt>
<dd><a class=collapse href=/address/{0}>{0}</a></dd>.*",
core.state().change_addresses[0],
core.state().change_addresses.iter().next().unwrap(),
),
);

Expand Down
1 change: 1 addition & 0 deletions tests/wallet/offer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::*;

mod accept;
mod create;
46 changes: 46 additions & 0 deletions tests/wallet/offer/accept.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use super::*;

type Accept = ord::subcommand::wallet::offer::accept::Output;

#[test]
fn accepted_offer_works() {
let core = mockcore::spawn();

let ord = TestServer::spawn_with_server_args(&core, &[], &[]);

create_wallet(&core, &ord);

let (inscription, txid) = inscribe_with_options(&core, &ord, Some(9000), 0);

let address = Address::from_script(
&core.tx_by_id(txid).output[0].script_pubkey,
Network::Bitcoin,
)
.unwrap();

core.state().remove_wallet_address(address);
}

#[test]
fn error_on_base64_psbt_decode() {}

#[test]
fn error_on_psbt_deserialize() {}

#[test]
fn psbt_contains_exactly_one_input_owned_by_wallet() {}

#[test]
fn outgoing_does_not_contain_runes() {}

#[test]
fn must_have_inscription_index_to_accept() {}

#[test]
fn exactly_one_outgoing_inscription() {}

#[test]
fn expected_outgoing_inscription() {}

#[test]
fn expected_balance_change() {}

0 comments on commit cf63074

Please sign in to comment.