Skip to content

Commit d2beeaa

Browse files
ci: move clippy step as a final touch step
Sometimes it is nice to have a fixup commit and be able to run the tests without having to pass clippy or other repo rules passing before running the e2e tests. In other works clippy is a final touch check from the code prospective, so probably make sense move to the end. Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent abb262b commit d2beeaa

File tree

5 files changed

+526
-13
lines changed

5 files changed

+526
-13
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,8 @@ jobs:
4141
- name: Disallow squash! commits
4242
run: git log --pretty=format:%s origin/master..HEAD | grep -zv squash!
4343

44-
clippy:
45-
runs-on: ubuntu-latest
46-
steps:
47-
- uses: actions/checkout@v4
48-
- uses: extractions/setup-just@v2
49-
- uses: dtolnay/rust-toolchain@master
50-
with:
51-
toolchain: stable
52-
- uses: Swatinem/rust-cache@v2
53-
- run: cargo clippy --all-targets --all-features -- -D warnings
54-
5544
unit-tests:
5645
runs-on: ubuntu-latest
57-
needs: [ clippy ]
5846
steps:
5947
- uses: actions/checkout@v4
6048
- uses: extractions/setup-just@v2
@@ -66,7 +54,6 @@ jobs:
6654
run: RUST_BACKTRACE=1 cargo test --workspace --exclude ark-secp256k1
6755

6856
e2e-tests:
69-
needs: [ clippy ]
7057
strategy:
7158
fail-fast: false
7259
matrix:
@@ -123,3 +110,15 @@ jobs:
123110

124111
- name: Build crates for WASM
125112
run: PATH="/opt/homebrew/opt/llvm/bin:$PATH" cargo build -p ark-core -p ark-rest --target wasm32-unknown-unknown
113+
114+
clippy:
115+
runs-on: ubuntu-latest
116+
needs: [ unit-tests, e2e-tests, wasm_ubuntu, wasm_macos ]
117+
steps:
118+
- uses: actions/checkout@v4
119+
- uses: extractions/setup-just@v2
120+
- uses: dtolnay/rust-toolchain@master
121+
with:
122+
toolchain: stable
123+
- uses: Swatinem/rust-cache@v2
124+
- run: cargo clippy --all-targets --all-features -- -D warnings

ark-core/src/arknote.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use crate::vtxo::VirtualUtxoScript;
2+
use bitcoin::Amount;
3+
use bitcoin::OutPoint;
4+
use bitcoin::ScriptBuf;
5+
use serde::Deserialize;
6+
use serde::Serialize;
7+
8+
pub const PREIMAGE_LENGTH: usize = 32;
9+
10+
#[derive(Debug, Clone)]
11+
pub struct ArkNote {
12+
pub script: ScriptBuf,
13+
pub note_script: ScriptBuf,
14+
vtxo_script: VirtualUtxoScript,
15+
outpoint: OutPoint,
16+
value: Amount,
17+
preimage: [u8; PREIMAGE_LENGTH],
18+
}
19+
20+
impl ArkNote {
21+
pub fn new(
22+
script: ScriptBuf,
23+
note_script: ScriptBuf,
24+
vtxo_script: VirtualUtxoScript,
25+
outpoint: OutPoint,
26+
value: Amount,
27+
preimage: [u8; PREIMAGE_LENGTH],
28+
) -> Self {
29+
Self {
30+
script,
31+
note_script,
32+
vtxo_script,
33+
outpoint,
34+
value,
35+
preimage,
36+
}
37+
}
38+
39+
pub fn vtxo_script(&self) -> &VirtualUtxoScript {
40+
&self.vtxo_script
41+
}
42+
43+
pub fn outpoint(&self) -> OutPoint {
44+
self.outpoint
45+
}
46+
47+
pub fn value(&self) -> Amount {
48+
self.value
49+
}
50+
51+
pub fn preimage(&self) -> &[u8; PREIMAGE_LENGTH] {
52+
&self.preimage
53+
}
54+
}
55+
56+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
57+
pub enum Status {
58+
Pending,
59+
Confirmed,
60+
Failed,
61+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Script to generate test vectors from TypeScript SDK for comparison
2+
// Run this in the arkade-os/ts-sdk repository to get the expected hex values
3+
4+
const { VhtlcScript } = require('../path/to/ts-sdk'); // Adjust path as needed
5+
6+
// Test data from fixtures (same as used in Rust tests)
7+
const testData = {
8+
preimageHash: Buffer.from('4d487dd3753a89bc9fe98401d1196523058251fc', 'hex'),
9+
receiver: Buffer.from('021e1bb85455fe3f5aed60d101aa4dbdb9e7714f6226769a97a17a5331dadcd53b', 'hex'),
10+
sender: Buffer.from('030192e796452d6df9697c280542e1560557bcf79a347d925895043136225c7cb4', 'hex'),
11+
server: Buffer.from('03aad52d58162e9eefeafc7ad8a1cdca8060b5f01df1e7583362d052e266208f88', 'hex'),
12+
refundLocktime: 265,
13+
unilateralClaimDelay: { type: 'blocks', value: 17 },
14+
unilateralRefundDelay: { type: 'blocks', value: 144 },
15+
unilateralRefundWithoutReceiverDelay: { type: 'blocks', value: 144 }
16+
};
17+
18+
try {
19+
// Create VHTLC instance
20+
const vhtlc = new VhtlcScript(testData);
21+
22+
console.log('=== TypeScript SDK VHTLC Script Vectors ===\n');
23+
24+
// Export all script hex values
25+
const vectors = {
26+
claim: vhtlc.claim().script.toString('hex'),
27+
refund: vhtlc.refund().script.toString('hex'),
28+
refundWithoutReceiver: vhtlc.refundWithoutReceiver().script.toString('hex'),
29+
unilateralClaim: vhtlc.unilateralClaim().script.toString('hex'),
30+
unilateralRefund: vhtlc.unilateralRefund().script.toString('hex'),
31+
unilateralRefundWithoutReceiver: vhtlc.unilateralRefundWithoutReceiver().script.toString('hex')
32+
};
33+
34+
// Output for comparison
35+
console.log('TypeScript SDK Script Vectors:');
36+
console.log('1. Claim Script: ', vectors.claim);
37+
console.log('2. Refund Script: ', vectors.refund);
38+
console.log('3. Refund Without Receiver Script: ', vectors.refundWithoutReceiver);
39+
console.log('4. Unilateral Claim Script: ', vectors.unilateralClaim);
40+
console.log('5. Unilateral Refund Script: ', vectors.unilateralRefund);
41+
console.log('6. Unilateral Refund Without Receiver: ', vectors.unilateralRefundWithoutReceiver);
42+
43+
// Also output as JSON for easy parsing
44+
console.log('\n=== JSON Format ===');
45+
console.log(JSON.stringify(vectors, null, 2));
46+
47+
// Export taproot address for comparison
48+
const address = vhtlc.address('testnet'); // or 'mainnet'
49+
console.log('\n=== Address ===');
50+
console.log('TypeScript SDK Address:', address);
51+
52+
} catch (error) {
53+
console.error('Error generating TypeScript vectors:', error);
54+
console.log('\nPlease ensure:');
55+
console.log('1. You are running this in the arkade-os/ts-sdk directory');
56+
console.log('2. The path to VhtlcScript is correct');
57+
console.log('3. All dependencies are installed (npm install)');
58+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/// Comparison tests with TypeScript SDK output
2+
///
3+
/// To use this test:
4+
/// 1. Run generate_ts_vectors.js in the arkade-os/ts-sdk repository
5+
/// 2. Copy the hex output and paste it into the EXPECTED_TS_VECTORS constant below
6+
/// 3. Run this test to compare our Rust output with TypeScript SDK output
7+
8+
use ark_lightning::vhtlc::{VhtlcOptions, VhtlcScript};
9+
use bitcoin::{Sequence, XOnlyPublicKey};
10+
use hex;
11+
use std::str::FromStr;
12+
13+
// TODO: Replace these with actual values from TypeScript SDK output
14+
const EXPECTED_TS_VECTORS: &str = r#"{
15+
"claim": "REPLACE_WITH_TS_OUTPUT",
16+
"refund": "REPLACE_WITH_TS_OUTPUT",
17+
"refundWithoutReceiver": "REPLACE_WITH_TS_OUTPUT",
18+
"unilateralClaim": "REPLACE_WITH_TS_OUTPUT",
19+
"unilateralRefund": "REPLACE_WITH_TS_OUTPUT",
20+
"unilateralRefundWithoutReceiver": "REPLACE_WITH_TS_OUTPUT"
21+
}"#;
22+
23+
#[test]
24+
fn compare_rust_vs_typescript_scripts() {
25+
// Same test data as used in TypeScript SDK
26+
let sender = XOnlyPublicKey::from_str("0192e796452d6df9697c280542e1560557bcf79a347d925895043136225c7cb4").unwrap();
27+
let receiver = XOnlyPublicKey::from_str("1e1bb85455fe3f5aed60d101aa4dbdb9e7714f6226769a97a17a5331dadcd53b").unwrap();
28+
let server = XOnlyPublicKey::from_str("aad52d58162e9eefeafc7ad8a1cdca8060b5f01df1e7583362d052e266208f88").unwrap();
29+
let preimage_hash: [u8; 20] = hex::decode("4d487dd3753a89bc9fe98401d1196523058251fc")
30+
.unwrap()
31+
.try_into()
32+
.unwrap();
33+
34+
let options = VhtlcOptions {
35+
sender,
36+
receiver,
37+
server,
38+
preimage_hash,
39+
refund_locktime: 265,
40+
unilateral_claim_delay: Sequence::from_height(17),
41+
unilateral_refund_delay: Sequence::from_height(144),
42+
unilateral_refund_without_receiver_delay: Sequence::from_height(144),
43+
};
44+
45+
let vhtlc = VhtlcScript::new(options).expect("Failed to create VHTLC");
46+
47+
// Generate Rust script hex values
48+
let rust_vectors = serde_json::json!({
49+
"claim": hex::encode(vhtlc.claim_script().as_bytes()),
50+
"refund": hex::encode(vhtlc.refund_script().as_bytes()),
51+
"refundWithoutReceiver": hex::encode(vhtlc.refund_without_receiver_script().as_bytes()),
52+
"unilateralClaim": hex::encode(vhtlc.unilateral_claim_script().as_bytes()),
53+
"unilateralRefund": hex::encode(vhtlc.unilateral_refund_script().as_bytes()),
54+
"unilateralRefundWithoutReceiver": hex::encode(vhtlc.unilateral_refund_without_receiver_script().as_bytes())
55+
});
56+
57+
println!("=== RUST VS TYPESCRIPT SDK COMPARISON ===\n");
58+
59+
// Parse expected TypeScript vectors (when available)
60+
if EXPECTED_TS_VECTORS.contains("REPLACE_WITH_TS_OUTPUT") {
61+
println!("⚠️ TypeScript SDK vectors not yet provided!");
62+
println!("Please:");
63+
println!("1. Run generate_ts_vectors.js in the arkade-os/ts-sdk repository");
64+
println!("2. Copy the JSON output and replace EXPECTED_TS_VECTORS in this test");
65+
println!("3. Re-run this test for comparison");
66+
67+
println!("\n=== RUST IMPLEMENTATION OUTPUT ===");
68+
println!("{}", serde_json::to_string_pretty(&rust_vectors).unwrap());
69+
return;
70+
}
71+
72+
let expected: serde_json::Value = serde_json::from_str(EXPECTED_TS_VECTORS)
73+
.expect("Failed to parse expected TypeScript vectors");
74+
75+
println!("Rust Implementation:");
76+
println!("{}", serde_json::to_string_pretty(&rust_vectors).unwrap());
77+
78+
println!("\nTypeScript SDK Expected:");
79+
println!("{}", serde_json::to_string_pretty(&expected).unwrap());
80+
81+
// Compare each script
82+
compare_script("Claim", &rust_vectors["claim"], &expected["claim"]);
83+
compare_script("Refund", &rust_vectors["refund"], &expected["refund"]);
84+
compare_script("Refund Without Receiver", &rust_vectors["refundWithoutReceiver"], &expected["refundWithoutReceiver"]);
85+
compare_script("Unilateral Claim", &rust_vectors["unilateralClaim"], &expected["unilateralClaim"]);
86+
compare_script("Unilateral Refund", &rust_vectors["unilateralRefund"], &expected["unilateralRefund"]);
87+
compare_script("Unilateral Refund Without Receiver", &rust_vectors["unilateralRefundWithoutReceiver"], &expected["unilateralRefundWithoutReceiver"]);
88+
}
89+
90+
fn compare_script(name: &str, rust_hex: &serde_json::Value, ts_hex: &serde_json::Value) {
91+
let rust_str = rust_hex.as_str().unwrap();
92+
let ts_str = ts_hex.as_str().unwrap();
93+
94+
println!("\n=== {} SCRIPT COMPARISON ===", name.to_uppercase());
95+
96+
if rust_str == ts_str {
97+
println!("✅ MATCH: Scripts are identical");
98+
return;
99+
}
100+
101+
println!("❌ MISMATCH:");
102+
println!("Rust: {}", rust_str);
103+
println!("TypeScript: {}", ts_str);
104+
105+
// Analyze differences
106+
if rust_str.len() != ts_str.len() {
107+
println!("Length difference: Rust={} bytes, TypeScript={} bytes", rust_str.len()/2, ts_str.len()/2);
108+
}
109+
110+
// Find first difference
111+
for (i, (r, t)) in rust_str.chars().zip(ts_str.chars()).enumerate() {
112+
if r != t {
113+
println!("First difference at position {}: Rust='{}', TypeScript='{}'", i, r, t);
114+
break;
115+
}
116+
}
117+
}
118+
119+
#[test]
120+
#[ignore] // Run manually when you have TypeScript vectors
121+
fn manual_script_comparison() {
122+
// This test can be manually enabled with specific hex values for debugging
123+
let rust_claim_hex = "a9144d487dd3753a89bc9fe98401d1196523058251fc8769201e1bb85455fe3f5aed60d101aa4dbdb9e7714f6226769a97a17a5331dadcd53bad20aad52d58162e9eefeafc7ad8a1cdca8060b5f01df1e7583362d052e266208f88ac";
124+
let ts_claim_hex = ""; // Paste TypeScript output here
125+
126+
if !ts_claim_hex.is_empty() {
127+
println!("Comparing claim scripts:");
128+
println!("Rust: {}", rust_claim_hex);
129+
println!("TS: {}", ts_claim_hex);
130+
assert_eq!(rust_claim_hex, ts_claim_hex, "Claim scripts should match");
131+
} else {
132+
println!("Please provide TypeScript SDK hex output for comparison");
133+
}
134+
}

0 commit comments

Comments
 (0)