Skip to content

Commit

Permalink
Merge #97: Fix integration tests
Browse files Browse the repository at this point in the history
5a7c2b6 fix: fuzz regression (Christian Lewe)
6ce45fa fix: integration test fails at runtime (Christian Lewe)
977eb6c chore: Update elements nix derivation (Christian Lewe)

Pull request description:

  Bring the integration tests up to speed with Liquid testnet. Fix a bug that the fuzzer found.

ACKs for top commit:
  apoelstra:
    ACK 5a7c2b6 successfully ran local tests

Tree-SHA512: fdebb2e91be2a69a00d8e1daa1c1a90652075309a09ee39a95f8da98152720b605045000aa3af7f65ef1f10647e28fd04fad82ce87576a3044d69427a6168958
  • Loading branch information
uncomputable committed Oct 12, 2024
2 parents 8432240 + 5a7c2b6 commit 67eabe5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
6 changes: 3 additions & 3 deletions bitcoind-tests/elementsd-simplicity.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{ pkgs
}:
pkgs.elementsd.overrideAttrs (_: {
version = "unstable-2024-09-02";
version = "liquid-testnet-2024-10-08";
src = pkgs.fetchFromGitHub {
owner = "ElementsProject";
repo = "elements";
rev = "37c231153a9c61f02f932c2cb802656ae47cff32"; # <-- update this to latest `simplicity` branch: https://github.com/ElementsProject/elements/commits/simplicity
sha256 = "sha256-QYywe7lfBQIjp7CecxA/6/XsWAOaBckGbT432Xe2ru0="; # <-- overwrite this, rerun and place the expected hash
rev = "f957d3cde17c85afb18c6747f9c0b4fcb599f19a"; # <-- update this to latest `simplicity` branch: https://github.com/ElementsProject/elements/commits/simplicity
sha256 = "sha256-XzdfbrQ7s4PfM5N00oP1jo5BNmD4WUMUe79QsTxsL4s="; # <-- overwrite this, rerun and place the expected hash
};
withWallet = true;
withGui = false;
Expand Down
1 change: 1 addition & 0 deletions bitcoind-tests/tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub fn setup() -> (ElementsD, elements::BlockHash) {
Some(i) => conf.0.args[i] = "-initialfreecoins=210000000000",
None => conf.0.args.push("-initialfreecoins=210000000000"),
};
conf.0.args.push("-evbparams=simplicity:-1:::");

let elementsd = ElementsD::with_conf(elementsd::exe_path().unwrap(), &conf).unwrap();

Expand Down
18 changes: 10 additions & 8 deletions bitcoind-tests/tests/test_arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! Arith expression fragment integration tests
//!

use std::path::Path;
use std::str::FromStr;

use ::secp256k1::XOnlyPublicKey;
Expand Down Expand Up @@ -38,12 +37,15 @@ fn get_vout(cl: &ElementsD, txid: Txid, value: u64, spk: Script) -> (OutPoint, T
unreachable!("Only call get vout on functions which have the expected outpoint");
}

pub fn test_simplicity(cl: &ElementsD, program_file: &str, witness_file: &str) {
let program_path = Path::new(program_file);
let witness_path = Path::new(witness_file);
let program_text = std::fs::read_to_string(program_path).unwrap();
let witness_text = std::fs::read_to_string(witness_path).unwrap();
let witness_values = serde_json::from_str::<WitnessValues>(&witness_text).unwrap();
pub fn test_simplicity(cl: &ElementsD, program_file: &str, witness_file: Option<&str>) {
let program_text = std::fs::read_to_string(program_file).unwrap();
let witness_values = match witness_file {
Some(file) => {
let text = std::fs::read_to_string(file).unwrap();
serde_json::from_str::<WitnessValues>(&text).unwrap()
}
None => WitnessValues::default(),
};
let program = SatisfiedProgram::new(&program_text, &witness_values).unwrap();

let secp = secp256k1::Secp256k1::new();
Expand Down Expand Up @@ -99,6 +101,6 @@ fn test_arith() {
let (cl, _genesis_hash) = &setup::setup();
println!("{}", cl.get_new_address());

test_simplicity(cl, "../examples/cat.simf", "../examples/empty.wit");
test_simplicity(cl, "../examples/cat.simf", None);
// TODO: Other examples require custom signatures
}
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,12 @@ fn main() {

#[test]
fn fuzz_regression_1() {
CompiledProgram::new("type f=f").unwrap_err();
parse::Program::parse_from_str("type f=f").unwrap();
}

#[test]
fn fuzz_regression_2() {
parse::Program::parse_from_str("fn dbggscas(h: bool, asyxhaaaa: a) {\nfalse}\n\n").unwrap();
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/minimal.pest
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ block_expression = { "{" ~ (statement ~ ";")* ~ expression? ~ "}" }
identifier = @{ !builtin_type ~ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC | "_")* }
jet = @{ "jet::" ~ (ASCII_ALPHANUMERIC | "_")+ }
witness_name = @{ (ASCII_ALPHANUMERIC | "_")+ }
builtin_type = @{ "Either" | "Option" | "bool" | "List" | unsigned_type }
builtin_type = @{ ("Either" | "Option" | "bool" | "List" | unsigned_type) ~ !ASCII_ALPHANUMERIC }

builtin_function = @{ jet | "unwrap_left" | "unwrap_right" | "for_while" | "is_none" | "unwrap" | "assert" | "panic" | "match" | "into" | "fold" | "dbg" }
builtin_function = @{ (jet | "unwrap_left" | "unwrap_right" | "for_while" | "is_none" | "unwrap" | "assert" | "panic" | "match" | "into" | "fold" | "dbg") ~ !ASCII_ALPHANUMERIC }
function_name = { !builtin_function ~ identifier }
typed_identifier = { identifier ~ ":" ~ ty }
function_params = { "(" ~ (typed_identifier ~ ("," ~ typed_identifier)*)? ~ ")" }
Expand Down

0 comments on commit 67eabe5

Please sign in to comment.