From 739e0ed151ecdb37f223d2085cc83cdb5a7b2192 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Tue, 28 May 2019 11:34:05 +0100 Subject: [PATCH] Fix Travis builds --- .travis/test_06_script_a.sh | 2 +- .travis/test_06_script_b.sh | 2 +- src/qt/walletmodel.cpp | 4 + src/qt/walletmodel.h | 7 ++ src/test/mempool_tests.cpp | 174 ++++++++++++++++++------------------ 5 files changed, 100 insertions(+), 89 deletions(-) diff --git a/.travis/test_06_script_a.sh b/.travis/test_06_script_a.sh index 830197fdc3a..dfd916bb731 100755 --- a/.travis/test_06_script_a.sh +++ b/.travis/test_06_script_a.sh @@ -71,7 +71,7 @@ fi if [ "$RUN_FEDPEG_BITCOIND_TEST" = "true" ]; then BEGIN_FOLD fedpeg-bitcoind-test - BITCOIND_VERSION=0.17.1 + BITCOIND_VERSION=0.18.0 BITCOIND_ARCH=x86_64-linux-gnu DOCKER_EXEC curl -O https://bitcoincore.org/bin/bitcoin-core-$BITCOIND_VERSION/bitcoin-$BITCOIND_VERSION-$BITCOIND_ARCH.tar.gz DOCKER_EXEC tar -zxf bitcoin-$BITCOIND_VERSION-$BITCOIND_ARCH.tar.gz diff --git a/.travis/test_06_script_b.sh b/.travis/test_06_script_b.sh index e13abfd52f3..268d6fde9e6 100755 --- a/.travis/test_06_script_b.sh +++ b/.travis/test_06_script_b.sh @@ -6,7 +6,7 @@ export LC_ALL=C.UTF-8 -cd "build/bitcoin-$HOST" || (echo "could not enter distdir build/bitcoin-$HOST"; exit 1) +cd "build/elements-$HOST" || (echo "could not enter distdir build/bitcoin-$HOST"; exit 1) if [ "$RUN_UNIT_TESTS" = "true" ]; then BEGIN_FOLD unit-tests diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index eae0033e7ad..2fbb0beeadf 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -39,7 +39,11 @@ SendAssetsRecipient::SendAssetsRecipient(SendCoinsRecipient r) : asset(Params().GetConsensus().pegged_asset), asset_amount(r.amount), message(r.message), +#ifdef ENABLE_BIP70 paymentRequest(r.paymentRequest), +#else + sPaymentRequest(r.sPaymentRequest), +#endif authenticatedMerchant(r.authenticatedMerchant), fSubtractFeeFromAmount(r.fSubtractFeeFromAmount) { diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 2df9d35f146..6fba8f25138 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -133,7 +133,14 @@ class SendAssetsRecipient CAmount asset_amount; QString message; +#ifdef ENABLE_BIP70 + // If from a payment request, paymentRequest.IsInitialized() will be true PaymentRequestPlus paymentRequest; +#else + // If building with BIP70 is disabled, keep the payment request around as + // serialized string to ensure load/store is lossless + std::string sPaymentRequest; +#endif QString authenticatedMerchant; bool fSubtractFeeFromAmount; // memory only diff --git a/src/test/mempool_tests.cpp b/src/test/mempool_tests.cpp index 397f82af5f4..dbf75b2c3da 100644 --- a/src/test/mempool_tests.cpp +++ b/src/test/mempool_tests.cpp @@ -420,93 +420,6 @@ BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest) CheckSort(pool, sortedOrder); } -// ELEMENTS: -BOOST_AUTO_TEST_CASE(PeginSpentTest) -{ - CBlockPolicyEstimator feeEst; - CTxMemPool pool(&feeEst); - LOCK(pool.cs); - - std::set > setPeginsSpent; - TestMemPoolEntryHelper entry; - - std::pair pegin1, pegin2, pegin3; - GetRandBytes(pegin1.first.begin(), pegin1.first.size()); - GetRandBytes(pegin2.first.begin(), pegin2.first.size()); - GetRandBytes(pegin3.first.begin(), pegin3.first.size()); - GetRandBytes(pegin1.second.hash.begin(), pegin1.second.hash.size()); - GetRandBytes(pegin2.second.hash.begin(), pegin2.second.hash.size()); - pegin3.second.hash = pegin2.second.hash; - pegin1.second.n = 0; - pegin2.second.n = 0; - pegin3.second.n = 1; - - CMutableTransaction tx; - tx.vin.resize(1); - tx.vout.resize(1); - tx.vout[0].nValue = 0; - pool.addUnchecked(entry.PeginsSpent(setPeginsSpent).FromTx(tx)); - BOOST_CHECK(pool.mapPeginsSpentToTxid.empty()); - - setPeginsSpent = {pegin1}; - GetRandBytes(tx.vin[0].prevout.hash.begin(), tx.vin[0].prevout.hash.size()); - tx.vout.resize(2); - tx.vout[1].nValue = 0; - const uint256 tx2Hash(tx.GetHash()); - pool.addUnchecked(entry.PeginsSpent(setPeginsSpent).FromTx(tx)); - BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid[pegin1].ToString(), tx2Hash.ToString()); - - setPeginsSpent = {pegin2}; - GetRandBytes(tx.vin[0].prevout.hash.begin(), tx.vin[0].prevout.hash.size()); - tx.vout.resize(3); - tx.vout[2].nValue = 0; - const uint256 tx3Hash(tx.GetHash()); - pool.addUnchecked(entry.PeginsSpent(setPeginsSpent).FromTx(tx)); - BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid[pegin2].ToString(), tx3Hash.ToString()); - - setPeginsSpent = {pegin3}; - GetRandBytes(tx.vin[0].prevout.hash.begin(), tx.vin[0].prevout.hash.size()); - tx.vout.resize(4); - tx.vout[3].nValue = 0; - CTransactionRef txref(MakeTransactionRef(tx)); - pool.removeForBlock({txref}, 1, setPeginsSpent); - - BOOST_CHECK_EQUAL(pool.size(), 3); - BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid.size(), 2); - BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid[pegin1].ToString(), tx2Hash.ToString()); - BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid[pegin2].ToString(), tx3Hash.ToString()); - - setPeginsSpent = {pegin1}; - GetRandBytes(tx.vin[0].prevout.hash.begin(), tx.vin[0].prevout.hash.size()); - tx.vout.resize(5); - tx.vout[4].nValue = 0; - txref = MakeTransactionRef(tx); - pool.removeForBlock({txref}, 2, setPeginsSpent); - - BOOST_CHECK_EQUAL(pool.size(), 2); - BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid.size(), 1); - BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid[pegin2].ToString(), tx3Hash.ToString()); - - setPeginsSpent = {pegin1, pegin3}; - GetRandBytes(tx.vin[0].prevout.hash.begin(), tx.vin[0].prevout.hash.size()); - tx.vout.resize(6); - tx.vout[5].nValue = 0; - const uint256 tx4Hash(tx.GetHash()); - pool.addUnchecked(entry.PeginsSpent(setPeginsSpent).FromTx(tx)); - BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid[pegin1].ToString(), tx4Hash.ToString()); - BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid[pegin3].ToString(), tx4Hash.ToString()); - - setPeginsSpent = {pegin2, pegin3}; - GetRandBytes(tx.vin[0].prevout.hash.begin(), tx.vin[0].prevout.hash.size()); - tx.vout.resize(7); - tx.vout[6].nValue = 0; - txref = MakeTransactionRef(tx); - pool.removeForBlock({txref}, 3, setPeginsSpent); - - BOOST_CHECK_EQUAL(pool.size(), 1); - BOOST_CHECK(pool.mapPeginsSpentToTxid.empty()); -} - BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest) { CTxMemPool pool; @@ -838,4 +751,91 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests) BOOST_CHECK_EQUAL(descendants, 6ULL); } +// ELEMENTS: +BOOST_AUTO_TEST_CASE(PeginSpentTest) +{ + CBlockPolicyEstimator feeEst; + CTxMemPool pool(&feeEst); + LOCK2(cs_main, pool.cs); + + std::set > setPeginsSpent; + TestMemPoolEntryHelper entry; + + std::pair pegin1, pegin2, pegin3; + GetRandBytes(pegin1.first.begin(), pegin1.first.size()); + GetRandBytes(pegin2.first.begin(), pegin2.first.size()); + GetRandBytes(pegin3.first.begin(), pegin3.first.size()); + GetRandBytes(pegin1.second.hash.begin(), pegin1.second.hash.size()); + GetRandBytes(pegin2.second.hash.begin(), pegin2.second.hash.size()); + pegin3.second.hash = pegin2.second.hash; + pegin1.second.n = 0; + pegin2.second.n = 0; + pegin3.second.n = 1; + + CMutableTransaction tx; + tx.vin.resize(1); + tx.vout.resize(1); + tx.vout[0].nValue = 0; + pool.addUnchecked(entry.PeginsSpent(setPeginsSpent).FromTx(tx)); + BOOST_CHECK(pool.mapPeginsSpentToTxid.empty()); + + setPeginsSpent = {pegin1}; + GetRandBytes(tx.vin[0].prevout.hash.begin(), tx.vin[0].prevout.hash.size()); + tx.vout.resize(2); + tx.vout[1].nValue = 0; + const uint256 tx2Hash(tx.GetHash()); + pool.addUnchecked(entry.PeginsSpent(setPeginsSpent).FromTx(tx)); + BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid[pegin1].ToString(), tx2Hash.ToString()); + + setPeginsSpent = {pegin2}; + GetRandBytes(tx.vin[0].prevout.hash.begin(), tx.vin[0].prevout.hash.size()); + tx.vout.resize(3); + tx.vout[2].nValue = 0; + const uint256 tx3Hash(tx.GetHash()); + pool.addUnchecked(entry.PeginsSpent(setPeginsSpent).FromTx(tx)); + BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid[pegin2].ToString(), tx3Hash.ToString()); + + setPeginsSpent = {pegin3}; + GetRandBytes(tx.vin[0].prevout.hash.begin(), tx.vin[0].prevout.hash.size()); + tx.vout.resize(4); + tx.vout[3].nValue = 0; + CTransactionRef txref(MakeTransactionRef(tx)); + pool.removeForBlock({txref}, 1, setPeginsSpent); + + BOOST_CHECK_EQUAL(pool.size(), 3); + BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid.size(), 2); + BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid[pegin1].ToString(), tx2Hash.ToString()); + BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid[pegin2].ToString(), tx3Hash.ToString()); + + setPeginsSpent = {pegin1}; + GetRandBytes(tx.vin[0].prevout.hash.begin(), tx.vin[0].prevout.hash.size()); + tx.vout.resize(5); + tx.vout[4].nValue = 0; + txref = MakeTransactionRef(tx); + pool.removeForBlock({txref}, 2, setPeginsSpent); + + BOOST_CHECK_EQUAL(pool.size(), 2); + BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid.size(), 1); + BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid[pegin2].ToString(), tx3Hash.ToString()); + + setPeginsSpent = {pegin1, pegin3}; + GetRandBytes(tx.vin[0].prevout.hash.begin(), tx.vin[0].prevout.hash.size()); + tx.vout.resize(6); + tx.vout[5].nValue = 0; + const uint256 tx4Hash(tx.GetHash()); + pool.addUnchecked(entry.PeginsSpent(setPeginsSpent).FromTx(tx)); + BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid[pegin1].ToString(), tx4Hash.ToString()); + BOOST_CHECK_EQUAL(pool.mapPeginsSpentToTxid[pegin3].ToString(), tx4Hash.ToString()); + + setPeginsSpent = {pegin2, pegin3}; + GetRandBytes(tx.vin[0].prevout.hash.begin(), tx.vin[0].prevout.hash.size()); + tx.vout.resize(7); + tx.vout[6].nValue = 0; + txref = MakeTransactionRef(tx); + pool.removeForBlock({txref}, 3, setPeginsSpent); + + BOOST_CHECK_EQUAL(pool.size(), 1); + BOOST_CHECK(pool.mapPeginsSpentToTxid.empty()); +} + BOOST_AUTO_TEST_SUITE_END()