Skip to content

Commit

Permalink
Initial work on tests allowing the test app to build.
Browse files Browse the repository at this point in the history
Signed-off-by: aciddude <david@walton.io>
  • Loading branch information
aciddude committed Jan 18, 2017
1 parent 0cda989 commit dcbb5df
Show file tree
Hide file tree
Showing 26 changed files with 504 additions and 1,464 deletions.
4 changes: 2 additions & 2 deletions src/main.cpp
Expand Up @@ -2357,8 +2357,8 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
reverse(vConnect.begin(), vConnect.end());

if (vDisconnect.size() > 0) {
LogPrintf("SetBestChain:120: Disconnect %"PRIszu" blocks; %s...\n", vDisconnect.size(), pfork->GetBlockHash().ToString());
LogPrintf("SetBestChain:120: Connect %"PRIszu" blocks; ...%s\n", vConnect.size(), pindexNew->GetBlockHash().ToString());
LogPrintf("SetBestChain:120: Disconnect %" PRIszu " blocks; %s...\n", vDisconnect.size(), pfork->GetBlockHash().ToString());
LogPrintf("SetBestChain:120: Connect %" PRIszu " blocks; ...%s\n", vConnect.size(), pindexNew->GetBlockHash().ToString());
}


Expand Down
8 changes: 4 additions & 4 deletions src/qt/walletmodel.cpp
Expand Up @@ -321,7 +321,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
LogPrintf("sxAddr.spend_secret= %s\n", HexStr(sxAddr.spend_secret).c_str()); //
LogPrintf("sxAddr.spend_pubkey= %s\n",HexStr(sxAddr.spend_pubkey).c_str()); //pkSpend[0]
LogPrintf("secretShared.e=%s \n",HexStr(&secretShared.e[0],&secretShared.e[32]).c_str()); //sharedSOut
LogPrintf("pkSendTo= %"PRIszu": %s\n", pkSendTo.size(), HexStr(pkSendTo).c_str());//pkOut
LogPrintf("pkSendTo= %" PRIszu ": %s\n", pkSendTo.size(), HexStr(pkSendTo).c_str());//pkOut
LogPrintf("send: secret = ephem_secret, pubkey = scan_pubkey....\n");
};

Expand All @@ -338,7 +338,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
LogPrintf("sxAddr.spend_secret= %s\n", HexStr(sxAddr.spend_secret).c_str()); //
LogPrintf("sxAddr.spend_pubkey= %s\n",HexStr(sxAddr.spend_pubkey).c_str()); //pkSpend[0]
LogPrintf("secretShared.e=%s \n",HexStr(&secretShared.e[0],&secretShared.e[32]).c_str()); //sharedSOut
LogPrintf("pkSendTo= %"PRIszu": %s\n", pkSendTo.size(), HexStr(pkSendTo).c_str());//pkOut
LogPrintf("pkSendTo= %" PRIszu ": %s\n", pkSendTo.size(), HexStr(pkSendTo).c_str());//pkOut
};

CPubKey cpkTo(pkSendTo);
Expand All @@ -360,9 +360,9 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact

if (true)
{
LogPrintf("Stealth send to generated pubkey,pkSendTo= %"PRIszu": %s\n", pkSendTo.size(), HexStr(pkSendTo).c_str());
LogPrintf("Stealth send to generated pubkey,pkSendTo= %" PRIszu ": %s\n", pkSendTo.size(), HexStr(pkSendTo).c_str());
LogPrintf("hash, Address= %s\n", addrTo.ToString().c_str());
LogPrintf("enerate ephem public key,ephem_pubkey= %"PRIszu": %s\n", ephem_pubkey.size(), HexStr(ephem_pubkey).c_str());
LogPrintf("enerate ephem public key,ephem_pubkey= %" PRIszu ": %s\n", ephem_pubkey.size(), HexStr(ephem_pubkey).c_str());
};

CScript scriptPubKey;
Expand Down
18 changes: 9 additions & 9 deletions src/test/Checkpoints_tests.cpp
Expand Up @@ -18,21 +18,21 @@ BOOST_AUTO_TEST_SUITE(Checkpoints_tests)

BOOST_AUTO_TEST_CASE(sanity)
{
uint256 p11111 = uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d");
uint256 p134444 = uint256("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe");
BOOST_CHECK(Checkpoints::CheckBlock(11111, p11111));
BOOST_CHECK(Checkpoints::CheckBlock(134444, p134444));
uint256 p1 = uint256("0xfdbe99b90c90bae7505796461471d89ae8388ab953997aa06a355bbda8d915cb");
uint256 p41300 = uint256("0x8c4e02f6c0d20e856fd7e952a147fee30ce145ca6932a284f354924362d2b408");
BOOST_CHECK(Checkpoints::CheckBlock(1, p1));
BOOST_CHECK(Checkpoints::CheckBlock(41300, p41300));


// Wrong hashes at checkpoints should fail:
BOOST_CHECK(!Checkpoints::CheckBlock(11111, p134444));
BOOST_CHECK(!Checkpoints::CheckBlock(134444, p11111));
BOOST_CHECK(!Checkpoints::CheckBlock(1, p41300));
BOOST_CHECK(!Checkpoints::CheckBlock(41300, p1));

// ... but any hash not at a checkpoint should succeed:
BOOST_CHECK(Checkpoints::CheckBlock(11111+1, p134444));
BOOST_CHECK(Checkpoints::CheckBlock(134444+1, p11111));
BOOST_CHECK(Checkpoints::CheckBlock(1+1, p41300));
BOOST_CHECK(Checkpoints::CheckBlock(41300+1, p1));

BOOST_CHECK(Checkpoints::GetTotalBlocksEstimate() >= 134444);
BOOST_CHECK(Checkpoints::GetTotalBlocksEstimate() >= 40000);
}

BOOST_AUTO_TEST_SUITE_END()
19 changes: 14 additions & 5 deletions src/test/DoS_tests.cpp
Expand Up @@ -23,7 +23,8 @@
#include <boost/test/unit_test.hpp>

// Tests this internal-to-main.cpp method:
extern bool AddOrphanTx(const CTransaction& tx);
extern bool AddOrphanTx(const CTransaction& tx, NodeId peer);
extern void EraseOrphansFor(NodeId peer);
extern unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans);
extern std::map<uint256, CTransaction> mapOrphanTransactions;
extern std::map<uint256, std::set<uint256> > mapOrphanTransactionsByPrev;
Expand Down Expand Up @@ -177,7 +178,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
tx.vout[0].nValue = 1*CENT;
tx.vout[0].scriptPubKey.SetDestination(key.GetPubKey().GetID());

AddOrphanTx(tx);
AddOrphanTx(tx, i);
}

// ... and 50 that depend on other orphans:
Expand All @@ -194,7 +195,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
tx.vout[0].scriptPubKey.SetDestination(key.GetPubKey().GetID());
SignSignature(keystore, txPrev, tx, 0);

AddOrphanTx(tx);
AddOrphanTx(tx, i);
}

// This really-big orphan should be ignored:
Expand All @@ -218,7 +219,15 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
for (unsigned int j = 1; j < tx.vin.size(); j++)
tx.vin[j].scriptSig = tx.vin[0].scriptSig;

BOOST_CHECK(!AddOrphanTx(tx));
BOOST_CHECK(!AddOrphanTx(tx, i));
}

// Test EraseOrphansFor:
for (NodeId i = 0; i < 3; i++)
{
size_t sizeBefore = mapOrphanTransactions.size();
EraseOrphansFor(i);
BOOST_CHECK(mapOrphanTransactions.size() < sizeBefore);
}

// Test LimitOrphanTxSize() function:
Expand Down Expand Up @@ -255,7 +264,7 @@ BOOST_AUTO_TEST_CASE(DoS_checkSig)
tx.vout[0].nValue = 1*CENT;
tx.vout[0].scriptPubKey.SetDestination(key.GetPubKey().GetID());

AddOrphanTx(tx);
AddOrphanTx(tx, 0);
}

// Create a transaction that depends on orphans:
Expand Down
1 change: 1 addition & 0 deletions src/test/Makefile.am
Expand Up @@ -61,6 +61,7 @@ test_bitcoin_SOURCES = \
transaction_tests.cpp \
uint256_tests.cpp \
util_tests.cpp \
scriptnum_tests.cpp \
sighash_tests.cpp \
$(JSON_TEST_FILES) $(RAW_TEST_FILES)

Expand Down
21 changes: 21 additions & 0 deletions src/test/README.md
@@ -0,0 +1,21 @@
# Notes
The sources in this directory are unit test cases. Boost includes a
unit testing framework, and since bitcoin already uses boost, it makes
sense to simply use this framework rather than require developers to
configure some other framework (we want as few impediments to creating
unit tests as possible).

The build system is setup to compile an executable called "test_bitcoin"
that runs all of the unit tests. The main source file is called
test_bitcoin.cpp, which simply includes other files that contain the
actual unit tests (outside of a couple required preprocessor
directives). The pattern is to create one test file for each class or
source file for which you want to create unit tests. The file naming
convention is "<source_filename>_tests.cpp" and such files should wrap
their tests in a test suite called "<source_filename>_tests". For an
examples of this pattern, examine uint160_tests.cpp and
uint256_tests.cpp.

For further reading, I found the following website to be helpful in
explaining how the boost unit test framework works:
[http://www.alittlemadness.com/2009/03/31/c-unit-testing-with-boosttest/](http://www.alittlemadness.com/2009/03/31/c-unit-testing-with-boosttest/).
183 changes: 0 additions & 183 deletions src/test/alert_tests.cpp

This file was deleted.

0 comments on commit dcbb5df

Please sign in to comment.