10 #include <boost/test/unit_test.hpp>
16 const CKeyID* keyid = boost::get<CKeyID>(&dest);
21 BOOST_ERROR(
"Destination is not a CKeyID");
48 int nRequiredRet = -1;
49 std::vector<CTxDestination> destVector;
76 static const CAmount amtIn = 200 * COIN;
77 static const unsigned int flags = STANDARD_SCRIPT_VERIFY_FLAGS;
81 scriptP2CS = GetNewP2CS(stakerKey,
ownerKey, fLastOutFree);
85 txFrom.
vout.resize(1);
86 txFrom.
vout[0].nValue = amtIn;
87 txFrom.
vout[0].scriptPubKey = scriptP2CS;
93 tx.
vin[0].prevout.n = 0;
95 tx.
vout[0].nValue = 0;
96 tx.
vout[0].scriptPubKey.clear();
97 tx.
vout[1].nValue = amtIn + 2 * COIN;
98 tx.
vout[1].scriptPubKey = scriptP2CS;
105 assert(nIn < (
int) tx.
vin.size());
106 tx.
vin[nIn].scriptSig.clear();
110 std::vector<unsigned char> vchSig;
113 std::vector<unsigned char> selector(1, fStaker ? (
int)
OP_TRUE :
OP_FALSE);
137 BOOST_CHECK(CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
140 tx.
vout[1].nValue -= 3 * COIN;
142 BOOST_CHECK(!CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
146 tx.
vout.emplace_back(3 * COIN, scriptP2CS);
148 BOOST_CHECK(CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
152 const CScript& dummyP2PKH = GetDummyP2PKH(dummyKeyID);
155 tx.
vout.emplace_back(3 * COIN, dummyP2PKH);
157 BOOST_CHECK(CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
160 tx.
vout[2].nValue -= 3 * COIN;
161 tx.
vout[3].nValue += 3 * COIN;
163 BOOST_CHECK(!CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
168 tx.
vout[1].nValue -= 3 * COIN;
169 tx.
vout.emplace_back(3 * COIN, dummyP2PKH);
170 tx.
vout.emplace_back(3 * COIN, dummyP2PKH);
172 BOOST_CHECK(!CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
176 BOOST_CHECK(CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
180 tx.
vout[1].scriptPubKey = GetDummyP2CS(dummyKeyID);
182 BOOST_CHECK(!CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
186 BOOST_CHECK(CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
192 BOOST_CHECK(!CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
196 BOOST_CHECK(CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
213 BOOST_CHECK(CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
216 tx.
vout[1].nValue -= 3 * COIN;
218 BOOST_CHECK(!CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
222 tx.
vout.emplace_back(3 * COIN, scriptP2CS);
224 BOOST_CHECK(CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
228 const CScript& dummyP2PKH = GetDummyP2PKH(dummyKeyID);
231 tx.
vout.emplace_back(3 * COIN, dummyP2PKH);
233 BOOST_CHECK(!CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
237 BOOST_CHECK(CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
242 tx.
vout.emplace_back(3 * COIN, scriptP2CS);
244 BOOST_CHECK(!CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
248 BOOST_CHECK(CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
252 tx.
vout[1].scriptPubKey = GetDummyP2CS(dummyKeyID);
254 BOOST_CHECK(!CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
258 BOOST_CHECK(CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
264 BOOST_CHECK(!CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
268 BOOST_CHECK(CheckP2CSScript(tx.
vin[0].scriptSig, scriptP2CS, tx, err));
288 tx.
vin[0].scriptSig.clear();
292 std::vector<unsigned char> vchSig;
318 const CScript& scriptP2CS = GetFakeLockingScript(stakerId, ownerId);
322 txFrom.
vout.resize(1);
323 txFrom.
vout[0].nValue = amtIn;
324 txFrom.
vout[0].scriptPubKey = scriptP2CS;
int64_t CAmount
Amount in PIV (Can be negative)
bool GetKey(const CKeyID &address, CKey &keyOut) const override
An encapsulated private key.
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
CPubKey GetPubKey() const
Compute the public key from a private key.
bool Sign(const uint256 &hash, std::vector< unsigned char > &vchSig, uint32_t test_case=0) const
Create a DER-serialized signature.
A reference to a CKey: the Hash160 of its serialized public key.
An encapsulated public key.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Serialized script, used inside transaction inputs and outputs.
bool IsPayToColdStaking() const
The basic transaction that is broadcasted on the network and contained in blocks.
SigVersion GetRequiredSigVersion() const
An output of a transaction.
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
BOOST_AUTO_TEST_SUITE_END()
bool GetKeyFromPool(CPubKey &key, const uint8_t &type=HDChain::ChangeType::EXTERNAL)
bool SetMinVersion(enum WalletFeature, WalletBatch *batch_in=nullptr, bool fExplicit=false)
signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVe...
bool AddToWallet(const CWalletTx &wtxIn, bool fFlushOnClose=true)
const CWalletTx * GetWalletTx(const uint256 &hash) const
bool SetupSPKM(bool newKeypool=true, bool memOnly=false)
Generates hd wallet //.
CAmount GetAvailableCredit(bool fUseCache=true, const isminefilter &filter=ISMINE_SPENDABLE) const
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, unsigned int flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptError *serror)
uint256 SignatureHash(const CScript &scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache)
@ ISMINE_SPENDABLE_TRANSPARENT
CKey DecodeSecret(const std::string &str)
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
void setupWallet(CWallet &wallet)
std::vector< unsigned char > ToByteVector(const T &in)
opcodetype
Script opcodes.
@ OP_CHECKCOLDSTAKEVERIFY
BOOST_AUTO_TEST_CASE(extract_cold_staking_destination_keys)
void FakeUnlockColdStake(CMutableTransaction &tx, const CScript &prevScript, const CKey &key)
void CheckValidKeyId(const CTxDestination &dest, const CKeyID &expectedKey)
void SignColdStake(CMutableTransaction &tx, int nIn, const CScript &prevScript, const CKey &key, bool fStaker)
const char * ScriptErrorString(const ScriptError serror)
enum ScriptError_t ScriptError
@ SCRIPT_ERR_CHECKCOLDSTAKEVERIFY
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< CTxDestination > &addressRet, int &nRequiredRet)
Parse a standard scriptPubKey with one or more destination addresses.
CScript GetScriptForStakeDelegation(const CKeyID &stakingKey, const CKeyID &spendingKey)
Generate a P2CS script for the given staker and owner keys.
CScript GetScriptForStakeDelegationLOF(const CKeyID &stakingKey, const CKeyID &spendingKey)
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a PIVX scriptPubKey for the given CTxDestination.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet, bool fColdStake)
Parse a standard scriptPubKey for the destination address.
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.
SigVersion GetRequiredSigVersion() const
std::vector< CTxOut > vout