Skip to content

Commit

Permalink
transaction tests - header, includes, namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
barton2526 committed Oct 15, 2021
1 parent 2b41a7e commit 913cdb6
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/test/transaction_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
// Copyright (c) 2011-2020 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <map>
#include <string>
#include <vector>
#include <boost/test/unit_test.hpp>

#include "main.h"
#include "streams.h"
#include "wallet/wallet.h"
#include <main.h>
#include <streams.h>
#include <wallet/wallet.h>
#include <policy/policy.h>

#include "test/data/tx_valid.json.h"
#include "test/data/tx_invalid.json.h"
#include <test/data/tx_valid.json.h>
#include <test/data/tx_invalid.json.h>

#include <univalue.h>

using namespace std;

// In script_tests.cpp
extern UniValue read_json(const std::string& jsondata);
extern CScript ParseScript(string s);
extern CScript ParseScript(std::string s);

// This is in anonymous namespace as the CMutableBitcoinTransaction is only used here in this testing suite.
namespace {
Expand Down Expand Up @@ -74,7 +77,7 @@ BOOST_AUTO_TEST_CASE(tx_valid)
for (unsigned int idx = 0; idx < tests.size(); idx++)
{
UniValue test = tests[idx];
string strTest = test.write();
std::string strTest = test.write();
if (test[0].isArray())
{
if (test.size() != 3 || !test[1].isStr() || !test[2].isBool())
Expand All @@ -83,7 +86,7 @@ BOOST_AUTO_TEST_CASE(tx_valid)
continue;
}

map<COutPoint, CScript> mapprevOutScriptPubKeys;
std::map<COutPoint, CScript> mapprevOutScriptPubKeys;
UniValue inputs = test[0].get_array();
bool fValid = true;
for (unsigned int inpIdx = 0; inpIdx < inputs.size(); inpIdx++)
Expand Down Expand Up @@ -111,7 +114,7 @@ BOOST_AUTO_TEST_CASE(tx_valid)
continue;
}

string transaction = test[1].get_str();
std::string transaction = test[1].get_str();
CDataStream stream(ParseHex(transaction), SER_NETWORK, PROTOCOL_VERSION);
CMutableBitcoinTransaction btx;
stream >> btx;
Expand Down Expand Up @@ -155,7 +158,7 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
continue;
}

map<COutPoint, CScript> mapprevOutScriptPubKeys;
std::map<COutPoint, CScript> mapprevOutScriptPubKeys;
UniValue inputs = test[0].get_array();
bool fValid = true;
for (unsigned int inpIdx = 0; inpIdx < inputs.size(); inpIdx++)
Expand All @@ -179,7 +182,7 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
continue;
}

string transaction = test[1].get_str();
std::string transaction = test[1].get_str();
CDataStream stream(ParseHex(transaction), SER_NETWORK, PROTOCOL_VERSION);
CMutableBitcoinTransaction btx;
stream >> btx;
Expand Down Expand Up @@ -228,7 +231,7 @@ BOOST_AUTO_TEST_CASE(basic_transaction_tests)
0x00, 0x19, 0x76, 0xa9, 0x14, 0xc1, 0x09, 0x32, 0x48, 0x3f, 0xec, 0x93,
0xed, 0x51, 0xf5, 0xfe, 0x95, 0xe7, 0x25, 0x59, 0xf2, 0xcc, 0x70, 0x43,
0xf9, 0x88, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00};
vector<unsigned char> vch(ch, ch + sizeof(ch) -1);
std::vector<unsigned char> vch(ch, ch + sizeof(ch) -1);
CDataStream stream(vch, SER_DISK, CLIENT_VERSION);
CMutableBitcoinTransaction btx;
stream >> btx;
Expand Down Expand Up @@ -266,14 +269,14 @@ SetupDummyInputs(CBasicKeyStore& keystoreRet, MapPrevTx& inputsRet)
dummyTransactions[0].vout[0].scriptPubKey << key[0].GetPubKey() << OP_CHECKSIG;
dummyTransactions[0].vout[1].nValue = 50*CENT;
dummyTransactions[0].vout[1].scriptPubKey << key[1].GetPubKey() << OP_CHECKSIG;
inputsRet[dummyTransactions[0].GetHash()] = make_pair(CTxIndex(), dummyTransactions[0]);
inputsRet[dummyTransactions[0].GetHash()] = std::make_pair(CTxIndex(), dummyTransactions[0]);

dummyTransactions[1].vout.resize(2);
dummyTransactions[1].vout[0].nValue = 21*CENT;
dummyTransactions[1].vout[0].scriptPubKey.SetDestination(key[2].GetPubKey().GetID());
dummyTransactions[1].vout[1].nValue = 22*CENT;
dummyTransactions[1].vout[1].scriptPubKey.SetDestination(key[3].GetPubKey().GetID());
inputsRet[dummyTransactions[1].GetHash()] = make_pair(CTxIndex(), dummyTransactions[1]);
inputsRet[dummyTransactions[1].GetHash()] = std::make_pair(CTxIndex(), dummyTransactions[1]);

return dummyTransactions;
}
Expand Down

0 comments on commit 913cdb6

Please sign in to comment.