test: Fix OverwinterExpiryHeight test after ZIP 203 contextual changes

This commit is contained in:
Jack Grigg 2021-07-01 13:16:31 +01:00
parent 9a5951aab1
commit 0a78f4c6ec
3 changed files with 23 additions and 6 deletions

View File

@ -744,17 +744,16 @@ TEST(ChecktransactionTests, OverwinterValidTx) {
} }
TEST(ChecktransactionTests, OverwinterExpiryHeight) { TEST(ChecktransactionTests, OverwinterExpiryHeight) {
CMutableTransaction mtx = GetValidTransaction(); const auto& params = RegtestActivateOverwinter();
CMutableTransaction mtx = GetValidTransaction(0x5ba81b19);
mtx.vJoinSplit.resize(0); mtx.vJoinSplit.resize(0);
mtx.fOverwintered = true;
mtx.nVersion = OVERWINTER_TX_VERSION;
mtx.nVersionGroupId = OVERWINTER_VERSION_GROUP_ID;
mtx.nExpiryHeight = 0; mtx.nExpiryHeight = 0;
{ {
CTransaction tx(mtx); CTransaction tx(mtx);
MockCValidationState state; MockCValidationState state;
EXPECT_TRUE(CheckTransactionWithoutProofVerification(tx, state)); EXPECT_TRUE(CheckTransactionWithoutProofVerification(tx, state));
EXPECT_TRUE(ContextualCheckTransaction(tx, state, params, 1, true));
} }
{ {
@ -762,23 +761,28 @@ TEST(ChecktransactionTests, OverwinterExpiryHeight) {
CTransaction tx(mtx); CTransaction tx(mtx);
MockCValidationState state; MockCValidationState state;
EXPECT_TRUE(CheckTransactionWithoutProofVerification(tx, state)); EXPECT_TRUE(CheckTransactionWithoutProofVerification(tx, state));
EXPECT_TRUE(ContextualCheckTransaction(tx, state, params, 1, true));
} }
{ {
mtx.nExpiryHeight = TX_EXPIRY_HEIGHT_THRESHOLD; mtx.nExpiryHeight = TX_EXPIRY_HEIGHT_THRESHOLD;
CTransaction tx(mtx); CTransaction tx(mtx);
MockCValidationState state; MockCValidationState state;
EXPECT_TRUE(CheckTransactionWithoutProofVerification(tx, state));
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-tx-expiry-height-too-high", false)).Times(1); EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-tx-expiry-height-too-high", false)).Times(1);
ContextualCheckTransaction(tx, state, Params(), 1, true); ContextualCheckTransaction(tx, state, params, 1, true);
} }
{ {
mtx.nExpiryHeight = std::numeric_limits<uint32_t>::max(); mtx.nExpiryHeight = std::numeric_limits<uint32_t>::max();
CTransaction tx(mtx); CTransaction tx(mtx);
MockCValidationState state; MockCValidationState state;
EXPECT_TRUE(CheckTransactionWithoutProofVerification(tx, state));
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-tx-expiry-height-too-high", false)).Times(1); EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-tx-expiry-height-too-high", false)).Times(1);
CheckTransactionWithoutProofVerification(tx, state); ContextualCheckTransaction(tx, state, params, 1, true);
} }
RegtestDeactivateSapling();
} }
TEST(checktransaction_tests, BlossomExpiryHeight) { TEST(checktransaction_tests, BlossomExpiryHeight) {

View File

@ -196,6 +196,16 @@ CWalletTx GetValidSproutSpend(const libzcash::SproutSpendingKey& sk,
return wtx; return wtx;
} }
const CChainParams& RegtestActivateOverwinter() {
SelectParams(CBaseChainParams::REGTEST);
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
return Params();
}
void RegtestDeactivateOverwinter() {
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT);
}
// Sapling // Sapling
const Consensus::Params& RegtestActivateSapling() { const Consensus::Params& RegtestActivateSapling() {
SelectParams(CBaseChainParams::REGTEST); SelectParams(CBaseChainParams::REGTEST);

View File

@ -37,6 +37,9 @@ struct TestSaplingNote {
SaplingMerkleTree tree; SaplingMerkleTree tree;
}; };
const CChainParams& RegtestActivateOverwinter();
void RegtestDeactivateOverwinter();
const Consensus::Params& RegtestActivateSapling(); const Consensus::Params& RegtestActivateSapling();
void RegtestDeactivateSapling(); void RegtestDeactivateSapling();