From da59407655cf6b2fd83002026eb4bee720e6be41 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 9 Jan 2023 19:16:26 -0800 Subject: [PATCH 1/2] Use Inscription::to_witness in test --- src/inscription.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/inscription.rs b/src/inscription.rs index d64519f348..c742a4eaa1 100644 --- a/src/inscription.rs +++ b/src/inscription.rs @@ -591,13 +591,6 @@ mod tests { #[test] fn do_not_extract_from_second_input() { - let script = script::Builder::new() - .push_opcode(opcodes::OP_FALSE) - .push_opcode(opcodes::all::OP_IF) - .push_slice("ord".as_bytes()) - .push_opcode(opcodes::all::OP_ENDIF) - .into_script(); - let tx = Transaction { version: 0, lock_time: bitcoin::PackedLockTime(0), @@ -612,7 +605,7 @@ mod tests { previous_output: OutPoint::null(), script_sig: Script::new(), sequence: Sequence(0), - witness: Witness::from_vec(vec![script.into_bytes(), vec![]]), + witness: inscription("foo", [1; 1040]).to_witness(), }, ], output: Vec::new(), From f42ccbcb1bf2f20a92b9326dfbbf288b7a0282b8 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 9 Jan 2023 19:24:50 -0800 Subject: [PATCH 2/2] Add test that second inscription is ignored --- src/inscription.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/inscription.rs b/src/inscription.rs index c742a4eaa1..82712c2c7b 100644 --- a/src/inscription.rs +++ b/src/inscription.rs @@ -63,7 +63,7 @@ impl Inscription { }) } - pub(crate) fn append_reveal_script(&self, mut builder: script::Builder) -> Script { + fn append_reveal_script_to_builder(&self, mut builder: script::Builder) -> script::Builder { builder = builder .push_opcode(opcodes::OP_FALSE) .push_opcode(opcodes::all::OP_IF) @@ -82,7 +82,11 @@ impl Inscription { } } - builder.push_opcode(opcodes::all::OP_ENDIF).into_script() + builder.push_opcode(opcodes::all::OP_ENDIF) + } + + pub(crate) fn append_reveal_script(&self, builder: script::Builder) -> Script { + self.append_reveal_script_to_builder(builder).into_script() } pub(crate) fn content(&self) -> Option { @@ -614,6 +618,32 @@ mod tests { assert_eq!(Inscription::from_transaction(&tx), None); } + #[test] + fn do_not_extract_from_second_envelope() { + let mut builder = script::Builder::new(); + builder = inscription("foo", [1; 100]).append_reveal_script_to_builder(builder); + builder = inscription("bar", [1; 100]).append_reveal_script_to_builder(builder); + + let witness = Witness::from_vec(vec![builder.into_script().into_bytes(), vec![]]); + + let tx = Transaction { + version: 0, + lock_time: bitcoin::PackedLockTime(0), + input: vec![TxIn { + previous_output: OutPoint::null(), + script_sig: Script::new(), + sequence: Sequence(0), + witness, + }], + output: Vec::new(), + }; + + assert_eq!( + Inscription::from_transaction(&tx), + Some(inscription("foo", [1; 100])) + ); + } + #[test] fn inscribe_png() { assert_eq!(