fork.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. This file is part of cpp-ethereum.
  3. cpp-ethereum is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. cpp-ethereum is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /** @file fork.cpp
  15. * @author Marko Simovic <markobarko@gmail.com>
  16. * @date 2014
  17. * Tests for different forking behavior
  18. */
  19. #include <boost/test/unit_test.hpp>
  20. #include <boost/filesystem/operations.hpp>
  21. #include <libethereum/Client.h>
  22. #include <libethereum/BlockChain.h>
  23. #include <libethereum/EthereumHost.h>
  24. #include "TestHelper.h"
  25. using namespace std;
  26. using namespace dev;
  27. using namespace dev::eth;
  28. // Disabled since tests shouldn't block. Need a short cut to avoid real mining.
  29. /*
  30. BOOST_AUTO_TEST_CASE(simple_chain_fork)
  31. {
  32. //start a client and mine a short chain
  33. Client c1("TestClient1", KeyPair::create().address(),
  34. (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
  35. mine(c1, 4);
  36. //start another client and mine a longer chain
  37. Client c2("TestClient2", KeyPair::create().address(),
  38. (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
  39. mine(c2, 6);
  40. //connect the two clients up to resolve chain
  41. c1.startNetwork(20000);
  42. c2.startNetwork(21000);
  43. c2.connect("127.0.0.1", 20000);
  44. //mine an extra block to cement it
  45. mine(c1, 1);
  46. //check the balances are where they should be
  47. //c1's chain should have been clobbered by c2
  48. BOOST_REQUIRE(c1.state().balance(c1.address()) == 0);
  49. BOOST_REQUIRE(c2.state().balance(c2.address()) > 0);
  50. }
  51. */