Changeset View
Changeset View
Standalone View
Standalone View
src/test/coins_tests.cpp
Show First 20 Lines • Show All 521 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(coin_serialization) { | ||||
// Good example | // Good example | ||||
CDataStream ss2( | CDataStream ss2( | ||||
ParseHex("8ddf77bbd123008c988f1a4a4de2161e0f50aac7f17e7f9555caa4"), | ParseHex("8ddf77bbd123008c988f1a4a4de2161e0f50aac7f17e7f9555caa4"), | ||||
SER_DISK, CLIENT_VERSION); | SER_DISK, CLIENT_VERSION); | ||||
Coin c2; | Coin c2; | ||||
ss2 >> c2; | ss2 >> c2; | ||||
BOOST_CHECK_EQUAL(c2.IsCoinBase(), true); | BOOST_CHECK_EQUAL(c2.IsCoinBase(), true); | ||||
BOOST_CHECK_EQUAL(c2.GetHeight(), 120891); | BOOST_CHECK_EQUAL(c2.GetHeight(), 120891U); | ||||
BOOST_CHECK_EQUAL(c2.GetTxOut().nValue, 110397 * SATOSHI); | BOOST_CHECK_EQUAL(c2.GetTxOut().nValue, 110397 * SATOSHI); | ||||
BOOST_CHECK_EQUAL(HexStr(c2.GetTxOut().scriptPubKey), | BOOST_CHECK_EQUAL(HexStr(c2.GetTxOut().scriptPubKey), | ||||
HexStr(GetScriptForDestination(CKeyID(uint160(ParseHex( | HexStr(GetScriptForDestination(CKeyID(uint160(ParseHex( | ||||
"8c988f1a4a4de2161e0f50aac7f17e7f9555caa4")))))); | "8c988f1a4a4de2161e0f50aac7f17e7f9555caa4")))))); | ||||
// Smallest possible example | // Smallest possible example | ||||
CDataStream ss3(ParseHex("000006"), SER_DISK, CLIENT_VERSION); | CDataStream ss3(ParseHex("000006"), SER_DISK, CLIENT_VERSION); | ||||
Coin c3; | Coin c3; | ||||
ss3 >> c3; | ss3 >> c3; | ||||
BOOST_CHECK_EQUAL(c3.IsCoinBase(), false); | BOOST_CHECK_EQUAL(c3.IsCoinBase(), false); | ||||
BOOST_CHECK_EQUAL(c3.GetHeight(), 0); | BOOST_CHECK_EQUAL(c3.GetHeight(), 0U); | ||||
BOOST_CHECK_EQUAL(c3.GetTxOut().nValue, Amount::zero()); | BOOST_CHECK_EQUAL(c3.GetTxOut().nValue, Amount::zero()); | ||||
BOOST_CHECK_EQUAL(c3.GetTxOut().scriptPubKey.size(), 0); | BOOST_CHECK_EQUAL(c3.GetTxOut().scriptPubKey.size(), 0U); | ||||
// scriptPubKey that ends beyond the end of the stream | // scriptPubKey that ends beyond the end of the stream | ||||
CDataStream ss4(ParseHex("000007"), SER_DISK, CLIENT_VERSION); | CDataStream ss4(ParseHex("000007"), SER_DISK, CLIENT_VERSION); | ||||
try { | try { | ||||
Coin c4; | Coin c4; | ||||
ss4 >> c4; | ss4 >> c4; | ||||
BOOST_CHECK_MESSAGE(false, "We should have thrown"); | BOOST_CHECK_MESSAGE(false, "We should have thrown"); | ||||
} catch (const std::ios_base::failure &e) { | } catch (const std::ios_base::failure &e) { | ||||
▲ Show 20 Lines • Show All 363 Lines • Show Last 20 Lines |