From 16cd02156e5086154da8bfde03b62e3206544bda Mon Sep 17 00:00:00 2001 From: Nicholas Dudfield Date: Thu, 18 Jun 2026 09:54:30 +0700 Subject: [PATCH] test(rng): use a nonzero sentinel in the hook entropy-requirement test testInvalidEntropyRequirements rejects four invalid dice/random requirements then returned accept(0,0,0) on success. But a valid dice(6,..) returns 0..5, so a regression that let the min_tier=0 requirement through (returning a value that happened to be 0) would still pass ~1/6 of the time -- the weakest spot is exactly the min_tier lower bound it most needs to prove (review finding). Return sentinel 42 (distinct from any dice/random result and from INVALID_ARGUMENT) and assert ==42, so any leaked requirement returns its own non-42 code and fails. WASM block recompiled; ConsensusEntropy 138 tests, 0 failures. Follow-up to F1 (fb9e2710c). --- src/test/app/ConsensusEntropy_test.cpp | 9 +++++++-- src/test/app/ConsensusEntropy_test_hooks.h | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/test/app/ConsensusEntropy_test.cpp b/src/test/app/ConsensusEntropy_test.cpp index 24c136236..95166476a 100644 --- a/src/test/app/ConsensusEntropy_test.cpp +++ b/src/test/app/ConsensusEntropy_test.cpp @@ -538,7 +538,10 @@ class ConsensusEntropy_test : public beast::unit_test::suite if (bad_random_tier != INVALID_ARGUMENT) return accept(0, 0, bad_random_tier); - return accept(0, 0, 0); + // Sentinel distinct from any dice (0..5) / random result and + // from INVALID_ARGUMENT, so a regression that lets a bad + // requirement through returns its own code, not this one. + return accept(0, 0, 42); } )[test.hook]"]; @@ -559,7 +562,9 @@ class ConsensusEntropy_test : public beast::unit_test::suite auto const hookExecutions = meta->getFieldArray(sfHookExecutions); BEAST_REQUIRE(hookExecutions.size() == 1); - BEAST_EXPECT(hookReturnCode(hookExecutions[0]) == 0); + // 42 only if all four invalid requirements were rejected; any bad + // requirement leaking through returns its own (non-42) code. + BEAST_EXPECT(hookReturnCode(hookExecutions[0]) == 42); BEAST_EXPECT(hookExecutions[0].getFieldU8(sfHookResult) == 3); } diff --git a/src/test/app/ConsensusEntropy_test_hooks.h b/src/test/app/ConsensusEntropy_test_hooks.h index 72e3231e3..39f16ffec 100644 --- a/src/test/app/ConsensusEntropy_test_hooks.h +++ b/src/test/app/ConsensusEntropy_test_hooks.h @@ -280,7 +280,10 @@ inline std::map> consensusentropy_test_wasm = if (bad_random_tier != INVALID_ARGUMENT) return accept(0, 0, bad_random_tier); - return accept(0, 0, 0); + // Sentinel distinct from any dice (0..5) / random result and + // from INVALID_ARGUMENT, so a regression that lets a bad + // requirement through returns its own code, not this one. + return accept(0, 0, 42); } )[test.hook]", { @@ -313,7 +316,7 @@ inline std::map> consensusentropy_test_wasm = 0x04U, 0x41U, 0x00U, 0x10U, 0x03U, 0x22U, 0x01U, 0x42U, 0x79U, 0x52U, 0x04U, 0x40U, 0x41U, 0x00U, 0x41U, 0x00U, 0x20U, 0x01U, 0x10U, 0x02U, 0x0CU, 0x01U, 0x0BU, 0x41U, 0x00U, 0x41U, 0x00U, - 0x42U, 0x00U, 0x10U, 0x02U, 0x0BU, 0x21U, 0x01U, 0x20U, 0x00U, + 0x42U, 0x2AU, 0x10U, 0x02U, 0x0BU, 0x21U, 0x01U, 0x20U, 0x00U, 0x41U, 0x20U, 0x6AU, 0x24U, 0x00U, 0x20U, 0x01U, 0x0BU, }},