diff options
author | Gav Wood <g@ethdev.com> | 2015-01-10 00:45:09 +0800 |
---|---|---|
committer | Gav Wood <g@ethdev.com> | 2015-01-10 00:45:09 +0800 |
commit | 8bc90cb7f82aebfdfc0c9367a838f3a936d5ff1a (patch) | |
tree | 68bf041c8ab659435899afcac649fe5a146c6e80 | |
parent | 8cc70a12c6fc726c0ec1dada49003d48406b65a0 (diff) | |
parent | dfeef25fc2907658914324b130376a20e12d2a8d (diff) | |
download | dexon-solidity-8bc90cb7f82aebfdfc0c9367a838f3a936d5ff1a.tar dexon-solidity-8bc90cb7f82aebfdfc0c9367a838f3a936d5ff1a.tar.gz dexon-solidity-8bc90cb7f82aebfdfc0c9367a838f3a936d5ff1a.tar.bz2 dexon-solidity-8bc90cb7f82aebfdfc0c9367a838f3a936d5ff1a.tar.lz dexon-solidity-8bc90cb7f82aebfdfc0c9367a838f3a936d5ff1a.tar.xz dexon-solidity-8bc90cb7f82aebfdfc0c9367a838f3a936d5ff1a.tar.zst dexon-solidity-8bc90cb7f82aebfdfc0c9367a838f3a936d5ff1a.zip |
Merge pull request #766 from debris/web3sha3test
web3.sha3 test
-rw-r--r-- | jsonrpc.cpp | 18 | ||||
-rw-r--r-- | webthreestubclient.h | 10 |
2 files changed, 28 insertions, 0 deletions
diff --git a/jsonrpc.cpp b/jsonrpc.cpp index eed54ed8..42b1a5eb 100644 --- a/jsonrpc.cpp +++ b/jsonrpc.cpp @@ -74,6 +74,12 @@ struct Setup } }; +string fromAscii(string _s) +{ + bytes b = asBytes(_s); + return "0x" + toHex(b); +} + BOOST_FIXTURE_TEST_SUITE(environment, Setup) BOOST_AUTO_TEST_CASE(jsonrpc_defaultBlock) @@ -312,6 +318,18 @@ BOOST_AUTO_TEST_CASE(contract_storage) } } +BOOST_AUTO_TEST_CASE(sha3) +{ + cnote << "Testing jsonrpc sha3..."; + string testString = "multiply(uint256)"; + h256 expected = dev::sha3(testString); + + auto hexValue = fromAscii(testString); + string result = jsonrpcClient->web3_sha3(hexValue); + BOOST_CHECK_EQUAL(toJS(expected), result); + BOOST_CHECK_EQUAL("0xc6888fa159d67f77c2f3d7a402e199802766bd7e8d4d1ecd2274fc920265d56a", result); +} + BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END() diff --git a/webthreestubclient.h b/webthreestubclient.h index 9b36c364..6a82263d 100644 --- a/webthreestubclient.h +++ b/webthreestubclient.h @@ -12,6 +12,16 @@ class WebThreeStubClient : public jsonrpc::Client public: WebThreeStubClient(jsonrpc::IClientConnector &conn) : jsonrpc::Client(conn) {} + std::string web3_sha3(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("web3_sha3",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } std::string eth_coinbase() throw (jsonrpc::JsonRpcException) { Json::Value p; |