Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHIA-786] extended AGG_SIG_* conditions test coverage #582

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions crates/chia-consensus/src/gen/test_generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
);
}
}
}

Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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>(
Expand Down
2 changes: 1 addition & 1 deletion generator-tests/infinity-g1.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ff01ffffffa00101010101010101010101010101010101010101010101010101010101010101ffff01ffff2bffb0c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff86666f6f6261728080ff7bff80808080
SPENDS:
- coin id: 10d6c244183579e7704ea71e862098f15d28d63fb63c6a54779d1fe901ca48b1 ph: 99d9c5fd60cc6d5bca3390783d3489cd744139f7f143191ea911de3a22b50907
cost: 1352512
cost: 2552512
arvidn marked this conversation as resolved.
Show resolved Hide resolved
removal_amount: 123
addition_amount: 0
STRICT:
Expand Down
12 changes: 12 additions & 0 deletions generator-tests/new-agg-sigs.txt
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions tests/run_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 23 additions & 4 deletions tests/test-generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from chia_rs import (
MEMPOOL_MODE,
ENABLE_MESSAGE_CONDITIONS,
ENABLE_SOFTFORK_CONDITION,
ALLOW_BACKREFS,
SpendBundleConditions,
)
Expand Down Expand Up @@ -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)

Expand Down
Loading