refactor: use CTransaction for immutable tx in evo_assetlocks_tests

This commit is contained in:
Alessandro Rezzi 2024-03-04 21:00:44 +01:00 committed by ale
parent ca0fe8c208
commit d9f0e93498

View File

@ -134,7 +134,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)
CKey key; CKey key;
key.MakeNewKey(true); key.MakeNewKey(true);
const CMutableTransaction tx = CreateAssetLockTx(keystore, coins, key); const CTransaction tx = CreateAssetLockTx(keystore, coins, key);
std::string reason; std::string reason;
BOOST_CHECK(IsStandardTx(CTransaction(tx), reason)); BOOST_CHECK(IsStandardTx(CTransaction(tx), reason));
@ -159,7 +159,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)
{ {
// Wrong type "Asset Unlock TX" instead "Asset Lock TX" // Wrong type "Asset Unlock TX" instead "Asset Lock TX"
CMutableTransaction txWrongType = tx; CMutableTransaction txWrongType(tx);
txWrongType.nType = TRANSACTION_ASSET_UNLOCK; txWrongType.nType = TRANSACTION_ASSET_UNLOCK;
BOOST_CHECK(!CheckAssetLockTx(CTransaction(txWrongType), tx_state)); BOOST_CHECK(!CheckAssetLockTx(CTransaction(txWrongType), tx_state));
BOOST_CHECK(tx_state.GetRejectReason() == "bad-assetlocktx-type"); BOOST_CHECK(tx_state.GetRejectReason() == "bad-assetlocktx-type");
@ -175,13 +175,13 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)
BOOST_CHECK(inSum == outSum); BOOST_CHECK(inSum == outSum);
// Outputs should not be bigger than inputs // Outputs should not be bigger than inputs
CMutableTransaction txBigOutput = tx; CMutableTransaction txBigOutput(tx);
txBigOutput.vout[0].nValue += 1; txBigOutput.vout[0].nValue += 1;
BOOST_CHECK(!CheckAssetLockTx(CTransaction(txBigOutput), tx_state)); BOOST_CHECK(!CheckAssetLockTx(CTransaction(txBigOutput), tx_state));
BOOST_CHECK(tx_state.GetRejectReason() == "bad-assetlocktx-creditamount"); BOOST_CHECK(tx_state.GetRejectReason() == "bad-assetlocktx-creditamount");
// Smaller outputs are allown // Smaller outputs are allown
CMutableTransaction txSmallOutput = tx; CMutableTransaction txSmallOutput(tx);
txSmallOutput.vout[1].nValue -= 1; txSmallOutput.vout[1].nValue -= 1;
BOOST_CHECK(CheckAssetLockTx(CTransaction(txSmallOutput), tx_state)); BOOST_CHECK(CheckAssetLockTx(CTransaction(txSmallOutput), tx_state));
} }
@ -195,7 +195,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)
wrongOutput[0].nValue += CENT; wrongOutput[0].nValue += CENT;
CAssetLockPayload greaterCreditsPayload(wrongOutput); CAssetLockPayload greaterCreditsPayload(wrongOutput);
CMutableTransaction txGreaterCredits = tx; CMutableTransaction txGreaterCredits(tx);
SetTxPayload(txGreaterCredits, greaterCreditsPayload); SetTxPayload(txGreaterCredits, greaterCreditsPayload);
BOOST_CHECK(!CheckAssetLockTx(CTransaction(txGreaterCredits), tx_state)); BOOST_CHECK(!CheckAssetLockTx(CTransaction(txGreaterCredits), tx_state));
@ -205,7 +205,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)
wrongOutput[1].nValue -= 2 * CENT; wrongOutput[1].nValue -= 2 * CENT;
CAssetLockPayload lessCreditsPayload(wrongOutput); CAssetLockPayload lessCreditsPayload(wrongOutput);
CMutableTransaction txLessCredits = tx; CMutableTransaction txLessCredits(tx);
SetTxPayload(txLessCredits, lessCreditsPayload); SetTxPayload(txLessCredits, lessCreditsPayload);
BOOST_CHECK(!CheckAssetLockTx(CTransaction(txLessCredits), tx_state)); BOOST_CHECK(!CheckAssetLockTx(CTransaction(txLessCredits), tx_state));
@ -218,7 +218,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)
creditOutputsOutOfRange[0].nValue = 0; creditOutputsOutOfRange[0].nValue = 0;
CAssetLockPayload invalidOutputsPayload(creditOutputsOutOfRange); CAssetLockPayload invalidOutputsPayload(creditOutputsOutOfRange);
CMutableTransaction txInvalidOutputs = tx; CMutableTransaction txInvalidOutputs(tx);
SetTxPayload(txInvalidOutputs, invalidOutputsPayload); SetTxPayload(txInvalidOutputs, invalidOutputsPayload);
BOOST_CHECK(!CheckAssetLockTx(CTransaction(txInvalidOutputs), tx_state)); BOOST_CHECK(!CheckAssetLockTx(CTransaction(txInvalidOutputs), tx_state));
@ -243,7 +243,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)
creditOutputsNotPubkey[0].scriptPubKey = CScript() << OP_1; creditOutputsNotPubkey[0].scriptPubKey = CScript() << OP_1;
CAssetLockPayload notPubkeyPayload(creditOutputsNotPubkey); CAssetLockPayload notPubkeyPayload(creditOutputsNotPubkey);
CMutableTransaction txNotPubkey = tx; CMutableTransaction txNotPubkey(tx);
SetTxPayload(txNotPubkey, notPubkeyPayload); SetTxPayload(txNotPubkey, notPubkeyPayload);
BOOST_CHECK(!CheckAssetLockTx(CTransaction(txNotPubkey), tx_state)); BOOST_CHECK(!CheckAssetLockTx(CTransaction(txNotPubkey), tx_state));
@ -253,7 +253,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)
{ {
// OP_RETURN must be only one, not more // OP_RETURN must be only one, not more
CMutableTransaction txMultipleReturn = tx; CMutableTransaction txMultipleReturn(tx);
txMultipleReturn.vout[1].scriptPubKey = CScript() << OP_RETURN << ParseHex(""); txMultipleReturn.vout[1].scriptPubKey = CScript() << OP_RETURN << ParseHex("");
BOOST_CHECK(!CheckAssetLockTx(CTransaction(txMultipleReturn), tx_state)); BOOST_CHECK(!CheckAssetLockTx(CTransaction(txMultipleReturn), tx_state));
@ -263,7 +263,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)
{ {
// zero/negative OP_RETURN // zero/negative OP_RETURN
CMutableTransaction txReturnOutOfRange = tx; CMutableTransaction txReturnOutOfRange(tx);
txReturnOutOfRange.vout[0].nValue = 0; txReturnOutOfRange.vout[0].nValue = 0;
BOOST_CHECK(!CheckAssetLockTx(CTransaction(txReturnOutOfRange), tx_state)); BOOST_CHECK(!CheckAssetLockTx(CTransaction(txReturnOutOfRange), tx_state));
@ -278,7 +278,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)
{ {
// OP_RETURN is missing // OP_RETURN is missing
CMutableTransaction txNoReturn = tx; CMutableTransaction txNoReturn(tx);
txNoReturn.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey())); txNoReturn.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
BOOST_CHECK(!CheckAssetLockTx(CTransaction(txNoReturn), tx_state)); BOOST_CHECK(!CheckAssetLockTx(CTransaction(txNoReturn), tx_state));
@ -287,7 +287,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)
{ {
// OP_RETURN should not have any data // OP_RETURN should not have any data
CMutableTransaction txReturnData = tx; CMutableTransaction txReturnData(tx);
txReturnData.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("abc"); txReturnData.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("abc");
BOOST_CHECK(!CheckAssetLockTx(CTransaction(txReturnData), tx_state)); BOOST_CHECK(!CheckAssetLockTx(CTransaction(txReturnData), tx_state));
@ -303,7 +303,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetunlock, TestChain100Setup)
CKey key; CKey key;
key.MakeNewKey(true); key.MakeNewKey(true);
const CMutableTransaction tx = CreateAssetUnlockTx(keystore, key); const CTransaction tx = CreateAssetUnlockTx(keystore, key);
std::string reason; std::string reason;
BOOST_CHECK(IsStandardTx(CTransaction(tx), reason)); BOOST_CHECK(IsStandardTx(CTransaction(tx), reason));
@ -322,7 +322,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetunlock, TestChain100Setup)
CCoinsViewCache coins(&coinsDummy); CCoinsViewCache coins(&coinsDummy);
std::vector<CMutableTransaction> dummyTransactions = SetupDummyInputs(keystore, coins); std::vector<CMutableTransaction> dummyTransactions = SetupDummyInputs(keystore, coins);
CMutableTransaction txNonemptyInput = tx; CMutableTransaction txNonemptyInput(tx);
txNonemptyInput.vin.resize(1); txNonemptyInput.vin.resize(1);
txNonemptyInput.vin[0].prevout.hash = dummyTransactions[0].GetHash(); txNonemptyInput.vin[0].prevout.hash = dummyTransactions[0].GetHash();
txNonemptyInput.vin[0].prevout.n = 1; txNonemptyInput.vin[0].prevout.n = 1;
@ -344,7 +344,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetunlock, TestChain100Setup)
BOOST_CHECK(unlockPayload->getIndex() == 0x001122334455667788L); BOOST_CHECK(unlockPayload->getIndex() == 0x001122334455667788L);
// Wrong type "Asset Lock TX" instead "Asset Unlock TX" // Wrong type "Asset Lock TX" instead "Asset Unlock TX"
CMutableTransaction txWrongType = tx; CMutableTransaction txWrongType(tx);
txWrongType.nType = TRANSACTION_ASSET_LOCK; txWrongType.nType = TRANSACTION_ASSET_LOCK;
BOOST_CHECK(!CheckAssetUnlockTx(CTransaction(txWrongType), block_index, std::nullopt, tx_state)); BOOST_CHECK(!CheckAssetUnlockTx(CTransaction(txWrongType), block_index, std::nullopt, tx_state));
BOOST_CHECK(tx_state.GetRejectReason() == "bad-assetunlocktx-type"); BOOST_CHECK(tx_state.GetRejectReason() == "bad-assetunlocktx-type");
@ -358,7 +358,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetunlock, TestChain100Setup)
unlockPayload->getRequestedHeight(), unlockPayload->getRequestedHeight(),
unlockPayload->getQuorumHash(), unlockPayload->getQuorumHash(),
unlockPayload->getQuorumSig()}; unlockPayload->getQuorumSig()};
CMutableTransaction txWrongVersion = tx; CMutableTransaction txWrongVersion(tx);
SetTxPayload(txWrongVersion, unlockPayload_tmp); SetTxPayload(txWrongVersion, unlockPayload_tmp);
if (payload_version != 1) { if (payload_version != 1) {
BOOST_CHECK(!CheckAssetUnlockTx(CTransaction(txWrongVersion), block_index, std::nullopt, tx_state)); BOOST_CHECK(!CheckAssetUnlockTx(CTransaction(txWrongVersion), block_index, std::nullopt, tx_state));
@ -372,7 +372,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetunlock, TestChain100Setup)
{ {
// Exactly 32 withdrawal is fine // Exactly 32 withdrawal is fine
CMutableTransaction txManyOutputs = tx; CMutableTransaction txManyOutputs(tx);
int outputsLimit = 32; int outputsLimit = 32;
txManyOutputs.vout.resize(outputsLimit); txManyOutputs.vout.resize(outputsLimit);
for (auto& out : txManyOutputs.vout) { for (auto& out : txManyOutputs.vout) {