Test.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 Test.cpp
  15. * @authors:
  16. * Dimitry Khokhlov <dimitry@ethdev.com>
  17. * @date 2016
  18. */
  19. #include "Test.h"
  20. #include <jsonrpccpp/common/errors.h>
  21. #include <jsonrpccpp/common/exception.h>
  22. #include <libethereum/ClientTest.h>
  23. #include <libethereum/ChainParams.h>
  24. using namespace std;
  25. using namespace dev;
  26. using namespace dev::rpc;
  27. using namespace jsonrpc;
  28. Test::Test(eth::Client& _eth): m_eth(_eth) {}
  29. bool Test::test_setChainParams(Json::Value const& param1)
  30. {
  31. try
  32. {
  33. Json::StreamWriterBuilder swb;
  34. std::string output = Json::writeString(swb, param1);
  35. asClientTest(m_eth).setChainParams(output);
  36. }
  37. catch (std::exception const&)
  38. {
  39. BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
  40. }
  41. return true;
  42. }
  43. bool Test::test_mineBlocks(int _number)
  44. {
  45. try
  46. {
  47. asClientTest(m_eth).mineBlocks(_number);
  48. }
  49. catch (std::exception const&)
  50. {
  51. BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
  52. }
  53. return true;
  54. }
  55. bool Test::test_modifyTimestamp(int _timestamp)
  56. {
  57. try
  58. {
  59. asClientTest(m_eth).modifyTimestamp(u256(_timestamp));
  60. }
  61. catch (std::exception const&)
  62. {
  63. BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
  64. }
  65. return true;
  66. }
  67. bool Test::test_addBlock(std::string const& _rlp)
  68. {
  69. try
  70. {
  71. asClientTest(m_eth).addBlock(_rlp);
  72. }
  73. catch (std::exception const&)
  74. {
  75. BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
  76. }
  77. return true;
  78. }
  79. bool Test::test_rewindToBlock(int _number)
  80. {
  81. try
  82. {
  83. m_eth.rewind(_number);
  84. }
  85. catch (std::exception const&)
  86. {
  87. BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
  88. }
  89. return true;
  90. }