Skip to content

Commit

Permalink
Add testcase: try_union_unpack_id
Browse files Browse the repository at this point in the history
  • Loading branch information
joii2020 committed Jan 17, 2024
1 parent fde681e commit 217a42c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions c/cobuild.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions tests/omni_lock_rust/tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -1484,6 +1494,7 @@ pub struct TestConfig {
pub chain_config: Option<Box<dyn ChainConfig>>,
pub cobuild_enabled: bool,
pub cobuild_message: Message,
pub custom_extension_witnesses: Option<Vec<Bytes>>,
}

#[derive(Copy, Clone, PartialEq)]
Expand Down Expand Up @@ -1584,6 +1595,7 @@ impl TestConfig {
chain_config: None,
cobuild_enabled: false,
cobuild_message: Message::default(),
custom_extension_witnesses: None,
}
}

Expand Down
45 changes: 45 additions & 0 deletions tests/omni_lock_rust/tests/test_omni_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 217a42c

Please sign in to comment.