From 5d20782dea534f7a9502a3fa8ebf2d6071522dcd Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 5 Mar 2015 00:33:44 +0100 Subject: jsonrpc api changes in progress --- webthreestubclient.h | 76 +++++++++------------------------------------------- 1 file changed, 13 insertions(+), 63 deletions(-) diff --git a/webthreestubclient.h b/webthreestubclient.h index 70aa9db9..14afd706 100644 --- a/webthreestubclient.h +++ b/webthreestubclient.h @@ -22,43 +22,33 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - std::string eth_coinbase() throw (jsonrpc::JsonRpcException) + std::string net_peerCount() throw (jsonrpc::JsonRpcException) { Json::Value p; p = Json::nullValue; - Json::Value result = this->CallMethod("eth_coinbase",p); + Json::Value result = this->CallMethod("net_peerCount",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; - p.append(param1); - Json::Value result = this->CallMethod("eth_setCoinbase",p); - if (result.isBool()) - return result.asBool(); - else - throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); - } - bool eth_listening() throw (jsonrpc::JsonRpcException) + bool net_listening() throw (jsonrpc::JsonRpcException) { Json::Value p; p = Json::nullValue; - Json::Value result = this->CallMethod("eth_listening",p); + Json::Value result = this->CallMethod("net_listening",p); if (result.isBool()) return result.asBool(); else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - bool eth_setListening(bool param1) throw (jsonrpc::JsonRpcException) + std::string eth_coinbase() throw (jsonrpc::JsonRpcException) { Json::Value p; - p.append(param1); - Json::Value result = this->CallMethod("eth_setListening",p); - if (result.isBool()) - return result.asBool(); + p = Json::nullValue; + Json::Value result = this->CallMethod("eth_coinbase",p); + if (result.isString()) + return result.asString(); else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } @@ -72,16 +62,6 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - bool eth_setMining(bool param1) throw (jsonrpc::JsonRpcException) - { - Json::Value p; - p.append(param1); - Json::Value result = this->CallMethod("eth_setMining",p); - if (result.isBool()) - return result.asBool(); - else - throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); - } std::string eth_gasPrice() throw (jsonrpc::JsonRpcException) { Json::Value p; @@ -102,43 +82,13 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - int eth_peerCount() throw (jsonrpc::JsonRpcException) - { - Json::Value p; - p = Json::nullValue; - Json::Value result = this->CallMethod("eth_peerCount",p); - if (result.isInt()) - return result.asInt(); - else - throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); - } - int eth_defaultBlock() throw (jsonrpc::JsonRpcException) + std::string eth_blockNumber() throw (jsonrpc::JsonRpcException) { Json::Value p; p = Json::nullValue; - Json::Value result = this->CallMethod("eth_defaultBlock",p); - if (result.isInt()) - return result.asInt(); - else - throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); - } - bool eth_setDefaultBlock(int param1) throw (jsonrpc::JsonRpcException) - { - Json::Value p; - p.append(param1); - Json::Value result = this->CallMethod("eth_setDefaultBlock",p); - if (result.isBool()) - return result.asBool(); - else - throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); - } - int eth_number() throw (jsonrpc::JsonRpcException) - { - Json::Value p; - p = Json::nullValue; - Json::Value result = this->CallMethod("eth_number",p); - if (result.isInt()) - return result.asInt(); + Json::Value result = this->CallMethod("eth_blockNumber",p); + if (result.isString()) + return result.asString(); else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } -- cgit v1.2.3 From 13d14289d8339b60b00086a5f6f57e2c7f69167a Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 5 Mar 2015 01:14:31 +0100 Subject: jsonrpc api changes in progress2 --- webthreestubclient.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/webthreestubclient.h b/webthreestubclient.h index 14afd706..4c92f52d 100644 --- a/webthreestubclient.h +++ b/webthreestubclient.h @@ -92,34 +92,36 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - std::string eth_balanceAt(const std::string& param1) throw (jsonrpc::JsonRpcException) + std::string eth_getBalance(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_balanceAt",p); + p.append(param2); + Json::Value result = this->CallMethod("eth_getBalance",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 eth_getStorage(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); p.append(param2); - Json::Value result = this->CallMethod("eth_stateAt",p); - if (result.isString()) - return result.asString(); + Json::Value result = this->CallMethod("eth_getStorage",p); + if (result.isObject()) + return result; else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_storageAt(const std::string& param1) throw (jsonrpc::JsonRpcException) + std::string eth_stateAt(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_storageAt",p); - if (result.isObject()) - return result; + p.append(param2); + Json::Value result = this->CallMethod("eth_stateAt",p); + if (result.isString()) + return result.asString(); else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } -- cgit v1.2.3 From d3e65ba8a44c75f9fd180309ba6c07dd03a2a9d5 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 5 Mar 2015 01:34:02 +0100 Subject: jsonrpc api changes in progress3 --- webthreestubclient.h | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/webthreestubclient.h b/webthreestubclient.h index 4c92f52d..824beee7 100644 --- a/webthreestubclient.h +++ b/webthreestubclient.h @@ -114,44 +114,46 @@ class WebThreeStubClient : public jsonrpc::Client 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) + std::string eth_getStorageAt(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); p.append(param2); - Json::Value result = this->CallMethod("eth_stateAt",p); + p.append(param3); + Json::Value result = this->CallMethod("eth_getStorageAt",p); if (result.isString()) return result.asString(); else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - double eth_countAt(const std::string& param1) throw (jsonrpc::JsonRpcException) + std::string eth_getTransactionCount(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_countAt",p); - if (result.isDouble()) - return result.asDouble(); + p.append(param2); + Json::Value result = this->CallMethod("eth_getTransactionCount",p); + if (result.isString()) + return result.asString(); else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - double eth_transactionCountByHash(const std::string& param1) throw (jsonrpc::JsonRpcException) + std::string eth_getBlockTransactionCountByHash(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_transactionCountByHash",p); - if (result.isDouble()) - return result.asDouble(); + Json::Value result = this->CallMethod("eth_getBlockTransactionCountByHash",p); + if (result.isString()) + return result.asString(); else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - double eth_transactionCountByNumber(int param1) throw (jsonrpc::JsonRpcException) + std::string eth_getBlockTransactionCountByNumber(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_transactionCountByNumber",p); - if (result.isDouble()) - return result.asDouble(); + Json::Value result = this->CallMethod("eth_getBlockTransactionCountByNumber",p); + if (result.isString()) + return result.asString(); else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } -- cgit v1.2.3 From bbe0e15208299218f59f517ae9043c900b88b8cf Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 5 Mar 2015 02:02:42 +0100 Subject: jsonrpc api changes in progress4 --- webthreestubclient.h | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/webthreestubclient.h b/webthreestubclient.h index 824beee7..f37e855e 100644 --- a/webthreestubclient.h +++ b/webthreestubclient.h @@ -157,41 +157,42 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - double eth_uncleCountByHash(const std::string& param1) throw (jsonrpc::JsonRpcException) + std::string eth_getUncleCountByBlockHash(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_uncleCountByHash",p); - if (result.isDouble()) - return result.asDouble(); + Json::Value result = this->CallMethod("eth_getUncleCountByBlockHash",p); + if (result.isString()) + return result.asString(); else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - double eth_uncleCountByNumber(int param1) throw (jsonrpc::JsonRpcException) + std::string eth_getUncleCountByBlockNumber(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_uncleCountByNumber",p); - if (result.isDouble()) - return result.asDouble(); + Json::Value result = this->CallMethod("eth_getUncleCountByBlockNumber",p); + if (result.isString()) + return result.asString(); else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - std::string eth_codeAt(const std::string& param1) throw (jsonrpc::JsonRpcException) + std::string eth_getData(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_codeAt",p); + p.append(param2); + Json::Value result = this->CallMethod("eth_getData",p); if (result.isString()) return result.asString(); else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - std::string eth_transact(const Json::Value& param1) throw (jsonrpc::JsonRpcException) + std::string eth_sendTransaction(const Json::Value& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_transact",p); + Json::Value result = this->CallMethod("eth_sendTransaction",p); if (result.isString()) return result.asString(); else @@ -217,21 +218,21 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_blockByHash(const std::string& param1) throw (jsonrpc::JsonRpcException) + Json::Value eth_getBlockByHash(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_blockByHash",p); + Json::Value result = this->CallMethod("eth_getBlockByHash",p); if (result.isObject()) return result; else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_blockByNumber(int param1) throw (jsonrpc::JsonRpcException) + Json::Value eth_getBlockByNumber(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_blockByNumber",p); + Json::Value result = this->CallMethod("eth_getBlockByNumber",p); if (result.isObject()) return result; else -- cgit v1.2.3 From 46d40d399d235f048eb6454d4f76bc482bf012bc Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 5 Mar 2015 10:12:01 +0100 Subject: jsonrpc api changes in progress5 --- webthreestubclient.h | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/webthreestubclient.h b/webthreestubclient.h index f37e855e..a13744bf 100644 --- a/webthreestubclient.h +++ b/webthreestubclient.h @@ -238,85 +238,95 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_transactionByHash(const std::string& param1, int param2) throw (jsonrpc::JsonRpcException) + Json::Value eth_getTransactionByHash(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_getTransactionByHash",p); + if (result.isObject()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value eth_getTransactionByBlockHashAndIndex(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); p.append(param2); - Json::Value result = this->CallMethod("eth_transactionByHash",p); + Json::Value result = this->CallMethod("eth_getTransactionByBlockHashAndIndex",p); if (result.isObject()) return result; else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_transactionByNumber(int param1, int param2) throw (jsonrpc::JsonRpcException) + Json::Value eth_getTransactionByBlockNumberAndIndex(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); p.append(param2); - Json::Value result = this->CallMethod("eth_transactionByNumber",p); + Json::Value result = this->CallMethod("eth_getTransactionByBlockNumberAndIndex",p); if (result.isObject()) return result; else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_uncleByHash(const std::string& param1, int param2) throw (jsonrpc::JsonRpcException) + Json::Value eth_getUncleByBlockHashAndIndex(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); p.append(param2); - Json::Value result = this->CallMethod("eth_uncleByHash",p); + Json::Value result = this->CallMethod("eth_getUncleByBlockHashAndIndex",p); if (result.isObject()) return result; else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_uncleByNumber(int param1, int param2) throw (jsonrpc::JsonRpcException) + Json::Value eth_getUncleByBlockNumberAndIndex(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); p.append(param2); - Json::Value result = this->CallMethod("eth_uncleByNumber",p); + Json::Value result = this->CallMethod("eth_getUncleByBlockNumberAndIndex",p); if (result.isObject()) return result; else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_compilers() throw (jsonrpc::JsonRpcException) + Json::Value eth_getCompilers() throw (jsonrpc::JsonRpcException) { Json::Value p; p = Json::nullValue; - Json::Value result = this->CallMethod("eth_compilers",p); + Json::Value result = this->CallMethod("eth_getCompilers",p); if (result.isArray()) return result; else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - std::string eth_lll(const std::string& param1) throw (jsonrpc::JsonRpcException) + std::string eth_compileLLL(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_lll",p); + Json::Value result = this->CallMethod("eth_compileLLL",p); if (result.isString()) return result.asString(); else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - std::string eth_solidity(const std::string& param1) throw (jsonrpc::JsonRpcException) + std::string eth_compileSerpent(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_solidity",p); + Json::Value result = this->CallMethod("eth_compileSerpent",p); if (result.isString()) return result.asString(); else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - std::string eth_serpent(const std::string& param1) throw (jsonrpc::JsonRpcException) + std::string eth_compileSolidity(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_serpent",p); + Json::Value result = this->CallMethod("eth_compileSolidity",p); if (result.isString()) return result.asString(); else -- cgit v1.2.3 From 4aaa414a83dcf3345c42381d233f960598eba11e Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 5 Mar 2015 11:16:54 +0100 Subject: jsonrpc api changes in progress6, almost finished --- webthreestubclient.h | 77 ++++++++++++++++++---------------------------------- 1 file changed, 27 insertions(+), 50 deletions(-) diff --git a/webthreestubclient.h b/webthreestubclient.h index a13744bf..050207f2 100644 --- a/webthreestubclient.h +++ b/webthreestubclient.h @@ -332,27 +332,27 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - int eth_newFilter(const Json::Value& param1) throw (jsonrpc::JsonRpcException) + std::string eth_newFilter(const Json::Value& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); Json::Value result = this->CallMethod("eth_newFilter",p); - if (result.isInt()) - return result.asInt(); + if (result.isString()) + return result.asString(); else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - int eth_newFilterString(const std::string& param1) throw (jsonrpc::JsonRpcException) + std::string eth_newBlockFilter(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_newFilterString",p); - if (result.isInt()) - return result.asInt(); + Json::Value result = this->CallMethod("eth_newBlockFilter",p); + if (result.isString()) + return result.asString(); else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - bool eth_uninstallFilter(int param1) throw (jsonrpc::JsonRpcException) + bool eth_uninstallFilter(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -362,31 +362,31 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_changed(int param1) throw (jsonrpc::JsonRpcException) + Json::Value eth_getFilterChanges(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_changed",p); + Json::Value result = this->CallMethod("eth_getFilterChanges",p); if (result.isArray()) return result; else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_filterLogs(int param1) throw (jsonrpc::JsonRpcException) + Json::Value eth_getFilterLogs(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_filterLogs",p); + Json::Value result = this->CallMethod("eth_getFilterLogs",p); if (result.isArray()) return result; else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_logs(const Json::Value& param1) throw (jsonrpc::JsonRpcException) + Json::Value eth_getLogs(const Json::Value& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_logs",p); + Json::Value result = this->CallMethod("eth_getLogs",p); if (result.isArray()) return result; else @@ -412,17 +412,17 @@ 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) + std::string 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(); + if (result.isString()) + return result.asString(); else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - bool eth_unregister(int param1) throw (jsonrpc::JsonRpcException) + bool eth_unregister(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -432,7 +432,7 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_queuedTransactions(int param1) throw (jsonrpc::JsonRpcException) + Json::Value eth_queuedTransactions(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -465,29 +465,6 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - bool db_putString(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException) - { - Json::Value p; - p.append(param1); - p.append(param2); - p.append(param3); - Json::Value result = this->CallMethod("db_putString",p); - if (result.isBool()) - return result.asBool(); - else - throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); - } - std::string db_getString(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) - { - Json::Value p; - p.append(param1); - p.append(param2); - Json::Value result = this->CallMethod("db_getString",p); - if (result.isString()) - return result.asString(); - else - throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); - } bool shh_post(const Json::Value& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; @@ -508,11 +485,11 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - bool shh_haveIdentity(const std::string& param1) throw (jsonrpc::JsonRpcException) + bool shh_hasIdentity(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("shh_haveIdentity",p); + Json::Value result = this->CallMethod("shh_hasIdentity",p); if (result.isBool()) return result.asBool(); else @@ -540,17 +517,17 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - int shh_newFilter(const Json::Value& param1) throw (jsonrpc::JsonRpcException) + std::string shh_newFilter(const Json::Value& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); Json::Value result = this->CallMethod("shh_newFilter",p); - if (result.isInt()) - return result.asInt(); + if (result.isString()) + return result.asString(); else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - bool shh_uninstallFilter(int param1) throw (jsonrpc::JsonRpcException) + bool shh_uninstallFilter(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -560,7 +537,7 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value shh_changed(int param1) throw (jsonrpc::JsonRpcException) + Json::Value shh_changed(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); @@ -570,7 +547,7 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value shh_getMessages(int param1) throw (jsonrpc::JsonRpcException) + Json::Value shh_getMessages(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); -- cgit v1.2.3 From 4e115bc671df4e361507da288c7438ef25bb9265 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 5 Mar 2015 12:19:16 +0100 Subject: eth_getBlock returns also transactions --- webthreestubclient.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/webthreestubclient.h b/webthreestubclient.h index 050207f2..298f166a 100644 --- a/webthreestubclient.h +++ b/webthreestubclient.h @@ -218,20 +218,22 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_getBlockByHash(const std::string& param1) throw (jsonrpc::JsonRpcException) + Json::Value eth_getBlockByHash(const std::string& param1, bool param2) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); + p.append(param2); Json::Value result = this->CallMethod("eth_getBlockByHash",p); if (result.isObject()) return result; else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_getBlockByNumber(const std::string& param1) throw (jsonrpc::JsonRpcException) + Json::Value eth_getBlockByNumber(const std::string& param1, bool param2) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); + p.append(param2); Json::Value result = this->CallMethod("eth_getBlockByNumber",p); if (result.isObject()) return result; -- cgit v1.2.3 From dcbd78735bb14db5520cabb413fe802bf50d9ff7 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 5 Mar 2015 20:32:18 +0100 Subject: shh_changed -> shh_getFilterChanges --- webthreestubclient.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webthreestubclient.h b/webthreestubclient.h index 298f166a..8b1893a4 100644 --- a/webthreestubclient.h +++ b/webthreestubclient.h @@ -539,11 +539,11 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value shh_changed(const std::string& param1) throw (jsonrpc::JsonRpcException) + Json::Value shh_getFilterChanges(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("shh_changed",p); + Json::Value result = this->CallMethod("shh_getFilterChanges",p); if (result.isArray()) return result; else -- cgit v1.2.3 From 223a102aff41ad44bf82b348643fd100ba5fa6a8 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 10 Mar 2015 11:40:30 +0100 Subject: eth_call on block with number --- webthreestubclient.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webthreestubclient.h b/webthreestubclient.h index 454162e7..7f47fe78 100644 --- a/webthreestubclient.h +++ b/webthreestubclient.h @@ -198,10 +198,11 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - std::string eth_call(const Json::Value& param1) throw (jsonrpc::JsonRpcException) + std::string eth_call(const Json::Value& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); + p.append(param2); Json::Value result = this->CallMethod("eth_call",p); if (result.isString()) return result.asString(); -- cgit v1.2.3 From 792c3e7094a086ff679aedf22208be78d44896b0 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 10 Mar 2015 17:41:32 +0100 Subject: Squashed 'libjsqrc/ethereumjs/' changes from 7d6b35a..9926e27 9926e27 upgraded version to 0.1.0 7a44f76 add shh post formatting 27d5421 merged from ethereum again 3848d3a fixed logs 18e1367 gulp f831dde Merge branch 'apiOverhaul' of https://github.com/frozeman/ethereum.js into apiOverhaul 27fca17 common fixes 1c9f50f changed topic to topics 8d7d00d fixed input parser test 1269731 Merge branch 'apiOverhaul' of https://github.com/frozeman/ethereum.js into apiOverhaul 2c740b0 add filter value conversion 38f6567 fixed examples fa5d4b5 Merge branch 'apiOverhaul' of https://github.com/frozeman/ethereum.js into apiOverhaul 8a2444b add default paramter for getBlock 2850bee fixed eth_getFilterChanges b454587 Merge branch 'develop' of https://github.com/ethereum/ethereum.js into apiOverhaul ede88f8 Merge pull request #105 from jorisbontje/balance-example 51a075c add in-output until eth_getBlockByHash 9c0d3e3 fixed to/fromWei a0b5353 changed outputs up to storageAt c2ed233 update balance example for new api 1f6c195 fixed toBigNumber e5cc501 updated readme 4eb857e increased meteor package version c7f8373 separated formatters files 068bdd7 changed project structure ddb90c2 refactoring formatters a6110a5 common changes d3569e4 more coverage tests e2352b4 utils.js docs 344428b tests... 9fe105e fixed from decimal; 50fc611 test for utils.toBigNumber 60ae274 code comments b8505d1 common changes ccb3775 new api method names 2b17ad6 refactoring 0a995e1 common changes in utils, fixing code complexity 3f63109 fix all failing karma tests 1fd1a31 Merge branch 'develop' into apiOverhaul 0b9d450 fixed karma test 75e92c8 Merge branch 'master' into develop a869780 Merge branch 'master' into apiOverhaul 2cdf08b Merge pull request #101 from chevdor/master 437e273 Helping travis a bit... old boy! d88effa Add node 0.12 + virtual screen for browsers/karma. 743eb30 Including Karma to Travis f0da6ef Merge remote-tracking branch 'upstream/master' cbb1efe test(eth): Disable few tests b819391 fixed tests c1136a0 Merge branch 'master' into develop 1b475aa downgrade to unreachable-branch-transform 0.1.0 636fb4b updated outdated deps cf3fa10 Merge branch 'ch' 96f3076 karma 9c72d43 Merge pull request #100 from chevdor/master 96fede8 Merge pull request #98 from kumavis/develop 833b810 doc(readme): Information about Karma in the readme e46f6f1 test(utils): Add test for the toEth() function 1e0d76e Remove phantomjs af5fef0 test(karma): Add Karma support 20c4e28 Move envify and unreachable-branch-transform to normal dependencies for external browserify support. 333c3ff merged develop b07ddb4 add defualt block 024433f Merge branch 'master' into develop 601c8ab ignore for maxcomplexity warning d9d190e Merge branch 'master' into develop a05742f Add internal defaultBlock 6cd96c9 add net object 48c107e update meteor package 9c4080b made filter polling async 869bb66 add optional callback 4096fb8 merged develop 5c4a36b working on adding callbacks 30111f7 Merge pull request #87 from kumavis/develop f2029b4 Merge pull request #85 from ethers/abiString ee686b0 Move browserify transforms to package.json 4b9bc17 constants should be before (dynamic) string contents 1c136e3 merged develop aef0171 add shh topic auto transformation for filter options 37e6d11 add shh output formatters and test c03a949 add package-init.js a69c04d add version file 487e0ac mdae it a meteor package 8cf8b9e gulp fd85749 Merge pull request #81 from ethers/arraySupport fcab219 vary the length of the arrays f8db634 need to save/concat per iteration ce664d6 fix test descriptions 66196ee constants should be before array contents, fixes #30 2cd4f02 add build files 47412c3 add more tests for blocks 545de25 add more tests 2e9a411 Merge pull request #71 from frozeman/apiOverhaul 30518ae fixed complexities 84900e6 merged with solved conflicts eaef1a2 merged develop 9981b97 fixed ) 8128342 fixed small change request 5ea5be2 add deprecated transact 181f109 changed getCode to getData 1fa7fa6 toFromWei fix ee65b2c add input formatter for transactions fec54d8 add depreaction warnring to contractFromAbi 684c495 changed contract API 36ca47f Changed watch to filter for eth and shh 7fde77d add formatter b41d7b3 Merge branch 'master' into develop 5424406 Merge pull request #69 from frozeman/apiOverhaul 1e3edbb Merge branch 'develop' of https://github.com/ethereum/ethereum.js into apiOverhaul 60cda4e fixed tests 91c015e Made to/fromWei return strings instead of numbers 85c843e Merge pull request #67 from frozeman/apiOverhaul ed7d473 Removed enumerable from methods, fixed number property ce141d8 Removed circular dependencies 188e9e5 Add toWei/fromWei and isAddress 5c994ff changed most of the function names REVERT: 7d6b35a Merge branch 'master' into cpp REVERT: ea250e6 Merge commit 'be3bfb76bef1d1f113033cd9093e03a00066d5d1' into ethereumjs_timeout REVERT: c08cea1 Improvement to AZ - confirmation disabler. Fix network crash. git-subtree-dir: libjsqrc/ethereumjs git-subtree-split: 9926e27a84fe21f3e7250e7e245977a7125ddf63 --- abi.inputParser.js | 18 +++++++++- abi.outputParser.js | 18 +++++++++- eth.contract.js | 48 ++++++++++++++----------- eth.methods.js | 61 ++++++++++++++++++++++---------- event.inputParser.js | 50 +++++++++++++------------- event.outputParser.js | 2 +- filter.methods.js | 13 +++---- formatters.inputPostFormatter.js | 28 +++++++++++++++ formatters.inputTransactionFormatter.js | 26 ++++++++++++++ formatters.outputBlockFormatter.js | 48 +++++++++++++++++++++++++ formatters.outputLogFormatter.js | 27 ++++++++++++++ formatters.outputPostFormatter.js | 26 ++++++++++++++ formatters.outputTransactionFormatter.js | 26 ++++++++++++++ jsonrpc.isValidResponse.js | 2 +- jsonrpc.toBatchPayload.js | 2 +- jsonrpc.toPayload.js | 2 +- net.methods.js | 10 ++++++ shh.methods.js | 3 +- utils.extractDisplayName.js | 2 +- utils.extractTypeName.js | 2 +- utils.filters.js | 2 +- utils.fromDecimal.js | 43 ++++++++++++++++++++++ utils.fromWei.js | 22 ++++++++++++ utils.isAddress.js | 23 ++++++++++++ utils.isBigNumber.js | 26 ++++++++++++++ utils.isFunction.js | 21 +++++++++++ utils.isString.js | 22 ++++++++++++ utils.toBigNumber.js | 45 +++++++++++++++++++++++ utils.toDecimal.js | 14 ++++++++ utils.toHex.js | 42 ++++++++++++++++++++++ utils.toWei.js | 25 +++++++++++++ web3.methods.js | 5 ++- 32 files changed, 620 insertions(+), 84 deletions(-) create mode 100644 formatters.inputPostFormatter.js create mode 100644 formatters.inputTransactionFormatter.js create mode 100644 formatters.outputBlockFormatter.js create mode 100644 formatters.outputLogFormatter.js create mode 100644 formatters.outputPostFormatter.js create mode 100644 formatters.outputTransactionFormatter.js create mode 100644 net.methods.js create mode 100644 utils.fromDecimal.js create mode 100644 utils.fromWei.js create mode 100644 utils.isAddress.js create mode 100644 utils.isBigNumber.js create mode 100644 utils.isFunction.js create mode 100644 utils.isString.js create mode 100644 utils.toBigNumber.js create mode 100644 utils.toDecimal.js create mode 100644 utils.toHex.js create mode 100644 utils.toWei.js diff --git a/abi.inputParser.js b/abi.inputParser.js index edfc2b58..2ee87761 100644 --- a/abi.inputParser.js +++ b/abi.inputParser.js @@ -1,6 +1,6 @@ var assert = require('assert'); var BigNumber = require('bignumber.js'); -var abi = require('../lib/abi.js'); +var abi = require('../lib/solidity/abi.js'); var clone = function (object) { return JSON.parse(JSON.stringify(object)); }; var description = [{ @@ -544,5 +544,21 @@ describe('abi', function() { }); + it('should throw an incorrect type error', function () { + + // given + var d = clone(description); + d[0].inputs = [ + { type: 'uin' } + ] + + // when + var parser = abi.inputParser(d); + + // then + assert.throws(function () {parser.test('0x')}, Error); + + }); + }); }); diff --git a/abi.outputParser.js b/abi.outputParser.js index 723c408f..1ddd9d4f 100644 --- a/abi.outputParser.js +++ b/abi.outputParser.js @@ -1,6 +1,6 @@ var assert = require('assert'); var BigNumber = require('bignumber.js'); -var abi = require('../lib/abi.js'); +var abi = require('../lib/solidity/abi.js'); var clone = function (object) { return JSON.parse(JSON.stringify(object)); }; var description = [{ @@ -456,6 +456,22 @@ describe('abi', function() { }); + it('should throw an incorrect type error', function () { + + // given + var d = clone(description); + d[0].outputs = [ + { type: 'uin' } + ] + + // when + var parser = abi.outputParser(d); + + // then + assert.throws(function () {parser.test('0x')}, Error); + + }); + }); }); diff --git a/eth.contract.js b/eth.contract.js index 1a92ec88..59ad51b2 100644 --- a/eth.contract.js +++ b/eth.contract.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var contract = require('../lib/contract.js'); +var contract = require('../lib/web3/contract.js'); describe('contract', function() { it('should create simple contract with one method from abi with explicit type name', function () { @@ -22,11 +22,12 @@ describe('contract', function() { }]; // when - var con = contract(null, description); + var Con = contract(description); + var myCon = new Con(null); // then - assert.equal('function', typeof con.test); - assert.equal('function', typeof con.test['uint256']); + assert.equal('function', typeof myCon.test); + assert.equal('function', typeof myCon.test['uint256']); }); it('should create simple contract with one method from abi with implicit type name', function () { @@ -49,11 +50,12 @@ describe('contract', function() { }]; // when - var con = contract(null, description); + var Con = contract(description); + var myCon = new Con(null); // then - assert.equal('function', typeof con.test); - assert.equal('function', typeof con.test['uint256']); + assert.equal('function', typeof myCon.test); + assert.equal('function', typeof myCon.test['uint256']); }); it('should create contract with multiple methods', function () { @@ -90,13 +92,14 @@ describe('contract', function() { }]; // when - var con = contract(null, description); + var Con = contract(description); + var myCon = new Con(null); // then - assert.equal('function', typeof con.test); - assert.equal('function', typeof con.test['uint256']); - assert.equal('function', typeof con.test2); - assert.equal('function', typeof con.test2['uint256']); + assert.equal('function', typeof myCon.test); + assert.equal('function', typeof myCon.test['uint256']); + assert.equal('function', typeof myCon.test2); + assert.equal('function', typeof myCon.test2['uint256']); }); it('should create contract with overloaded methods', function () { @@ -133,12 +136,13 @@ describe('contract', function() { }]; // when - var con = contract(null, description); + var Con = contract(description); + var myCon = new Con(null); // then - assert.equal('function', typeof con.test); - assert.equal('function', typeof con.test['uint256']); - assert.equal('function', typeof con.test['string']); + assert.equal('function', typeof myCon.test); + assert.equal('function', typeof myCon.test['uint256']); + assert.equal('function', typeof myCon.test['string']); }); it('should create contract with no methods', function () { @@ -161,10 +165,11 @@ describe('contract', function() { // when - var con = contract(null, description); + var Con = contract(description); + var myCon = new Con(null); // then - assert.equal('undefined', typeof con.test); + assert.equal('undefined', typeof myCon.test); }); @@ -189,11 +194,12 @@ describe('contract', function() { // when - var con = contract(null, description); + var Con = contract(description); + var myCon = new Con(null); // then - assert.equal('function', typeof con.test); - assert.equal('function', typeof con.test['uint256']); + assert.equal('function', typeof myCon.test); + assert.equal('function', typeof myCon.test['uint256']); }); diff --git a/eth.methods.js b/eth.methods.js index 9ea0ad59..e1eea1ec 100644 --- a/eth.methods.js +++ b/eth.methods.js @@ -4,33 +4,56 @@ var u = require('./test.utils.js'); describe('web3', function() { describe('eth', function() { - u.methodExists(web3.eth, 'balanceAt'); - u.methodExists(web3.eth, 'stateAt'); - u.methodExists(web3.eth, 'storageAt'); - u.methodExists(web3.eth, 'countAt'); - u.methodExists(web3.eth, 'codeAt'); - u.methodExists(web3.eth, 'transact'); + u.methodExists(web3.eth, 'getBalance'); + u.methodExists(web3.eth, 'getStorageAt'); + u.methodExists(web3.eth, 'getStorage'); + u.methodExists(web3.eth, 'getTransactionCount'); + u.methodExists(web3.eth, 'getData'); + u.methodExists(web3.eth, 'sendTransaction'); u.methodExists(web3.eth, 'call'); - u.methodExists(web3.eth, 'block'); - u.methodExists(web3.eth, 'transaction'); - u.methodExists(web3.eth, 'uncle'); - u.methodExists(web3.eth, 'compilers'); - u.methodExists(web3.eth, 'lll'); - u.methodExists(web3.eth, 'solidity'); - u.methodExists(web3.eth, 'serpent'); - u.methodExists(web3.eth, 'logs'); - u.methodExists(web3.eth, 'transactionCount'); - u.methodExists(web3.eth, 'uncleCount'); + u.methodExists(web3.eth, 'getBlock'); + u.methodExists(web3.eth, 'getTransaction'); + u.methodExists(web3.eth, 'getUncle'); + u.methodExists(web3.eth, 'getCompilers'); + u.methodExists(web3.eth.compile, 'lll'); + u.methodExists(web3.eth.compile, 'solidity'); + u.methodExists(web3.eth.compile, 'serpent'); + u.methodExists(web3.eth, 'getBlockTransactionCount'); + u.methodExists(web3.eth, 'getBlockUncleCount'); + u.methodExists(web3.eth, 'filter'); + u.methodExists(web3.eth, 'contract'); u.propertyExists(web3.eth, 'coinbase'); - u.propertyExists(web3.eth, 'listening'); u.propertyExists(web3.eth, 'mining'); u.propertyExists(web3.eth, 'gasPrice'); u.propertyExists(web3.eth, 'accounts'); - u.propertyExists(web3.eth, 'peerCount'); u.propertyExists(web3.eth, 'defaultBlock'); - u.propertyExists(web3.eth, 'number'); + u.propertyExists(web3.eth, 'blockNumber'); }); + + // Fail at the moment + // describe('eth', function(){ + // it('should be a positive balance', function() { + // // when + // var testAddress = '0x50f4ed0e83f9da907017bcfb444e3e25407f59bb'; + // var balance = web3.eth.balanceAt(testAddress); + // // then + // assert(balance > 0, 'Balance is ' + balance); + // }); + + // it('should return a block', function() { + // // when + // var block = web3.eth.block(0); + + // // then + // assert.notEqual(block, null); + // assert.equal(block.number, 0); + // assert(web3.toDecimal(block.difficulty) > 0); + // }); + // }); }); + + + diff --git a/event.inputParser.js b/event.inputParser.js index 8f9790a2..a2ce2711 100644 --- a/event.inputParser.js +++ b/event.inputParser.js @@ -1,6 +1,6 @@ var assert = require('assert'); -var event = require('../lib/event.js'); -var f = require('../lib/formatters.js'); +var event = require('../lib/web3/event.js'); +var f = require('../lib/solidity/formatters.js'); describe('event', function () { describe('inputParser', function () { @@ -20,8 +20,8 @@ describe('event', function () { // then assert.equal(result.address, address); - assert.equal(result.topic.length, 1); - assert.equal(result.topic[0], signature); + assert.equal(result.topics.length, 1); + assert.equal(result.topics[0], signature); }); @@ -31,10 +31,10 @@ describe('event', function () { var address = '0x012345'; var signature = '0x987654'; var options = { - earliest: 1, - latest: 2, + fromBlock: 1, + toBlock: 2, offset: 3, - max: 4 + limit: 4 }; var e = { name: 'Event', @@ -47,12 +47,12 @@ describe('event', function () { // then assert.equal(result.address, address); - assert.equal(result.topic.length, 1); - assert.equal(result.topic[0], signature); - assert.equal(result.earliest, options.earliest); - assert.equal(result.latest, options.latest); + assert.equal(result.topics.length, 1); + assert.equal(result.topics[0], signature); + assert.equal(result.fromBlock, options.fromBlock); + assert.equal(result.toBlock, options.toBlock); assert.equal(result.offset, options.offset); - assert.equal(result.max, options.max); + assert.equal(result.limit, options.limit); }); @@ -62,10 +62,10 @@ describe('event', function () { var address = '0x012345'; var signature = '0x987654'; var options = { - earliest: 1, - latest: 2, + fromBlock: 1, + toBlock: 2, offset: 3, - max: 4 + limit: 4 }; var e = { name: 'Event', @@ -78,13 +78,13 @@ describe('event', function () { // then assert.equal(result.address, address); - assert.equal(result.topic.length, 2); - assert.equal(result.topic[0], signature); - assert.equal(result.topic[1], f.formatInputInt(4)); - assert.equal(result.earliest, options.earliest); - assert.equal(result.latest, options.latest); + assert.equal(result.topics.length, 2); + assert.equal(result.topics[0], signature); + assert.equal(result.topics[1], f.formatInputInt(4)); + assert.equal(result.fromBlock, options.fromBlock); + assert.equal(result.toBlock, options.toBlock); assert.equal(result.offset, options.offset); - assert.equal(result.max, options.max); + assert.equal(result.limit, options.limit); }); @@ -110,10 +110,10 @@ describe('event', function () { // then assert.equal(result.address, address); - assert.equal(result.topic.length, 2); - assert.equal(result.topic[0], signature); - assert.equal(result.topic[1][0], f.formatInputInt(4)); - assert.equal(result.topic[1][1], f.formatInputInt(69)); + assert.equal(result.topics.length, 2); + assert.equal(result.topics[0], signature); + assert.equal(result.topics[1][0], f.formatInputInt(4)); + assert.equal(result.topics[1][1], f.formatInputInt(69)); assert.equal(result.earliest, options.earliest); assert.equal(result.latest, options.latest); assert.equal(result.offset, options.offset); diff --git a/event.outputParser.js b/event.outputParser.js index 22f4ed39..93b50ff2 100644 --- a/event.outputParser.js +++ b/event.outputParser.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var event = require('../lib/event.js'); +var event = require('../lib/web3/event.js'); describe('event', function () { describe('outputParser', function () { diff --git a/filter.methods.js b/filter.methods.js index 9f81ec38..d039ec9b 100644 --- a/filter.methods.js +++ b/filter.methods.js @@ -1,11 +1,11 @@ var assert = require('assert'); -var filter = require('../lib/filter'); +var filter = require('../lib/web3/filter'); var u = require('./test.utils.js'); var empty = function () {}; var implementation = { newFilter: empty, - getMessages: empty, + getLogs: empty, uninstallFilter: empty, startPolling: empty, stopPolling: empty, @@ -16,12 +16,9 @@ describe('web3', function () { describe('filter', function () { var f = filter({}, implementation); - u.methodExists(f, 'arrived'); - u.methodExists(f, 'happened'); - u.methodExists(f, 'changed'); - u.methodExists(f, 'messages'); - u.methodExists(f, 'logs'); - u.methodExists(f, 'uninstall'); + u.methodExists(f, 'watch'); + u.methodExists(f, 'stopWatching'); + u.methodExists(f, 'get'); }); }); }); diff --git a/formatters.inputPostFormatter.js b/formatters.inputPostFormatter.js new file mode 100644 index 00000000..0995d6d7 --- /dev/null +++ b/formatters.inputPostFormatter.js @@ -0,0 +1,28 @@ +var chai = require('chai'); +var formatters = require('../lib/web3/formatters.js'); +var assert = chai.assert; + +describe('formatters', function () { + describe('inputPostFormatter', function () { + it('should return the correct value', function () { + + // input as strings and numbers + assert.deepEqual(formatters.inputPostFormatter({ + from: '0x00000', + to: '0x00000', + payload: {test: 'test'}, + ttl: 200, + priority: 1000, + topics: ['hello','mytopics'] + }), { + from: '0x00000', + to: '0x00000', + payload: '0x7b2274657374223a2274657374227d', + ttl: '0xc8', + priority: '0x3e8', + topics: ['0x68656c6c6f','0x6d79746f70696373'] + }); + + }); + }); +}); diff --git a/formatters.inputTransactionFormatter.js b/formatters.inputTransactionFormatter.js new file mode 100644 index 00000000..5ff0526e --- /dev/null +++ b/formatters.inputTransactionFormatter.js @@ -0,0 +1,26 @@ +var assert = require('assert'); +var formatters = require('../lib/web3/formatters.js'); +var BigNumber = require('bignumber.js'); + +describe('formatters', function () { + describe('inputTransactionFormatter', function () { + it('should return the correct value', function () { + + assert.deepEqual(formatters.inputTransactionFormatter({ + data: '0x34234kjh23kj4234', + value: new BigNumber(100), + from: '0x00000', + to: '0x00000', + gas: 1000, + gasPrice: new BigNumber(1000), + }), { + data: '0x34234kjh23kj4234', + value: '0x64', + from: '0x00000', + to: '0x00000', + gas: '0x3e8', + gasPrice: '0x3e8', + }); + }); + }); +}); diff --git a/formatters.outputBlockFormatter.js b/formatters.outputBlockFormatter.js new file mode 100644 index 00000000..f31cced9 --- /dev/null +++ b/formatters.outputBlockFormatter.js @@ -0,0 +1,48 @@ +var assert = require('assert'); +var formatters = require('../lib/web3/formatters.js'); +var BigNumber = require('bignumber.js'); + +describe('formatters', function () { + describe('outputBlockFormatter', function () { + it('should return the correct value', function () { + + assert.deepEqual(formatters.outputBlockFormatter({ + hash: '0x34234kjh23kj4234', + parentHash: '0x34234kjh23kj4234', + miner: '0x34234kjh23kj4234', + stateRoot: '0x34234kjh23kj4234', + sha3Uncles: '0x34234kjh23kj4234', + bloom: '0x34234kjh23kj4234', + difficulty: '0x3e8', + totalDifficulty: '0x3e8', + number: '0x3e8', + minGasPrice: '0x3e8', + gasLimit: '0x3e8', + gasUsed: '0x3e8', + timestamp: '0x3e8', + extraData: '0x34234kjh23kj4234', + nonce: '0x34234kjh23kj4234', + children: ['0x34234kjh23kj4234'], + size: '0x3e8' + }), { + hash: '0x34234kjh23kj4234', + parentHash: '0x34234kjh23kj4234', + miner: '0x34234kjh23kj4234', + stateRoot: '0x34234kjh23kj4234', + sha3Uncles: '0x34234kjh23kj4234', + bloom: '0x34234kjh23kj4234', + difficulty: new BigNumber(1000), + totalDifficulty: new BigNumber(1000), + number: 1000, + minGasPrice: new BigNumber(1000), + gasLimit: 1000, + gasUsed: 1000, + timestamp: 1000, + extraData: '0x34234kjh23kj4234', + nonce: '0x34234kjh23kj4234', + children: ['0x34234kjh23kj4234'], + size: 1000 + }); + }); + }); +}); diff --git a/formatters.outputLogFormatter.js b/formatters.outputLogFormatter.js new file mode 100644 index 00000000..495a6462 --- /dev/null +++ b/formatters.outputLogFormatter.js @@ -0,0 +1,27 @@ +var assert = require('assert'); +var formatters = require('../lib/web3/formatters.js'); + +describe('formatters', function () { + describe('outputLogFormatter', function () { + it('should return the correct value', function () { + + assert.deepEqual(formatters.outputLogFormatter({ + transactionIndex: '0x3e8', + logIndex: '0x3e8', + blockNumber: '0x3e8', + transactionHash: '0x7b2274657374223a2274657374227d', + blockHash: '0x7b2274657374223a2274657374227d', + data: '0x7b2274657374223a2274657374227d', + topics: ['0x68656c6c6f','0x6d79746f70696373'] + }), { + transactionIndex: 1000, + logIndex: 1000, + blockNumber: 1000, + transactionHash: '0x7b2274657374223a2274657374227d', + blockHash: '0x7b2274657374223a2274657374227d', + data: '0x7b2274657374223a2274657374227d', + topics: ['0x68656c6c6f','0x6d79746f70696373'] + }); + }); + }); +}); diff --git a/formatters.outputPostFormatter.js b/formatters.outputPostFormatter.js new file mode 100644 index 00000000..850d3d80 --- /dev/null +++ b/formatters.outputPostFormatter.js @@ -0,0 +1,26 @@ +var assert = require('assert'); +var formatters = require('../lib/web3/formatters.js'); + +describe('formatters', function () { + describe('outputPostFormatter', function () { + it('should return the correct value', function () { + + assert.deepEqual(formatters.outputPostFormatter({ + expiry: '0x3e8', + sent: '0x3e8', + ttl: '0x3e8', + workProved: '0x3e8', + payload: '0x7b2274657374223a2274657374227d', + topics: ['0x68656c6c6f','0x6d79746f70696373'] + }), { + expiry: 1000, + sent: 1000, + ttl: 1000, + workProved: 1000, + payload: {test: 'test'}, + payloadRaw: '0x7b2274657374223a2274657374227d', + topics: ['hello','mytopics'] + }); + }); + }); +}); diff --git a/formatters.outputTransactionFormatter.js b/formatters.outputTransactionFormatter.js new file mode 100644 index 00000000..f42ed849 --- /dev/null +++ b/formatters.outputTransactionFormatter.js @@ -0,0 +1,26 @@ +var assert = require('assert'); +var formatters = require('../lib/web3/formatters.js'); +var BigNumber = require('bignumber.js'); + +describe('formatters', function () { + describe('outputTransactionFormatter', function () { + it('should return the correct value', function () { + + assert.deepEqual(formatters.outputTransactionFormatter({ + input: '0x34234kjh23kj4234', + from: '0x00000', + to: '0x00000', + value: '0x3e8', + gas: '0x3e8', + gasPrice: '0x3e8' + }), { + input: '0x34234kjh23kj4234', + from: '0x00000', + to: '0x00000', + value: new BigNumber(1000), + gas: 1000, + gasPrice: new BigNumber(1000), + }); + }); + }); +}); diff --git a/jsonrpc.isValidResponse.js b/jsonrpc.isValidResponse.js index 920b5f3a..78388a44 100644 --- a/jsonrpc.isValidResponse.js +++ b/jsonrpc.isValidResponse.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var jsonrpc = require('../lib/jsonrpc'); +var jsonrpc = require('../lib/web3/jsonrpc'); describe('jsonrpc', function () { describe('isValidResponse', function () { diff --git a/jsonrpc.toBatchPayload.js b/jsonrpc.toBatchPayload.js index 1c1aafeb..c9a1e51e 100644 --- a/jsonrpc.toBatchPayload.js +++ b/jsonrpc.toBatchPayload.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var jsonrpc = require('../lib/jsonrpc'); +var jsonrpc = require('../lib/web3/jsonrpc'); describe('jsonrpc', function () { describe('toBatchPayload', function () { diff --git a/jsonrpc.toPayload.js b/jsonrpc.toPayload.js index 6d6f003b..a79501d7 100644 --- a/jsonrpc.toPayload.js +++ b/jsonrpc.toPayload.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var jsonrpc = require('../lib/jsonrpc'); +var jsonrpc = require('../lib/web3/jsonrpc'); describe('jsonrpc', function () { describe('toPayload', function () { diff --git a/net.methods.js b/net.methods.js new file mode 100644 index 00000000..26d9c224 --- /dev/null +++ b/net.methods.js @@ -0,0 +1,10 @@ +var assert = require('assert'); +var web3 = require('../index.js'); +var u = require('./test.utils.js'); + +describe('web3', function() { + describe('net', function() { + u.propertyExists(web3.net, 'listening'); + u.propertyExists(web3.net, 'peerCount'); + }); +}); \ No newline at end of file diff --git a/shh.methods.js b/shh.methods.js index 91ca3cab..f8501d52 100644 --- a/shh.methods.js +++ b/shh.methods.js @@ -6,9 +6,10 @@ describe('web3', function() { describe('shh', function() { u.methodExists(web3.shh, 'post'); u.methodExists(web3.shh, 'newIdentity'); - u.methodExists(web3.shh, 'haveIdentity'); + u.methodExists(web3.shh, 'hasIdentity'); u.methodExists(web3.shh, 'newGroup'); u.methodExists(web3.shh, 'addToGroup'); + u.methodExists(web3.shh, 'filter'); }); }); diff --git a/utils.extractDisplayName.js b/utils.extractDisplayName.js index 148653ab..c401b7e6 100644 --- a/utils.extractDisplayName.js +++ b/utils.extractDisplayName.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var utils = require('../lib/utils.js'); +var utils = require('../lib/utils/utils.js'); describe('utils', function () { describe('extractDisplayName', function () { diff --git a/utils.extractTypeName.js b/utils.extractTypeName.js index 2b4bbe76..7211ff61 100644 --- a/utils.extractTypeName.js +++ b/utils.extractTypeName.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var utils = require('../lib/utils.js'); +var utils = require('../lib/utils/utils.js'); describe('utils', function () { describe('extractTypeName', function () { diff --git a/utils.filters.js b/utils.filters.js index f2d2788b..4629e4fe 100644 --- a/utils.filters.js +++ b/utils.filters.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var utils = require('../lib/utils.js'); +var utils = require('../lib/utils/utils.js'); describe('utils', function() { it('should filter functions and events from input array properly', function () { diff --git a/utils.fromDecimal.js b/utils.fromDecimal.js new file mode 100644 index 00000000..4dc774c7 --- /dev/null +++ b/utils.fromDecimal.js @@ -0,0 +1,43 @@ +var chai = require('chai'); +var utils = require('../lib/utils/utils.js'); +var assert = chai.assert; + +var tests = [ + { value: 1, expected: '0x1' }, + { value: '1', expected: '0x1' }, + { value: '0x1', expected: '0x1'}, + { value: '0x01', expected: '0x1'}, + { value: 15, expected: '0xf'}, + { value: '15', expected: '0xf'}, + { value: '0xf', expected: '0xf'}, + { value: '0x0f', expected: '0xf'}, + { value: -1, expected: '-0x1'}, + { value: '-1', expected: '-0x1'}, + { value: '-0x1', expected: '-0x1'}, + { value: '-0x01', expected: '-0x1'}, + { value: -15, expected: '-0xf'}, + { value: '-15', expected: '-0xf'}, + { value: '-0xf', expected: '-0xf'}, + { value: '-0x0f', expected: '-0xf'}, + { value: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}, + { value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'}, + { value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}, + { value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'}, + { value: 0, expected: '0x0'}, + { value: '0', expected: '0x0'}, + { value: '0x0', expected: '0x0'}, + { value: -0, expected: '0x0'}, + { value: '-0', expected: '0x0'}, + { value: '-0x0', expected: '0x0'} +]; + +describe('utils', function () { + describe('fromDecimal', function () { + tests.forEach(function (test) { + it('should turn ' + test.value + ' to ' + test.expected, function () { + assert.equal(utils.fromDecimal(test.value), test.expected); + }); + }); + }); +}); + diff --git a/utils.fromWei.js b/utils.fromWei.js new file mode 100644 index 00000000..735575c6 --- /dev/null +++ b/utils.fromWei.js @@ -0,0 +1,22 @@ +var assert = require('assert'); +var utils = require('../lib/utils/utils.js'); + +describe('utils', function () { + describe('fromWei', function () { + it('should return the correct value', function () { + + assert.equal(utils.fromWei(1000000000000000000, 'wei'), '1000000000000000000'); + assert.equal(utils.fromWei(1000000000000000000, 'kwei'), '1000000000000000'); + assert.equal(utils.fromWei(1000000000000000000, 'mwei'), '1000000000000'); + assert.equal(utils.fromWei(1000000000000000000, 'gwei'), '1000000000'); + assert.equal(utils.fromWei(1000000000000000000, 'szabo'), '1000000'); + assert.equal(utils.fromWei(1000000000000000000, 'finney'), '1000'); + assert.equal(utils.fromWei(1000000000000000000, 'ether'), '1'); + assert.equal(utils.fromWei(1000000000000000000, 'kether'), '0.001'); + assert.equal(utils.fromWei(1000000000000000000, 'grand'), '0.001'); + assert.equal(utils.fromWei(1000000000000000000, 'mether'), '0.000001'); + assert.equal(utils.fromWei(1000000000000000000, 'gether'), '0.000000001'); + assert.equal(utils.fromWei(1000000000000000000, 'tether'), '0.000000000001'); + }); + }); +}); diff --git a/utils.isAddress.js b/utils.isAddress.js new file mode 100644 index 00000000..d2d087ff --- /dev/null +++ b/utils.isAddress.js @@ -0,0 +1,23 @@ +var chai = require('chai'); +var utils = require('../lib/utils/utils.js'); +var assert = chai.assert; + +var tests = [ + { value: function () {}, is: false}, + { value: new Function(), is: false}, + { value: 'function', is: false}, + { value: {}, is: false}, + { value: '0xc6d9d2cd449a754c494264e1809c50e34d64562b', is: true }, + { value: 'c6d9d2cd449a754c494264e1809c50e34d64562b', is: true } +]; + +describe('utils', function () { + describe('isAddress', function () { + tests.forEach(function (test) { + it('shoud test if value ' + test.value + ' is address: ' + test.is, function () { + assert.equal(utils.isAddress(test.value), test.is); + }); + }); + }); +}); + diff --git a/utils.isBigNumber.js b/utils.isBigNumber.js new file mode 100644 index 00000000..a3de3691 --- /dev/null +++ b/utils.isBigNumber.js @@ -0,0 +1,26 @@ +var chai = require('chai'); +var utils = require('../lib/utils/utils.js'); +var BigNumber = require('bignumber.js'); +var assert = chai.assert; + +var tests = [ + { value: function () {}, is: false}, + { value: new Function(), is: false}, + { value: 'function', is: false}, + { value: {}, is: false}, + { value: new String('hello'), is: false}, + { value: new BigNumber(0), is: true}, + { value: 132, is: false}, + { value: '0x12', is: false}, + +]; + +describe('utils', function () { + describe('isBigNumber', function () { + tests.forEach(function (test) { + it('shoud test if value ' + test.func + ' is BigNumber: ' + test.is, function () { + assert.equal(utils.isBigNumber(test.value), test.is); + }); + }); + }); +}); diff --git a/utils.isFunction.js b/utils.isFunction.js new file mode 100644 index 00000000..c113bc33 --- /dev/null +++ b/utils.isFunction.js @@ -0,0 +1,21 @@ +var chai = require('chai'); +var utils = require('../lib/utils/utils.js'); +var assert = chai.assert; + +var tests = [ + { func: function () {}, is: true}, + { func: new Function(), is: true}, + { func: 'function', is: false}, + { func: {}, is: false} +]; + +describe('utils', function () { + describe('isFunction', function () { + tests.forEach(function (test) { + it('shoud test if value ' + test.func + ' is function: ' + test.is, function () { + assert.equal(utils.isFunction(test.func), test.is); + }); + }); + }); +}); + diff --git a/utils.isString.js b/utils.isString.js new file mode 100644 index 00000000..bb36ccd6 --- /dev/null +++ b/utils.isString.js @@ -0,0 +1,22 @@ +var chai = require('chai'); +var utils = require('../lib/utils/utils.js'); +var assert = chai.assert; + +var tests = [ + { value: function () {}, is: false}, + { value: new Function(), is: false}, + { value: 'function', is: true}, + { value: {}, is: false}, + { value: new String('hello'), is: true} +]; + +describe('utils', function () { + describe('isString', function () { + tests.forEach(function (test) { + it('shoud test if value ' + test.func + ' is string: ' + test.is, function () { + assert.equal(utils.isString(test.value), test.is); + }); + }); + }); +}); + diff --git a/utils.toBigNumber.js b/utils.toBigNumber.js new file mode 100644 index 00000000..2d293c12 --- /dev/null +++ b/utils.toBigNumber.js @@ -0,0 +1,45 @@ +var chai = require('chai'); +var utils = require('../lib/utils/utils.js'); +var BigNumber = require('bignumber.js'); +var assert = chai.assert; + +var tests = [ + { value: 1, expected: '1' }, + { value: '1', expected: '1' }, + { value: '0x1', expected: '1'}, + { value: '0x01', expected: '1'}, + { value: 15, expected: '15'}, + { value: '15', expected: '15'}, + { value: '0xf', expected: '15'}, + { value: '0x0f', expected: '15'}, + { value: new BigNumber('f', 16), expected: '15'}, + { value: -1, expected: '-1'}, + { value: '-1', expected: '-1'}, + { value: '-0x1', expected: '-1'}, + { value: '-0x01', expected: '-1'}, + { value: -15, expected: '-15'}, + { value: '-15', expected: '-15'}, + { value: '-0xf', expected: '-15'}, + { value: '-0x0f', expected: '-15'}, + { value: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '115792089237316195423570985008687907853269984665640564039457584007913129639935'}, + { value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '115792089237316195423570985008687907853269984665640564039457584007913129639933'}, + { value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-115792089237316195423570985008687907853269984665640564039457584007913129639935'}, + { value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-115792089237316195423570985008687907853269984665640564039457584007913129639933'}, + { value: 0, expected: '0'}, + { value: '0', expected: '0'}, + { value: '0x0', expected: '0'}, + { value: -0, expected: '0'}, + { value: '-0', expected: '0'}, + { value: '-0x0', expected: '0'}, + { value: new BigNumber(0), expected: '0'} +]; + +describe('utils', function () { + describe('toBigNumber', function () { + tests.forEach(function (test) { + it('should turn ' + test.value + ' to ' + test.expected, function () { + assert.equal(utils.toBigNumber(test.value).toString(10), test.expected); + }); + }); + }); +}); diff --git a/utils.toDecimal.js b/utils.toDecimal.js new file mode 100644 index 00000000..d785b044 --- /dev/null +++ b/utils.toDecimal.js @@ -0,0 +1,14 @@ +var assert = require('assert'); +var utils = require('../lib/utils/utils.js'); + +describe('utils', function () { + describe('toDecimal', function () { + it('should return the correct value', function () { + + assert.equal(utils.toDecimal("0x3e8"), '1000'); + // allow compatiblity + assert.equal(utils.toDecimal(100000), '100000'); + assert.equal(utils.toDecimal('100000'), '100000'); + }); + }); +}); diff --git a/utils.toHex.js b/utils.toHex.js new file mode 100644 index 00000000..2e9c59cb --- /dev/null +++ b/utils.toHex.js @@ -0,0 +1,42 @@ +var chai = require('chai'); +var utils = require('../lib/utils/utils'); +var BigNumber = require('bignumber.js'); +var assert = chai.assert; + +var tests = [ + { value: 1, expected: '0x1' }, + { value: '1', expected: '0x1' }, + { value: '0x1', expected: '0x1'}, + { value: '15', expected: '0xf'}, + { value: '0xf', expected: '0xf'}, + { value: -1, expected: '-0x1'}, + { value: '-1', expected: '-0x1'}, + { value: '-0x1', expected: '-0x1'}, + { value: '-15', expected: '-0xf'}, + { value: '-0xf', expected: '-0xf'}, + { value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'}, + { value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}, + { value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'}, + { value: 0, expected: '0x0'}, + { value: '0', expected: '0x0'}, + { value: '0x0', expected: '0x0'}, + { value: -0, expected: '0x0'}, + { value: '-0', expected: '0x0'}, + { value: '-0x0', expected: '0x0'}, + { value: [1,2,3,{test: 'data'}], expected: '0x5b312c322c332c7b2274657374223a2264617461227d5d'}, + { value: {test: 'test'}, expected: '0x7b2274657374223a2274657374227d'}, + { value: '{"test": "test"}', expected: '0x7b2274657374223a202274657374227d'}, + { value: 'myString', expected: '0x6d79537472696e67'}, + { value: new BigNumber(15), expected: '0xf'} +]; + +describe('utils', function () { + describe('toHex', function () { + tests.forEach(function (test) { + it('should turn ' + test.value + ' to ' + test.expected, function () { + assert.equal(utils.toHex(test.value), test.expected); + }); + }); + }); +}); + diff --git a/utils.toWei.js b/utils.toWei.js new file mode 100644 index 00000000..33e03ffc --- /dev/null +++ b/utils.toWei.js @@ -0,0 +1,25 @@ +var chai = require('chai'); +var utils = require('../lib/utils/utils'); +var assert = chai.assert; + +describe('utils', function () { + describe('toWei', function () { + it('should return the correct value', function () { + + assert.equal(utils.toWei(1, 'wei'), '1'); + assert.equal(utils.toWei(1, 'kwei'), '1000'); + assert.equal(utils.toWei(1, 'mwei'), '1000000'); + assert.equal(utils.toWei(1, 'gwei'), '1000000000'); + assert.equal(utils.toWei(1, 'szabo'), '1000000000000'); + assert.equal(utils.toWei(1, 'finney'), '1000000000000000'); + assert.equal(utils.toWei(1, 'ether'), '1000000000000000000'); + assert.equal(utils.toWei(1, 'kether'), '1000000000000000000000'); + assert.equal(utils.toWei(1, 'grand'), '1000000000000000000000'); + assert.equal(utils.toWei(1, 'mether'), '1000000000000000000000000'); + assert.equal(utils.toWei(1, 'gether'), '1000000000000000000000000000'); + assert.equal(utils.toWei(1, 'tether'), '1000000000000000000000000000000'); + + assert.throws(function () {utils.toWei(1, 'wei1');}, Error); + }); + }); +}); diff --git a/web3.methods.js b/web3.methods.js index 8dcc6110..92d4e160 100644 --- a/web3.methods.js +++ b/web3.methods.js @@ -8,7 +8,10 @@ describe('web3', function() { u.methodExists(web3, 'fromAscii'); u.methodExists(web3, 'toDecimal'); u.methodExists(web3, 'fromDecimal'); - u.methodExists(web3, 'toEth'); + u.methodExists(web3, 'fromWei'); + u.methodExists(web3, 'toWei'); + u.methodExists(web3, 'toBigNumber'); + u.methodExists(web3, 'isAddress'); u.methodExists(web3, 'setProvider'); u.methodExists(web3, 'reset'); -- cgit v1.2.3 From 192b18f05f9950c337ee6219778844af3064ed86 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 11 Mar 2015 09:42:23 +0100 Subject: eth_queuedTransactions renamed to eth_fetchQueuedTransactions --- webthreestubclient.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webthreestubclient.h b/webthreestubclient.h index 7f47fe78..baa0798a 100644 --- a/webthreestubclient.h +++ b/webthreestubclient.h @@ -436,11 +436,11 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - Json::Value eth_queuedTransactions(const std::string& param1) throw (jsonrpc::JsonRpcException) + Json::Value eth_fetchQueuedTransactions(const std::string& param1) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); - Json::Value result = this->CallMethod("eth_queuedTransactions",p); + Json::Value result = this->CallMethod("eth_fetchQueuedTransactions",p); if (result.isArray()) return result; else -- cgit v1.2.3 From e18c7b99cb440639adc0063c33c26566ba9589a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 12 Mar 2015 11:55:00 +0100 Subject: testeth: optional VM tracing (--vmtrace), command line options refactoring. Closes ethereum/cpp-ethereum#1280 --- TestHelper.cpp | 80 +++++++++++++++++++++++++++++++++++---------------------- TestHelper.h | 27 ++++++++++++++++++- state.cpp | 60 +++++++++++++++++++------------------------ transaction.cpp | 17 +++++------- vm.cpp | 69 +++++++++++++++++-------------------------------- 5 files changed, 132 insertions(+), 121 deletions(-) diff --git a/TestHelper.cpp b/TestHelper.cpp index 9ac64107..fcca4630 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -439,8 +439,6 @@ void userDefinedTest(string testTypeFlag, std::function 0, "Contents of " + dir.string() + "/" + _name + "Filler.json is empty."); - json_spirit::read_string(s, v); - doTests(v, true); - writeFile(testPath + "/" + _name + ".json", asBytes(json_spirit::write_string(v, true))); - } - catch (Exception const& _e) - { - BOOST_ERROR("Failed filling test with Exception: " << diagnostic_information(_e)); - } - catch (std::exception const& _e) - { - BOOST_ERROR("Failed filling test with Exception: " << _e.what()); - } - break; + cnote << "Populating tests..."; + json_spirit::mValue v; + boost::filesystem::path p(__FILE__); + boost::filesystem::path dir = p.parent_path(); + string s = asString(dev::contents(dir.string() + "/" + _name + "Filler.json")); + BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + dir.string() + "/" + _name + "Filler.json is empty."); + json_spirit::read_string(s, v); + doTests(v, true); + writeFile(testPath + "/" + _name + ".json", asBytes(json_spirit::write_string(v, true))); + } + catch (Exception const& _e) + { + BOOST_ERROR("Failed filling test with Exception: " << diagnostic_information(_e)); + } + catch (std::exception const& _e) + { + BOOST_ERROR("Failed filling test with Exception: " << _e.what()); } } @@ -541,21 +534,48 @@ RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject& _tObj) return rlpStream; } -void processCommandLineOptions() +Options::Options() { auto argc = boost::unit_test::framework::master_test_suite().argc; auto argv = boost::unit_test::framework::master_test_suite().argv; - for (auto i = 0; i < argc; ++i) + for (auto i = 0; i < argc; ++i) { - if (std::string(argv[i]) == "--jit") + auto arg = std::string{argv[i]}; + if (arg == "--jit") { + jit = true; eth::VMFactory::setKind(eth::VMKind::JIT); - break; + } + else if (arg == "--vmtrace") + vmtrace = true; + else if (arg == "--performance") + performance = true; + else if (arg == "--quadratic") + quadratic = true; + else if (arg == "--memory") + memory = true; + else if (arg == "--inputlimits") + inputLimits = true; + else if (arg == "--bigdata") + bigData = true; + else if (arg == "--all") + { + performance = true; + quadratic = true; + memory = true; + inputLimits = true; + bigData = true; } } } +Options const& Options::get() +{ + static Options instance; + return instance; +} + LastHashes lastHashes(u256 _currentBlockNumber) { LastHashes ret; diff --git a/TestHelper.h b/TestHelper.h index d378848a..9efed0fa 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -141,7 +141,6 @@ void executeTests(const std::string& _name, const std::string& _testPathAppendix std::string getTestPath(); void userDefinedTest(std::string testTypeFlag, std::function doTests); RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject& _tObj); -void processCommandLineOptions(); eth::LastHashes lastHashes(u256 _currentBlockNumber); json_spirit::mObject fillJsonWithState(eth::State _state); @@ -158,5 +157,31 @@ void checkAddresses(mapType& _expectedAddrs, mapType& _resultAddrs) BOOST_CHECK(_expectedAddrs == _resultAddrs); } +class Options +{ +public: + bool jit = false; ///< Use JIT + bool vmtrace = false; ///< Create EVM execution tracer // TODO: Link with log verbosity? + bool showTimes = false; ///< Print test groups execution times + bool fillTests = false; ///< Create JSON test files from execution results + + /// Test selection + /// @{ + bool performance = false; + bool quadratic = false; + bool memory = false; + bool inputLimits = false; + bool bigData = false; + /// @} + + /// Get reference to options + /// The first time used, options are parsed + static Options const& get(); + +private: + Options(); + Options(Options const&) = delete; +}; + } } diff --git a/state.cpp b/state.cpp index 5202aff2..7fd51d40 100644 --- a/state.cpp +++ b/state.cpp @@ -41,7 +41,7 @@ namespace dev { namespace test { void doStateTests(json_spirit::mValue& v, bool _fillin) { - processCommandLineOptions(); + Options::get(); // process command line options for (auto& i: v.get_obj()) { @@ -172,48 +172,40 @@ BOOST_AUTO_TEST_CASE(stBlockHashTest) BOOST_AUTO_TEST_CASE(stQuadraticComplexityTest) { - for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) - { - string arg = boost::unit_test::framework::master_test_suite().argv[i]; - if (arg == "--quadratic" || arg == "--all") - { - auto start = chrono::steady_clock::now(); - - dev::test::executeTests("stQuadraticComplexityTest", "/StateTests", dev::test::doStateTests); - - auto end = chrono::steady_clock::now(); - auto duration(chrono::duration_cast(end - start)); - cnote << "test duration: " << duration.count() << " milliseconds.\n"; - } - } + if (test::Options::get().quadratic) + { + auto start = chrono::steady_clock::now(); + + dev::test::executeTests("stQuadraticComplexityTest", "/StateTests", dev::test::doStateTests); + + auto end = chrono::steady_clock::now(); + auto duration(chrono::duration_cast(end - start)); + cnote << "test duration: " << duration.count() << " milliseconds.\n"; + } } BOOST_AUTO_TEST_CASE(stMemoryStressTest) { - for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) - { - string arg = boost::unit_test::framework::master_test_suite().argv[i]; - if (arg == "--memory" || arg == "--all") - { - auto start = chrono::steady_clock::now(); - - dev::test::executeTests("stMemoryStressTest", "/StateTests", dev::test::doStateTests); - - auto end = chrono::steady_clock::now(); - auto duration(chrono::duration_cast(end - start)); - cnote << "test duration: " << duration.count() << " milliseconds.\n"; - } - } + if (test::Options::get().memory) + { + auto start = chrono::steady_clock::now(); + + dev::test::executeTests("stMemoryStressTest", "/StateTests", dev::test::doStateTests); + + auto end = chrono::steady_clock::now(); + auto duration(chrono::duration_cast(end - start)); + cnote << "test duration: " << duration.count() << " milliseconds.\n"; + } } - BOOST_AUTO_TEST_CASE(stSolidityTest) - { - dev::test::executeTests("stSolidityTest", "/StateTests", dev::test::doStateTests); - } +BOOST_AUTO_TEST_CASE(stSolidityTest) +{ + dev::test::executeTests("stSolidityTest", "/StateTests", dev::test::doStateTests); +} BOOST_AUTO_TEST_CASE(stMemoryTest) { - dev::test::executeTests("stMemoryTest", "/StateTests", dev::test::doStateTests); + dev::test::executeTests("stMemoryTest", "/StateTests", dev::test::doStateTests); } diff --git a/transaction.cpp b/transaction.cpp index 83fd8da4..77f6ecda 100644 --- a/transaction.cpp +++ b/transaction.cpp @@ -116,21 +116,16 @@ BOOST_AUTO_TEST_CASE(ttWrongRLPTransaction) BOOST_AUTO_TEST_CASE(tt10mbDataField) { - for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) + if (test::Options::get().bigData) { - string arg = boost::unit_test::framework::master_test_suite().argv[i]; - if (arg == "--bigdata" || arg == "--all") - { - auto start = chrono::steady_clock::now(); + auto start = chrono::steady_clock::now(); - dev::test::executeTests("tt10mbDataField", "/TransactionTests", dev::test::doTransactionTests); + dev::test::executeTests("tt10mbDataField", "/TransactionTests", dev::test::doTransactionTests); - auto end = chrono::steady_clock::now(); - auto duration(chrono::duration_cast(end - start)); - cnote << "test duration: " << duration.count() << " milliseconds.\n"; - } + auto end = chrono::steady_clock::now(); + auto duration(chrono::duration_cast(end - start)); + cnote << "test duration: " << duration.count() << " milliseconds.\n"; } - } BOOST_AUTO_TEST_CASE(ttCreateTest) diff --git a/vm.cpp b/vm.cpp index a39f0005..4433a60e 100644 --- a/vm.cpp +++ b/vm.cpp @@ -312,7 +312,7 @@ namespace dev { namespace test { void doVMTests(json_spirit::mValue& v, bool _fillin) { - processCommandLineOptions(); + Options::get(); // process command line options // TODO: We need to control the main() function for (auto& i: v.get_obj()) { @@ -344,7 +344,8 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) try { auto vm = eth::VMFactory::create(fev.gas); - output = vm->go(fev, fev.simpleTrace()).toBytes(); + auto vmtrace = Options::get().vmtrace ? fev.simpleTrace() : OnOpFunc{}; + output = vm->go(fev, vmtrace).toBytes(); gas = vm->gas(); } catch (VMException const&) @@ -364,18 +365,12 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) } auto endTime = std::chrono::high_resolution_clock::now(); - auto argc = boost::unit_test::framework::master_test_suite().argc; - auto argv = boost::unit_test::framework::master_test_suite().argv; - for (auto i = 0; i < argc; ++i) + if (Options::get().showTimes) { - if (std::string(argv[i]) == "--show-times") - { - auto testDuration = endTime - startTime; - cnote << "Execution time: " - << std::chrono::duration_cast(testDuration).count() - << " ms"; - break; - } + auto testDuration = endTime - startTime; + cnote << "Execution time: " + << std::chrono::duration_cast(testDuration).count() + << " ms"; } // delete null entries in storage for the sake of comparison @@ -517,58 +512,42 @@ BOOST_AUTO_TEST_CASE(vmSystemOperationsTest) BOOST_AUTO_TEST_CASE(vmPerformanceTest) { - for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) + if (test::Options::get().performance) { - string arg = boost::unit_test::framework::master_test_suite().argv[i]; - if (arg == "--performance" || arg == "--all") - { - auto start = chrono::steady_clock::now(); + auto start = chrono::steady_clock::now(); - dev::test::executeTests("vmPerformanceTest", "/VMTests", dev::test::doVMTests); + dev::test::executeTests("vmPerformanceTest", "/VMTests", dev::test::doVMTests); - auto end = chrono::steady_clock::now(); - auto duration(chrono::duration_cast(end - start)); - cnote << "test duration: " << duration.count() << " milliseconds.\n"; - } + auto end = chrono::steady_clock::now(); + auto duration(chrono::duration_cast(end - start)); + cnote << "test duration: " << duration.count() << " milliseconds.\n"; } } BOOST_AUTO_TEST_CASE(vmInputLimitsTest1) { - for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) + if (test::Options::get().inputLimits) { - string arg = boost::unit_test::framework::master_test_suite().argv[i]; - if (arg == "--inputlimits" || arg == "--all") - { - auto start = chrono::steady_clock::now(); + auto start = chrono::steady_clock::now(); - dev::test::executeTests("vmInputLimits1", "/VMTests", dev::test::doVMTests); + dev::test::executeTests("vmInputLimits1", "/VMTests", dev::test::doVMTests); - auto end = chrono::steady_clock::now(); - auto duration(chrono::duration_cast(end - start)); - cnote << "test duration: " << duration.count() << " milliseconds.\n"; - } + auto end = chrono::steady_clock::now(); + auto duration(chrono::duration_cast(end - start)); + cnote << "test duration: " << duration.count() << " milliseconds.\n"; } } BOOST_AUTO_TEST_CASE(vmInputLimitsTest2) { - for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) - { - string arg = boost::unit_test::framework::master_test_suite().argv[i]; - if (arg == "--inputlimits" || arg == "--all") - dev::test::executeTests("vmInputLimits2", "/VMTests", dev::test::doVMTests); - } + if (test::Options::get().inputLimits) + dev::test::executeTests("vmInputLimits2", "/VMTests", dev::test::doVMTests); } BOOST_AUTO_TEST_CASE(vmInputLimitsLightTest) { - for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) - { - string arg = boost::unit_test::framework::master_test_suite().argv[i]; - if (arg == "--inputlimits" || arg == "--all") - dev::test::executeTests("vmInputLimitsLight", "/VMTests", dev::test::doVMTests); - } + if (test::Options::get().inputLimits) + dev::test::executeTests("vmInputLimitsLight", "/VMTests", dev::test::doVMTests); } BOOST_AUTO_TEST_CASE(vmRandom) -- cgit v1.2.3