Skip to content

Commit

Permalink
Cobuild ownerlock/timelock/mutisig testcase (#12)
Browse files Browse the repository at this point in the history
* Add ownerlock and timelock testcase

* Add sudt supply testcases

* Add multisig testcase

* Add ethereum/ethereum_displaying testcase
  • Loading branch information
mohanson authored Jan 23, 2024
1 parent a8309eb commit d3a5ab8
Show file tree
Hide file tree
Showing 3 changed files with 412 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/omni_lock_rust/tests/test_multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,66 @@ fn test_multisig_0_2_3_unlock_smt_in_input() {
let verify_result = verifier.verify(MAX_CYCLES);
verify_result.expect("pass verification");
}

#[test]
fn test_cobuild_multisig_0_2_3_unlock() {
let mut data_loader = DummyDataLoader::new();

let mut config = TestConfig::new(IDENTITY_FLAGS_MULTISIG, true);
config.cobuild_enabled = true;
config.set_multisig(0, 2, 3);

config.scheme = TestScheme::OnWhiteList;

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_cobuild_multisig_invalid_flags() {
let mut data_loader = DummyDataLoader::new();

let mut config = TestConfig::new(IDENTITY_FLAGS_MULTISIG, true);
config.set_multisig(0, 2, 3);
config.multisig.set(0, 2, 4);
config.cobuild_enabled = true;

config.scheme = TestScheme::OnWhiteList;

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_MULTSIG_SCRIPT_HASH)
}

#[test]
fn test_cobuild_multisig_invalid_flags2() {
let mut data_loader = DummyDataLoader::new();

let mut config = TestConfig::new(IDENTITY_FLAGS_MULTISIG, true);
config.set_multisig(0, 2, 3);
config.multisig.set(0, 3, 3);
config.cobuild_enabled = true;

config.scheme = TestScheme::OnWhiteList;

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_MULTSIG_SCRIPT_HASH)
}
243 changes: 243 additions & 0 deletions tests/omni_lock_rust/tests/test_omni_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,3 +1135,246 @@ fn test_big_message() {
let verify_result = verifier.verify(MAX_CYCLES);
verify_result.expect("pass verification");
}

#[test]
fn test_cobuild_simple_owner_lock() {
let mut data_loader = DummyDataLoader::new();

let mut config = TestConfig::new(IDENTITY_FLAGS_OWNER_LOCK, false);
config.cobuild_enabled = true;

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_cobuild_simple_owner_lock_mismatched() {
let mut data_loader = DummyDataLoader::new();

let mut config = TestConfig::new(IDENTITY_FLAGS_OWNER_LOCK, false);
config.cobuild_enabled = true;
config.scheme = TestScheme::OwnerLockMismatched;

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_LOCK_SCRIPT_HASH_NOT_FOUND)
}

#[test]
fn test_cobuild_owner_lock_on_wl() {
let mut data_loader = DummyDataLoader::new();

let mut config = TestConfig::new(IDENTITY_FLAGS_OWNER_LOCK, true);
config.cobuild_enabled = true;
config.scheme = TestScheme::OnWhiteList;

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_cobuild_owner_lock_on_wl_without_witness() {
let mut data_loader = DummyDataLoader::new();

let mut config = TestConfig::new(IDENTITY_FLAGS_OWNER_LOCK, true);
config.cobuild_enabled = true;
config.scheme = TestScheme::OnWhiteList;
config.scheme2 = TestScheme2::NoWitness;

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!(verify_result.is_err());
}

#[test]
fn test_cobuild_rsa_via_dl_unlock_with_time_lock() {
let mut data_loader = DummyDataLoader::new();

let args_since = 0x2000_0000_0000_0000u64 + 200;
let input_since = 0x2000_0000_0000_0000u64 + 200;
let mut config = TestConfig::new(IDENTITY_FLAGS_DL, false);
config.cobuild_enabled = true;
config.set_rsa();
config.set_since(args_since, input_since);

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_cobuild_rsa_via_dl_unlock_with_time_lock_failed() {
let mut data_loader = DummyDataLoader::new();

let args_since = 0x2000_0000_0000_0000u64 + 200;
let input_since = 0x2000_0000_0000_0000u64 + 100;
let mut config = TestConfig::new(IDENTITY_FLAGS_DL, false);
config.cobuild_enabled = true;
config.set_rsa();
config.set_since(args_since, input_since);

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_INCORRECT_SINCE_VALUE);
}

#[test]
fn tested_by_append_witnessargs_acp() {
let mut data_loader: DummyDataLoader = 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.set_acp_config(Some((0, 0)));

config.custom_extension_witnesses = Some(vec![WitnessArgsBuilder::default()
.lock(Some(Bytes::from([0u8; 65].to_vec())).pack())
.build()
.as_bytes()]);

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 tested_by_append_witnessargs_since() {
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,
}));

let args_since = 0x2000_0000_0000_0000u64 + 200;
let input_since = 0x2000_0000_0000_0000u64 + 200;
config.set_since(args_since, input_since);

config.custom_extension_witnesses = Some(vec![WitnessArgsBuilder::default()
.lock(Some(Bytes::from([0u8; 65].to_vec())).pack())
.build()
.as_bytes()]);

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 tested_by_append_other_witnesslayout_acp() {
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.set_acp_config(Some((0, 0)));

config.custom_extension_witnesses = Some(vec![WitnessLayoutBuilder::default()
.set(WitnessLayoutUnion::SighashAllOnly(
SighashAllOnlyBuilder::default()
.seal(Bytes::from([0u8; 32].to_vec()).pack())
.build(),
))
.build()
.as_bytes()]);

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_cobuild_eth_unlock() {
let mut data_loader = DummyDataLoader::new();

let mut config = TestConfig::new(IDENTITY_FLAGS_ETHEREUM, false);
config.cobuild_enabled = true;
config.set_chain_config(Box::new(EthereumConfig::default()));

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_cobuild_eth_displaying_unlock() {
let mut data_loader = DummyDataLoader::new();

let mut config = TestConfig::new(IDENTITY_FLAGS_ETHEREUM_DISPLAYING, false);
config.cobuild_enabled = true;
config.set_chain_config(Box::new(EthereumDisplayConfig::default()));

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");
}
Loading

0 comments on commit d3a5ab8

Please sign in to comment.