Skip to content

Commit

Permalink
Add testcase: multisig since (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
joii2020 authored Feb 6, 2024
1 parent bfc04c0 commit a4a242c
Show file tree
Hide file tree
Showing 2 changed files with 267 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/omni_lock_rust/tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub const ERROR_NO_WHITE_LIST: i8 = 83;
pub const ERROR_ON_BLACK_LIST: i8 = 57;
pub const ERROR_RCE_EMERGENCY_HALT: i8 = 54;
pub const ERROR_RSA_VERIFY_FAILED: i8 = 42;
pub const ERROR_INCORRECT_SINCE_FLAGS: i8 = -23;
pub const ERROR_INCORRECT_SINCE_VALUE: i8 = -24;
pub const ERROR_ISO97962_INVALID_ARG9: i8 = 61;
pub const ERROR_MOL2_ERR_OVERFLOW: i8 = 8;
Expand Down
267 changes: 266 additions & 1 deletion tests/omni_lock_rust/tests/test_multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ckb_script::{ScriptError, ScriptGroupType, TransactionScriptsVerifier, TxVer
use ckb_types::{
bytes::Bytes,
bytes::BytesMut,
core::{cell::ResolvedTransaction, HeaderView},
core::{cell::ResolvedTransaction, EpochNumberWithFraction, HeaderView},
packed::WitnessArgs,
prelude::*,
H256,
Expand Down Expand Up @@ -277,3 +277,268 @@ fn test_cobuild_multisig_invalid_flags2() {
let verify_result = verifier.verify(MAX_CYCLES);
assert_script_error(verify_result.unwrap_err(), ERROR_MULTSIG_SCRIPT_HASH)
}

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

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

let since = 0x0000_0000_8888_8888u64;
config.set_since(since, 0);
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 test_multisig_0_2_3_unlock_with_since_minus_1() {
let mut data_loader = DummyDataLoader::new();

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

let since = 0x0000_0000_8888_8888u64;
config.set_since(since, since - 1);
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 test_multisig_0_2_3_unlock_with_since_eq() {
let mut data_loader = DummyDataLoader::new();

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

let since = 0x0000_0000_8888_8888u64;
config.set_since(since, 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_multisig_0_2_3_unlock_with_since_flags() {
let mut data_loader = DummyDataLoader::new();

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

let since = 0x0000_0000_8888_8888u64;
config.set_since(since, since | 0x2000_0000_0000_0000);
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_FLAGS)
}

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

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

let since = 0x0000_0000_8888_8888u64;
config.set_since(since, since + 1);
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");
}

lazy_static! {
static ref TESTDATA_SINCE_EPOCH: EpochNumberWithFraction = EpochNumberWithFraction::new(200, 5, 100);
static ref TESTDATA_SINCE_EPOCH_VAL: u64 = 0x2000_0000_0000_0000u64;
}

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

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

let since = TESTDATA_SINCE_EPOCH_VAL.clone() + TESTDATA_SINCE_EPOCH.full_value();

config.set_since(since, 0);
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_FLAGS)
}

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

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

let since = TESTDATA_SINCE_EPOCH_VAL.clone() + TESTDATA_SINCE_EPOCH.full_value();

let epoch = EpochNumberWithFraction::new(200, 2, 200);
config.set_since(since, TESTDATA_SINCE_EPOCH_VAL.clone() + epoch.full_value());
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 test_multisig_0_2_3_unlock_with_since_epoch_add2() {
let mut data_loader = DummyDataLoader::new();

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

let since = TESTDATA_SINCE_EPOCH_VAL.clone() + TESTDATA_SINCE_EPOCH.full_value();

let epoch = EpochNumberWithFraction::new(200, 1, 600);
config.set_since(since, TESTDATA_SINCE_EPOCH_VAL.clone() + epoch.full_value());
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 test_multisig_0_2_3_unlock_with_since_epoch_add3() {
let mut data_loader = DummyDataLoader::new();

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

let since = TESTDATA_SINCE_EPOCH_VAL.clone() + TESTDATA_SINCE_EPOCH.full_value();

let epoch = EpochNumberWithFraction::new(200, 6, 50);
config.set_since(since, TESTDATA_SINCE_EPOCH_VAL.clone() + epoch.full_value());
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_multisig_0_2_3_unlock_with_since_epoch_add4() {
let mut data_loader = DummyDataLoader::new();

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

let since = TESTDATA_SINCE_EPOCH_VAL.clone() + TESTDATA_SINCE_EPOCH.full_value();

let epoch = EpochNumberWithFraction::new(200, 1, 2);
config.set_since(since, TESTDATA_SINCE_EPOCH_VAL.clone() + epoch.full_value());
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_multisig_0_2_3_unlock_with_since_epoch_add5() {
let mut data_loader = DummyDataLoader::new();

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

let since = TESTDATA_SINCE_EPOCH_VAL.clone() + TESTDATA_SINCE_EPOCH.full_value();

let epoch = EpochNumberWithFraction::new(200, 6, 100);
config.set_since(since, TESTDATA_SINCE_EPOCH_VAL.clone() + epoch.full_value());
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_multisig_0_2_3_unlock_with_since_epoch_add6() {
let mut data_loader = DummyDataLoader::new();

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

let since = TESTDATA_SINCE_EPOCH_VAL.clone() + TESTDATA_SINCE_EPOCH.full_value();

config.set_since(since, since + 1);
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_multisig_0_2_3_unlock_with_since_epoch_eq() {
let mut data_loader = DummyDataLoader::new();

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

let since = TESTDATA_SINCE_EPOCH_VAL.clone() + TESTDATA_SINCE_EPOCH.full_value();

config.set_since(since, 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");
}

0 comments on commit a4a242c

Please sign in to comment.