Fix tests for JoinSplit signatures

This commit is contained in:
Taylor Hornby
2016-05-30 10:53:04 -06:00
parent a138f81404
commit b48122b57b
7 changed files with 561 additions and 520 deletions

File diff suppressed because one or more lines are too long

View File

@@ -13,6 +13,7 @@
#include "util.h"
#include "version.h"
#include "sodium.h"
#include "key.h"
#include <iostream>
@@ -81,6 +82,8 @@ uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, un
txTmp.vin.resize(1);
}
txTmp.joinSplitSig = {};
// Serialize and hash
CHashWriter ss(SER_GETHASH, 0);
ss << txTmp << nHashType;
@@ -139,6 +142,21 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle) {
tx.vpour.push_back(pourtx);
}
CKey joinSplitPrivKey;
joinSplitPrivKey.MakeNewKey(true);
CCompressedPubKey joinSplitPubKey(joinSplitPrivKey.GetPubKey());
tx.joinSplitPubKey = joinSplitPubKey;
CTransaction signTx(tx);
// TODO: #966
static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
CScript scriptCode;
uint256 dataToBeSigned = SignatureHash(scriptCode, signTx, NOT_AN_INPUT, SIGHASH_ALL);
BOOST_CHECK(dataToBeSigned != one);
// Add the signature
joinSplitPrivKey.Sign(dataToBeSigned, tx.joinSplitSig);
}
}

View File

@@ -396,7 +396,27 @@ BOOST_AUTO_TEST_CASE(test_simple_pour_invalidity)
pourtx->serials[0] = GetRandHash();
pourtx->serials[1] = GetRandHash();
BOOST_CHECK_MESSAGE(CheckTransaction(newTx, state), state.GetRejectReason());
BOOST_CHECK(!CheckTransaction(newTx, state));
BOOST_CHECK(state.GetRejectReason() == "invalid-joinsplit-signature");
CKey joinSplitPrivKey;
joinSplitPrivKey.MakeNewKey(true);
CCompressedPubKey joinSplitPubKey(joinSplitPrivKey.GetPubKey());
newTx.joinSplitPubKey = joinSplitPubKey;
CTransaction signTx(newTx);
// TODO: #966
static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
CScript scriptCode;
uint256 dataToBeSigned = SignatureHash(scriptCode, signTx, NOT_AN_INPUT, SIGHASH_ALL);
BOOST_CHECK(dataToBeSigned != one);
// Add the signature
joinSplitPrivKey.Sign(dataToBeSigned, newTx.joinSplitSig);
BOOST_CHECK(CheckTransaction(newTx, state));
}
{
// Ensure that values within the pour are well-formed.