diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2014-11-18 23:37:24 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2014-11-18 23:37:24 +0800 |
commit | 0eb527859fac01620f5d977726497ee8e9fd67e1 (patch) | |
tree | 0a1a94ed88ba5f8b260623f631aefc83a9eb7382 /jsonrpc.cpp | |
parent | cf58cd775425647a112edec9551a1cd56d176924 (diff) | |
parent | 9544173e3b930dffe6b44e168c2b5664a5702a0c (diff) | |
download | dexon-solidity-0eb527859fac01620f5d977726497ee8e9fd67e1.tar.gz dexon-solidity-0eb527859fac01620f5d977726497ee8e9fd67e1.tar.zst dexon-solidity-0eb527859fac01620f5d977726497ee8e9fd67e1.zip |
Merge branch 'develop' into mk_jsonrpc_upgrade
Conflicts:
libweb3jsonrpc/abstractwebthreestubserver.h
libweb3jsonrpc/spec.json
test/webthreestubclient.h
Diffstat (limited to 'jsonrpc.cpp')
-rw-r--r-- | jsonrpc.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/jsonrpc.cpp b/jsonrpc.cpp index 25468dcc..09e44346 100644 --- a/jsonrpc.cpp +++ b/jsonrpc.cpp @@ -238,7 +238,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() |