Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/primitives/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class CTxIn
}

std::string ToString() const;
std::string toString() const;
};

/** An output of a transaction. It contains the public key that the next input
Expand Down Expand Up @@ -356,6 +357,19 @@ class CTransaction
}
return false;
}

std::string toString() {
std::string ret;
for(uint64_t i=0; i<vin.size(); i++) {
ret += vin[i].ToString();
}
ret += "\n+++\n";
for(uint64_t i=0; i<vout.size(); i++) {
ret += vout[i].ToString();
}
ret += "\n---------\n";
return ret;
}
};

/** A mutable version of CTransaction. */
Expand Down
4 changes: 4 additions & 0 deletions src/script/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,10 @@ static bool VerifyWitnessProgram(const CScriptWitness& witness, int witversion,
return true;
}

// scriptPubKey is a locking script placed on the output of a Bitcoin transaction that requires certain conditions to be met
// in order for a recipient to spend his/her bitcoins; scriptPubKey is also known as PubKey Script outside of the Bitcoin code.
// Conversely, scriptSig is the unlocking script that satisfies the conditions placed on the output by the scriptPubKey,
// and is what allows it to be spent; outside of code, scriptSig is also known as Signature scripts.
bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CScriptWitness* witness, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* serror)
{
static const CScriptWitness emptyWitness;
Expand Down
3 changes: 2 additions & 1 deletion src/test/addrman_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class CAddrManTest : public CAddrMan
{
public:
explicit CAddrManTest(bool makeDeterministic = true)
explicit CAddrManTest(bool makeDeterministic = true) // pay attention to this explicit
{
if (makeDeterministic) {
// Set addrman addr placement to be deterministic.
Expand Down Expand Up @@ -85,6 +85,7 @@ static CService ResolveService(std::string ip, int port = 0)

BOOST_FIXTURE_TEST_SUITE(addrman_tests, BasicTestingSetup)

// READ stplaydog 06/27/2019
BOOST_AUTO_TEST_CASE(addrman_simple)
{
CAddrManTest addrman;
Expand Down
6 changes: 5 additions & 1 deletion src/test/allocator_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

BOOST_FIXTURE_TEST_SUITE(allocator_tests, BasicTestingSetup)

// READ stplaydog 06/27/2019
BOOST_AUTO_TEST_CASE(arena_tests)
{
// Fake memory base address for testing
Expand Down Expand Up @@ -128,6 +129,7 @@ BOOST_AUTO_TEST_CASE(arena_tests)
BOOST_CHECK(b.stats().free == synth_size);
}

// READ stplaydog 06/27/2019
/** Mock LockedPageAllocator for testing */
class TestLockedPageAllocator: public LockedPageAllocator
{
Expand Down Expand Up @@ -160,10 +162,11 @@ class TestLockedPageAllocator: public LockedPageAllocator
int lockedcount;
};

// READ stplaydog 06/27/2019
BOOST_AUTO_TEST_CASE(lockedpool_tests_mock)
{
// Test over three virtual arenas, of which one will succeed being locked
std::unique_ptr<LockedPageAllocator> x = MakeUnique<TestLockedPageAllocator>(3, 1);
std::unique_ptr<LockedPageAllocator> x = MakeUnique<TestLockedPageAllocator>(3, 1); // pay attention to 3
LockedPool pool(std::move(x));
BOOST_CHECK(pool.stats().total == 0);
BOOST_CHECK(pool.stats().locked == 0);
Expand Down Expand Up @@ -206,6 +209,7 @@ BOOST_AUTO_TEST_CASE(lockedpool_tests_mock)
BOOST_CHECK(pool.stats().used == 0);
}

// READ stplaydog 06/27/2019
// These tests used the live LockedPoolManager object, this is also used
// by other tests so the conditions are somewhat less controllable and thus the
// tests are somewhat more error-prone.
Expand Down
4 changes: 4 additions & 0 deletions src/test/amount_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

BOOST_FIXTURE_TEST_SUITE(amount_tests, BasicTestingSetup)

// READ stplaydog 06/26/2019
BOOST_AUTO_TEST_CASE(MoneyRangeTest)
{
BOOST_CHECK_EQUAL(MoneyRange(CAmount(-1)), false);
Expand All @@ -19,6 +20,7 @@ BOOST_AUTO_TEST_CASE(MoneyRangeTest)
BOOST_CHECK_EQUAL(MoneyRange(MAX_MONEY + CAmount(1)), false);
}

// READ stplaydog 06/26/2019
BOOST_AUTO_TEST_CASE(GetFeeTest)
{
CFeeRate feeRate, altFeeRate;
Expand Down Expand Up @@ -86,6 +88,7 @@ BOOST_AUTO_TEST_CASE(GetFeeTest)
CFeeRate(MAX_MONEY, std::numeric_limits<size_t>::max() >> 1).GetFeePerK();
}

// READ stplaydog 06/26/2019
BOOST_AUTO_TEST_CASE(BinaryOperatorTest)
{
CFeeRate a, b;
Expand All @@ -103,6 +106,7 @@ BOOST_AUTO_TEST_CASE(BinaryOperatorTest)
BOOST_CHECK(a == b);
}

// READ stplaydog 06/26/2019
BOOST_AUTO_TEST_CASE(ToStringTest)
{
CFeeRate feeRate;
Expand Down
1 change: 1 addition & 0 deletions src/test/arith_uint256_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static std::string ArrayToString(const unsigned char A[], unsigned int width)
return Stream.str();
}

// READ stplaydog 06/26/2019
BOOST_AUTO_TEST_CASE( basics ) // constructors, equality, inequality
{
BOOST_CHECK(1 == 0+1);
Expand Down
1 change: 1 addition & 0 deletions src/test/base32_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

BOOST_FIXTURE_TEST_SUITE(base32_tests, BasicTestingSetup)

// READ stplaydog 06/27/2019
BOOST_AUTO_TEST_CASE(base32_testvectors)
{
static const std::string vstrIn[] = {"","f","fo","foo","foob","fooba","foobar"};
Expand Down
2 changes: 2 additions & 0 deletions src/test/base58_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern UniValue read_json(const std::string& jsondata);

BOOST_FIXTURE_TEST_SUITE(base58_tests, BasicTestingSetup)

// READ stplaydog 06/27/2019
// Goal: test low-level base58 encoding functionality
BOOST_AUTO_TEST_CASE(base58_EncodeBase58)
{
Expand All @@ -37,6 +38,7 @@ BOOST_AUTO_TEST_CASE(base58_EncodeBase58)
}
}

// READ stplaydog 06/27/2019
// Goal: test low-level base58 decoding functionality
BOOST_AUTO_TEST_CASE(base58_DecodeBase58)
{
Expand Down
1 change: 1 addition & 0 deletions src/test/base64_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

BOOST_FIXTURE_TEST_SUITE(base64_tests, BasicTestingSetup)

// READ stplaydog 06/27/2019
BOOST_AUTO_TEST_CASE(base64_testvectors)
{
static const std::string vstrIn[] = {"","f","fo","foo","foob","fooba","foobar"};
Expand Down
2 changes: 2 additions & 0 deletions src/test/bech32_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static bool CaseInsensitiveEqual(const std::string &s1, const std::string &s2)
return true;
}

// READ stplaydog 06/27/2019
BOOST_AUTO_TEST_CASE(bip173_testvectors_valid)
{
static const std::string CASES[] = {
Expand All @@ -42,6 +43,7 @@ BOOST_AUTO_TEST_CASE(bip173_testvectors_valid)
}
}

// READ stplaydog 06/27/2019
BOOST_AUTO_TEST_CASE(bip173_testvectors_invalid)
{
static const std::string CASES[] = {
Expand Down
6 changes: 4 additions & 2 deletions src/test/bswap_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

BOOST_FIXTURE_TEST_SUITE(bswap_tests, BasicTestingSetup)

// READ stplaydog 06/26/2019
// endianess change
BOOST_AUTO_TEST_CASE(bswap_tests)
{
// Sibling in bitcoin/src/qt/test/compattests.cpp
uint16_t u1 = 0x1234;
uint16_t u1 = 0x1234; // 1001-0001-10100
uint32_t u2 = 0x56789abc;
uint64_t u3 = 0xdef0123456789abc;
uint16_t e1 = 0x3412;
uint16_t e1 = 0x3412; // 1110-0110
uint32_t e2 = 0xbc9a7856;
uint64_t e3 = 0xbc9a78563412f0de;
BOOST_CHECK(bswap_16(u1) == e1);
Expand Down
1 change: 1 addition & 0 deletions src/test/fs_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

BOOST_FIXTURE_TEST_SUITE(fs_tests, BasicTestingSetup)

// READ stplaydog 06/26/2019
BOOST_AUTO_TEST_CASE(fsbridge_fstream)
{
fs::path tmpfolder = SetDataDir("fsbridge_fstream");
Expand Down
11 changes: 8 additions & 3 deletions src/test/transaction_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(tx_valid)
// Read tests from test/data/tx_valid.json
// Format is an array of arrays
// Inner arrays are either [ "comment" ]
// or [[[prevout hash, prevout index, prevout scriptPubKey], [input 2], ...],"], serializedTransaction, verifyFlags
// or [[[prevout hash, transaction, script flag], [input 2], ...],"], serializedTransaction, verifyFlags
// ... where all scripts are stringified scripts.
//
// verifyFlags is a comma separated list of script verification flags to apply, or "NONE"
Expand All @@ -116,12 +116,14 @@ BOOST_AUTO_TEST_CASE(tx_valid)
continue;
}

//std::cout<<test[1].write()<<std::endl;

std::map<COutPoint, CScript> mapprevOutScriptPubKeys;
std::map<COutPoint, int64_t> mapprevOutValues;
UniValue inputs = test[0].get_array();
bool fValid = true;
for (unsigned int inpIdx = 0; inpIdx < inputs.size(); inpIdx++) {
const UniValue& input = inputs[inpIdx];
for (unsigned int inpIdx = 0; inpIdx < inputs.size(); inpIdx++) {
const UniValue& input = inputs[inpIdx];
if (!input.isArray())
{
fValid = false;
Expand Down Expand Up @@ -149,12 +151,15 @@ BOOST_AUTO_TEST_CASE(tx_valid)
std::string transaction = test[1].get_str();
CDataStream stream(ParseHex(transaction), SER_NETWORK, PROTOCOL_VERSION);
CTransaction tx(deserialize, stream);

std::cout<<tx.toString()<<std::endl;

CValidationState state;
BOOST_CHECK_MESSAGE(CheckTransaction(tx, state), strTest);
BOOST_CHECK(state.IsValid());

PrecomputedTransactionData txdata(tx);
std::cout<<"script flag: "<<test[2].get_str()<<std::endl;
for (unsigned int i = 0; i < tx.vin.size(); i++)
{
if (!mapprevOutScriptPubKeys.count(tx.vin[i].prevout))
Expand Down