mirror of
https://github.com/Xahau/xahaud.git
synced 2026-07-30 02:20:10 +00:00
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).
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user