aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGav Wood <i@gavwood.com>2014-11-18 20:40:53 +0800
committerGav Wood <i@gavwood.com>2014-11-18 20:40:53 +0800
commit9544173e3b930dffe6b44e168c2b5664a5702a0c (patch)
tree3a14d91cd2c97e6ad8c1a3e4e7653e78ab4a05fe
parent00c21e4bccf901b449fc5b0643f6c848ee0ef847 (diff)
parentede6da24d7df5f4236023a7fa4f7bd8b4d21fc10 (diff)
downloaddexon-solidity-9544173e3b930dffe6b44e168c2b5664a5702a0c.tar.gz
dexon-solidity-9544173e3b930dffe6b44e168c2b5664a5702a0c.tar.zst
dexon-solidity-9544173e3b930dffe6b44e168c2b5664a5702a0c.zip
Merge branch 'filter_logs' into develop
-rw-r--r--jsonrpc.cpp66
-rw-r--r--webthreestubclient.h85
2 files changed, 134 insertions, 17 deletions
diff --git a/jsonrpc.cpp b/jsonrpc.cpp
index 4c748a95..d17c5a59 100644
--- a/jsonrpc.cpp
+++ b/jsonrpc.cpp
@@ -237,7 +237,73 @@ BOOST_AUTO_TEST_CASE(jsonrpc_transact)
BOOST_CHECK_EQUAL(jsToDecimal(balanceString2), "750000000000000000");
BOOST_CHECK_EQUAL(txAmount, balance2);
}
+
+
+BOOST_AUTO_TEST_CASE(simple_contract)
+{
+ cnote << "Testing jsonrpc contract...";
+ KeyPair kp = KeyPair::create();
+ web3->ethereum()->setAddress(kp.address());
+ jsonrpcServer->setAccounts({kp});
+
+ dev::eth::mine(*(web3->ethereum()), 1);
+
+ char const* sourceCode = "contract test {\n"
+ " function f(uint a) returns(uint d) { return a * 7; }\n"
+ "}\n";
+
+ string compiled = jsonrpcClient->eth_solidity(sourceCode);
+
+ Json::Value create;
+ create["code"] = compiled;
+ string contractAddress = jsonrpcClient->eth_transact(create);
+ dev::eth::mine(*(web3->ethereum()), 1);
+ Json::Value call;
+ call["to"] = contractAddress;
+ call["data"] = "0x00000000000000000000000000000000000000000000000000000000000000001";
+ string result = jsonrpcClient->eth_call(call);
+ BOOST_CHECK_EQUAL(result, "0x0000000000000000000000000000000000000000000000000000000000000007");
+}
+
+BOOST_AUTO_TEST_CASE(contract_storage)
+{
+ cnote << "Testing jsonrpc contract storage...";
+ KeyPair kp = KeyPair::create();
+ web3->ethereum()->setAddress(kp.address());
+ jsonrpcServer->setAccounts({kp});
+
+ dev::eth::mine(*(web3->ethereum()), 1);
+
+ char const* sourceCode = R"(
+ contract test {
+ uint hello;
+ function writeHello(uint value) returns(bool d){
+ hello = value;
+ return true;
+ }
+ }
+ )";
+
+ string compiled = jsonrpcClient->eth_solidity(sourceCode);
+
+ Json::Value create;
+ create["code"] = compiled;
+ string contractAddress = jsonrpcClient->eth_transact(create);
+ dev::eth::mine(*(web3->ethereum()), 1);
+
+ Json::Value transact;
+ transact["to"] = contractAddress;
+ transact["data"] = "0x00000000000000000000000000000000000000000000000000000000000000003";
+ jsonrpcClient->eth_transact(transact);
+ dev::eth::mine(*(web3->ethereum()), 1);
+
+ Json::Value storage = jsonrpcClient->eth_storageAt(contractAddress);
+ BOOST_CHECK_EQUAL(storage.getMemberNames().size(), 1);
+ for (auto name: storage.getMemberNames())
+ BOOST_CHECK_EQUAL(storage[name].asString(), "0x03");
+}
+
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
diff --git a/webthreestubclient.h b/webthreestubclient.h
index 179c620a..f5fee4c0 100644
--- a/webthreestubclient.h
+++ b/webthreestubclient.h
@@ -179,14 +179,13 @@ p.append(param3);
}
- std::string eth_compile(const std::string& param1) throw (jsonrpc::JsonRpcException)
+ Json::Value eth_compilers() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
- p.append(param1);
-
- Json::Value result = this->client->CallMethod("eth_compile",p);
- if (result.isString())
- return result.asString();
+ p = Json::nullValue;
+ Json::Value result = this->client->CallMethod("eth_compilers",p);
+ if (result.isArray())
+ return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
@@ -217,26 +216,26 @@ p.append(param3);
}
- std::string eth_gasPrice() throw (jsonrpc::JsonRpcException)
+ Json::Value eth_filterLogs(const int& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
- p = Json::nullValue;
- Json::Value result = this->client->CallMethod("eth_gasPrice",p);
- if (result.isString())
- return result.asString();
+ p.append(param1);
+
+ Json::Value result = this->client->CallMethod("eth_filterLogs",p);
+ if (result.isArray())
+ return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
- Json::Value eth_getMessages(const int& param1) throw (jsonrpc::JsonRpcException)
+ std::string eth_gasPrice() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
- p.append(param1);
-
- Json::Value result = this->client->CallMethod("eth_getMessages",p);
- if (result.isArray())
- return result;
+ p = Json::nullValue;
+ Json::Value result = this->client->CallMethod("eth_gasPrice",p);
+ if (result.isString())
+ return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
@@ -267,6 +266,19 @@ p.append(param3);
}
+ Json::Value eth_logs(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
+ {
+ Json::Value p;
+ p.append(param1);
+
+ Json::Value result = this->client->CallMethod("eth_logs",p);
+ if (result.isArray())
+ return result;
+ else
+ throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
+
+ }
+
bool eth_mining() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
@@ -329,6 +341,19 @@ p.append(param3);
}
+ std::string eth_serpent(const std::string& param1) throw (jsonrpc::JsonRpcException)
+ {
+ Json::Value p;
+ p.append(param1);
+
+ Json::Value result = this->client->CallMethod("eth_serpent",p);
+ if (result.isString())
+ return result.asString();
+ else
+ throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
+
+ }
+
bool eth_setCoinbase(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
@@ -381,6 +406,19 @@ p.append(param3);
}
+ std::string eth_solidity(const std::string& param1) throw (jsonrpc::JsonRpcException)
+ {
+ Json::Value p;
+ p.append(param1);
+
+ Json::Value result = this->client->CallMethod("eth_solidity",p);
+ if (result.isString())
+ return result.asString();
+ else
+ throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
+
+ }
+
std::string eth_stateAt(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
@@ -395,6 +433,19 @@ p.append(param2);
}
+ Json::Value eth_storageAt(const std::string& param1) throw (jsonrpc::JsonRpcException)
+ {
+ Json::Value p;
+ p.append(param1);
+
+ Json::Value result = this->client->CallMethod("eth_storageAt",p);
+ if (result.isObject())
+ return result;
+ else
+ throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
+
+ }
+
std::string eth_transact(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;