|
3 | 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
4 | 4 |
|
5 | 5 | #include "libzerocoin/Denominations.h" |
| 6 | +#include "libzerocoin/Coin.h" |
6 | 7 | #include "amount.h" |
7 | 8 | #include "chainparams.h" |
8 | 9 | #include "coincontrol.h" |
9 | 10 | #include "main.h" |
10 | 11 | #include "wallet/wallet.h" |
11 | 12 | #include "wallet/walletdb.h" |
12 | 13 | #include "txdb.h" |
| 14 | +#include "zpiv/zpivmodule.h" |
13 | 15 | #include <boost/test/unit_test.hpp> |
14 | 16 | #include <iostream> |
15 | 17 |
|
@@ -53,4 +55,62 @@ BOOST_AUTO_TEST_CASE(zerocoin_spend_test) |
53 | 55 |
|
54 | 56 | } |
55 | 57 |
|
| 58 | +BOOST_AUTO_TEST_CASE(zerocoin_public_spend_test) |
| 59 | +{ |
| 60 | + SelectParams(CBaseChainParams::MAIN); |
| 61 | + ZerocoinParams *ZCParams = Params().Zerocoin_Params(false); |
| 62 | + (void)ZCParams; |
| 63 | + |
| 64 | + ZPIVModule zpivModule; |
| 65 | + |
| 66 | + PrivateCoin privCoin(ZCParams, libzerocoin::CoinDenomination::ZQ_ONE, true); |
| 67 | + const CPrivKey privKey = privCoin.getPrivKey(); |
| 68 | + |
| 69 | + CZerocoinMint mint = CZerocoinMint( |
| 70 | + privCoin.getPublicCoin().getDenomination(), |
| 71 | + privCoin.getPublicCoin().getValue(), |
| 72 | + privCoin.getRandomness(), |
| 73 | + privCoin.getSerialNumber(), |
| 74 | + false, |
| 75 | + privCoin.getVersion(), |
| 76 | + nullptr); |
| 77 | + mint.SetPrivKey(privKey); |
| 78 | + |
| 79 | + |
| 80 | + // Mint tx |
| 81 | + CTransaction prevTx; |
| 82 | + |
| 83 | + CScript scriptSerializedCoin = CScript() |
| 84 | + << OP_ZEROCOINMINT << privCoin.getPublicCoin().getValue().getvch().size() << privCoin.getPublicCoin().getValue().getvch(); |
| 85 | + CTxOut out = CTxOut(libzerocoin::ZerocoinDenominationToAmount(privCoin.getPublicCoin().getDenomination()), scriptSerializedCoin); |
| 86 | + prevTx.vout.push_back(out); |
| 87 | + |
| 88 | + mint.SetOutputIndex(0); |
| 89 | + mint.SetTxHash(prevTx.GetHash()); |
| 90 | + |
| 91 | + // Spend tx |
| 92 | + CMutableTransaction tx; |
| 93 | + tx.vout.resize(1); |
| 94 | + tx.vout[0].nValue = 1*CENT; |
| 95 | + tx.vout[0].scriptPubKey = GetScriptForDestination(CBitcoinAddress("D9Ti4LEhF1n6dR2hGd2SyNADD51AVgva6q").Get()); |
| 96 | + |
| 97 | + CTxIn in; |
| 98 | + if (!zpivModule.createInput(in, mint, tx.GetHash())){ |
| 99 | + BOOST_CHECK_MESSAGE(false, "Failed to create zc input"); |
| 100 | + } |
| 101 | + |
| 102 | + PublicCoinSpend publicSpend(ZCParams); |
| 103 | + if (!zpivModule.validateInput(in, out, tx, publicSpend)){ |
| 104 | + BOOST_CHECK_MESSAGE(false, "Failed to validate zc input"); |
| 105 | + } |
| 106 | + |
| 107 | + PublicCoinSpend publicSpendTest(ZCParams); |
| 108 | + BOOST_CHECK_MESSAGE(zpivModule.parseCoinSpend(in, tx, out, publicSpendTest), "Failed to parse public spend"); |
| 109 | + libzerocoin::CoinSpend *spend = &publicSpendTest; |
| 110 | + |
| 111 | + BOOST_CHECK_MESSAGE(publicSpendTest.HasValidSignature(), "Failed to validate public spend signature"); |
| 112 | + BOOST_CHECK_MESSAGE(spend->HasValidSignature(), "Failed to validate spend signature"); |
| 113 | + |
| 114 | +} |
| 115 | + |
56 | 116 | BOOST_AUTO_TEST_SUITE_END() |
0 commit comments