From dbd9c236dd81fa68904394bbcc7871f6e9f926d7 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Mon, 23 Dec 2024 14:47:30 +0100 Subject: [PATCH] Add tests --- src/subcommand/server.rs | 90 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 9 deletions(-) diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 1041f21edc..33748cb824 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -6367,16 +6367,66 @@ next .index_runes() .build(); + let rune = Rune(RUNE); + + let (txid, id) = server.etch( + Runestone { + edicts: vec![Edict { + id: RuneId::default(), + amount: u128::MAX, + output: 0, + }], + etching: Some(Etching { + divisibility: Some(1), + rune: Some(rune), + premine: Some(u128::MAX), + ..default() + }), + ..default() + }, + 1, + None, + ); + + pretty_assert_eq!( + server.index.runes().unwrap(), + [( + id, + RuneEntry { + block: id.block, + divisibility: 1, + etching: txid, + spaced_rune: SpacedRune { rune, spacers: 0 }, + premine: u128::MAX, + timestamp: id.block, + ..default() + } + )] + ); + server.mine_blocks(1); + let address = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqdku202" + .parse::>() + .unwrap() + .require_network(Network::Regtest) + .unwrap(); + + // merge rune with two inscriptions let txid = server.core.broadcast_tx(TransactionTemplate { - inputs: &[(1, 0, 0, inscription("text/plain", "foo").to_witness())], + inputs: &[ + (6, 0, 0, inscription("text/plain", "foo").to_witness()), + (7, 0, 0, inscription("text/plain", "bar").to_witness()), + (7, 1, 0, Witness::new()), + ], + recipient: Some(address.clone()), ..default() }); server.mine_blocks(1); let inscription_id = InscriptionId { txid, index: 0 }; + let second_inscription_id = InscriptionId { txid, index: 1 }; let outpoint: OutPoint = OutPoint { txid, vout: 0 }; let output_recursive = @@ -6385,12 +6435,27 @@ next pretty_assert_eq!( output_recursive, api::OutputRecursive { - address: None, - inscriptions: Some(vec![inscription_id]), - runes: Some(BTreeMap::new()), - sat_ranges: Some(vec![(50 * COIN_VALUE, 100 * COIN_VALUE)]), - script_pubkey: ScriptBuf::new(), - value: 50 * COIN_VALUE, + address: Some(address.as_unchecked().clone()), + inscriptions: Some(vec![inscription_id, second_inscription_id]), + runes: Some( + [( + SpacedRune { rune, spacers: 0 }, + Pile { + amount: u128::MAX, + divisibility: 1, + symbol: None + } + )] + .into_iter() + .collect() + ), + sat_ranges: Some(vec![ + (6 * 50 * COIN_VALUE, 7 * 50 * COIN_VALUE), + (7 * 50 * COIN_VALUE, 8 * 50 * COIN_VALUE), + (50 * COIN_VALUE, 2 * 50 * COIN_VALUE) + ]), + script_pubkey: address.script_pubkey(), + value: 150 * COIN_VALUE, } ); } @@ -6401,8 +6466,15 @@ next server.mine_blocks(1); + let address = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqdku202" + .parse::>() + .unwrap() + .require_network(Network::Regtest) + .unwrap(); + let txid = server.core.broadcast_tx(TransactionTemplate { inputs: &[(1, 0, 0, inscription("text/plain", "foo").to_witness())], + recipient: Some(address.clone()), ..default() }); @@ -6417,11 +6489,11 @@ next pretty_assert_eq!( output_recursive, api::OutputRecursive { - address: None, + address: Some(address.as_unchecked().clone()), inscriptions: Some(vec![inscription_id]), runes: None, sat_ranges: None, - script_pubkey: ScriptBuf::new(), + script_pubkey: address.script_pubkey(), value: 50 * COIN_VALUE, } );