Skip to content

Commit

Permalink
Add btc/eth e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Jul 25, 2024
1 parent 6c16d56 commit 3a684c4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/Cargo.lock

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

1 change: 1 addition & 0 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
base64 = "0.22"
blake2b-ref = "0.3.1"
ckb-chain-spec = "0.116.0"
ckb-crypto = "0.116.0"
Expand Down
27 changes: 27 additions & 0 deletions tests/src/test_btc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::common::{assert_script_error, generate_sighash_all, println_hex, ripemd160_sha256, sha256_sha256};
use crate::core::{Pickaxer, Resource, Verifier};
use base64::Engine;
use ckb_types::prelude::{Builder, Entity, Pack};

static BINARY_CCC_LOCK_BTC: &[u8] = include_bytes!("../../build/release/ccc-btc-lock");
Expand Down Expand Up @@ -225,3 +226,29 @@ fn test_failure_can_not_recover() {
let verifier = Verifier::default();
assert_script_error(verifier.verify(&tx_resolved, &dl).unwrap_err(), 36);
}

#[test]
fn test_e2e() {
let mut dl = Resource::default();
let mut px = Pickaxer::default();
let tx = default_tx(&mut dl, &mut px);

// 1. Install Unisat
// 2. Import account with private key 0x000...0001
// 3. Open F12
// 4. Run await unisat.signMessage('Signing a CKB transaction: 0x82ddc4b050a85087fc7cf2c371b12fd6c58645a7f45d8631464f10e8bb0459f4\n\nIMPORTANT: Please verify the integrity and authenticity of connected BTC wallet before signing this message\n')
let wa = ckb_types::packed::WitnessArgs::new_unchecked(tx.witnesses().get_unchecked(0).raw_data());
let mut wa_lock = wa.lock().to_opt().unwrap().raw_data().to_vec();
wa_lock.copy_from_slice(
&base64::prelude::BASE64_STANDARD
.decode("ICS5RSHHicZMoZdLwp2Muw7iGoDpbjwbhgSDYSyi04mKG5UdzsKUl6wBcIt513eLNUf+WZ6dyXTAkqti/ycK7uw=")
.unwrap(),
);
let wa = wa.as_builder().lock(Some(ckb_types::bytes::Bytes::from(wa_lock)).pack()).build();
let tx = tx.as_advanced_builder().set_witnesses(vec![wa.as_bytes().pack()]).build();

let tx_resolved =
ckb_types::core::cell::resolve_transaction(tx, &mut std::collections::HashSet::new(), &dl, &dl).unwrap();
let verifier = Verifier::default();
verifier.verify(&tx_resolved, &dl).unwrap();
}
23 changes: 23 additions & 0 deletions tests/src/test_eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,26 @@ fn test_failure_sig_use_high_s() {
let verifier = Verifier::default();
assert_script_error(verifier.verify(&tx_resolved, &dl).unwrap_err(), 37);
}

#[test]
fn test_e2e() {
let mut dl = Resource::default();
let mut px = Pickaxer::default();
let tx = default_tx(&mut dl, &mut px);

// 1. Install Metamask
// 2. Import account with private key 0x000...0001
// 3. Open F12
// 4. Run await ethereum.enable()
// 5. Run await ethereum.send('personal_sign', ['0x5369676e696e67206120434b42207472616e73616374696f6e3a203078363439343565376335383133663961383261633534316630386435363137643637363963373961393264623264663763346438376633633033316638623262380a0a494d504f5254414e543a20506c65617365207665726966792074686520696e7465677269747920616e642061757468656e746963697479206f6620636f6e6e656374656420457468657265756d2077616c6c6574206265666f7265207369676e696e672074686973206d6573736167650a', '0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf'])
let wa = ckb_types::packed::WitnessArgs::new_unchecked(tx.witnesses().get_unchecked(0).raw_data());
let mut wa_lock = wa.lock().to_opt().unwrap().raw_data().to_vec();
wa_lock.copy_from_slice(&hex::decode("88e0ccbc92a65671ead73682fee2f59938fe91dfd9d0739e43ff9ac9d20eba9d2940a0c665702e6b8c0a7da4d5494b2a00d00fee66d0969b0f32fed4c3b847b31b").unwrap());
let wa = wa.as_builder().lock(Some(ckb_types::bytes::Bytes::from(wa_lock)).pack()).build();
let tx = tx.as_advanced_builder().set_witnesses(vec![wa.as_bytes().pack()]).build();

let tx_resolved =
ckb_types::core::cell::resolve_transaction(tx, &mut std::collections::HashSet::new(), &dl, &dl).unwrap();
let verifier = Verifier::default();
verifier.verify(&tx_resolved, &dl).unwrap();
}

0 comments on commit 3a684c4

Please sign in to comment.