From 217a42cfb404dfb2d4fdad4f41b70c08f4e198ff Mon Sep 17 00:00:00 2001 From: joii2020 Date: Tue, 16 Jan 2024 18:02:47 +0800 Subject: [PATCH] Add testcase: try_union_unpack_id --- c/cobuild.c | 2 + tests/omni_lock_rust/tests/misc.rs | 12 ++++++ tests/omni_lock_rust/tests/test_omni_lock.rs | 45 ++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/c/cobuild.c b/c/cobuild.c index 7389740..4eaaa91 100644 --- a/c/cobuild.c +++ b/c/cobuild.c @@ -277,6 +277,8 @@ static uint32_t try_union_unpack_id(const mol2_cursor_t *cursor, uint32_t *id) { uint32_t len = mol2_read_at(cursor, (uint8_t *)id, 4); if (len != 4) { // joii + // testcase: test_try_union_unpack_id_by_defualt + // testcase: test_try_union_unpack_id_by_cobuild return MOL2_ERR_DATA; } return CKB_SUCCESS; diff --git a/tests/omni_lock_rust/tests/misc.rs b/tests/omni_lock_rust/tests/misc.rs index facbf29..a39929b 100644 --- a/tests/omni_lock_rust/tests/misc.rs +++ b/tests/omni_lock_rust/tests/misc.rs @@ -86,6 +86,8 @@ pub const ERROR_EXCEED_SUPPLY: i8 = 90; pub const ERROR_SUPPLY_AMOUNT: i8 = 91; pub const ERROR_BURN: i8 = 92; pub const ERROR_NO_INFO_CELL: i8 = 93; +// cobuild +pub const ERROR_COBUILD_MOL2_ERR_DATA: i8 = 0x07; // https://github.com/bitcoin-core/secp256k1/blob/d373bf6d08c82ac5496bf8103698c9f54d8d99d2/include/secp256k1.h#L219 pub const SECP256K1_TAG_PUBKEY_EVEN: u8 = 0x02; @@ -987,6 +989,14 @@ pub fn gen_tx_with_grouped_args( } } + match &config.custom_extension_witnesses { + Some(ws) => { + for w in ws { + tx_builder = tx_builder.witness(w.pack()); + } + } + _ => {} + }; tx_builder.build() } @@ -1484,6 +1494,7 @@ pub struct TestConfig { pub chain_config: Option>, pub cobuild_enabled: bool, pub cobuild_message: Message, + pub custom_extension_witnesses: Option>, } #[derive(Copy, Clone, PartialEq)] @@ -1584,6 +1595,7 @@ impl TestConfig { chain_config: None, cobuild_enabled: false, cobuild_message: Message::default(), + custom_extension_witnesses: None, } } diff --git a/tests/omni_lock_rust/tests/test_omni_lock.rs b/tests/omni_lock_rust/tests/test_omni_lock.rs index bea3c81..9ebc416 100644 --- a/tests/omni_lock_rust/tests/test_omni_lock.rs +++ b/tests/omni_lock_rust/tests/test_omni_lock.rs @@ -681,3 +681,48 @@ fn test_binary_unchanged() { &actual_hash ); } + +#[test] +fn test_try_union_unpack_id_by_defualt() { + let mut data_loader = DummyDataLoader::new(); + + let mut config = TestConfig::new(IDENTITY_FLAGS_BITCOIN, false); + config.set_chain_config(Box::new(BitcoinConfig { + sign_vtype: BITCOIN_V_TYPE_P2PKHCOMPRESSED, + pubkey_err: false, + })); + + config.custom_extension_witnesses = Some(vec![Bytes::from([00, 00].to_vec())]); + + let tx = gen_tx(&mut data_loader, &mut config); + let tx = sign_tx(&mut data_loader, tx, &mut config); + let resolved_tx = build_resolved_tx(&data_loader, &tx); + + let mut verifier = verify_tx(resolved_tx, data_loader); + verifier.set_debug_printer(debug_printer); + let verify_result = verifier.verify(MAX_CYCLES); + verify_result.expect("pass verification"); +} + +#[test] +fn test_try_union_unpack_id_by_cobuild() { + let mut data_loader = DummyDataLoader::new(); + + let mut config = TestConfig::new(IDENTITY_FLAGS_BITCOIN, false); + config.cobuild_enabled = true; + config.set_chain_config(Box::new(BitcoinConfig { + sign_vtype: BITCOIN_V_TYPE_P2PKHCOMPRESSED, + pubkey_err: false, + })); + + config.custom_extension_witnesses = Some(vec![Bytes::from([00, 00].to_vec())]); + + let tx = gen_tx(&mut data_loader, &mut config); + let tx = sign_tx(&mut data_loader, tx, &mut config); + let resolved_tx = build_resolved_tx(&data_loader, &tx); + + let mut verifier = verify_tx(resolved_tx, data_loader); + verifier.set_debug_printer(debug_printer); + let verify_result = verifier.verify(MAX_CYCLES); + assert_script_error(verify_result.unwrap_err(), ERROR_COBUILD_MOL2_ERR_DATA) +}