Fix regtest mining smoke test

This commit is contained in:
root
2026-04-29 15:46:42 +00:00
parent 47495ff4cf
commit 52b7f4ce5b
6 changed files with 104 additions and 13 deletions
+3
View File
@@ -56,6 +56,9 @@ core.*
# Autotools-generated headers # Autotools-generated headers
/src/config/bitcoin-config.h /src/config/bitcoin-config.h
/src/config/bitcoin-config.h.in /src/config/bitcoin-config.h.in
/src/config/agrarian-config.h
/src/config/agrarian-config.h.in
/test/config.ini
# ----------------------------- # -----------------------------
# Build outputs # Build outputs
+85
View File
@@ -0,0 +1,85 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
DATADIR="${DATADIR:-$(mktemp -d /tmp/agrarian-smoke-regtest.XXXXXX)}"
RPCPORT="${RPCPORT:-36235}"
PORT="${PORT:-36236}"
BLOCKS="${BLOCKS:-1}"
WAIT_SECONDS="${WAIT_SECONDS:-90}"
AGRARIAND="${AGRARIAND:-$ROOT/src/agrariand}"
AGRARIAN_CLI="${AGRARIAN_CLI:-$ROOT/src/agrarian-cli}"
cleanup() {
if [[ -x "$AGRARIAN_CLI" && -d "$DATADIR" ]]; then
"$AGRARIAN_CLI" -datadir="$DATADIR" -regtest \
-rpcuser=smoke -rpcpassword=smoke-pass -rpcport="$RPCPORT" stop >/dev/null 2>&1 || true
fi
}
trap cleanup EXIT
require_path() {
if [[ ! -x "$1" ]]; then
echo "Missing executable: $1" >&2
exit 1
fi
}
rpc() {
"$AGRARIAN_CLI" -datadir="$DATADIR" -regtest \
-rpcuser=smoke -rpcpassword=smoke-pass -rpcconnect=127.0.0.1 \
-rpcport="$RPCPORT" "$@"
}
require_path "$AGRARIAND"
require_path "$AGRARIAN_CLI"
mkdir -p "$DATADIR"
cat > "$DATADIR/agrarian.conf" <<EOF
regtest=1
server=1
rpcuser=smoke
rpcpassword=smoke-pass
rpcbind=127.0.0.1
rpcallowip=127.0.0.1
listen=0
dnsseed=0
upnp=0
staking=0
keypool=1
EOF
"$AGRARIAND" -datadir="$DATADIR" -regtest -server -listen=0 -dnsseed=0 \
-connect=0 -upnp=0 -staking=0 -rpcuser=smoke -rpcpassword=smoke-pass \
-rpcbind=127.0.0.1 -rpcport="$RPCPORT" -port="$PORT" -keypool=1 -daemon
for _ in $(seq 1 "$WAIT_SECONDS"); do
if rpc getinfo >/dev/null 2>&1; then
break
fi
sleep 1
done
if ! rpc getinfo >/dev/null; then
echo "Timed out waiting for RPC on 127.0.0.1:$RPCPORT" >&2
tail -n 80 "$DATADIR/regtest/debug.log" >&2 || true
exit 1
fi
rpc getwalletinfo >/dev/null
rpc getmininginfo >/dev/null
rpc getstakingstatus >/dev/null
rpc getnewaddress smoke >/dev/null
before="$(rpc getblockcount)"
rpc generate "$BLOCKS" >/dev/null
after="$(rpc getblockcount)"
expected=$((before + BLOCKS))
if [[ "$after" -ne "$expected" ]]; then
echo "Expected block count $expected after mining, got $after" >&2
exit 1
fi
echo "Agrarian daemon smoke test passed"
echo " datadir: $DATADIR"
echo " blocks: $before -> $after"
+11
View File
@@ -75,6 +75,17 @@ Qt 5.15 and protobuf 3.x emit compatibility/deprecation warnings in a few Qt
translation units. Those warnings are expected while the Windows build remains translation units. Those warnings are expected while the Windows build remains
pinned to Qt 5.9.7 and protobuf 2.6.1. pinned to Qt 5.9.7 and protobuf 2.6.1.
Functional smoke test
---------------------
After building the daemon, run the isolated regtest smoke test:
./contrib/smoke-test-daemon.sh
The script starts `agrariand` with a temporary regtest datadir, confirms RPC and
wallet calls work, mines one block with `generate`, checks the block count, and
stops the daemon.
OpenSSL 3 OpenSSL 3
--------- ---------
+2 -3
View File
@@ -528,10 +528,9 @@ std::string HelpMessage(HelpMessageMode mode)
if (GetBoolArg("-help-debug", false)) { if (GetBoolArg("-help-debug", false)) {
strUsage += HelpMessageOpt("-printpriority", strprintf(_("Log transaction priority and fee per kB when mining blocks (default: %u)"), 0)); strUsage += HelpMessageOpt("-printpriority", strprintf(_("Log transaction priority and fee per kB when mining blocks (default: %u)"), 0));
strUsage += HelpMessageOpt("-privdb", strprintf(_("Sets the DB_PRIVATE flag in the wallet db environment (default: %u)"), 1)); strUsage += HelpMessageOpt("-privdb", strprintf(_("Sets the DB_PRIVATE flag in the wallet db environment (default: %u)"), 1));
strUsage += HelpMessageOpt("-regtest", _("Enter regression test mode, which uses a special chain in which blocks can be solved instantly.") + " " +
_("This is intended for regression testing tools and app development.") + " " +
_("In this mode -genproclimit controls how many blocks are generated immediately."));
} }
strUsage += HelpMessageOpt("-regtest", _("Enter regression test mode, which uses a special chain in which blocks can be solved instantly.") + " " +
_("This is intended for regression testing tools and app development."));
strUsage += HelpMessageOpt("-shrinkdebugfile", _("Shrink debug.log file on client startup (default: 1 when no -debug)")); strUsage += HelpMessageOpt("-shrinkdebugfile", _("Shrink debug.log file on client startup (default: 1 when no -debug)"));
strUsage += HelpMessageOpt("-testnet", _("Use the test network")); strUsage += HelpMessageOpt("-testnet", _("Use the test network"));
strUsage += HelpMessageOpt("-litemode=<n>", strprintf(_("Disable all Agrarian specific functionality (Masternodes, Zerocoin, SwiftX, Budgeting) (0-1, default: %u)"), 0)); strUsage += HelpMessageOpt("-litemode=<n>", strprintf(_("Disable all Agrarian specific functionality (Masternodes, Zerocoin, SwiftX, Budgeting) (0-1, default: %u)"), 0));
+1
View File
@@ -255,6 +255,7 @@ int64_t GetMasternodePayment(int nHeight, int64_t blockValue, int nMasternodeCou
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader* pblock, bool fProofOfStake); unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader* pblock, bool fProofOfStake);
bool ActivateBestChain(CValidationState& state, CBlock* pblock = NULL, bool fAlreadyChecked = false); bool ActivateBestChain(CValidationState& state, CBlock* pblock = NULL, bool fAlreadyChecked = false);
CAmount GetBlockValue(int nHeight, bool fProofOfStake);
CAmount GetBlockValue(int nHeight); CAmount GetBlockValue(int nHeight);
/** Create a new block index entry for a given block hash */ /** Create a new block index entry for a given block hash */
+2 -10
View File
@@ -113,20 +113,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
pindexPrev = chainActive.Tip(); pindexPrev = chainActive.Tip();
} }
const int nHeight = pindexPrev->nHeight + 1;
// Make sure to create the correct block version after zerocoin is enabled
bool fZerocoinActive = nHeight >= Params().Zerocoin_StartHeight();
pblock->nVersion = 5; // Supports CLTV activation pblock->nVersion = 5; // Supports CLTV activation
// -regtest only: allow overriding block.nVersion with // -regtest only: allow overriding block.nVersion with
// -blockversion=N to test forking scenarios // -blockversion=N to test forking scenarios
if (Params().MineBlocksOnDemand()) { if (Params().MineBlocksOnDemand()) {
if (fZerocoinActive)
pblock->nVersion = 5;
else
pblock->nVersion = 3;
pblock->nVersion = GetArg("-blockversion", pblock->nVersion); pblock->nVersion = GetArg("-blockversion", pblock->nVersion);
} }
@@ -458,7 +449,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
if (txNew.vout.size() > 1) { if (txNew.vout.size() > 1) {
pblock->payee = txNew.vout[1].scriptPubKey; pblock->payee = txNew.vout[1].scriptPubKey;
} else { } else {
CAmount blockValue = nFees + GetBlockValue(pindexPrev->nHeight); CAmount blockValue = nFees + GetBlockValue(nHeight, false);
txNew.vout[0].nValue = blockValue; txNew.vout[0].nValue = blockValue;
txNew.vin[0].scriptSig = CScript() << nHeight << OP_0; txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
} }
@@ -483,6 +474,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
pblock->nNonce = 0; pblock->nNonce = 0;
//Calculate the accumulator checkpoint only if the previous cached checkpoint need to be updated //Calculate the accumulator checkpoint only if the previous cached checkpoint need to be updated
bool fZerocoinActive = nHeight >= Params().Zerocoin_StartHeight();
if (fZerocoinActive) { if (fZerocoinActive) {
uint256 nCheckpoint; uint256 nCheckpoint;
uint256 hashBlockLastAccumulated = chainActive[max(0, nHeight - (nHeight % 10) - 10)]->GetBlockHash(); uint256 hashBlockLastAccumulated = chainActive[max(0, nHeight - (nHeight % 10) - 10)]->GetBlockHash();