Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: CI

# Build and test on every push to main and every pull request.
#
# The `simplicityhl` git dependency dominates build time, so both jobs lean on
# `Swatinem/rust-cache` and run with `--locked`: the lock file pins that dependency to
# an exact rev, and a build that silently updated it would no longer be testing what a
# release builds.
on:
push:
branches: [main]
pull_request:

# A new push to a PR makes the in-flight run obsolete; don't pay to finish it.
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always

jobs:
test:
name: test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
# Linux is the reference platform; Windows is what the project is developed on
# and what `tests/cli_parses_examples.rs` exercises path handling against.
os: [ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Cache cargo build
uses: Swatinem/rust-cache@v2

# Plain `cargo test` (not `--all-targets`) so doc-tests run too. This also
# compiles `examples/`, which is what keeps `gen_schema` from bit-rotting.
#
# Deliberately NOT `--all-features`: the `simplicity_eval` feature needs the
# `compile_function` fork of SimplicityHL, and does not compile against the
# upstream master rev this workspace pins. See txmanifest_lib/Cargo.toml.
- name: Test
run: cargo test --workspace --locked

lint:
name: lint
runs-on: ubuntu-latest
timeout-minutes: 30
# NON-BLOCKING for now: the tree is not yet rustfmt-clean and clippy reports 22
# warnings (all warnings, no errors). This job exists to make both visible on a PR
# without gating merges on a cleanup nobody has done yet.
#
# To turn it into a real gate: run `cargo fmt --all`, clear the clippy warnings
# (`cargo clippy --fix` handles most), then delete this line and add
# `-- -D warnings` to the clippy step.
continue-on-error: true

steps:
- uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- name: Cache cargo build
uses: Swatinem/rust-cache@v2

- name: Formatting
run: cargo fmt --all --check

- name: Clippy
# `--all-targets` so tests and examples are linted too — that is where the
# shadowed-binding and unused-variable classes of bug actually show up.
run: cargo clippy --workspace --all-targets --locked
23 changes: 17 additions & 6 deletions txmanifest_lib/examples/covaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@ fn main() {
hints.insert("SCRIPT_HASH".to_string(), "bytes32".to_string());

let tapleaf = covenant::compute_tapleaf_hash(&simf, &params, &hints, true).unwrap();
let spk_hash =
covenant::compute_covenant_script_hash(&simf, &params, &hints, ElementsNetwork::LiquidTestnet, true)
.unwrap();
let addr =
covenant::compute_covenant_address(&simf, &params, &hints, &[], ElementsNetwork::LiquidTestnet, true)
.unwrap();
let spk_hash = covenant::compute_covenant_script_hash(
&simf,
&params,
&hints,
ElementsNetwork::LiquidTestnet,
true,
)
.unwrap();
let addr = covenant::compute_covenant_address(
&simf,
&params,
&hints,
&[],
ElementsNetwork::LiquidTestnet,
true,
)
.unwrap();

eprintln!("---- result ----");
println!("simf = {}", simf.display());
Expand Down
17 changes: 13 additions & 4 deletions txmanifest_lib/examples/factory_opreturn_recon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
// reissuance_flags (8, u64 LE)
// The program-id derivation is done HERE (authoring time); the tx-encoder now sees only a
// plain `bytes` constant (the manifest's FACTORY_PROGRAM_ID param default).
use std::collections::HashMap;
use lwk_wollet::elements::hashes::{sha256, Hash};
use std::collections::HashMap;
use tx_manifest_lib::{context::ExecutionContext, eval};

fn program_id(simf_path: &std::path::Path) -> String {
let src = std::fs::read_to_string(simf_path).unwrap().replace("\r\n", "\n");
let src = std::fs::read_to_string(simf_path)
.unwrap()
.replace("\r\n", "\n");
let h = sha256::Hash::hash(src.as_bytes()).to_byte_array();
h[..4].iter().map(|b| format!("{b:02x}")).collect()
}
Expand All @@ -37,9 +39,16 @@ fn main() {
println!("creation op_return = {hex} ({} bytes)", bytes.len());
println!(" program_id = {pid}");
println!(" issuing_utxos_count= {}", bytes[4]);
println!(" reissuance_flags = {}", u64::from_le_bytes(bytes[5..13].try_into().unwrap()));
println!(
" reissuance_flags = {}",
u64::from_le_bytes(bytes[5..13].try_into().unwrap())
);
assert_eq!(bytes.len(), 13, "creation metadata must be 13 bytes");
assert_eq!(bytes[4], 2, "issuing_utxos_count must be 2");
assert_eq!(&bytes[5..13], &0u64.to_le_bytes(), "reissuance_flags must be 0");
assert_eq!(
&bytes[5..13],
&0u64.to_le_bytes(),
"reissuance_flags must be 0"
);
println!("OK: layout matches IssuanceFactoryCreationMetadata::encode");
}
12 changes: 10 additions & 2 deletions txmanifest_lib/examples/factory_recon.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Reproduce the issuance_factory covenant (out[1]) and compare to on-chain.
use std::collections::HashMap;
use lwk_wollet::ElementsNetwork;
use std::collections::HashMap;
use tx_manifest_lib::covenant;

fn main() {
Expand All @@ -11,7 +11,15 @@ fn main() {
h.insert("ISSUING_UTXOS_COUNT".to_string(), "u8".to_string());
p.insert("REISSUANCE_FLAGS".to_string(), "0".to_string());
h.insert("REISSUANCE_FLAGS".to_string(), "u64".to_string());
let addr = covenant::compute_covenant_address(&d.join("issuance_factory.simf"), &p, &h, &[], ElementsNetwork::LiquidTestnet, true).unwrap();
let addr = covenant::compute_covenant_address(
&d.join("issuance_factory.simf"),
&p,
&h,
&[],
ElementsNetwork::LiquidTestnet,
true,
)
.unwrap();
eprintln!("---- result ----");
println!("factory out[1] spk (repro) = {:x}", addr.script_pubkey());
println!("factory out[1] spk (chain) = 5120456881785cc7d561caaa059e02f1a2823066bd860423996bea3e92c621bb064b");
Expand Down
4 changes: 3 additions & 1 deletion txmanifest_lib/examples/gen_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use tx_manifest_lib::schema::{json_schema_string, SCHEMA_PATH};

fn main() -> anyhow::Result<()> {
// Examples run with the crate root as CWD; the schema lives at the workspace root.
let out = Path::new(env!("CARGO_MANIFEST_DIR")).join("..").join(SCHEMA_PATH);
let out = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("..")
.join(SCHEMA_PATH);
if let Some(dir) = out.parent() {
std::fs::create_dir_all(dir)?;
}
Expand Down
Loading
Loading