Skip to content

Commit

Permalink
Fix fuzz testers (#3740)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeasonstudio authored May 17, 2024
1 parent 6cc8212 commit 0a5ffd6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
31 changes: 26 additions & 5 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/runestone_decipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ fuzz_target!(|input: Vec<Vec<u8>>| {
version: 2,
};

Runestone::from_transaction(&tx);
Runestone::decipher(&tx);
});
30 changes: 15 additions & 15 deletions fuzz/fuzz_targets/transaction_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use {
arbitrary::Arbitrary,
bitcoin::{
address::{Address, NetworkUnchecked},
Amount, OutPoint,
Amount, OutPoint, TxOut,
},
libfuzzer_sys::fuzz_target,
ord::{FeeRate, Target, TransactionBuilder},
ord::{FeeRate, InscriptionId, Target, TransactionBuilder},
ordinals::SatPoint,
std::collections::{BTreeMap, BTreeSet},
};
Expand All @@ -16,7 +16,6 @@ use {
struct Input {
output_value: Option<u64>,
fee_rate: f64,
utxos: Vec<u64>,
}

fuzz_target!(|input: Input| {
Expand All @@ -29,23 +28,24 @@ fuzz_target!(|input: Input| {
.unwrap();

let inscription_id = "1111111111111111111111111111111111111111111111111111111111111111i1"
.parse()
.parse::<InscriptionId>()
.unwrap();

let mut inscriptions = BTreeMap::new();
inscriptions.insert(satpoint, inscription_id);
inscriptions.insert(satpoint, vec![inscription_id]);

let address = "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4"
.parse::<Address<NetworkUnchecked>>()
.unwrap()
.assume_checked();
let mut amounts = BTreeMap::new();
amounts.insert(outpoint, Amount::from_sat(1_000_000));

for (i, value) in input.utxos.into_iter().enumerate() {
amounts.insert(
format!("0000000000000000000000000000000000000000000000000000000000000000:{i}",)
.parse()
.unwrap(),
Amount::from_sat(value),
);
}
amounts.insert(
outpoint,
TxOut {
value: 50_000,
script_pubkey: address.script_pubkey(),
},
);

let recipient = "bc1pdqrcrxa8vx6gy75mfdfj84puhxffh4fq46h3gkp6jxdd0vjcsdyspfxcv6"
.parse::<Address<NetworkUnchecked>>()
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/varint_decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fuzz_target!(|input: &[u8]| {
let mut i = 0;

while i < input.len() {
let Some((decoded, length)) = varint::decode(&input[i..]) else {
let Ok((decoded, length)) = varint::decode(&input[i..]) else {
break;
};
let mut encoded = Vec::new();
Expand Down

0 comments on commit 0a5ffd6

Please sign in to comment.