23 #include <unordered_set>
25 #include <boost/test/unit_test.hpp>
35 class PushCurrentDirectory {
37 explicit PushCurrentDirectory(
const std::string &new_cwd)
38 : old_cwd(fs::current_path()) {
39 fs::current_path(new_cwd);
42 ~PushCurrentDirectory() {
43 fs::current_path(old_cwd);
69 std::set<libzcash::SaplingPaymentAddress> addrs;
70 m_wallet.GetSaplingPaymentAddresses(addrs);
74 BOOST_CHECK_NO_THROW(retValue =
CallRPC(
"validateaddress ptestsapling1nrn6exksuqtpld9gu6fwdz4hwg54h2x37gutdds89pfyg6mtjf63km45a8eare5qla45cj75vs8"));
80 BOOST_CHECK_NO_THROW(retValue =
CallRPC(
"validateaddress ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej"));
87 BOOST_CHECK_EQUAL(
find_value(resultObj,
"diversifiedtransmissionkey").get_str(),
"d35e0d0897edbd3cf02b3d2327622a14c685534dbd2d3f4f4fa3e0e56cc2f008");
95 LOCK(m_wallet.cs_wallet);
97 m_wallet.SetupSPKM(
false);
105 BOOST_CHECK_THROW(
CallRPC(
"getshieldbalance ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej -1"), std::runtime_error);
106 BOOST_CHECK_NO_THROW(
CallRPC(
"getshieldbalance ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej 0"));
107 BOOST_CHECK_THROW(
CallRPC(
"getshieldbalance tnRZ8bPq2pff3xBWhTJhNkVUkm2uhzksDeW5PvEa7aFKGT9Qi3YgTALZfjaY4jU3HLVKBtHdSXxoPoLA3naMPcHBcY88FcF 1"), std::runtime_error);
114 BOOST_CHECK_THROW(
CallRPC(
"listreceivedbyshieldaddress DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ -1"), std::runtime_error);
118 BOOST_CHECK_THROW(
CallRPC(
"listreceivedbyshieldaddress ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej 1"), std::runtime_error);
126 LOCK(m_wallet.cs_wallet);
128 m_wallet.SetupSPKM(
false);
132 auto testAddress = [](
const std::string& key) {
142 testAddress(
"p-secret-spending-key-main1qv09u0wlqqqqpqp75kpmat6l3ce29k"
143 "g9half9epsm80wya5n92j4d8mtmesrukzxlsmm2f74v3nvvx2shxy4z5v5x39p"
144 "eelsy5y2uxmvadaku8crd20q6vt8cvd68wp08cjyec6cku0dcf5lc9c2kykg5c"
145 "8uqmqlx8ccxpsw7ae243quhwr0zyekrrc520gs9z0j8pm954c3cev2yvp29vrc"
146 "0zweu7stxkwhp593p6drheps9uhz9pvkrfgvpxzte8d60uzw0qxadnsc77tcd");
157 LOCK(m_wallet.cs_wallet);
159 m_wallet.SetupSPKM(
false);
184 std::set<libzcash::SaplingPaymentAddress> saplingAddrs;
185 m_wallet.GetSaplingPaymentAddresses(saplingAddrs);
189 for (
int i = 0; i < n1; i++) {
191 auto testSaplingSpendingKey = m.Derive(i);
192 auto testSaplingPaymentAddress = testSaplingSpendingKey.DefaultAddress();
206 std::unordered_set<std::string> myaddrs;
208 myaddrs.insert(element.get_str());
212 for (
int i=0; i<n2; i++) {
217 int numAddrs = myaddrs.size();
219 m_wallet.GetSaplingPaymentAddresses(saplingAddrs);
220 BOOST_CHECK((
int) saplingAddrs.size() == numAddrs);
228 std::unordered_set<std::string> listaddrs;
230 listaddrs.insert(element.get_str());
245 auto addr_of_type = boost::get<libzcash::SaplingPaymentAddress>(&addr);
246 BOOST_ASSERT(addr_of_type !=
nullptr);
253 LOCK(m_wallet.cs_wallet);
255 m_wallet.SetupSPKM(
false);
271 LOCK(m_wallet.cs_wallet);
273 m_wallet.SetupSPKM(
false);
283 "INVALIDDMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ []"), std::runtime_error);
286 "DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ []"), std::runtime_error);
290 "ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej []"), std::runtime_error);
294 "DDTBEPEaub5sk31mUifiv5nHGXtHGnuAJc "
295 "[{\"address\":\"DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ\", \"amount\":50.0},"
296 " {\"address\":\"DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ\", \"amount\":12.0} ]"
297 ), std::runtime_error);
301 "DDTBEPEaub5sk31mUifiv5nHGXtHGnuAJc "
302 "[{\"address\":\"DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ\", \"amount\":50.0}] "
304 ), std::runtime_error);
308 "DDTBEPEaub5sk31mUifiv5nHGXtHGnuAJc "
309 "[{\"address\":\"DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ\", \"amount\":50.0}] "
311 ), std::runtime_error);
315 "DDTBEPEaub5sk31mUifiv5nHGXtHGnuAJc "
316 "[{\"address\":\"DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ\", \"amount\":50.0}] "
318 ), std::runtime_error);
322 std::fill(v.begin(),v.end(),
'A');
323 std::string badmemo(v.begin(), v.end());
324 auto pa = m_wallet.GenerateNewSaplingZKey();
327 +
"[{\"address\":\"" + zaddr1 +
"\", \"amount\":123.456}]"), std::runtime_error);
337 m_wallet.SetupSPKM(
false);
346 const std::string& taddrStr = retValue.
get_str();
348 const auto& zaddr1 = m_wallet.GenerateNewSaplingZKey();
353 std::vector<SendManyRecipient> recipients = {
SendManyRecipient(zaddr1, COIN,
"DEADBEEF",
false) };
358 BOOST_CHECK(res.getError().find(
"Insufficient funds, no available UTXO to spend") != std::string::npos);
363 std::vector<SendManyRecipient> recipients = {
SendManyRecipient(zaddr1, COIN,
"DEADBEEF",
false) };
368 BOOST_CHECK(res.getError().find(
"Minconf cannot be zero when sending from shielded address") != std::string::npos);
373 std::vector<SendManyRecipient> recipients = {
SendManyRecipient(taddr1, COIN,
false) };
378 BOOST_CHECK(res.getError().find(
"Insufficient funds, no available notes to spend") != std::string::npos);
383 std::string memoStr =
"Sapling memo!";
384 std::array<unsigned char, ZC_MEMO_SIZE> memo;
401 std::fill(v.begin(),v.end(),
'A');
402 std::string bigmemo(v.begin(), v.end());
406 const std::string& errStr = res.
getError();
407 BOOST_CHECK(errStr.find(
"too big") != std::string::npos);
418 m_wallet.SetupSPKM(
false);
425 auto res = m_wallet.getNewAddress(
"");
429 auto zaddr1 = m_wallet.GenerateNewSaplingZKey();
437 CWalletTx wtxIn(&m_wallet, MakeTransactionRef(mtx));
438 m_wallet.LoadToWallet(wtxIn);
445 block.
vtx.emplace_back(wtx.
tx);
447 auto blockHash = block.
GetHash();
449 fakeIndex.nHeight = 1;
450 BlockMap::iterator mi =
mapBlockIndex.emplace(blockHash, &fakeIndex).first;
451 fakeIndex.phashBlock = &((*mi).first);
455 m_wallet.BlockConnected(std::make_shared<CBlock>(block), mi->second);
456 BOOST_CHECK_MESSAGE(m_wallet.GetAvailableBalance() > 0,
"tx not confirmed");
458 std::vector<SendManyRecipient> recipients = {
SendManyRecipient(zaddr1, 1 * COIN,
"ABCD",
false) };
466 std::vector<SendManyRecipient> recipients2 = {
SendManyRecipient(zaddr1, 1 * COIN,
"ABCD",
false) };
478 BOOST_ASSERT(!tx.
sapData->vShieldedOutput.empty());
482 tx.
sapData->vShieldedOutput[0].outCiphertext,
484 tx.
sapData->vShieldedOutput[0].cv,
485 tx.
sapData->vShieldedOutput[0].cmu,
486 tx.
sapData->vShieldedOutput[0].ephemeralKey));
489 tx.
sapData->vShieldedOutput[0].outCiphertext,
490 m_wallet.GetSaplingScriptPubKeyMan()->getCommonOVK(),
491 tx.
sapData->vShieldedOutput[0].cv,
492 tx.
sapData->vShieldedOutput[0].cmu,
493 tx.
sapData->vShieldedOutput[0].ephemeralKey));
504 LOCK(m_wallet.cs_wallet);
505 m_wallet.SetupSPKM(
false);
524 BOOST_CHECK_THROW(
CallRPC(
"listshieldunspent 1 999 false ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej"), std::runtime_error);
530 BOOST_CHECK_THROW(
CallRPC(
"listshieldunspent 1 999 false [\"ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej\"]"), std::runtime_error);
533 BOOST_CHECK_NO_THROW(
CallRPC(
"listshieldunspent 1 999 true [\"ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej\"]"));
536 BOOST_CHECK_THROW(
CallRPC(
"listshieldunspent 1 999 true [\"ptestsapling1wpurflqllgkcs48m46yu9ktlfe3ahndely20dpaanqq3lw9l5xw7yfehst68yclvlpz7x8cltxe\"]"), std::runtime_error);
540 std::string myzaddr = retValue.
get_str();
548 BOOST_CHECK_THROW(
CallRPC(
"listshieldunspent 1 999 false [\"" + myzaddr +
"\", \"" + myzaddr +
"\"]"), std::runtime_error);
bool IsValidPaymentAddress(const libzcash::PaymentAddress &zaddr)
Check whether a PaymentAddress is not an InvalidEncoding.
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given chain name.
const CChainParams & Params()
Return the currently selected parameters.
static const std::string MAIN
Chain name strings.
std::vector< CTransactionRef > vtx
The block chain is a tree shaped structure starting with the genesis block at the root,...
uint256 GetBlockHash() const
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or nullptr if none.
int Height() const
Return the maximal height in the chain.
void SetTip(CBlockIndex *pindex)
Set/initialize a chain with a given tip.
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
const Consensus::Params & GetConsensus() const
The basic transaction that is broadcasted on the network and contained in blocks.
Optional< SaplingTxData > sapData
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
bool HaveSpendingKeyForPaymentAddress(const libzcash::SaplingPaymentAddress &zaddr) const
Returns true if the wallet contains the spending key.
A transaction with a bunch of additional info that only the owner cares about.
std::string getError() const
CTransaction getFinalTx()
void setFromAddress(const CTxDestination &)
SaplingOperation * setRecipients(std::vector< SendManyRecipient > &vec)
SaplingOperation * setMinDepth(int _mindepth)
OperationResult buildAndSend(std::string &retTxHash)
SaplingOperation * setSelectTransparentCoins(const bool select, const bool _fIncludeDelegated=false)
const std::string & get_str() const
const UniValue & get_obj() const
const std::vector< UniValue > & getValues() const
const UniValue & get_array() const
std::string EncodeHexTx(const CTransaction &tx)
BOOST_AUTO_TEST_SUITE_END()
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
std::string EncodePaymentAddress(const libzcash::PaymentAddress &zaddr)
libzcash::PaymentAddress DecodePaymentAddress(const std::string &str)
std::string EncodeSpendingKey(const libzcash::SpendingKey &zkey)
std::string EncodeDestination(const CWDestination &address, const CChainParams::Base58Type addrType)
CWDestination DecodeDestination(const std::string &strAddress)
boost::variant< InvalidEncoding, SaplingPaymentAddress > PaymentAddress
Optional< SaplingOutPlaintext > AttemptSaplingOutDecryption(const SaplingOutCiphertext &ciphertext, const uint256 &ovk, const uint256 &cv, const uint256 &cm, const uint256 &epk)
RecursiveMutex cs_main
Global state.
#define BOOST_CHECK_THROW(stmt, excMatch)
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK_NO_THROW(stmt)
#define BOOST_CHECK(expr)
OperationResult GetMemoFromString(const std::string &s, std::array< unsigned char, ZC_MEMO_SIZE > &memoRet)
UniValue CallRPC(std::string args)
BOOST_AUTO_TEST_CASE(rpc_wallet_sapling_validateaddress)
This test covers RPC command validateaddress.
void CheckHaveAddr(CWallet &pwallet, const libzcash::PaymentAddress &addr)
constexpr deserialize_type deserialize
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.
A mutable version of CTransaction.
uint256 GetHash() const
Compute the hash of this CMutableTransaction.
std::vector< CTxOut > vout
const UniValue & find_value(const UniValue &obj, const std::string &name)
std::vector< unsigned char > ParseHex(const char *psz)
libzcash::SaplingExtendedSpendingKey GetTestMasterSaplingSpendingKey()
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
std::vector< CWalletRef > vpwallets