Skip to content

Commit

Permalink
refactor: use CTransaction for immutable tx in evo_assetlocks_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
panleone committed Mar 24, 2024
1 parent ca0fe8c commit d9f0e93
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/test/evo_assetlocks_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)
CKey key;
key.MakeNewKey(true);

const CMutableTransaction tx = CreateAssetLockTx(keystore, coins, key);
const CTransaction tx = CreateAssetLockTx(keystore, coins, key);
std::string reason;
BOOST_CHECK(IsStandardTx(CTransaction(tx), reason));

Expand All @@ -159,7 +159,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)

{
// Wrong type "Asset Unlock TX" instead "Asset Lock TX"
CMutableTransaction txWrongType = tx;
CMutableTransaction txWrongType(tx);
txWrongType.nType = TRANSACTION_ASSET_UNLOCK;
BOOST_CHECK(!CheckAssetLockTx(CTransaction(txWrongType), tx_state));
BOOST_CHECK(tx_state.GetRejectReason() == "bad-assetlocktx-type");
Expand All @@ -175,13 +175,13 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)
BOOST_CHECK(inSum == outSum);

// Outputs should not be bigger than inputs
CMutableTransaction txBigOutput = tx;
CMutableTransaction txBigOutput(tx);
txBigOutput.vout[0].nValue += 1;
BOOST_CHECK(!CheckAssetLockTx(CTransaction(txBigOutput), tx_state));
BOOST_CHECK(tx_state.GetRejectReason() == "bad-assetlocktx-creditamount");

// Smaller outputs are allown
CMutableTransaction txSmallOutput = tx;
CMutableTransaction txSmallOutput(tx);
txSmallOutput.vout[1].nValue -= 1;
BOOST_CHECK(CheckAssetLockTx(CTransaction(txSmallOutput), tx_state));
}
Expand All @@ -195,7 +195,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)
wrongOutput[0].nValue += CENT;
CAssetLockPayload greaterCreditsPayload(wrongOutput);

CMutableTransaction txGreaterCredits = tx;
CMutableTransaction txGreaterCredits(tx);
SetTxPayload(txGreaterCredits, greaterCreditsPayload);

BOOST_CHECK(!CheckAssetLockTx(CTransaction(txGreaterCredits), tx_state));
Expand All @@ -205,7 +205,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)
wrongOutput[1].nValue -= 2 * CENT;
CAssetLockPayload lessCreditsPayload(wrongOutput);

CMutableTransaction txLessCredits = tx;
CMutableTransaction txLessCredits(tx);
SetTxPayload(txLessCredits, lessCreditsPayload);

BOOST_CHECK(!CheckAssetLockTx(CTransaction(txLessCredits), tx_state));
Expand All @@ -218,7 +218,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)
creditOutputsOutOfRange[0].nValue = 0;
CAssetLockPayload invalidOutputsPayload(creditOutputsOutOfRange);

CMutableTransaction txInvalidOutputs = tx;
CMutableTransaction txInvalidOutputs(tx);
SetTxPayload(txInvalidOutputs, invalidOutputsPayload);

BOOST_CHECK(!CheckAssetLockTx(CTransaction(txInvalidOutputs), tx_state));
Expand All @@ -243,7 +243,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)
creditOutputsNotPubkey[0].scriptPubKey = CScript() << OP_1;
CAssetLockPayload notPubkeyPayload(creditOutputsNotPubkey);

CMutableTransaction txNotPubkey = tx;
CMutableTransaction txNotPubkey(tx);
SetTxPayload(txNotPubkey, notPubkeyPayload);

BOOST_CHECK(!CheckAssetLockTx(CTransaction(txNotPubkey), tx_state));
Expand All @@ -253,7 +253,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)

{
// OP_RETURN must be only one, not more
CMutableTransaction txMultipleReturn = tx;
CMutableTransaction txMultipleReturn(tx);
txMultipleReturn.vout[1].scriptPubKey = CScript() << OP_RETURN << ParseHex("");

BOOST_CHECK(!CheckAssetLockTx(CTransaction(txMultipleReturn), tx_state));
Expand All @@ -263,7 +263,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)

{
// zero/negative OP_RETURN
CMutableTransaction txReturnOutOfRange = tx;
CMutableTransaction txReturnOutOfRange(tx);
txReturnOutOfRange.vout[0].nValue = 0;

BOOST_CHECK(!CheckAssetLockTx(CTransaction(txReturnOutOfRange), tx_state));
Expand All @@ -278,7 +278,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)

{
// OP_RETURN is missing
CMutableTransaction txNoReturn = tx;
CMutableTransaction txNoReturn(tx);
txNoReturn.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));

BOOST_CHECK(!CheckAssetLockTx(CTransaction(txNoReturn), tx_state));
Expand All @@ -287,7 +287,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetlock, TestChain100Setup)

{
// OP_RETURN should not have any data
CMutableTransaction txReturnData = tx;
CMutableTransaction txReturnData(tx);
txReturnData.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("abc");

BOOST_CHECK(!CheckAssetLockTx(CTransaction(txReturnData), tx_state));
Expand All @@ -303,7 +303,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetunlock, TestChain100Setup)
CKey key;
key.MakeNewKey(true);

const CMutableTransaction tx = CreateAssetUnlockTx(keystore, key);
const CTransaction tx = CreateAssetUnlockTx(keystore, key);
std::string reason;
BOOST_CHECK(IsStandardTx(CTransaction(tx), reason));

Expand All @@ -322,7 +322,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetunlock, TestChain100Setup)
CCoinsViewCache coins(&coinsDummy);
std::vector<CMutableTransaction> dummyTransactions = SetupDummyInputs(keystore, coins);

CMutableTransaction txNonemptyInput = tx;
CMutableTransaction txNonemptyInput(tx);
txNonemptyInput.vin.resize(1);
txNonemptyInput.vin[0].prevout.hash = dummyTransactions[0].GetHash();
txNonemptyInput.vin[0].prevout.n = 1;
Expand All @@ -344,7 +344,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetunlock, TestChain100Setup)
BOOST_CHECK(unlockPayload->getIndex() == 0x001122334455667788L);

// Wrong type "Asset Lock TX" instead "Asset Unlock TX"
CMutableTransaction txWrongType = tx;
CMutableTransaction txWrongType(tx);
txWrongType.nType = TRANSACTION_ASSET_LOCK;
BOOST_CHECK(!CheckAssetUnlockTx(CTransaction(txWrongType), block_index, std::nullopt, tx_state));
BOOST_CHECK(tx_state.GetRejectReason() == "bad-assetunlocktx-type");
Expand All @@ -358,7 +358,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetunlock, TestChain100Setup)
unlockPayload->getRequestedHeight(),
unlockPayload->getQuorumHash(),
unlockPayload->getQuorumSig()};
CMutableTransaction txWrongVersion = tx;
CMutableTransaction txWrongVersion(tx);
SetTxPayload(txWrongVersion, unlockPayload_tmp);
if (payload_version != 1) {
BOOST_CHECK(!CheckAssetUnlockTx(CTransaction(txWrongVersion), block_index, std::nullopt, tx_state));
Expand All @@ -372,7 +372,7 @@ BOOST_FIXTURE_TEST_CASE(evo_assetunlock, TestChain100Setup)

{
// Exactly 32 withdrawal is fine
CMutableTransaction txManyOutputs = tx;
CMutableTransaction txManyOutputs(tx);
int outputsLimit = 32;
txManyOutputs.vout.resize(outputsLimit);
for (auto& out : txManyOutputs.vout) {
Expand Down

0 comments on commit d9f0e93

Please sign in to comment.