Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

add test_addTransaction #4924

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions libweb3jsonrpc/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <jsonrpccpp/common/exception.h>
#include <libethereum/ClientTest.h>
#include <libethereum/ChainParams.h>
#include <libweb3jsonrpc/JsonHelper.h>

using namespace std;
using namespace dev;
Expand All @@ -33,6 +34,21 @@ using namespace jsonrpc;

Test::Test(eth::Client& _eth): m_eth(_eth) {}

string Test::test_addTransaction(Json::Value const& param1)
{
try
{
eth::TransactionSkeleton tr = eth::toTransactionSkeleton(param1);
m_eth.submitTransaction(tr, Secret(param1["secretKey"].asString()));
}
catch (...)
{
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS));
}

return "";
}

bool Test::test_setChainParams(Json::Value const& param1)
{
try
Expand Down
3 changes: 2 additions & 1 deletion libweb3jsonrpc/Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class Test: public TestFace
return RPCModules{RPCModule{"test", "1.0"}};
}

virtual bool test_setChainParams(const Json::Value &param1) override;
virtual std::string test_addTransaction(const Json::Value& param1) override;
virtual bool test_setChainParams(const Json::Value &param1) override;
virtual bool test_mineBlocks(int _number) override;
virtual bool test_modifyTimestamp(int _timestamp) override;
virtual bool test_addBlock(std::string const& _rlp) override;
Expand Down
11 changes: 11 additions & 0 deletions libweb3jsonrpc/TestFace.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,22 @@ namespace dev {
public:
TestFace()
{
this->bindAndAddMethod(
jsonrpc::Procedure("test_addTransaction", jsonrpc::PARAMS_BY_POSITION,
jsonrpc::JSON_STRING, "param1", jsonrpc::JSON_OBJECT, NULL),
&dev::rpc::TestFace::test_addTransactionI);
this->bindAndAddMethod(jsonrpc::Procedure("test_setChainParams", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_OBJECT, NULL), &dev::rpc::TestFace::test_setChainParamsI);
this->bindAndAddMethod(jsonrpc::Procedure("test_mineBlocks", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_mineBlocksI);
this->bindAndAddMethod(jsonrpc::Procedure("test_modifyTimestamp", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_modifyTimestampI);
this->bindAndAddMethod(jsonrpc::Procedure("test_addBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &dev::rpc::TestFace::test_addBlockI);
this->bindAndAddMethod(jsonrpc::Procedure("test_rewindToBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_rewindToBlockI);
}

inline virtual void test_addTransactionI(
const Json::Value& request, Json::Value& response)
{
response = this->test_addTransaction(request[0u]);
}
inline virtual void test_setChainParamsI(const Json::Value &request, Json::Value &response)
{
response = this->test_setChainParams(request[0u]);
Expand All @@ -41,6 +50,8 @@ namespace dev {
{
response = this->test_rewindToBlock(request[0u].asInt());
}

virtual std::string test_addTransaction(const Json::Value& param1) = 0;
virtual bool test_setChainParams(const Json::Value& param1) = 0;
virtual bool test_mineBlocks(int param1) = 0;
virtual bool test_modifyTimestamp(int param1) = 0;
Expand Down
1 change: 1 addition & 0 deletions libweb3jsonrpc/test.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[
{ "name": "test_addTransaction", "params": [{}], "order": [], "returns": ""},
{ "name": "test_setChainParams", "params": [{}], "order": [], "returns": false},
{ "name": "test_mineBlocks", "params": [0], "returns": false },
{ "name": "test_modifyTimestamp", "params": [0], "returns": false },
Expand Down