MCPcopy Create free account
hub / github.com/ElementsProject/elements / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

src/test/blind_tests.cpp:26–370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24// TODO: Make deterministic blinding wrapper function, test caching more exactly
25
26BOOST_AUTO_TEST_CASE(naive_blinding_test)
27{
28 CKey key1;
29 CKey key2;
30 CKey keyDummy;
31
32 // Any asset id will do
33 CAsset bitcoinID(GetRandHash());
34 CAsset otherID(GetRandHash());
35 CAsset unblinded_id;
36 uint256 asset_blind;
37 CScript op_true(OP_TRUE);
38 std::vector<CKey> vDummy;
39
40 unsigned char k1[32] = {1,2,3};
41 unsigned char k2[32] = {22,33,44};
42 unsigned char kDummy[32] = {133,144,155};
43 key1.Set(&k1[0], &k1[32], true);
44 key2.Set(&k2[0], &k2[32], true);
45 keyDummy.Set(&kDummy[0], &kDummy[32], true);
46 CPubKey pubkey1 = key1.GetPubKey();
47 CPubKey pubkey2 = key2.GetPubKey();
48 CPubKey pubkeyDummy = keyDummy.GetPubKey();
49
50 uint256 blind3, blind4, blindDummy;
51
52 std::vector<CTxOut> inputs;
53 CTxOut btc_oo(bitcoinID, 11, CScript());
54 CTxOut btc_ooo(bitcoinID, 111, CScript());
55 CTxOut other_fzz(otherID, 500, CScript());
56 CTxOut blind_ozz; // Will be computed later
57
58 {
59 inputs.clear();
60 inputs.push_back(btc_oo);
61 inputs.push_back(btc_ooo);
62
63 // Build a transaction that spends 2 unblinded coins (11, 111), and produces a single blinded one (100) and fee (22).
64 CMutableTransaction tx3;
65 tx3.vin.resize(2);
66 tx3.vin[0].prevout.hash = ArithToUint256(1);
67
68 tx3.vin[0].prevout.n = 0;
69 tx3.vin[1].prevout.hash = ArithToUint256(2);
70 tx3.vin[1].prevout.n = 0;
71 tx3.vout.resize(0);
72 tx3.vout.push_back(CTxOut(bitcoinID, 100, CScript() << OP_TRUE));
73 // Fee outputs are blank scriptpubkeys, and unblinded value/asset
74 tx3.vout.push_back(CTxOut(bitcoinID, 22, CScript()));
75 BOOST_CHECK(VerifyAmounts(inputs, CTransaction(tx3), nullptr, false));
76
77 // Malleate the output and check for correct handling of bad commitments
78 // These will fail IsValid checks
79 std::vector<unsigned char> asset_copy(tx3.vout[0].nAsset.vchCommitment);
80 std::vector<unsigned char> value_copy(tx3.vout[0].nValue.vchCommitment);
81 tx3.vout[0].nAsset.vchCommitment[0] = 122;
82 BOOST_CHECK(!VerifyAmounts(inputs, CTransaction(tx3), nullptr, false));
83 tx3.vout[0].nAsset.vchCommitment = asset_copy;

Callers

nothing calls this directly

Calls 15

GetRandHashFunction · 0.85
ArithToUint256Function · 0.85
VerifyAmountsFunction · 0.85
BlindTransactionFunction · 0.85
UnblindConfidentialPairFunction · 0.85
CConfidentialValueClass · 0.85
secp256k1_context_createFunction · 0.85
CAssetClass · 0.85
IsExplicitMethod · 0.80
IsCommitmentMethod · 0.80

Tested by

no test coverage detected