14 #include <boost/test/unit_test.hpp>
27 auto fvk_from = sk_from.full_viewing_key();
30 auto fvk = sk.full_viewing_key();
31 auto ivk = fvk.in_viewing_key();
32 diversifier_t d = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
33 auto pk = *ivk.address(d);
38 builder.AddTransparentInput(
COutPoint(
uint256S(
"1234"), 0), scriptPubKey, 50000000);
39 builder.AddSaplingOutput(fvk_from.ovk, pk, 40000000, {});
40 builder.SetFee(10000000);
41 auto tx = builder.Build().GetTxOrThrow();
59 auto expsk = sk.expanded_spending_key();
60 auto fvk = sk.full_viewing_key();
61 auto pa = sk.default_address();
67 builder.AddSaplingSpend(expsk, testNote.note, testNote.tree.root(), testNote.tree.witness());
68 builder.SetFee(10000000);
72 BOOST_CHECK_THROW(builder.AddSaplingSpend(expsk, testNote.note,
uint256(), testNote.tree.witness()), std::runtime_error);
74 builder.AddSaplingOutput(fvk.ovk, pa, 29900000, {});
75 auto tx = builder.Build().GetTxOrThrow();
91 builder2.AddSaplingSpend(expsk, testNote2.note, testNote2.tree.root(), testNote2.tree.witness());
92 builder2.SetFee(10000000);
93 builder2.AddSaplingOutput(fvk.ovk, pa, 50000000, {});
94 auto tx2 = builder2.Build().GetTxOrThrow();
132 auto expsk = sk.expanded_spending_key();
133 auto fvk = sk.full_viewing_key();
134 auto pa = sk.default_address();
149 builder.AddSaplingOutput(fvk.ovk, pa, 50000000, {});
150 builder.SetFee(10000000);
156 builder.AddTransparentOutput(taddr, 50000000);
157 builder.SetFee(10000000);
162 builder.AddSaplingSpend(expsk, testNote.note, testNote.tree.root(), testNote.tree.witness());
166 builder.AddTransparentInput(
COutPoint(), scriptPubKey, 10000);
176 auto expsk = sk.expanded_spending_key();
177 auto pa = sk.default_address();
183 auto fvkOut = sk2.full_viewing_key();
184 auto zChangeAddr = sk2.default_address();
196 builder.SetFee(10000000);
197 builder.AddTransparentInput(
COutPoint(), scriptPubKey, 25000000);
198 BOOST_CHECK_EQUAL(
"Could not determine change address", builder.Build().GetError());
204 builder.SetFee(10000000);
205 builder.AddTransparentInput(
COutPoint(), scriptPubKey, 25000000);
206 builder.AddSaplingSpend(expsk, testNote.note, testNote.tree.root(), testNote.tree.witness());
207 auto tx = builder.Build().GetTxOrThrow();
219 builder.SetFee(10000000);
220 builder.AddTransparentInput(
COutPoint(), scriptPubKey, 25000000);
221 builder.SendChangeTo(zChangeAddr, fvkOut.ovk);
222 auto tx = builder.Build().GetTxOrThrow();
234 builder.SetFee(10000000);
235 builder.AddTransparentInput(
COutPoint(), scriptPubKey, 25000000);
236 builder.SendChangeTo(taddr);
237 auto tx = builder.Build().GetTxOrThrow();
254 auto expsk = sk.expanded_spending_key();
255 auto fvk = sk.full_viewing_key();
256 auto pa = sk.default_address();
263 builder.AddSaplingSpend(expsk, testNote.note, testNote.tree.root(), testNote.tree.witness());
264 builder.AddSaplingOutput(fvk.ovk, pa, 3 * COIN, {});
266 builder.SetFee(COIN);
267 auto tx = builder.Build().GetTxOrThrow();
282 auto expsk = sk.expanded_spending_key();
283 auto pk = sk.default_address();
287 builder.SetFee(10000000);
289 builder.AddSaplingOutput(
uint256(), pk, 12345, {});
290 }
catch (std::runtime_error
const & err) {
291 BOOST_CHECK_EQUAL(err.what(), std::string(
"TransactionBuilder cannot add Sapling output to pre-Sapling transaction"));
293 BOOST_CHECK_MESSAGE(
false,
"Expected std::runtime_error");
301 }
catch (std::runtime_error
const & err) {
302 BOOST_CHECK_EQUAL(err.what(), std::string(
"TransactionBuilder cannot add Sapling spend to pre-Sapling transaction"));
304 BOOST_CHECK_MESSAGE(
false,
"Expected std::runtime_error");
const CChainParams & Params()
Return the currently selected parameters.
Basic key store, that keeps keys in an address->secret map.
const Consensus::Params & GetConsensus() const
An encapsulated private key.
CPubKey GetPubKey() const
Compute the public key from a private key.
An outpoint - a combination of a transaction hash and an index n into its vout.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Serialized script, used inside transaction inputs and outputs.
Capture information about block/transaction validation.
std::string GetRejectReason() const
IncrementalWitness< Depth, Hash > witness() const
static SaplingSpendingKey random()
BOOST_AUTO_TEST_SUITE_END()
bool ContextualCheckTransaction(const CTransaction &tx, CValidationState &state, const CChainParams &chainparams, const int nHeight, const bool isMined, bool isInitBlockDownload)
Check a transaction contextually against a set of consensus rules valid at a given block height.
#define BOOST_CHECK_THROW(stmt, excMatch)
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
std::array< unsigned char, ZC_DIVERSIFIER_SIZE > diversifier_t
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.
Regtest setup with sapling always active.
BOOST_AUTO_TEST_CASE(TransparentToSapling)
uint256 uint256S(const char *str)
CKey AddTestCKeyToKeyStore(CBasicKeyStore &keyStore, bool genNewKey)
TestSaplingNote GetTestSaplingNote(const libzcash::SaplingPaymentAddress &pa, CAmount value)
Generate a dummy SaplingNote and a SaplingMerkleTree with that note's commitment.