12 #include <boost/test/unit_test.hpp>
31 int SAPLING_ACTIVATION_HEIGHT = 101;
57 static SaplingOperation createOperationAndBuildTx(std::unique_ptr<CWallet>& pwallet,
58 std::vector<SendManyRecipient> recipients,
59 bool selectTransparentCoins)
63 auto operationResult = operation.setRecipients(recipients)
64 ->setSelectTransparentCoins(selectTransparentCoins)
65 ->setSelectShieldedCoins(!selectTransparentCoins)
67 BOOST_ASSERT_MSG(operationResult, operationResult.getError().c_str());
72 "Invalid Sapling transaction");
79 auto ret = pwalletMain->getNewAddress(
"coinbase");
82 BOOST_ASSERT_MSG(ret,
"cannot create address");
84 BOOST_ASSERT_MSG(
IsMine(*pwalletMain, coinbaseDest),
"destination not from wallet");
90 int nGenerateBlocks = 110;
91 for (
int i = tipHeight; i < nGenerateBlocks; ++i) {
92 CreateAndProcessBlock({}, scriptPubKey);
105 std::vector<SendManyRecipient> recipients;
107 recipients.emplace_back(pa,
CAmount(100 * COIN),
"",
false);
110 SaplingOperation operation = createOperationAndBuildTx(pwalletMain, recipients,
true);
113 BOOST_ASSERT_MSG(operation.
send(retHash),
"error committing and broadcasting the transaction");
116 for (
int i = 1; i <= 5; ++i) {
117 CreateAndProcessBlock({}, scriptPubKey,
false );
129 auto res = pwalletMain->getNewAddress(
"receiveValid");
132 std::vector<SendManyRecipient> recipients2;
133 recipients2.emplace_back(tDest2,
CAmount(90 * COIN),
false);
134 SaplingOperation operation2 = createOperationAndBuildTx(pwalletMain, recipients2,
false);
137 res = pwalletMain->getNewAddress(
"receiveInvalid");
140 std::vector<SendManyRecipient> recipients3;
141 recipients3.emplace_back(tDest3,
CAmount(5 * COIN),
false);
142 SaplingOperation operation3 = createOperationAndBuildTx(pwalletMain, recipients3,
false);
145 std::string retTxHash2;
149 std::string retTxHash3;
150 auto opResult3 = operation3.
send(retTxHash3);
152 BOOST_CHECK(opResult3.getError().find(
"bad-txns-nullifier-double-spent"));
156 const CBlock& block = CreateAndProcessBlock({operation3.
getFinalTx()}, scriptPubKey,
false );
int64_t CAmount
Amount in PIV (Can be negative)
void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivationHeight)
Allows modifying the network upgrade regtest parameters.
const CChainParams & Params()
Return the currently selected parameters.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
static std::unique_ptr< BerkeleyDatabase > CreateMock()
Return object for accessing temporary in-memory database.
uint256 GetBlockHash() const
int nHeight
height of the entry in the chain. The genesis block has height 0
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or nullptr if none.
CPubKey GetPubKey() const
Compute the public key from a private key.
Serialized script, used inside transaction inputs and outputs.
Capture information about block/transaction validation.
CTransaction getFinalTx()
OperationResult send(std::string &retTxHash)
RAII object to check and reserve a wallet rescan.
BOOST_AUTO_TEST_SUITE_END()
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest)
bool IsValidDestination(const CWDestination &address)
RecursiveMutex cs_main
Global state.
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a PIVX scriptPubKey for the given CTxDestination.
boost::variant< CNoDestination, CKeyID, CScriptID, CExchangeKeyID > CTxDestination
A txout script template with a specific destination.
std::unique_ptr< CWallet > pwalletMain
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
bool CheckTransaction(const CTransaction &tx, CValidationState &state, bool fColdStakingActive)
Transaction validation functions.
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
void UnregisterValidationInterface(CValidationInterface *pwalletIn)
Unregister a wallet from core.
void RegisterValidationInterface(CValidationInterface *pwalletIn)
Register a wallet to receive updates from core.
void SyncWithValidationInterfaceQueue()
This is a synonym for the following, which asserts certain locks are not held: std::promise<void> pro...
BOOST_AUTO_TEST_CASE(test_in_block_and_mempool_notes_double_spend)