Changeset View
Changeset View
Standalone View
Standalone View
src/test/sigcache_tests.cpp
- This file was added.
// Copyright (c) 2012-2015 The Bitcoin Core developers | |||||
// Copyright (c) 2019- The Bitcoin developers | |||||
// Distributed under the MIT software license, see the accompanying | |||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | |||||
// (based on key_tests.cpp) | |||||
#include "key.h" | |||||
#include "base58.h" | |||||
#include "dstencode.h" | |||||
#include "script/interpreter.h" | |||||
#include "script/script.h" | |||||
#include "script/sigcache.h" | |||||
#include "test/test_bitcoin.h" | |||||
#include "uint256.h" | |||||
#include "util.h" | |||||
#include "utilstrencodings.h" | |||||
#include <string> | |||||
#include <vector> | |||||
#include <boost/test/unit_test.hpp> | |||||
static const std::string strSecret1 = | |||||
"5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtmAbrj"; | |||||
BOOST_FIXTURE_TEST_SUITE(sigcache_tests, BasicTestingSetup) | |||||
BOOST_AUTO_TEST_CASE(sigcache_test1) { | |||||
// Create a dummy transaction since the sigcache is only accessible | |||||
// via CachingTransactionSignatureChecker, which requires a tx. | |||||
CDataStream stream( | |||||
ParseHex( | |||||
"010000000122739e70fbee987a8be1788395a2f2e6ad18ccb7ff611cd798071539" | |||||
"dde3c38e000000000151ffffffff010000000000000000016a00000000"), | |||||
SER_NETWORK, PROTOCOL_VERSION); | |||||
CTransaction dummyTx(deserialize, stream); | |||||
PrecomputedTransactionData txdata(dummyTx); | |||||
// We access sigcache through CachingTransactionSignatureChecker | |||||
CachingTransactionSignatureChecker checker(&dummyTx, 0, 0 * SATOSHI, true, | |||||
txdata); | |||||
CBitcoinSecret bsecret1; | |||||
BOOST_CHECK(bsecret1.SetString(strSecret1)); | |||||
CKey key1 = bsecret1.GetKey(); | |||||
BOOST_CHECK(key1.IsCompressed() == false); | |||||
CPubKey pubkey1 = key1.GetPubKey(); | |||||
BOOST_CHECK(key1.VerifyPubKey(pubkey1)); | |||||
for (int n = 0; n < 16; n++) { | |||||
std::string strMsg = strprintf("Sigcache test %i: 11", n); | |||||
uint256 hashMsg = Hash(strMsg.begin(), strMsg.end()); | |||||
// Make Schnorr signature (64 bytes) | |||||
std::vector<uint8_t> sigSchnorr; | |||||
BOOST_CHECK(key1.SignSchnorr(hashMsg, sigSchnorr)); | |||||
// direct testing | |||||
BOOST_CHECK(pubkey1.VerifySchnorr(hashMsg, sigSchnorr)); | |||||
BOOST_CHECK(!pubkey1.VerifyECDSA(hashMsg, sigSchnorr)); | |||||
// put Schnorr signature into cache | |||||
BOOST_CHECK( | |||||
checker.VerifySignatureSchnorr(sigSchnorr, pubkey1, hashMsg)); | |||||
// make sure ECDSA signature doesn't verify | |||||
BOOST_CHECK( | |||||
!checker.VerifySignatureECDSA(sigSchnorr, pubkey1, hashMsg)); | |||||
} | |||||
} | |||||
BOOST_AUTO_TEST_SUITE_END() |