Skip to content

Commit

Permalink
Test that inscriptions in additional envelopes and outputs are ignored (
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Jan 10, 2023
1 parent f7195cd commit e8a6b74
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions src/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<Content> {
Expand Down Expand Up @@ -591,13 +595,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),
Expand All @@ -612,7 +609,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(),
Expand All @@ -621,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!(
Expand Down

0 comments on commit e8a6b74

Please sign in to comment.