|
22 | 22 | #include <impl/dgb/coin/rpc_conf.hpp> // #82 external-daemon RPC creds (digibyte.conf) |
23 | 23 | #include <impl/dgb/auto_ratchet.hpp> // Phase B: mint-side share-version ratchet |
24 | 24 | #include <impl/dgb/auto_ratchet_wire.hpp> // Phase B: production wire-in (base_version=35) |
| 25 | +#include <impl/dgb/run_loop_mint.hpp> // Phase B: run-loop {mint,vote} binding |
25 | 26 | #include <unistd.h> // getpid (AutoRatchet KAT temp state file) |
26 | 27 |
|
27 | 28 | #include <cstdio> |
@@ -465,3 +466,62 @@ TEST(DGB_share_test, AutoRatchetWireBootstrapMints35Votes36) |
465 | 466 | EXPECT_EQ(vote, 36); // always vote target |
466 | 467 | EXPECT_EQ(ar.state(), dgb::RatchetState::VOTING); |
467 | 468 | } |
| 469 | + |
| 470 | +// --------------------------------------------------------------------------- |
| 471 | +// Run-loop mint binding (run_loop_mint.hpp) — Phase B pool/share. |
| 472 | +// Proves the live create_local_share() caller stamps the version pair the |
| 473 | +// AutoRatchet selector returns, NOT a hardcoded 36/36. A bootstrap (VOTING, |
| 474 | +// empty tracker) node must mint the DGB baseline 35 while voting 36. |
| 475 | +// --------------------------------------------------------------------------- |
| 476 | +TEST(DGB_share_test, RunLoopMintBindsRatchetVersionsNotHardcoded) |
| 477 | +{ |
| 478 | + auto ar = dgb::make_dgb_ratchet(); |
| 479 | + dgb::ShareTracker tracker; |
| 480 | + |
| 481 | + int64_t seen_share_version = -1; |
| 482 | + uint64_t seen_desired_version = 0; |
| 483 | + uint256 sentinel; sentinel.SetHex( |
| 484 | + "00000000000000000000000000000000000000000000000000000000deadbeef"); |
| 485 | + |
| 486 | + // Inject a spy create-step: capture the version pair the helper forwards, |
| 487 | + // return a sentinel hash so we can also confirm pass-through. |
| 488 | + uint256 got = dgb::mint_local_share_with_ratchet( |
| 489 | + ar, tracker, uint256{}, |
| 490 | + [&](int64_t sv, uint64_t dv) -> uint256 { |
| 491 | + seen_share_version = sv; |
| 492 | + seen_desired_version = dv; |
| 493 | + return sentinel; |
| 494 | + }); |
| 495 | + |
| 496 | + EXPECT_EQ(seen_share_version, 35); // ratchet baseline (oracle), NOT 36 |
| 497 | + EXPECT_EQ(seen_desired_version, 36u); // always vote target |
| 498 | + EXPECT_NE(seen_share_version, seen_desired_version); // 35 != 36: both fields |
| 499 | + // independently threaded |
| 500 | + EXPECT_EQ(got, sentinel); // result returned verbatim |
| 501 | + EXPECT_EQ(ar.state(), dgb::RatchetState::VOTING); |
| 502 | +} |
| 503 | + |
| 504 | +// The helper must not consult/alter the ratchet beyond get_share_version — a |
| 505 | +// second call on the same VOTING state yields the same pair (idempotent stamp). |
| 506 | +TEST(DGB_share_test, RunLoopMintStampIsStableWhileVoting) |
| 507 | +{ |
| 508 | + auto ar = dgb::make_dgb_ratchet(); |
| 509 | + dgb::ShareTracker tracker; |
| 510 | + |
| 511 | + auto stamp = [&]() { |
| 512 | + std::pair<int64_t, uint64_t> p{0, 0}; |
| 513 | + dgb::mint_local_share_with_ratchet( |
| 514 | + ar, tracker, uint256{}, |
| 515 | + [&](int64_t sv, uint64_t dv) -> uint256 { |
| 516 | + p = {sv, dv}; |
| 517 | + return uint256{}; |
| 518 | + }); |
| 519 | + return p; |
| 520 | + }; |
| 521 | + |
| 522 | + auto a = stamp(); |
| 523 | + auto b = stamp(); |
| 524 | + EXPECT_EQ(a, b); |
| 525 | + EXPECT_EQ(a.first, 35); |
| 526 | + EXPECT_EQ(a.second, 36u); |
| 527 | +} |
0 commit comments