|
| 1 | +// KAT for the DASH min-protocol-version ratchet gate (#643, option a). |
| 2 | +// |
| 3 | +// Pins the two invariants integrator required for the SAFE-ADDITIVE leaf: |
| 4 | +// 1. NO-OP AT DEFAULT: a default-constructed gate carries the oracle floor |
| 5 | +// (1700) and MUST admit a peer at protocol=1700. Nobody may later read the |
| 6 | +// landed leaf as an already-live ratchet. |
| 7 | +// 2. PARAMETERIZED, NOT BAKED: the floor is a per-instance member, so raising |
| 8 | +// it rejects below-floor peers -- proving the ratchet MECHANISM works while |
| 9 | +// the default stays inert. |
| 10 | + |
| 11 | +#include <gtest/gtest.h> |
| 12 | + |
| 13 | +#include "impl/dash/config_pool.hpp" |
| 14 | +#include "impl/dash/min_protocol_gate.hpp" |
| 15 | + |
| 16 | +using dash::MinProtocolGate; |
| 17 | +using dash::SharechainConfig; |
| 18 | + |
| 19 | +// (1) Default gate == oracle accept-all floor, and it is a genuine no-op there. |
| 20 | +TEST(DashMinProtocolGate, DefaultFloorIsOracleAcceptAll) |
| 21 | +{ |
| 22 | + MinProtocolGate gate; |
| 23 | + EXPECT_EQ(gate.min_version, SharechainConfig::MINIMUM_PROTOCOL_VERSION); |
| 24 | + EXPECT_EQ(gate.min_version, 1700u); |
| 25 | + |
| 26 | + // A peer AT the floor MUST be accepted -- this is the no-op assertion. |
| 27 | + EXPECT_TRUE(gate.accepts(1700u)); |
| 28 | + EXPECT_FALSE(gate.rejects(1700u)); |
| 29 | + |
| 30 | + // Real DASH peers advertise >= 1700, so the default admits every one. |
| 31 | + EXPECT_TRUE(gate.accepts(1700u)); |
| 32 | + EXPECT_TRUE(gate.accepts(1800u)); |
| 33 | + EXPECT_TRUE(gate.accepts(70210u)); |
| 34 | +} |
| 35 | + |
| 36 | +// (2) Below the default floor is rejected -- boundary is >=, not >. |
| 37 | +TEST(DashMinProtocolGate, BelowDefaultFloorRejected) |
| 38 | +{ |
| 39 | + MinProtocolGate gate; |
| 40 | + EXPECT_FALSE(gate.accepts(1699u)); |
| 41 | + EXPECT_TRUE(gate.rejects(1699u)); |
| 42 | + EXPECT_FALSE(gate.accepts(0u)); |
| 43 | + // Exact boundary: floor-1 out, floor in. |
| 44 | + EXPECT_FALSE(gate.accepts(gate.min_version - 1)); |
| 45 | + EXPECT_TRUE(gate.accepts(gate.min_version)); |
| 46 | +} |
| 47 | + |
| 48 | +// (3) The floor is a settable per-instance member -- the ratchet mechanism. |
| 49 | +// Raising it to a hypothetical v36 value rejects the old-floor peer, but |
| 50 | +// this is a per-instance choice, NOT a committed constant. |
| 51 | +TEST(DashMinProtocolGate, RatchetIsParameterizedNotBaked) |
| 52 | +{ |
| 53 | + // Operator knob: raise the floor at G2-migration time. |
| 54 | + MinProtocolGate ratcheted(1800u); |
| 55 | + EXPECT_EQ(ratcheted.min_version, 1800u); |
| 56 | + EXPECT_FALSE(ratcheted.accepts(1700u)); // old-floor peer now rejected |
| 57 | + EXPECT_TRUE(ratcheted.accepts(1800u)); // at-new-floor peer admitted |
| 58 | + |
| 59 | + // The default gate is UNAFFECTED -- proving the ratchet is per-instance and |
| 60 | + // the leaf commits no premature v36 constant. |
| 61 | + MinProtocolGate defaulted; |
| 62 | + EXPECT_TRUE(defaulted.accepts(1700u)); |
| 63 | + EXPECT_EQ(defaulted.min_version, 1700u); |
| 64 | +} |
0 commit comments