yann300
10 years ago
89 changed files with 1707 additions and 1461 deletions
@ -0,0 +1,146 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file FixedHash.cpp
|
|||
* @author Lefterus <lefteris@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#include <libdevcore/FixedHash.h> |
|||
#include "../TestHelper.h" |
|||
|
|||
using namespace std; |
|||
using namespace dev; |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace test |
|||
{ |
|||
|
|||
BOOST_AUTO_TEST_SUITE(FixedHashTests) |
|||
|
|||
BOOST_AUTO_TEST_CASE(FixedHashComparisons) |
|||
{ |
|||
FixedHash<4> h1(sha3("abcd")); |
|||
FixedHash<4> h2(sha3("abcd")); |
|||
FixedHash<4> h3(sha3("aadd")); |
|||
FixedHash<4> h4(0xBAADF00D); |
|||
FixedHash<4> h5(0xAAAAAAAA); |
|||
FixedHash<4> h6(0xBAADF00D); |
|||
|
|||
BOOST_CHECK(h1 == h2); |
|||
BOOST_CHECK(h2 != h3); |
|||
|
|||
BOOST_CHECK(h4 > h5); |
|||
BOOST_CHECK(h5 < h4); |
|||
BOOST_CHECK(h6 <= h4); |
|||
BOOST_CHECK(h6 >= h4); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(FixedHashXOR) |
|||
{ |
|||
FixedHash<2> h1("0xAAAA"); |
|||
FixedHash<2> h2("0xBBBB"); |
|||
|
|||
BOOST_CHECK((h1 ^ h2) == FixedHash<2>("0x1111")); |
|||
h1 ^= h2; |
|||
BOOST_CHECK(h1 == FixedHash<2>("0x1111")); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(FixedHashOR) |
|||
{ |
|||
FixedHash<4> h1("0xD3ADB33F"); |
|||
FixedHash<4> h2("0xBAADF00D"); |
|||
FixedHash<4> res("0xFBADF33F"); |
|||
|
|||
BOOST_CHECK((h1 | h2) == res); |
|||
h1 |= h2; |
|||
BOOST_CHECK(h1 == res); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(FixedHashAND) |
|||
{ |
|||
FixedHash<4> h1("0xD3ADB33F"); |
|||
FixedHash<4> h2("0xBAADF00D"); |
|||
FixedHash<4> h3("0x92aDB00D"); |
|||
|
|||
BOOST_CHECK((h1 & h2) == h3); |
|||
h1 &= h2; |
|||
BOOST_CHECK(h1 = h3); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(FixedHashInvert) |
|||
{ |
|||
FixedHash<4> h1("0xD3ADB33F"); |
|||
FixedHash<4> h2("0x2C524CC0"); |
|||
|
|||
BOOST_CHECK(~h1 == h2); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(FixedHashContains) |
|||
{ |
|||
FixedHash<4> h1("0xD3ADB331"); |
|||
FixedHash<4> h2("0x0000B331"); |
|||
FixedHash<4> h3("0x0000000C"); |
|||
|
|||
BOOST_CHECK(h1.contains(h2)); |
|||
BOOST_CHECK(!h1.contains(h3)); |
|||
} |
|||
|
|||
void incrementSingleIteration(unsigned seed) |
|||
{ |
|||
unsigned next = seed + 1; |
|||
|
|||
FixedHash<4> h1(seed); |
|||
FixedHash<4> h2 = h1; |
|||
FixedHash<4> h3(next); |
|||
|
|||
FixedHash<32> hh1(seed); |
|||
FixedHash<32> hh2 = hh1; |
|||
FixedHash<32> hh3(next); |
|||
|
|||
BOOST_CHECK_EQUAL(++h2, h3); |
|||
BOOST_CHECK_EQUAL(++hh2, hh3); |
|||
|
|||
BOOST_CHECK(h2 > h1); |
|||
BOOST_CHECK(hh2 > hh1); |
|||
|
|||
unsigned reverse1 = ((FixedHash<4>::Arith)h2).convert_to<unsigned>(); |
|||
unsigned reverse2 = ((FixedHash<32>::Arith)hh2).convert_to<unsigned>(); |
|||
|
|||
BOOST_CHECK_EQUAL(next, reverse1); |
|||
BOOST_CHECK_EQUAL(next, reverse2); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(FixedHashIncrement) |
|||
{ |
|||
incrementSingleIteration(0); |
|||
incrementSingleIteration(1); |
|||
incrementSingleIteration(0xBAD); |
|||
incrementSingleIteration(0xBEEF); |
|||
incrementSingleIteration(0xFFFF); |
|||
incrementSingleIteration(0xFEDCBA); |
|||
incrementSingleIteration(0x7FFFFFFF); |
|||
|
|||
FixedHash<4> h(0xFFFFFFFF); |
|||
FixedHash<4> zero; |
|||
BOOST_CHECK_EQUAL(++h, zero); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_SUITE_END() |
|||
|
|||
} |
|||
} |
@ -0,0 +1,41 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file core.cpp
|
|||
* @author Dimitry Khokhlov <winsvega@mail.ru> |
|||
* @date 2014 |
|||
* CORE test functions. |
|||
*/ |
|||
|
|||
#include <boost/test/unit_test.hpp> |
|||
#include <libdevcore/CommonIO.h> |
|||
#include <test/TestHelper.h> |
|||
|
|||
BOOST_AUTO_TEST_SUITE(CoreLibTests) |
|||
|
|||
BOOST_AUTO_TEST_CASE(byteRef) |
|||
{ |
|||
cnote << "bytesRef copyTo and toString..."; |
|||
dev::bytes originalSequence = dev::fromHex("0102030405060708091011121314151617181920212223242526272829303132"); |
|||
dev::bytesRef out(&originalSequence.at(0), 32); |
|||
dev::h256 hash32("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"); |
|||
hash32.ref().copyTo(out); |
|||
|
|||
BOOST_CHECK_MESSAGE(out.size() == 32, "Error wrong result size when h256::ref().copyTo(dev::bytesRef out)"); |
|||
BOOST_CHECK_MESSAGE(out.toBytes() == originalSequence, "Error when h256::ref().copyTo(dev::bytesRef out)"); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_SUITE_END() |
@ -0,0 +1,277 @@ |
|||
{ |
|||
"SuicideTransaction" : { |
|||
"genesisBlockHeader" : { |
|||
"bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", |
|||
"coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", |
|||
"difficulty" : "131072", |
|||
"extraData" : "0x42", |
|||
"gasLimit" : "125000", |
|||
"gasUsed" : "0", |
|||
"mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|||
"nonce" : "0x0102030405060708", |
|||
"number" : "0", |
|||
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", |
|||
"receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|||
"stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", |
|||
"timestamp" : "0x54c98c81", |
|||
"transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|||
"uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" |
|||
}, |
|||
"expect" : { |
|||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { |
|||
"balance" : "10000000000" |
|||
} |
|||
}, |
|||
"pre" : { |
|||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { |
|||
"balance" : "90000000000000000000000000", |
|||
"nonce" : "0", |
|||
"code" : "", |
|||
"storage": {} |
|||
}, |
|||
"aaaf5374fce5edbc8e2a8697c15331677e6ebf0b" : { |
|||
"balance" : "10000000000", |
|||
"nonce" : "0", |
|||
"code" : "0x73a94f5374fce5edbc8e2a8697c15331677e6ebf0bff", |
|||
"storage": {} |
|||
} |
|||
}, |
|||
"blocks" : [ |
|||
{ |
|||
"transactions" : [ |
|||
{ |
|||
"data" : "", |
|||
"gasLimit" : "100000", |
|||
"gasPrice" : "10", |
|||
"nonce" : "0", |
|||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", |
|||
"to" : "aaaf5374fce5edbc8e2a8697c15331677e6ebf0b", |
|||
"value" : "10" |
|||
} |
|||
], |
|||
"uncleHeaders" : [ |
|||
] |
|||
} |
|||
] |
|||
}, |
|||
|
|||
"GasUsedHigherThanBlockGasLimitButNotWithRefundsSuicideLast" : { |
|||
"genesisBlockHeader" : { |
|||
"bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", |
|||
"coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", |
|||
"difficulty" : "131072", |
|||
"extraData" : "0x42", |
|||
"gasLimit" : "147000", |
|||
"gasUsed" : "0", |
|||
"mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|||
"nonce" : "0x0102030405060708", |
|||
"number" : "0", |
|||
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", |
|||
"receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|||
"stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", |
|||
"timestamp" : "0x54c98c81", |
|||
"transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|||
"uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" |
|||
}, |
|||
"expect" : { |
|||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { |
|||
"balance" : "10000000000" |
|||
} |
|||
}, |
|||
"pre" : { |
|||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { |
|||
"balance" : "90000000000000000000000000", |
|||
"nonce" : "0", |
|||
"code" : "", |
|||
"storage": {} |
|||
}, |
|||
"aaaf5374fce5edbc8e2a8697c15331677e6ebf0b" : { |
|||
"balance" : "10000000000", |
|||
"nonce" : "0", |
|||
"code" : "0x73a94f5374fce5edbc8e2a8697c15331677e6ebf0bff", |
|||
"storage": {} |
|||
} |
|||
}, |
|||
"blocks" : [ |
|||
{ |
|||
"transactions" : [ |
|||
{ |
|||
"data" : "", |
|||
"gasLimit" : "21000", |
|||
"gasPrice" : "10", |
|||
"nonce" : "0", |
|||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", |
|||
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b", |
|||
"value" : "10" |
|||
}, |
|||
{ |
|||
"data" : "", |
|||
"gasLimit" : "21000", |
|||
"gasPrice" : "10", |
|||
"nonce" : "1", |
|||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", |
|||
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b", |
|||
"value" : "10" |
|||
}, |
|||
{ |
|||
"data" : "", |
|||
"gasLimit" : "21000", |
|||
"gasPrice" : "10", |
|||
"nonce" : "2", |
|||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", |
|||
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b", |
|||
"value" : "10" |
|||
}, |
|||
{ |
|||
"data" : "", |
|||
"gasLimit" : "21000", |
|||
"gasPrice" : "10", |
|||
"nonce" : "3", |
|||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", |
|||
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b", |
|||
"value" : "10" |
|||
}, |
|||
{ |
|||
"data" : "", |
|||
"gasLimit" : "21000", |
|||
"gasPrice" : "10", |
|||
"nonce" : "4", |
|||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", |
|||
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b", |
|||
"value" : "10" |
|||
}, |
|||
{ |
|||
"data" : "", |
|||
"gasLimit" : "21000", |
|||
"gasPrice" : "10", |
|||
"nonce" : "5", |
|||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", |
|||
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b", |
|||
"value" : "10" |
|||
}, |
|||
{ |
|||
"data" : "", |
|||
"gasLimit" : "22000", |
|||
"gasPrice" : "10", |
|||
"nonce" : "6", |
|||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", |
|||
"to" : "aaaf5374fce5edbc8e2a8697c15331677e6ebf0b", |
|||
"value" : "10" |
|||
} |
|||
], |
|||
"uncleHeaders" : [ |
|||
] |
|||
} |
|||
] |
|||
}, |
|||
|
|||
"GasUsedHigherThanBlockGasLimitButNotWithRefundsSuicideFirst" : { |
|||
"genesisBlockHeader" : { |
|||
"bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", |
|||
"coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", |
|||
"difficulty" : "131072", |
|||
"extraData" : "0x42", |
|||
"gasLimit" : "147000", |
|||
"gasUsed" : "0", |
|||
"mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|||
"nonce" : "0x0102030405060708", |
|||
"number" : "0", |
|||
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", |
|||
"receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|||
"stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", |
|||
"timestamp" : "0x54c98c81", |
|||
"transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|||
"uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" |
|||
}, |
|||
"expect" : { |
|||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { |
|||
"balance" : "10000000000" |
|||
} |
|||
}, |
|||
"pre" : { |
|||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { |
|||
"balance" : "90000000000000000000000000", |
|||
"nonce" : "0", |
|||
"code" : "", |
|||
"storage": {} |
|||
}, |
|||
"aaaf5374fce5edbc8e2a8697c15331677e6ebf0b" : { |
|||
"balance" : "10000000000", |
|||
"nonce" : "0", |
|||
"code" : "0x73a94f5374fce5edbc8e2a8697c15331677e6ebf0bff", |
|||
"storage": {} |
|||
} |
|||
}, |
|||
"blocks" : [ |
|||
{ |
|||
"transactions" : [ |
|||
{ |
|||
"data" : "", |
|||
"gasLimit" : "21000", |
|||
"gasPrice" : "10", |
|||
"nonce" : "6", |
|||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", |
|||
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b", |
|||
"value" : "10" |
|||
}, |
|||
{ |
|||
"data" : "", |
|||
"gasLimit" : "21000", |
|||
"gasPrice" : "10", |
|||
"nonce" : "1", |
|||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", |
|||
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b", |
|||
"value" : "10" |
|||
}, |
|||
{ |
|||
"data" : "", |
|||
"gasLimit" : "21000", |
|||
"gasPrice" : "10", |
|||
"nonce" : "2", |
|||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", |
|||
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b", |
|||
"value" : "10" |
|||
}, |
|||
{ |
|||
"data" : "", |
|||
"gasLimit" : "21000", |
|||
"gasPrice" : "10", |
|||
"nonce" : "3", |
|||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", |
|||
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b", |
|||
"value" : "10" |
|||
}, |
|||
{ |
|||
"data" : "", |
|||
"gasLimit" : "21000", |
|||
"gasPrice" : "10", |
|||
"nonce" : "4", |
|||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", |
|||
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b", |
|||
"value" : "10" |
|||
}, |
|||
{ |
|||
"data" : "", |
|||
"gasLimit" : "21000", |
|||
"gasPrice" : "10", |
|||
"nonce" : "5", |
|||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", |
|||
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b", |
|||
"value" : "10" |
|||
}, |
|||
{ |
|||
"data" : "", |
|||
"gasLimit" : "22000", |
|||
"gasPrice" : "10", |
|||
"nonce" : "0", |
|||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", |
|||
"to" : "aaaf5374fce5edbc8e2a8697c15331677e6ebf0b", |
|||
"value" : "10" |
|||
} |
|||
], |
|||
"uncleHeaders" : [ |
|||
] |
|||
} |
|||
] |
|||
} |
|||
} |
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue