mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
State integration test.
Fixes to the FatTrie.
This commit is contained in:
parent
aa3f5f8c2d
commit
ac1b7fde0e
@ -26,7 +26,7 @@ target_link_libraries(testeth ethereum)
|
|||||||
target_link_libraries(testeth ethcore)
|
target_link_libraries(testeth ethcore)
|
||||||
target_link_libraries(testeth secp256k1)
|
target_link_libraries(testeth secp256k1)
|
||||||
target_link_libraries(testeth solidity)
|
target_link_libraries(testeth solidity)
|
||||||
if (NOT HEADLESS)
|
if (NOT HEADLESS AND NOT JUSTTESTS)
|
||||||
target_link_libraries(testeth webthree)
|
target_link_libraries(testeth webthree)
|
||||||
target_link_libraries(testeth natspec)
|
target_link_libraries(testeth natspec)
|
||||||
endif()
|
endif()
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
* State test functions.
|
* State test functions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
#include <boost/filesystem/operations.hpp>
|
#include <boost/filesystem/operations.hpp>
|
||||||
#include <secp256k1/secp256k1.h>
|
#include <secp256k1/secp256k1.h>
|
||||||
#include <libethereum/CanonBlockChain.h>
|
#include <libethereum/CanonBlockChain.h>
|
||||||
@ -29,7 +30,21 @@ using namespace std;
|
|||||||
using namespace dev;
|
using namespace dev;
|
||||||
using namespace dev::eth;
|
using namespace dev::eth;
|
||||||
|
|
||||||
int stateTest()
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace test
|
||||||
|
{
|
||||||
|
|
||||||
|
int stateTest();
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE(StateIntegration)
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(Basic)
|
||||||
|
{
|
||||||
|
State s;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(Complex)
|
||||||
{
|
{
|
||||||
cnote << "Testing State...";
|
cnote << "Testing State...";
|
||||||
|
|
||||||
@ -37,14 +52,15 @@ int stateTest()
|
|||||||
KeyPair myMiner = sha3("Gav's Miner");
|
KeyPair myMiner = sha3("Gav's Miner");
|
||||||
// KeyPair you = sha3("123");
|
// KeyPair you = sha3("123");
|
||||||
|
|
||||||
Defaults::setDBPath(boost::filesystem::temp_directory_path().string());
|
Defaults::setDBPath(boost::filesystem::temp_directory_path().string() + "/" + toString(chrono::system_clock::now().time_since_epoch().count()));
|
||||||
|
|
||||||
OverlayDB stateDB = State::openDB();
|
OverlayDB stateDB = State::openDB();
|
||||||
CanonBlockChain bc;
|
CanonBlockChain bc;
|
||||||
State s(myMiner.address(), stateDB);
|
|
||||||
|
|
||||||
cout << bc;
|
cout << bc;
|
||||||
|
|
||||||
|
State s(myMiner.address(), stateDB);
|
||||||
|
cout << s;
|
||||||
|
|
||||||
// Sync up - this won't do much until we use the last state.
|
// Sync up - this won't do much until we use the last state.
|
||||||
s.sync(bc);
|
s.sync(bc);
|
||||||
|
|
||||||
@ -52,7 +68,7 @@ int stateTest()
|
|||||||
|
|
||||||
// Mine to get some ether!
|
// Mine to get some ether!
|
||||||
s.commitToMine(bc);
|
s.commitToMine(bc);
|
||||||
while (!s.mine(100).completed) {}
|
while (!s.mine(100, true).completed) {}
|
||||||
s.completeMine();
|
s.completeMine();
|
||||||
bc.attemptImport(s.blockData(), stateDB);
|
bc.attemptImport(s.blockData(), stateDB);
|
||||||
|
|
||||||
@ -65,7 +81,7 @@ int stateTest()
|
|||||||
// Inject a transaction to transfer funds from miner to me.
|
// Inject a transaction to transfer funds from miner to me.
|
||||||
bytes tx;
|
bytes tx;
|
||||||
{
|
{
|
||||||
Transaction t(1000, 0, 0, me.address(), bytes(), s.transactionsFrom(myMiner.address()), myMiner.secret());
|
Transaction t(1000, 10000, 10000, me.address(), bytes(), s.transactionsFrom(myMiner.address()), myMiner.secret());
|
||||||
assert(t.sender() == myMiner.address());
|
assert(t.sender() == myMiner.address());
|
||||||
tx = t.rlp();
|
tx = t.rlp();
|
||||||
}
|
}
|
||||||
@ -76,7 +92,7 @@ int stateTest()
|
|||||||
// Mine to get some ether and set in stone.
|
// Mine to get some ether and set in stone.
|
||||||
s.commitToMine(bc);
|
s.commitToMine(bc);
|
||||||
s.commitToMine(bc);
|
s.commitToMine(bc);
|
||||||
while (!s.mine(50).completed) { s.commitToMine(bc); }
|
while (!s.mine(100, true).completed) {}
|
||||||
s.completeMine();
|
s.completeMine();
|
||||||
bc.attemptImport(s.blockData(), stateDB);
|
bc.attemptImport(s.blockData(), stateDB);
|
||||||
|
|
||||||
@ -85,7 +101,9 @@ int stateTest()
|
|||||||
s.sync(bc);
|
s.sync(bc);
|
||||||
|
|
||||||
cout << s;
|
cout << s;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
20
trie.cpp
20
trie.cpp
@ -52,6 +52,26 @@ using dev::operator <<;
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE(TrieTests)
|
BOOST_AUTO_TEST_SUITE(TrieTests)
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(fat_trie)
|
||||||
|
{
|
||||||
|
h256 r;
|
||||||
|
MemoryDB fm;
|
||||||
|
{
|
||||||
|
FatGenericTrieDB<MemoryDB> ft(&fm);
|
||||||
|
ft.init();
|
||||||
|
ft.insert(h256("69", h256::FromHex, h256::AlignRight).ref(), h256("414243", h256::FromHex, h256::AlignRight).ref());
|
||||||
|
for (auto i: ft)
|
||||||
|
cnote << i.first << i.second;
|
||||||
|
r = ft.root();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
FatGenericTrieDB<MemoryDB> ft(&fm);
|
||||||
|
ft.setRoot(r);
|
||||||
|
for (auto i: ft)
|
||||||
|
cnote << i.first << i.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(trie_test_anyorder)
|
BOOST_AUTO_TEST_CASE(trie_test_anyorder)
|
||||||
{
|
{
|
||||||
string testPath = test::getTestPath();
|
string testPath = test::getTestPath();
|
||||||
|
Loading…
Reference in New Issue
Block a user