diff options
author | Christian <c@ethdev.com> | 2015-02-19 22:13:03 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2015-02-21 01:48:45 +0800 |
commit | ba0a8a2bfc541809d21db208f6adc7c136492013 (patch) | |
tree | bc5bbfdd7c2b3aa18aa9c9bce128b620300b0e60 | |
parent | 3e79e23841670c27ceba34bce2d0715a7ef4a136 (diff) | |
download | dexon-solidity-ba0a8a2bfc541809d21db208f6adc7c136492013.tar dexon-solidity-ba0a8a2bfc541809d21db208f6adc7c136492013.tar.gz dexon-solidity-ba0a8a2bfc541809d21db208f6adc7c136492013.tar.bz2 dexon-solidity-ba0a8a2bfc541809d21db208f6adc7c136492013.tar.lz dexon-solidity-ba0a8a2bfc541809d21db208f6adc7c136492013.tar.xz dexon-solidity-ba0a8a2bfc541809d21db208f6adc7c136492013.tar.zst dexon-solidity-ba0a8a2bfc541809d21db208f6adc7c136492013.zip |
Implemented account proxy queues.
-rw-r--r-- | AccountHolder.cpp | 74 | ||||
-rw-r--r-- | webthreestubclient.h | 30 |
2 files changed, 104 insertions, 0 deletions
diff --git a/AccountHolder.cpp b/AccountHolder.cpp new file mode 100644 index 00000000..e8e42ff1 --- /dev/null +++ b/AccountHolder.cpp @@ -0,0 +1,74 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. + */ +/** + * @author Christian R <c@ethdev.com> + * @date 2015 + * Unit tests for the account holder used by the WebThreeStubServer. + */ + +#include <boost/test/unit_test.hpp> +#include <libweb3jsonrpc/AccountHolder.h> + +namespace dev +{ +namespace test +{ + +BOOST_AUTO_TEST_SUITE(AccountHolderTest) + +BOOST_AUTO_TEST_CASE(ProxyAccountUseCase) +{ + AccountHolder h = AccountHolder(std::function<eth::Interface*()>()); + BOOST_CHECK(h.getAllAccounts().empty()); + BOOST_CHECK(h.getRealAccounts().empty()); + Address addr("abababababababababababababababababababab"); + Address addr2("abababababababababababababababababababab"); + int id = h.addProxyAccount(addr); + BOOST_CHECK(h.getQueuedTransactions(id).empty()); + // register it again + int secondID = h.addProxyAccount(addr); + BOOST_CHECK(h.getQueuedTransactions(secondID).empty()); + + eth::TransactionSkeleton t1; + eth::TransactionSkeleton t2; + t1.from = addr; + t1.data = fromHex("12345678"); + t2.from = addr; + t2.data = fromHex("abcdef"); + BOOST_CHECK(h.getQueuedTransactions(id).empty()); + h.queueTransaction(t1); + BOOST_CHECK_EQUAL(1, h.getQueuedTransactions(id).size()); + h.queueTransaction(t2); + BOOST_REQUIRE_EQUAL(2, h.getQueuedTransactions(id).size()); + + // second proxy should not see transactions + BOOST_CHECK(h.getQueuedTransactions(secondID).empty()); + + BOOST_CHECK(h.getQueuedTransactions(id)[0].data == t1.data); + BOOST_CHECK(h.getQueuedTransactions(id)[1].data == t2.data); + + h.clearQueue(id); + BOOST_CHECK(h.getQueuedTransactions(id).empty()); + // removing fails because it never existed + BOOST_CHECK(!h.removeProxyAccount(secondID)); + BOOST_CHECK(h.removeProxyAccount(id)); +} + +BOOST_AUTO_TEST_SUITE_END() + +} +} diff --git a/webthreestubclient.h b/webthreestubclient.h index ee175b05..70aa9db9 100644 --- a/webthreestubclient.h +++ b/webthreestubclient.h @@ -447,6 +447,36 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } + int eth_register(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_register",p); + if (result.isInt()) + return result.asInt(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + bool eth_unregister(int param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_unregister",p); + if (result.isBool()) + return result.asBool(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value eth_queuedTransactions(int param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_queuedTransactions",p); + if (result.isArray()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } bool db_put(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException) { Json::Value p; |