Skip to content

Commit

Permalink
Updated transaction tests to report reason for failures.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeIsTheKey committed Oct 6, 2024
1 parent 02e6305 commit ae87106
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
9 changes: 6 additions & 3 deletions src/test/script_p2sh_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ BOOST_AUTO_TEST_CASE(sign)
txFrom.vout[i + 4].scriptPubKey = standardScripts[i];
txFrom.vout[i + 4].nValue = COIN;
}
BOOST_CHECK(IsStandardTx(CTransaction(txFrom), reason));
bool isStandardTx = IsStandardTx(CTransaction(txFrom), reason);
BOOST_CHECK_MESSAGE(isStandardTx, strprintf("IsStandardTx: reason: %s", reason.c_str()));

CMutableTransaction txTo[8]; // Spending transactions
for (int i = 0; i < 8; i++)
Expand Down Expand Up @@ -185,7 +186,8 @@ BOOST_AUTO_TEST_CASE(set)
txFrom.vout[i].scriptPubKey = outer[i];
txFrom.vout[i].nValue = CENT;
}
BOOST_CHECK(IsStandardTx(CTransaction(txFrom), reason));
bool isStandardTx = IsStandardTx(CTransaction(txFrom), reason);
BOOST_CHECK_MESSAGE(isStandardTx, strprintf("IsStandardTx: reason: %s", reason.c_str()));

CMutableTransaction txTo[4]; // Spending transactions
for (int i = 0; i < 4; i++)
Expand All @@ -201,7 +203,8 @@ BOOST_AUTO_TEST_CASE(set)
{
BOOST_CHECK_MESSAGE(SignSignature(keystore, CTransaction(txFrom), txTo[i], 0, SIGHASH_ALL),
strprintf("SignSignature %d", i));
BOOST_CHECK_MESSAGE(IsStandardTx(CTransaction(txTo[i]), reason), strprintf("txTo[%d].IsStandard", i));
bool isStandardTx = IsStandardTx(CTransaction(txTo[i]), reason);
BOOST_CHECK_MESSAGE(isStandardTx, strprintf("IsStandardTx: txTo[%d] reason: %s", i, reason.c_str()));
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/test/test_raptoreum.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ static inline uint64_t InsecureRandRange(uint64_t range) { return g_insecure_ran

static inline bool InsecureRandBool() { return g_insecure_rand_ctx.randbool(); }

static constexpr CAmount
CENT{
1000000};
static constexpr CAmount CENT{1000000};

/** Basic testing setup.
* This just configures logging and chain parameters.
Expand Down
28 changes: 19 additions & 9 deletions src/test/transaction_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
CCoinsView coinsDummy;
CCoinsViewCache coins(&coinsDummy);
std::vector<CMutableTransaction> dummyTransactions = SetupDummyInputs(keystore, coins);
bool isStandardTx;

CMutableTransaction t;
t.vin.resize(1);
Expand All @@ -326,7 +327,8 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
t.vout[0].scriptPubKey = GetScriptForDestination(key.GetPubKey().GetID());

std::string reason;
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
isStandardTx = IsStandardTx(CTransaction(t), reason);
BOOST_CHECK_MESSAGE(isStandardTx, strprintf("IsStandardTx: reason: %s", reason.c_str()));

// Check dust with default relay fee:
CAmount nDustThreshold = 182 * dustRelayFee.GetFeePerK()/1000;
Expand All @@ -336,7 +338,8 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
// not dust:
t.vout[0].nValue = nDustThreshold;
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
isStandardTx = IsStandardTx(CTransaction(t), reason);
BOOST_CHECK_MESSAGE(isStandardTx, strprintf("IsStandardTx: reason: %s", reason.c_str()));

// Check dust with odd relay fee to verify rounding:
// nDustThreshold = 182 * 3702 / 1000
Expand All @@ -346,7 +349,8 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
// not dust:
t.vout[0].nValue = 546;
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
isStandardTx = IsStandardTx(CTransaction(t), reason);
BOOST_CHECK_MESSAGE(isStandardTx, strprintf("IsStandardTx: reason: %s", reason.c_str()));
minRelayTxFee = CFeeRate(DUST_RELAY_TX_FEE);

t.vout[0].scriptPubKey = CScript() << OP_1;
Expand All @@ -355,7 +359,8 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
// MAX_OP_RETURN_RELAY-byte TX_NULL_DATA (standard)
t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
BOOST_CHECK_EQUAL(MAX_OP_RETURN_RELAY, t.vout[0].scriptPubKey.size());
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
isStandardTx = IsStandardTx(CTransaction(t), reason);
BOOST_CHECK_MESSAGE(isStandardTx, strprintf("IsStandardTx: reason: %s", reason.c_str()));

// MAX_OP_RETURN_RELAY+1-byte TX_NULL_DATA (non-standard)
t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3800");
Expand All @@ -364,14 +369,18 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)

// Data payload can be encoded in any way...
t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("");
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
isStandardTx = IsStandardTx(CTransaction(t), reason);
BOOST_CHECK_MESSAGE(isStandardTx, strprintf("IsStandardTx: reason: %s", reason.c_str()));
t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("00") << ParseHex("01");
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
isStandardTx = IsStandardTx(CTransaction(t), reason);
BOOST_CHECK_MESSAGE(isStandardTx, strprintf("IsStandardTx: reason: %s", reason.c_str()));
// OP_RESERVED *is* considered to be a PUSHDATA type opcode by IsPushOnly()!
t.vout[0].scriptPubKey = CScript() << OP_RETURN << OP_RESERVED << -1 << 0 << ParseHex("01") << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16;
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
isStandardTx = IsStandardTx(CTransaction(t), reason);
BOOST_CHECK_MESSAGE(isStandardTx, strprintf("IsStandardTx: reason: %s", reason.c_str()));
t.vout[0].scriptPubKey = CScript() << OP_RETURN << 0 << ParseHex("01") << 2 << ParseHex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
isStandardTx = IsStandardTx(CTransaction(t), reason);
BOOST_CHECK_MESSAGE(isStandardTx, strprintf("IsStandardTx: reason: %s", reason.c_str()));

// ...so long as it only contains PUSHDATA's
t.vout[0].scriptPubKey = CScript() << OP_RETURN << OP_RETURN;
Expand All @@ -380,7 +389,8 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
// TX_NULL_DATA w/o PUSHDATA
t.vout.resize(1);
t.vout[0].scriptPubKey = CScript() << OP_RETURN;
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
isStandardTx = IsStandardTx(CTransaction(t), reason);
BOOST_CHECK_MESSAGE(isStandardTx, strprintf("IsStandardTx: reason: %s", reason.c_str()));

// Only one TX_NULL_DATA permitted in all cases
t.vout.resize(2);
Expand Down

0 comments on commit ae87106

Please sign in to comment.