Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testcase: try_union_unpack_id
Browse files Browse the repository at this point in the history
joii2020 committed Jan 16, 2024
1 parent c423e0c commit b020566
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
@@ -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;
12 changes: 12 additions & 0 deletions tests/omni_lock_rust/tests/misc.rs
Original file line number Diff line number Diff line change
@@ -85,6 +85,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;
@@ -995,6 +997,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()
}

@@ -1492,6 +1502,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)]
@@ -1592,6 +1603,7 @@ impl TestConfig {
chain_config: None,
cobuild_enabled: false,
cobuild_message: Message::default(),
custom_extension_witnesses: None,
}
}

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
@@ -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 b020566

Please sign in to comment.