From 7a48e8f94200b2cd344a9c1287ea547fd1fd25de Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 19 Jun 2024 15:06:20 +0200 Subject: [PATCH] update the run_generator tests to run with the extended AGG_SIG_* conditions enabled. Update the test to support printing those. Add a test to cover them --- .../chia-consensus/src/gen/test_generators.rs | 48 +++++++++++-------- generator-tests/infinity-g1.txt | 2 +- generator-tests/new-agg-sigs.txt | 12 +++++ tests/run_gen.py | 12 +++++ tests/test-generators.py | 27 +++++++++-- 5 files changed, 77 insertions(+), 24 deletions(-) create mode 100644 generator-tests/new-agg-sigs.txt diff --git a/crates/chia-consensus/src/gen/test_generators.rs b/crates/chia-consensus/src/gen/test_generators.rs index 52e3d4ca5..b2742cc9d 100644 --- a/crates/chia-consensus/src/gen/test_generators.rs +++ b/crates/chia-consensus/src/gen/test_generators.rs @@ -2,7 +2,9 @@ use super::conditions::{MempoolVisitor, NewCoin, Spend, SpendBundleConditions}; use super::run_block_generator::{run_block_generator, run_block_generator2}; use crate::allocator::make_allocator; use crate::consensus_constants::TEST_CONSTANTS; -use crate::gen::flags::{ALLOW_BACKREFS, ENABLE_MESSAGE_CONDITIONS, MEMPOOL_MODE}; +use crate::gen::flags::{ + ALLOW_BACKREFS, ENABLE_MESSAGE_CONDITIONS, ENABLE_SOFTFORK_CONDITION, MEMPOOL_MODE, +}; use chia_protocol::{Bytes, Bytes48}; use clvmr::allocator::NodePtr; use clvmr::Allocator; @@ -84,17 +86,28 @@ fn print_conditions(a: &Allocator, c: &SpendBundleConditions) -> String { } } - let mut agg_sigs = Vec::<(Bytes48, Bytes)>::new(); - for (pk, msg) in s.agg_sig_me { - agg_sigs.push((pk.to_bytes().into(), a.atom(msg).as_ref().into())); - } - agg_sigs.sort(); - for (pk, msg) in agg_sigs { - ret += &format!( - " AGG_SIG_ME pk: {} msg: {}\n", - hex::encode(pk), - hex::encode(msg) - ); + for sig_conds in [ + (&s.agg_sig_me, "AGG_SIG_ME"), + (&s.agg_sig_parent, "AGG_SIG_PARENT"), + (&s.agg_sig_puzzle, "AGG_SIG_PUZZLE"), + (&s.agg_sig_amount, "AGG_SIG_AMOUNT"), + (&s.agg_sig_puzzle_amount, "AGG_SIG_PUZZLE_AMOUNT"), + (&s.agg_sig_parent_amount, "AGG_SIG_PARENT_AMOUNT"), + (&s.agg_sig_parent_puzzle, "AGG_SIG_PARENT_PUZZLE"), + ] { + let mut agg_sigs = Vec::<(Bytes48, Bytes)>::new(); + for (pk, msg) in sig_conds.0 { + agg_sigs.push((pk.to_bytes().into(), a.atom(*msg).as_ref().into())); + } + agg_sigs.sort(); + for (pk, msg) in &agg_sigs { + ret += &format!( + " {} pk: {} msg: {}\n", + sig_conds.1, + hex::encode(pk), + hex::encode(msg) + ); + } } } @@ -144,6 +157,7 @@ fn print_diff(output: &str, expected: &str) { } #[rstest] +#[case("new-agg-sigs")] #[case("infinity-g1")] #[case("block-1ee588dc")] #[case("block-6fe59b24")] @@ -215,13 +229,9 @@ fn run_generator(#[case] name: &str) { block_refs.push(hex::decode(env_hex).expect("hex decode env-file")); } - for (flags, expected) in zip( - &[ - ALLOW_BACKREFS | ENABLE_MESSAGE_CONDITIONS, - ALLOW_BACKREFS | MEMPOOL_MODE | ENABLE_MESSAGE_CONDITIONS, - ], - expected, - ) { + const DEFAULT_FLAGS: u32 = + ALLOW_BACKREFS | ENABLE_SOFTFORK_CONDITION | ENABLE_MESSAGE_CONDITIONS; + for (flags, expected) in zip(&[DEFAULT_FLAGS, DEFAULT_FLAGS | MEMPOOL_MODE], expected) { println!("flags: {flags:x}"); let mut a = make_allocator(*flags); let conds = run_block_generator::<_, MempoolVisitor>( diff --git a/generator-tests/infinity-g1.txt b/generator-tests/infinity-g1.txt index e0a1aeb06..f047b85ed 100644 --- a/generator-tests/infinity-g1.txt +++ b/generator-tests/infinity-g1.txt @@ -1,7 +1,7 @@ ff01ffffffa00101010101010101010101010101010101010101010101010101010101010101ffff01ffff2bffb0c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff86666f6f6261728080ff7bff80808080 SPENDS: - coin id: 10d6c244183579e7704ea71e862098f15d28d63fb63c6a54779d1fe901ca48b1 ph: 99d9c5fd60cc6d5bca3390783d3489cd744139f7f143191ea911de3a22b50907 -cost: 1352512 +cost: 2552512 removal_amount: 123 addition_amount: 0 STRICT: diff --git a/generator-tests/new-agg-sigs.txt b/generator-tests/new-agg-sigs.txt new file mode 100644 index 000000000..d183d5621 --- /dev/null +++ b/generator-tests/new-agg-sigs.txt @@ -0,0 +1,12 @@ +ff01ffffffa00101010101010101010101010101010101010101010101010101010101010101ffff01ffff2bffb097f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bbff86666f6f62617280ffff2cffb097f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bbff86626172666f6f80ffff2dffb097f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bbff8662617262617a80ffff2effb097f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bbff8662617a666f6f80ffff2fffb097f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bbff86666f6f62617a80ffff30ffb097f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bbff8662617a6261728080ff7bff80808080 +SPENDS: +- coin id: 127e50753d31f59760e239abc6d1571f92ed413deeeebe356f92370dc6853cb8 ph: 70ce4f9009de3f2a15c6f3d370c2c19bdf25486c4014d0114a4be99cacb5ab42 + AGG_SIG_PARENT pk: 97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb msg: 666f6f626172 + AGG_SIG_PUZZLE pk: 97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb msg: 626172666f6f + AGG_SIG_AMOUNT pk: 97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb msg: 62617262617a + AGG_SIG_PUZZLE_AMOUNT pk: 97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb msg: 62617a666f6f + AGG_SIG_PARENT_AMOUNT pk: 97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb msg: 666f6f62617a + AGG_SIG_PARENT_PUZZLE pk: 97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb msg: 62617a626172 +cost: 12334542 +removal_amount: 123 +addition_amount: 0 diff --git a/tests/run_gen.py b/tests/run_gen.py index 008b76081..d6ecddd12 100755 --- a/tests/run_gen.py +++ b/tests/run_gen.py @@ -152,6 +152,18 @@ def print_spend_bundle_conditions(result) -> str: ret += f" CREATE_COIN: ph: {a[0].hex()} amount: {a[1]}\n" for a in sorted(s.agg_sig_me): ret += f" AGG_SIG_ME pk: {a[0]} msg: {a[1].hex()}\n" + for a in sorted(s.agg_sig_parent): + ret += f" AGG_SIG_PARENT pk: {a[0]} msg: {a[1].hex()}\n" + for a in sorted(s.agg_sig_puzzle): + ret += f" AGG_SIG_PUZZLE pk: {a[0]} msg: {a[1].hex()}\n" + for a in sorted(s.agg_sig_amount): + ret += f" AGG_SIG_AMOUNT pk: {a[0]} msg: {a[1].hex()}\n" + for a in sorted(s.agg_sig_puzzle_amount): + ret += f" AGG_SIG_PUZZLE_AMOUNT pk: {a[0]} msg: {a[1].hex()}\n" + for a in sorted(s.agg_sig_parent_amount): + ret += f" AGG_SIG_PARENT_AMOUNT pk: {a[0]} msg: {a[1].hex()}\n" + for a in sorted(s.agg_sig_parent_puzzle): + ret += f" AGG_SIG_PARENT_PUZZLE pk: {a[0]} msg: {a[1].hex()}\n" ret += f"cost: {result.cost}\n" ret += f"removal_amount: {result.removal_amount}\n" ret += f"addition_amount: {result.addition_amount}\n" diff --git a/tests/test-generators.py b/tests/test-generators.py index 2767a9e49..18b2add5e 100755 --- a/tests/test-generators.py +++ b/tests/test-generators.py @@ -5,6 +5,7 @@ from chia_rs import ( MEMPOOL_MODE, ENABLE_MESSAGE_CONDITIONS, + ENABLE_SOFTFORK_CONDITION, ALLOW_BACKREFS, SpendBundleConditions, ) @@ -64,23 +65,41 @@ def validate_except_cost(output1: str, output2: str): name = f"{Path(g).name:43s}" stdout.write(f"{name} running generator...\r") stdout.flush() - consensus = run_generator(g, ALLOW_BACKREFS | ENABLE_MESSAGE_CONDITIONS, version=1) + consensus = run_generator( + g, + ALLOW_BACKREFS | ENABLE_SOFTFORK_CONDITION | ENABLE_MESSAGE_CONDITIONS, + version=1, + ) stdout.write(f"{name} running generator2...\r") stdout.flush() - consensus2 = run_generator(g, ALLOW_BACKREFS | ENABLE_MESSAGE_CONDITIONS, version=2) + consensus2 = run_generator( + g, + ALLOW_BACKREFS | ENABLE_SOFTFORK_CONDITION | ENABLE_MESSAGE_CONDITIONS, + version=2, + ) validate_except_cost(consensus.output, consensus2.output) stdout.write(f"{name} running generator (mempool mode) ...\r") stdout.flush() mempool = run_generator( - g, ALLOW_BACKREFS | MEMPOOL_MODE | ENABLE_MESSAGE_CONDITIONS, version=1 + g, + ALLOW_BACKREFS + | MEMPOOL_MODE + | ENABLE_SOFTFORK_CONDITION + | ENABLE_MESSAGE_CONDITIONS, + version=1, ) stdout.write(f"{name} running generator2 (mempool mode)...\r") stdout.flush() mempool2 = run_generator( - g, ALLOW_BACKREFS | MEMPOOL_MODE | ENABLE_MESSAGE_CONDITIONS, version=2 + g, + ALLOW_BACKREFS + | MEMPOOL_MODE + | ENABLE_SOFTFORK_CONDITION + | ENABLE_MESSAGE_CONDITIONS, + version=2, ) validate_except_cost(mempool.output, mempool2.output)