From ca1ac5df609f98c291feffc57dda6e22453ef030 Mon Sep 17 00:00:00 2001 From: subtly Date: Tue, 21 Apr 2015 05:31:33 -0400 Subject: [PATCH 01/41] update tests (v4 endpoint) From 78a03553431ea32c41586b3c573ba421e488c10b Mon Sep 17 00:00:00 2001 From: subtly Date: Tue, 21 Apr 2015 05:38:39 -0400 Subject: [PATCH 02/41] update net tests (v4 endpoint) From e8b0470eb6e6afa8aad96d3695145b339a7183fa Mon Sep 17 00:00:00 2001 From: subtly Date: Tue, 21 Apr 2015 06:13:31 -0400 Subject: [PATCH 03/41] update peer host test. support unspecified ip. From 685d08c41b4f3d6aa3dac31f185095bfeabaa402 Mon Sep 17 00:00:00 2001 From: subtly Date: Tue, 21 Apr 2015 18:13:45 -0400 Subject: [PATCH 04/41] more test updates (v4 endpoints. #1557, #1558) From ce6db27a5189b8178564c06a4abec92a7b73a732 Mon Sep 17 00:00:00 2001 From: subtly Date: Thu, 23 Apr 2015 03:04:35 +0100 Subject: [PATCH 05/41] handle new endpoint properties for ping From fb589c54acc8f7aa1da162f76b83e5958a9bdc13 Mon Sep 17 00:00:00 2001 From: subtly Date: Mon, 27 Apr 2015 14:17:30 +0100 Subject: [PATCH 06/41] encapsulate IP endpoint address as byte string From 81d7d0874e16584754dabe466d7c2e403571bacf Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Mon, 27 Apr 2015 21:42:51 +0200 Subject: [PATCH 07/41] v8 integration initial commit --- CMakeLists.txt | 4 ++++ libethconsole/CMakeLists.txt | 7 +++++++ libethconsole/JSV8ScopeBase.cpp | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 libethconsole/CMakeLists.txt create mode 100644 libethconsole/JSV8ScopeBase.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a97bb86fc..2413fc0a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,8 @@ add_subdirectory(libethereum) add_subdirectory(libevm) add_subdirectory(libnatspec) add_subdirectory(libp2p) +add_subdirectory(libethconsole) + if (SOLIDITY) add_subdirectory(libsolidity) endif () @@ -40,6 +42,7 @@ include_directories(BEFORE ..) include_directories(${Boost_INCLUDE_DIRS}) include_directories(${CRYPTOPP_INCLUDE_DIRS}) include_directories(${JSON_RPC_CPP_INCLUDE_DIRS}) +include_directories(${V8_INCLUDE_DIRS}) # search for test names and create ctest tests enable_testing() @@ -65,6 +68,7 @@ target_link_libraries(testeth ${CURL_LIBRARIES}) target_link_libraries(testeth ethereum) target_link_libraries(testeth ethcore) target_link_libraries(testeth secp256k1) +target_link_libraries(testeth ethconsole) if (SOLIDITY) target_link_libraries(testeth solidity) endif () diff --git a/libethconsole/CMakeLists.txt b/libethconsole/CMakeLists.txt new file mode 100644 index 000000000..610c58889 --- /dev/null +++ b/libethconsole/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_policy(SET CMP0015 NEW) + +aux_source_directory(. SRCS) + +add_sources(${SRCS}) + + diff --git a/libethconsole/JSV8ScopeBase.cpp b/libethconsole/JSV8ScopeBase.cpp new file mode 100644 index 000000000..5bd7bf6a5 --- /dev/null +++ b/libethconsole/JSV8ScopeBase.cpp @@ -0,0 +1,21 @@ +// +// Created by Marek Kotewicz on 27/04/15. +// + +#include +#include "../../libethconsole/JSV8ScopeBase.h" + +using namespace std; +using namespace dev; +using namespace dev::eth; + +BOOST_AUTO_TEST_SUITE(jsscope) + +BOOST_AUTO_TEST_CASE(common) +{ + JSV8ScopeBase scope; + string result = scope.evaluate("1 + 1"); + BOOST_CHECK_EQUAL(result, "2"); +} + +BOOST_AUTO_TEST_SUITE_END() From 189c0d460ba316f613388b22ca6108f757eabca6 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Mon, 27 Apr 2015 22:20:57 +0200 Subject: [PATCH 08/41] cleanup, libjsengine --- CMakeLists.txt | 4 ++-- libethconsole/CMakeLists.txt | 7 ------- libethconsole/JSV8ScopeBase.cpp | 21 --------------------- 3 files changed, 2 insertions(+), 30 deletions(-) delete mode 100644 libethconsole/CMakeLists.txt delete mode 100644 libethconsole/JSV8ScopeBase.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2413fc0a9..349ca9800 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ add_subdirectory(libethereum) add_subdirectory(libevm) add_subdirectory(libnatspec) add_subdirectory(libp2p) -add_subdirectory(libethconsole) +add_subdirectory(libjsengine) if (SOLIDITY) add_subdirectory(libsolidity) @@ -68,7 +68,7 @@ target_link_libraries(testeth ${CURL_LIBRARIES}) target_link_libraries(testeth ethereum) target_link_libraries(testeth ethcore) target_link_libraries(testeth secp256k1) -target_link_libraries(testeth ethconsole) +target_link_libraries(testeth jsengine) if (SOLIDITY) target_link_libraries(testeth solidity) endif () diff --git a/libethconsole/CMakeLists.txt b/libethconsole/CMakeLists.txt deleted file mode 100644 index 610c58889..000000000 --- a/libethconsole/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_policy(SET CMP0015 NEW) - -aux_source_directory(. SRCS) - -add_sources(${SRCS}) - - diff --git a/libethconsole/JSV8ScopeBase.cpp b/libethconsole/JSV8ScopeBase.cpp deleted file mode 100644 index 5bd7bf6a5..000000000 --- a/libethconsole/JSV8ScopeBase.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// -// Created by Marek Kotewicz on 27/04/15. -// - -#include -#include "../../libethconsole/JSV8ScopeBase.h" - -using namespace std; -using namespace dev; -using namespace dev::eth; - -BOOST_AUTO_TEST_SUITE(jsscope) - -BOOST_AUTO_TEST_CASE(common) -{ - JSV8ScopeBase scope; - string result = scope.evaluate("1 + 1"); - BOOST_CHECK_EQUAL(result, "2"); -} - -BOOST_AUTO_TEST_SUITE_END() From 5cb7fa670f2efe5dd98c4f1f37b3c07987897639 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 28 Apr 2015 00:43:37 +0200 Subject: [PATCH 09/41] libjsconsole init From b79f8a0b57acc7b9c7ca04eac87b6104c9dba557 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 28 Apr 2015 08:24:39 +0200 Subject: [PATCH 10/41] jsvalueprinter From c2bcd771de816854e19cfb14dfa4e8bc17a7dff8 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 29 Apr 2015 09:31:22 +0200 Subject: [PATCH 11/41] console command line option From 1988cecef16795906c0ed5ce262b4e08202b309e Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 30 Apr 2015 13:27:55 +0200 Subject: [PATCH 12/41] jsconsole optional for tests --- CMakeLists.txt | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 349ca9800..39a235c58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,10 @@ add_subdirectory(libethereum) add_subdirectory(libevm) add_subdirectory(libnatspec) add_subdirectory(libp2p) -add_subdirectory(libjsengine) + +if (JSCONSOLE) + add_subdirectory(libjsengine) +endif() if (SOLIDITY) add_subdirectory(libsolidity) @@ -42,7 +45,10 @@ include_directories(BEFORE ..) include_directories(${Boost_INCLUDE_DIRS}) include_directories(${CRYPTOPP_INCLUDE_DIRS}) include_directories(${JSON_RPC_CPP_INCLUDE_DIRS}) -include_directories(${V8_INCLUDE_DIRS}) + +if (JSCONSOLE) + include_directories(${V8_INCLUDE_DIRS}) +endif() # search for test names and create ctest tests enable_testing() @@ -68,15 +74,22 @@ target_link_libraries(testeth ${CURL_LIBRARIES}) target_link_libraries(testeth ethereum) target_link_libraries(testeth ethcore) target_link_libraries(testeth secp256k1) -target_link_libraries(testeth jsengine) + +if (JSCONSOLE) + target_link_libraries(testeth jsengine) +endif() + if (SOLIDITY) target_link_libraries(testeth solidity) endif () + target_link_libraries(testeth testutils) + if (GUI AND NOT JUSTTESTS) target_link_libraries(testeth webthree) target_link_libraries(testeth natspec) endif() + if (JSONRPC) target_link_libraries(testeth web3jsonrpc) target_link_libraries(testeth ${JSON_RPC_CPP_CLIENT_LIBRARIES}) From b759ee60ddb14d20b289f3f3630eea05ae166ce2 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 30 Apr 2015 17:40:17 +0200 Subject: [PATCH 13/41] printing v8 errors From 3bc28c100c5d42ca9f4ae9e501dc9b948c16f214 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Mon, 4 May 2015 12:58:56 +0200 Subject: [PATCH 14/41] rpc provider in progress From f59d81d33f4b7330f2bbcbe4afba19fc9564ac7a Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 5 May 2015 10:37:14 +0200 Subject: [PATCH 15/41] wrap const char* in jsstring From 8416a6260f3545ae7109091a09bef9291db59179 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 29 Apr 2015 18:16:05 +0200 Subject: [PATCH 16/41] Split known state from common subexpression eliminator. --- libsolidity/SolidityOptimizer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libsolidity/SolidityOptimizer.cpp b/libsolidity/SolidityOptimizer.cpp index 9cdaa5886..71463f919 100644 --- a/libsolidity/SolidityOptimizer.cpp +++ b/libsolidity/SolidityOptimizer.cpp @@ -90,7 +90,8 @@ public: for (AssemblyItem& item: input) item.setLocation(SourceLocation(1, 3, make_shared(""))); - eth::CommonSubexpressionEliminator cse; + eth::KnownState state; + eth::CommonSubexpressionEliminator cse(state); BOOST_REQUIRE(cse.feedItems(input.begin(), input.end()) == input.end()); AssemblyItems output = cse.getOptimizedItems(); @@ -231,7 +232,8 @@ BOOST_AUTO_TEST_CASE(function_calls) BOOST_AUTO_TEST_CASE(cse_intermediate_swap) { - eth::CommonSubexpressionEliminator cse; + eth::KnownState state; + eth::CommonSubexpressionEliminator cse(state); AssemblyItems input{ Instruction::SWAP1, Instruction::POP, Instruction::ADD, u256(0), Instruction::SWAP1, Instruction::SLOAD, Instruction::SWAP1, u256(100), Instruction::EXP, Instruction::SWAP1, From 3649c1fc60bf64171f843ec1cb73697b9f0ebd3f Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 30 Apr 2015 14:41:55 +0200 Subject: [PATCH 17/41] Common subexpression elimination ready for using pre-known state. --- libsolidity/SolidityOptimizer.cpp | 49 ++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/libsolidity/SolidityOptimizer.cpp b/libsolidity/SolidityOptimizer.cpp index 71463f919..59e8f04a8 100644 --- a/libsolidity/SolidityOptimizer.cpp +++ b/libsolidity/SolidityOptimizer.cpp @@ -83,15 +83,28 @@ public: "\nOptimized: " + toHex(optimizedOutput)); } - AssemblyItems getCSE(AssemblyItems const& _input) + AssemblyItems addDummyLocations(AssemblyItems const& _input) { // add dummy locations to each item so that we can check that they are not deleted AssemblyItems input = _input; for (AssemblyItem& item: input) item.setLocation(SourceLocation(1, 3, make_shared(""))); + return input; + } + eth::KnownState createInitialState(AssemblyItems const& _input) + { eth::KnownState state; - eth::CommonSubexpressionEliminator cse(state); + for (auto const& item: addDummyLocations(_input)) + state.feedItem(item); + return state; + } + + AssemblyItems getCSE(AssemblyItems const& _input, eth::KnownState const& _state = eth::KnownState()) + { + AssemblyItems input = addDummyLocations(_input); + + eth::CommonSubexpressionEliminator cse(_state); BOOST_REQUIRE(cse.feedItems(input.begin(), input.end()) == input.end()); AssemblyItems output = cse.getOptimizedItems(); @@ -102,9 +115,13 @@ public: return output; } - void checkCSE(AssemblyItems const& _input, AssemblyItems const& _expectation) + void checkCSE( + AssemblyItems const& _input, + AssemblyItems const& _expectation, + KnownState const& _state = eth::KnownState() + ) { - AssemblyItems output = getCSE(_input); + AssemblyItems output = getCSE(_input, _state); BOOST_CHECK_EQUAL_COLLECTIONS(_expectation.begin(), _expectation.end(), output.begin(), output.end()); } @@ -756,6 +773,30 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_content_noninterfering_store_in_between BOOST_CHECK_EQUAL(1, count(output.begin(), output.end(), AssemblyItem(Instruction::SHA3))); } +BOOST_AUTO_TEST_CASE(cse_with_initially_known_stack) +{ + eth::KnownState state = createInitialState(AssemblyItems{ + u256(0x12), + u256(0x20), + Instruction::ADD + }); + AssemblyItems input{ + u256(0x12 + 0x20) + }; + checkCSE(input, AssemblyItems{Instruction::DUP1}, state); +} + +BOOST_AUTO_TEST_CASE(cse_equality_on_initially_known_stack) +{ + eth::KnownState state = createInitialState(AssemblyItems{Instruction::DUP1}); + AssemblyItems input{ + Instruction::EQ + }; + AssemblyItems output = getCSE(input, state); + // check that it directly pushes 1 (true) + BOOST_CHECK(find(output.begin(), output.end(), AssemblyItem(u256(1))) != output.end()); +} + BOOST_AUTO_TEST_CASE(control_flow_graph_remove_unused) { // remove parts of the code that are unused From a0cc8abb2a162f883b5afd4757f52d926cf6df0b Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 5 May 2015 17:45:58 +0200 Subject: [PATCH 18/41] CFG returns vector of blocks instead of assembly items. --- libsolidity/SolidityOptimizer.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libsolidity/SolidityOptimizer.cpp b/libsolidity/SolidityOptimizer.cpp index 59e8f04a8..3cb6a536a 100644 --- a/libsolidity/SolidityOptimizer.cpp +++ b/libsolidity/SolidityOptimizer.cpp @@ -131,8 +131,12 @@ public: // Running it four times should be enough for these tests. for (unsigned i = 0; i < 4; ++i) { - eth::ControlFlowGraph cfg(output); - output = cfg.optimisedItems(); + ControlFlowGraph cfg(output); + AssemblyItems optItems; + for (BasicBlock const& block: cfg.optimisedBlocks()) + copy(output.begin() + block.begin, output.begin() + block.end, + back_inserter(optItems)); + output = move(optItems); } BOOST_CHECK_EQUAL_COLLECTIONS(_expectation.begin(), _expectation.end(), output.begin(), output.end()); } From de01400fb4bb0e3dc2ab246a437fb4b5c5f2adb1 Mon Sep 17 00:00:00 2001 From: arkpar Date: Thu, 7 May 2015 09:51:06 +0200 Subject: [PATCH 19/41] set and map to hash tables --- TestHelper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TestHelper.cpp b/TestHelper.cpp index 144a1a286..96e11e02c 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -305,7 +305,7 @@ void ImportTest::checkExpectedState(State const& _stateExpect, State const& _sta if (addressOptions.m_bHasStorage) { - map stateStorage = _statePost.storage(a.first); + unordered_map stateStorage = _statePost.storage(a.first); for (auto const& s: _stateExpect.storage(a.first)) CHECK(stateStorage[s.first] == s.second, "Check State: " << a.first << ": incorrect storage [" << s.first << "] = " << toHex(stateStorage[s.first]) << ", expected [" << s.first << "] = " << toHex(s.second)); From 1e2bd8afe4633391806396ed6773c70db59a1fde Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 7 May 2015 17:10:44 +0200 Subject: [PATCH 20/41] New ethash API integration part 1 - cpp-ethereum now compiles with the new API - Proper integration with testing will come with the next commits From 21f2af4793fee8701f8ad2bf028b99f87d80417e Mon Sep 17 00:00:00 2001 From: winsvega Date: Mon, 27 Apr 2015 14:38:32 +0300 Subject: [PATCH 21/41] Total Difficulty test From cfff783c2876640528312128c70ebf3a16a2632e Mon Sep 17 00:00:00 2001 From: winsvega Date: Tue, 28 Apr 2015 17:20:33 +0300 Subject: [PATCH 22/41] Total Difficulty: merge revert From 715643c3f28777aa69c4cdcde4fe1213d0b0df89 Mon Sep 17 00:00:00 2001 From: winsvega Date: Tue, 28 Apr 2015 17:43:29 +0300 Subject: [PATCH 23/41] Total Difficulty: blockweight test filler --- bcBlockWeightTestFiller.json | 106 +++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 bcBlockWeightTestFiller.json diff --git a/bcBlockWeightTestFiller.json b/bcBlockWeightTestFiller.json new file mode 100644 index 000000000..62158032e --- /dev/null +++ b/bcBlockWeightTestFiller.json @@ -0,0 +1,106 @@ +{ +"diffTooHigh" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "131072", + "extraData" : "0x42", + "gasLimit" : "3141592", + "gasUsed" : "0", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "nonce" : "0x0102030405060708", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "expect" : { + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "30" + }, + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "nonce" : "3" + }, + "acde5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "1312500000000000000" + } + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "blocks" : [ + { + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "1", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + { + "overwriteAndRedoPoW" : "difficulty", + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "acde5374fce5edbc8e2a8697c15331677e6ebf0b", + "difficulty" : "131073", + "extraData" : "0x", + "gasLimit" : "4141592", + "gasUsed" : "150000", + "hash" : "9de9879b6a81d1b6c4993c63c90a3c9d1e775f14572694778e828bc64972ae04", + "mixHash" : "b557f905d29ed0fca99d65d0adcce698dee97cf72a13c7cd8d7a7826b8eee770", + "nonce" : "18a524c1790fa83b", + "number" : "2", + "parentHash" : "6134fc6b5d99ee03c4aab1592640f6f9dcbc850668d75d631aee34989b938fae", + "receiptTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "ff640b30d613c35dad43e3693329e1b1ee6350f989cf46a288025a1cbfdab9cd", + "timestamp" : "142813170", + "transactionsTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + } + ] + } + ] + } +} From 2233d4e315ca880da251cecd8c23bb8045601aa5 Mon Sep 17 00:00:00 2001 From: winsvega Date: Tue, 28 Apr 2015 17:47:25 +0300 Subject: [PATCH 24/41] Total Difficulty: test filler --- bcBlockWeightTestFiller.json | 106 ----------------------------------- 1 file changed, 106 deletions(-) delete mode 100644 bcBlockWeightTestFiller.json diff --git a/bcBlockWeightTestFiller.json b/bcBlockWeightTestFiller.json deleted file mode 100644 index 62158032e..000000000 --- a/bcBlockWeightTestFiller.json +++ /dev/null @@ -1,106 +0,0 @@ -{ -"diffTooHigh" : { - "genesisBlockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "131072", - "extraData" : "0x42", - "gasLimit" : "3141592", - "gasUsed" : "0", - "number" : "0", - "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", - "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "timestamp" : "0x54c98c81", - "mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "nonce" : "0x0102030405060708", - "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, - "expect" : { - "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { - "balance" : "30" - }, - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "nonce" : "3" - }, - "acde5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "1312500000000000000" - } - }, - "pre" : { - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "10000000000000", - "nonce" : "0", - "code" : "", - "storage": {} - } - }, - "blocks" : [ - { - "transactions" : [ - { - "data" : "", - "gasLimit" : "314159", - "gasPrice" : "1", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "10" - } - ], - "uncleHeaders" : [ - ] - }, - { - "transactions" : [ - { - "data" : "", - "gasLimit" : "314159", - "gasPrice" : "1", - "nonce" : "1", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "10" - } - ], - "uncleHeaders" : [ - ] - }, - { - "transactions" : [ - { - "data" : "", - "gasLimit" : "314159", - "gasPrice" : "1", - "nonce" : "2", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "10" - } - ], - "uncleHeaders" : [ - { - "overwriteAndRedoPoW" : "difficulty", - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "acde5374fce5edbc8e2a8697c15331677e6ebf0b", - "difficulty" : "131073", - "extraData" : "0x", - "gasLimit" : "4141592", - "gasUsed" : "150000", - "hash" : "9de9879b6a81d1b6c4993c63c90a3c9d1e775f14572694778e828bc64972ae04", - "mixHash" : "b557f905d29ed0fca99d65d0adcce698dee97cf72a13c7cd8d7a7826b8eee770", - "nonce" : "18a524c1790fa83b", - "number" : "2", - "parentHash" : "6134fc6b5d99ee03c4aab1592640f6f9dcbc850668d75d631aee34989b938fae", - "receiptTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "ff640b30d613c35dad43e3693329e1b1ee6350f989cf46a288025a1cbfdab9cd", - "timestamp" : "142813170", - "transactionsTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - } - ] - } - ] - } -} From cd3a388f13ad8d719d6c41f3b40638009f135eb4 Mon Sep 17 00:00:00 2001 From: winsvega Date: Wed, 29 Apr 2015 18:56:28 +0300 Subject: [PATCH 25/41] Total Difficulty: new tests From c8092b4da3655924de1f3ceddc2a4127a325690d Mon Sep 17 00:00:00 2001 From: winsvega Date: Thu, 30 Apr 2015 15:49:06 +0300 Subject: [PATCH 26/41] Total Difficulty: style + rebase From eaf95687fe12b84bfd6d07a9dd8f29c7d249c0c3 Mon Sep 17 00:00:00 2001 From: winsvega Date: Tue, 5 May 2015 18:25:51 +0300 Subject: [PATCH 27/41] Total Difficulty: lastblockhash check From 81c1e3b4fe8ed7039996468a1ed538f26043aff0 Mon Sep 17 00:00:00 2001 From: winsvega Date: Tue, 5 May 2015 22:11:37 +0300 Subject: [PATCH 28/41] Total Difficulty: bug fix From 917ce1ad55381ca985244f25225bd47a2c12e658 Mon Sep 17 00:00:00 2001 From: winsvega Date: Thu, 7 May 2015 19:59:37 +0300 Subject: [PATCH 29/41] Total Difficulty: last block hash fix From ccf48882c9387bf153dca17777e1788de2277bca Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 8 May 2015 11:13:36 +0200 Subject: [PATCH 30/41] Basic key manager. From b11fa5996a1d79e27da99c91183a0daee303872f Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Fri, 8 May 2015 15:55:27 +0200 Subject: [PATCH 31/41] Further fixes in Ethash integration and testing From 135a67ad528eb6bb4da0502d9865e03f0b3526fb Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 8 May 2015 16:54:39 +0200 Subject: [PATCH 32/41] New ABI encoding for dynamic types. --- libsolidity/SolidityCompiler.cpp | 10 +++++----- libsolidity/SolidityEndToEndTest.cpp | 17 ++++++++++------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/libsolidity/SolidityCompiler.cpp b/libsolidity/SolidityCompiler.cpp index 7b0ceedb6..aa83c4650 100644 --- a/libsolidity/SolidityCompiler.cpp +++ b/libsolidity/SolidityCompiler.cpp @@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE(smoke_test) "}\n"; bytes code = compileContract(sourceCode); - unsigned boilerplateSize = 70; + unsigned boilerplateSize = 73; bytes expectation({byte(Instruction::JUMPDEST), byte(Instruction::PUSH1), 0x0, // initialize local variable x byte(Instruction::PUSH1), 0x2, @@ -114,8 +114,8 @@ BOOST_AUTO_TEST_CASE(ifStatement) " function f() { bool x; if (x) 77; else if (!x) 78; else 79; }" "}\n"; bytes code = compileContract(sourceCode); - unsigned shift = 57; - unsigned boilerplateSize = 70; + unsigned shift = 60; + unsigned boilerplateSize = 73; bytes expectation({byte(Instruction::JUMPDEST), byte(Instruction::PUSH1), 0x0, byte(Instruction::DUP1), @@ -155,8 +155,8 @@ BOOST_AUTO_TEST_CASE(loops) " function f() { while(true){1;break;2;continue;3;return;4;} }" "}\n"; bytes code = compileContract(sourceCode); - unsigned shift = 57; - unsigned boilerplateSize = 70; + unsigned shift = 60; + unsigned boilerplateSize = 73; bytes expectation({byte(Instruction::JUMPDEST), byte(Instruction::JUMPDEST), byte(Instruction::PUSH1), 0x1, diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index f168ad454..fd4c83b09 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -2962,12 +2962,13 @@ BOOST_AUTO_TEST_CASE(bytes_in_arguments) } )"; compileAndRun(sourceCode); + string innercalldata1 = asString(FixedHash<4>(dev::sha3("f(uint256,uint256)")).asBytes() + encodeArgs(8, 9)); - bytes calldata1 = encodeArgs(u256(innercalldata1.length()), 12, innercalldata1, 13); string innercalldata2 = asString(FixedHash<4>(dev::sha3("g(uint256)")).asBytes() + encodeArgs(3)); bytes calldata = encodeArgs( - 12, u256(innercalldata1.length()), u256(innercalldata2.length()), 13, - innercalldata1, innercalldata2); + 12, 32 * 4, u256(32 * 4 + 32 + (innercalldata1.length() + 31) / 32 * 32), 13, + u256(innercalldata1.length()), innercalldata1, + u256(innercalldata2.length()), innercalldata2); BOOST_CHECK(callContractFunction("test(uint256,bytes,bytes,uint256)", calldata) == encodeArgs(12, (8 + 9) * 3, 13, u256(innercalldata1.length()))); } @@ -3383,9 +3384,10 @@ BOOST_AUTO_TEST_CASE(external_array_args) compileAndRun(sourceCode); bytes params = encodeArgs( 1, 2, 3, 4, 5, 6, 7, 8, // a - 3, // b.length + 32 * (8 + 1 + 5 + 1 + 1 + 1), // offset to b 21, 22, 23, 24, 25, // c 0, 1, 2, // (a,b,c)_index + 3, // b.length 11, 12, 13 // b ); BOOST_CHECK(callContractFunction("test(uint256[8],uint256[],uint256[5],uint256,uint256,uint256)", params) == encodeArgs(1, 12, 23)); @@ -3422,8 +3424,8 @@ BOOST_AUTO_TEST_CASE(bytes_index_access) 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33}; - BOOST_CHECK(callContractFunction("direct(bytes,uint256)", u256(array.length()), 32, array) == encodeArgs(32)); - BOOST_CHECK(callContractFunction("storageCopyRead(bytes,uint256)", u256(array.length()), 32, array) == encodeArgs(32)); + BOOST_CHECK(callContractFunction("direct(bytes,uint256)", 64, 33, u256(array.length()), array) == encodeArgs(33)); + BOOST_CHECK(callContractFunction("storageCopyRead(bytes,uint256)", 64, 33, u256(array.length()), array) == encodeArgs(33)); BOOST_CHECK(callContractFunction("storageWrite()") == encodeArgs(0x193)); } @@ -3474,6 +3476,7 @@ BOOST_AUTO_TEST_CASE(array_copy_calldata_storage) compileAndRun(sourceCode); BOOST_CHECK(callContractFunction("store(uint256[9],uint8[3][])", encodeArgs( 21, 22, 23, 24, 25, 26, 27, 28, 29, // a + u256(32 * (9 + 1)), 4, // size of b 1, 2, 3, // b[0] 11, 12, 13, // b[1] @@ -3502,7 +3505,7 @@ BOOST_AUTO_TEST_CASE(array_copy_nested_array) )"; compileAndRun(sourceCode); BOOST_CHECK(callContractFunction("test(uint256[2][])", encodeArgs( - 3, + 32, 3, 7, 8, 9, 10, 11, 12 From 757972b4e35ab30774355a4868b6bc5a49dda3d9 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Tue, 5 May 2015 12:33:41 +0200 Subject: [PATCH 33/41] added test --- libsolidity/SolidityNameAndTypeResolution.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp index c317dad97..9616777ab 100644 --- a/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1761,6 +1761,25 @@ BOOST_AUTO_TEST_CASE(uninitialized_var) BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); } +BOOST_AUTO_TEST_CASE(deny_overwriting_of_attributes_when_deriving) +{ + // bug #1798 + char const* sourceCode = R"( + contract owned { + address owner; + } + + contract reg { + function owner(bytes32 x) returns (address) {} + } + + contract x is owned, reg { + } + )"; + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCode), "Parsing and Name Resolving Failed"); + //BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + BOOST_AUTO_TEST_SUITE_END() } From 960033de6bea1e436656ccc71b5152efd4314036 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Thu, 7 May 2015 18:12:58 +0200 Subject: [PATCH 34/41] fixed the test --- libsolidity/SolidityEndToEndTest.cpp | 29 +++++++++++++++++++ libsolidity/SolidityNameAndTypeResolution.cpp | 19 ------------ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index f168ad454..2fd1e2ec2 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -3910,6 +3910,35 @@ BOOST_AUTO_TEST_CASE(external_types_in_calls) BOOST_CHECK(callContractFunction("nonexisting") == encodeArgs(u256(9))); } +BOOST_AUTO_TEST_CASE(proper_order_of_overwriting_of_attributes) +{ + // bug #1798 + char const* sourceCode = R"( + contract init { + function isOk() returns (bool) { return false; } + bool public ok = false; + } + contract fix { + function isOk() returns (bool) { return true; } + bool public ok = true; + } + + contract init_fix is init, fix { + function checkOk() returns (bool) { return ok; } + } + contract fix_init is fix, init { + function checkOk() returns (bool) { return ok; } + } + )"; + compileAndRun(sourceCode, 0, "init_fix"); + BOOST_CHECK(callContractFunction("isOk()") == encodeArgs(true)); + BOOST_CHECK(callContractFunction("ok()") == encodeArgs(true)); + + compileAndRun(sourceCode, 0, "fix_init"); + BOOST_CHECK(callContractFunction("isOk()") == encodeArgs(false)); + BOOST_CHECK(callContractFunction("ok()") == encodeArgs(false)); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp index 9616777ab..c317dad97 100644 --- a/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1761,25 +1761,6 @@ BOOST_AUTO_TEST_CASE(uninitialized_var) BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); } -BOOST_AUTO_TEST_CASE(deny_overwriting_of_attributes_when_deriving) -{ - // bug #1798 - char const* sourceCode = R"( - contract owned { - address owner; - } - - contract reg { - function owner(bytes32 x) returns (address) {} - } - - contract x is owned, reg { - } - )"; - ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCode), "Parsing and Name Resolving Failed"); - //BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); -} - BOOST_AUTO_TEST_SUITE_END() } From 37fbf06c98c263052082a8a843e26b4cae69531c Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Fri, 8 May 2015 17:50:44 +0200 Subject: [PATCH 35/41] added one more test --- libsolidity/SolidityEndToEndTest.cpp | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 2fd1e2ec2..f32439a27 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -3939,6 +3939,61 @@ BOOST_AUTO_TEST_CASE(proper_order_of_overwriting_of_attributes) BOOST_CHECK(callContractFunction("ok()") == encodeArgs(false)); } +BOOST_AUTO_TEST_CASE(proper_overwriting_accessor_by_function) +{ + // bug #1798 + char const* sourceCode = R"( + contract attribute { + bool ok = false; + } + contract func { + function ok() returns (bool) { return true; } + } + + contract attr_func is attribute, func { + function checkOk() returns (bool) { return ok(); } + } + contract func_attr is func, attribute { + function checkOk() returns (bool) { return ok; } + } + )"; + compileAndRun(sourceCode, 0, "attr_func"); + BOOST_CHECK(callContractFunction("ok()") == encodeArgs(true)); + compileAndRun(sourceCode, 0, "func_attr"); + BOOST_CHECK(callContractFunction("checkOk()") == encodeArgs(false)); +} + + +BOOST_AUTO_TEST_CASE(overwriting_inheritance) +{ + // bug #1798 + char const* sourceCode = R"( + contract A { + function ok() returns (uint) { return 1; } + } + contract B { + function ok() returns (uint) { return 2; } + } + contract C { + uint ok = 6; + } + contract AB is A, B { + function ok() returns (uint) { return 4; } + } + contract reversedE is C, AB { + function checkOk() returns (uint) { return ok(); } + } + contract E is AB, C { + function checkOk() returns (uint) { return ok; } + } + )"; + compileAndRun(sourceCode, 0, "reversedE"); + BOOST_CHECK(callContractFunction("checkOk()") == encodeArgs(4)); + compileAndRun(sourceCode, 0, "E"); + BOOST_CHECK(callContractFunction("checkOk()") == encodeArgs(6)); +} + + BOOST_AUTO_TEST_SUITE_END() } From 2958ad88f3e75146be2e84b246733fe9dc9984c9 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Sun, 10 May 2015 15:52:25 +0200 Subject: [PATCH 36/41] Squashed 'libjsqrc/ethereumjs/' changes from 3b799d1..e908439 e908439 version 0.3.6 091c8e5 Merge branch 'develop' into tcoulter 272837e cleaned up param.js 38a13bc removed unused functions from coder.js 8e3158f Merge pull request #196 from debris/new_abi c6a57b3 cleanup and documentation 6e60e1f new solidity abi decoding 3f0d1c8 new abi proposal implementation of encoding 39d70e8 Merge pull request #195 from debris/fixed_abi f963855 removed unused functions from abi.js c59419e added new "dave" example 860ad2c fixed #194 22ca9b0 Merge branch 'develop' of https://github.com/ethereum/ethereum.js into develop 6739a1b "dave" example 08f3aae add optional nonce property to sendTransaction 2ca4240 Add error handling to synchronous methods (obligatory warning against using synchronous calls at all). 4690130 version 0.3.5 7949f6a Merge pull request #187 from debris/encoding 944c5cc removed unused test files 8a9c9c5 Merge branch 'develop' into encoding 330b0da more tests for encoding and decoding solidity params b064eab Handle this error properly. For instance, without this, if we cannot connect to the RPC client, JSON won't be able to parse the result (there is none), in which case would cause a RuntimeException. 7989607 version 0.3.4 afb61d5 Merge branch 'master' into develop 97f6e7d build files again 539ef7b Merge pull request #186 from ethereum/eventFilterFix ec0dc44 Merge pull request #188 from ethereum/develop bd73ccc added eth_hashrate baed4c8 fixed old encoding e9ec708 fixed event from and toBlock git-subtree-dir: libjsqrc/ethereumjs git-subtree-split: e90843973f3ae554069347b61cb5b393091c34d1 --- abi.inputParser.js | 515 ------------------------ abi.outputParser.js | 419 ------------------- coder.decodeParam.js | 45 ++- coder.encodeParam.js | 82 +++- contract.js | 1 + event.encode.js | 26 ++ formatters.inputTransactionFormatter.js | 70 +++- web3.eth.filter.js | 15 + web3.eth.hashRate.js | 38 ++ 9 files changed, 232 insertions(+), 979 deletions(-) delete mode 100644 abi.inputParser.js delete mode 100644 abi.outputParser.js create mode 100644 web3.eth.hashRate.js diff --git a/abi.inputParser.js b/abi.inputParser.js deleted file mode 100644 index 6700acd72..000000000 --- a/abi.inputParser.js +++ /dev/null @@ -1,515 +0,0 @@ -var chai = require('chai'); -var assert = chai.assert; -var BigNumber = require('bignumber.js'); -var abi = require('../lib/solidity/abi'); -var clone = function (object) { return JSON.parse(JSON.stringify(object)); }; - -var description = [{ - "name": "test", - "type": "function", - "inputs": [{ - "name": "a", - "type": "uint256" - } - ], - "outputs": [ - { - "name": "d", - "type": "uint256" - } - ] -}]; - -describe('lib/solidity/abi', function () { - describe('inputParser', function () { - it('should parse input uint', function () { - - // given - var d = clone(description); - - d[0].inputs = [ - { type: "uint" } - ]; - - // when - var parser = abi.inputParser(d); - - // then - assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); - assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); - assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - ); - assert.equal( - parser.test(new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16)), - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - ); - assert.equal(parser.test(0.1), "0000000000000000000000000000000000000000000000000000000000000000"); - assert.equal(parser.test(3.9), "0000000000000000000000000000000000000000000000000000000000000003"); - assert.equal(parser.test('0.1'), "0000000000000000000000000000000000000000000000000000000000000000"); - assert.equal(parser.test('3.9'), "0000000000000000000000000000000000000000000000000000000000000003"); - - }); - - it('should parse input uint128', function() { - - // given - var d = clone(description); - - d[0].inputs = [ - { type: "uint128" } - ]; - - // when - var parser = abi.inputParser(d); - - // then - assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); - assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); - assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - ); - assert.equal( - parser.test(new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16)), - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - ); - assert.equal(parser.test(0.1), "0000000000000000000000000000000000000000000000000000000000000000"); - assert.equal(parser.test(3.9), "0000000000000000000000000000000000000000000000000000000000000003"); - assert.equal(parser.test('0.1'), "0000000000000000000000000000000000000000000000000000000000000000"); - assert.equal(parser.test('3.9'), "0000000000000000000000000000000000000000000000000000000000000003"); - - }); - - it('should parse input uint256', function() { - - // given - var d = clone(description); - - d[0].inputs = [ - { type: "uint256" } - ]; - - // when - var parser = abi.inputParser(d); - - // then - assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); - assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); - assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - ); - assert.equal( - parser.test(new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16)), - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - ); - assert.equal(parser.test(0.1), "0000000000000000000000000000000000000000000000000000000000000000"); - assert.equal(parser.test(3.9), "0000000000000000000000000000000000000000000000000000000000000003"); - assert.equal(parser.test('0.1'), "0000000000000000000000000000000000000000000000000000000000000000"); - assert.equal(parser.test('3.9'), "0000000000000000000000000000000000000000000000000000000000000003"); - - }); - - it('should parse input int', function() { - - // given - var d = clone(description); - - d[0].inputs = [ - { type: "int" } - ]; - - // when - var parser = abi.inputParser(d); - - // then - assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); - assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); - assert.equal(parser.test(-1), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - assert.equal(parser.test(-2), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"); - assert.equal(parser.test(-16), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"); - assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - ); - assert.equal( - parser.test(new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16)), - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - ); - assert.equal(parser.test(0.1), "0000000000000000000000000000000000000000000000000000000000000000"); - assert.equal(parser.test(3.9), "0000000000000000000000000000000000000000000000000000000000000003"); - assert.equal(parser.test('0.1'), "0000000000000000000000000000000000000000000000000000000000000000"); - assert.equal(parser.test('3.9'), "0000000000000000000000000000000000000000000000000000000000000003"); - }); - - it('should parse input int128', function() { - - // given - var d = clone(description); - - d[0].inputs = [ - { type: "int128" } - ]; - - // when - var parser = abi.inputParser(d); - - // then - assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); - assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); - assert.equal(parser.test(-1), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - assert.equal(parser.test(-2), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"); - assert.equal(parser.test(-16), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"); - assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - ); - assert.equal( - parser.test(new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16)), - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - ); - assert.equal(parser.test(0.1), "0000000000000000000000000000000000000000000000000000000000000000"); - assert.equal(parser.test(3.9), "0000000000000000000000000000000000000000000000000000000000000003"); - assert.equal(parser.test('0.1'), "0000000000000000000000000000000000000000000000000000000000000000"); - assert.equal(parser.test('3.9'), "0000000000000000000000000000000000000000000000000000000000000003"); - - }); - - it('should parse input int256', function() { - - // given - var d = clone(description); - - d[0].inputs = [ - { type: "int256" } - ]; - - // when - var parser = abi.inputParser(d); - - // then - assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); - assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); - assert.equal(parser.test(-1), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - assert.equal(parser.test(-2), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"); - assert.equal(parser.test(-16), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"); - assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - ); - assert.equal( - parser.test(new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16)), - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - ); - assert.equal(parser.test(0.1), "0000000000000000000000000000000000000000000000000000000000000000"); - assert.equal(parser.test(3.9), "0000000000000000000000000000000000000000000000000000000000000003"); - assert.equal(parser.test('0.1'), "0000000000000000000000000000000000000000000000000000000000000000"); - assert.equal(parser.test('3.9'), "0000000000000000000000000000000000000000000000000000000000000003"); - - }); - - it('should parse input bool', function() { - - // given - var d = clone(description); - - d[0].inputs = [ - { type: 'bool' } - ]; - - // when - var parser = abi.inputParser(d); - - // then - assert.equal(parser.test(true), "0000000000000000000000000000000000000000000000000000000000000001"); - assert.equal(parser.test(false), "0000000000000000000000000000000000000000000000000000000000000000"); - - }); - - it('should parse input address', function () { - - // given - var d = clone(description); - - d[0].inputs = [ - { type: "address" } - ]; - - // when - var parser = abi.inputParser(d) - - // then - assert.equal(parser.test("0x407d73d8a49eeb85d32cf465507dd71d507100c1"), "000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"); - - }); - - it('should parse input fixed bytes type', function () { - - // given - var d = clone(description); - - d[0].inputs = [ - { type: "bytes" } - ]; - - // when - var parser = abi.inputParser(d); - - // then - assert.equal( - parser.test('hello'), - "0000000000000000000000000000000000000000000000000000000000000005" + - "68656c6c6f000000000000000000000000000000000000000000000000000000" - ); - assert.equal( - parser.test('world'), - "0000000000000000000000000000000000000000000000000000000000000005776f726c64000000000000000000000000000000000000000000000000000000" - ); - }); - - it('should parse input int followed by a fixed bytes type', function () { - - // given - var d = clone(description); - - d[0].inputs = [ - { type: "int" }, - { type: "bytes" } - ]; - - // when - var parser = abi.inputParser(d); - - // then - assert.equal( - parser.test(9, 'hello'), - "0000000000000000000000000000000000000000000000000000000000000005" + - "0000000000000000000000000000000000000000000000000000000000000009" + - "68656c6c6f000000000000000000000000000000000000000000000000000000" - ); - }); - - it('should parse input fixed bytes type followed by an int', function () { - - // given - var d = clone(description); - - d[0].inputs = [ - { type: "bytes" }, - { type: "int" } - ]; - - // when - var parser = abi.inputParser(d); - - // then - assert.equal( - parser.test('hello', 9), - "0000000000000000000000000000000000000000000000000000000000000005" + - "0000000000000000000000000000000000000000000000000000000000000009" + - "68656c6c6f000000000000000000000000000000000000000000000000000000" - ); - }); - - it('should use proper method name', function () { - - // given - var d = clone(description); - d[0].name = 'helloworld(int)'; - d[0].inputs = [ - { type: "int" } - ]; - - // when - var parser = abi.inputParser(d); - - // then - assert.equal(parser.helloworld(1), "0000000000000000000000000000000000000000000000000000000000000001"); - assert.equal(parser.helloworld['int'](1), "0000000000000000000000000000000000000000000000000000000000000001"); - - }); - - it('should parse multiple methods', function () { - - // given - var d = [{ - name: "test", - type: "function", - inputs: [{ type: "int" }], - outputs: [{ type: "int" }] - },{ - name: "test2", - type: "function", - inputs: [{ type: "bytes" }], - outputs: [{ type: "bytes" }] - }]; - - // when - var parser = abi.inputParser(d); - - //then - assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); - assert.equal( - parser.test2('hello'), - "000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000" - ); - - }); - - it('should parse input array of ints', function () { - - // given - var d = clone(description); - - d[0].inputs = [ - { type: "int[]" } - ]; - - // when - var parser = abi.inputParser(d); - - // then - assert.equal( - parser.test([5, 6]), - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "0000000000000000000000000000000000000000000000000000000000000006" - ); - }); - - it('should parse an array followed by an int', function () { - - // given - var d = clone(description); - - d[0].inputs = [ - { type: "int[]" }, - { type: "int" } - ]; - - // when - var parser = abi.inputParser(d); - - // then - assert.equal( - parser.test([5, 6], 3), - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000000000000000000000000000000000000000000003" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "0000000000000000000000000000000000000000000000000000000000000006" - ); - }); - - it('should parse an int followed by an array', function () { - - // given - var d = clone(description); - - d[0].inputs = [ - { type: "int" }, - { type: "int[]" } - ]; - - // when - var parser = abi.inputParser(d); - - // then - assert.equal( - parser.test(3, [5, 6]), - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000000000000000000000000000000000000000000003" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "0000000000000000000000000000000000000000000000000000000000000006" - ); - }); - - it('should parse mixture of arrays and ints', function () { - - // given - var d = clone(description); - - d[0].inputs = [ - { type: "int" }, - { type: "int[]" }, - { type: "int" }, - { type: "int[]" } - ]; - - // when - var parser = abi.inputParser(d); - - // then - assert.equal( - parser.test(3, [5, 6, 1, 2], 7, [8, 9]), - "0000000000000000000000000000000000000000000000000000000000000004" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000000000000000000000000000000000000000000003" + - "0000000000000000000000000000000000000000000000000000000000000007" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "0000000000000000000000000000000000000000000000000000000000000006" + - "0000000000000000000000000000000000000000000000000000000000000001" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000000000000000000000000000000000000000000008" + - "0000000000000000000000000000000000000000000000000000000000000009" - ); - }); - - it('should parse input real', function () { - - // given - var d = clone(description); - - d[0].inputs = [ - { type: 'real' } - ]; - - // when - var parser = abi.inputParser(d); - - // then - assert.equal(parser.test(1), "0000000000000000000000000000000100000000000000000000000000000000"); - assert.equal(parser.test(2.125), "0000000000000000000000000000000220000000000000000000000000000000"); - assert.equal(parser.test(8.5), "0000000000000000000000000000000880000000000000000000000000000000"); - assert.equal(parser.test(-1), "ffffffffffffffffffffffffffffffff00000000000000000000000000000000"); - - }); - - it('should parse input ureal', function () { - - // given - var d = clone(description); - - d[0].inputs = [ - { type: 'ureal' } - ]; - - // when - var parser = abi.inputParser(d); - - // then - assert.equal(parser.test(1), "0000000000000000000000000000000100000000000000000000000000000000"); - assert.equal(parser.test(2.125), "0000000000000000000000000000000220000000000000000000000000000000"); - assert.equal(parser.test(8.5), "0000000000000000000000000000000880000000000000000000000000000000"); - - }); - - 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 deleted file mode 100644 index 5fe23e28a..000000000 --- a/abi.outputParser.js +++ /dev/null @@ -1,419 +0,0 @@ -var assert = require('assert'); -var BigNumber = require('bignumber.js'); -var abi = require('../lib/solidity/abi.js'); -var clone = function (object) { return JSON.parse(JSON.stringify(object)); }; - -var description = [{ - "name": "test", - "type": "function", - "inputs": [{ - "name": "a", - "type": "uint256" - } - ], - "outputs": [ - { - "name": "d", - "type": "uint256" - } - ] -}]; - -describe('lib/solidity/abi', function() { - describe('outputParser', function() { - it('should parse output fixed bytes type', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: "bytes" } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal( - parser.test( - "0000000000000000000000000000000000000000000000000000000000000005" + - "68656c6c6f000000000000000000000000000000000000000000000000000000")[0], - 'hello' - ); - assert.equal( - parser.test( - "0000000000000000000000000000000000000000000000000000000000000005" + - "776f726c64000000000000000000000000000000000000000000000000000000")[0], - 'world' - ); - - }); - - it('should parse output uint', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'uint' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal( - parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), - new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) - ); - assert.equal( - parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), - new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(10) - ); - }); - - it('should parse output uint256', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'uint256' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal( - parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), - new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) - ); - assert.equal( - parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), - new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(10) - ); - }); - - it('should parse output uint128', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'uint128' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal( - parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), - new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) - ); - assert.equal( - parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), - new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(10) - ); - }); - - it('should parse output int', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'int' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal(parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); - assert.equal(parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); - }); - - it('should parse output int256', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'int256' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal(parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); - assert.equal(parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); - }); - - it('should parse output int128', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'int128' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal(parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); - assert.equal(parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); - }); - - it('should parse output address', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'address' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal( - parser.test("000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], - "0x407d73d8a49eeb85d32cf465507dd71d507100c1" - ); - }); - - it('should parse output bool', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'bool' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], true); - assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000000")[0], false); - - - }); - - it('should parse output real', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'real' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0000000000000000000000000000000100000000000000000000000000000000")[0], 1); - assert.equal(parser.test("0000000000000000000000000000000220000000000000000000000000000000")[0], 2.125); - assert.equal(parser.test("0000000000000000000000000000000880000000000000000000000000000000")[0], 8.5); - assert.equal(parser.test("ffffffffffffffffffffffffffffffff00000000000000000000000000000000")[0], -1); - - }); - - it('should parse output ureal', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'ureal' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0000000000000000000000000000000100000000000000000000000000000000")[0], 1); - assert.equal(parser.test("0000000000000000000000000000000220000000000000000000000000000000")[0], 2.125); - assert.equal(parser.test("0000000000000000000000000000000880000000000000000000000000000000")[0], 8.5); - - }); - - - it('should parse multiple output fixed bytes type', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: "bytes" }, - { type: "bytes" } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal( - parser.test( - "0000000000000000000000000000000000000000000000000000000000000005" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "68656c6c6f000000000000000000000000000000000000000000000000000000" + - "776f726c64000000000000000000000000000000000000000000000000000000")[0], - 'hello' - ); - assert.equal( - parser.test( - "0000000000000000000000000000000000000000000000000000000000000005" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "68656c6c6f000000000000000000000000000000000000000000000000000000" + - "776f726c64000000000000000000000000000000000000000000000000000000")[1], - 'world' - ); - - }); - - it('should use proper method name', function () { - - // given - var d = clone(description); - d[0].name = 'helloworld(int)'; - d[0].outputs = [ - { type: "int" } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.helloworld("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.helloworld['int']("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - - }); - - - it('should parse multiple methods', function () { - - // given - var d = [{ - name: "test", - type: "function", - inputs: [{ type: "int" }], - outputs: [{ type: "int" }] - },{ - name: "test2", - type: "function", - inputs: [{ type: "bytes" }], - outputs: [{ type: "bytes" }] - }]; - - // when - var parser = abi.outputParser(d); - - //then - assert.equal(parser.test("00000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test2( - "0000000000000000000000000000000000000000000000000000000000000005" + - "68656c6c6f000000000000000000000000000000000000000000000000000000")[0], - "hello" - ); - - }); - - it('should parse output array', function () { - - // given - var d = clone(description); - d[0].outputs = [ - { type: 'int[]' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test( - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "0000000000000000000000000000000000000000000000000000000000000006")[0][0], - 5 - ); - assert.equal(parser.test( - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "0000000000000000000000000000000000000000000000000000000000000006")[0][1], - 6 - ); - - }); - - it('should parse 0x0 value', function () { - - // given - var d = clone(description); - d[0].outputs = [ - { type: 'int' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0x0")[0], 0); - - }); - - it('should parse 0x0 value', function () { - - // given - var d = clone(description); - d[0].outputs = [ - { type: 'uint' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0x0")[0], 0); - - }); - - 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/coder.decodeParam.js b/coder.decodeParam.js index 3eea9dd6f..23b0228eb 100644 --- a/coder.decodeParam.js +++ b/coder.decodeParam.js @@ -21,17 +21,32 @@ describe('lib/solidity/coder', function () { test({ type: 'int256', expected: new bn(16), value: '0000000000000000000000000000000000000000000000000000000000000010'}); test({ type: 'int256', expected: new bn(-1), value: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}); test({ type: 'bytes32', expected: 'gavofyork', value: '6761766f66796f726b0000000000000000000000000000000000000000000000'}); - test({ type: 'bytes', expected: 'gavofyork', value: '0000000000000000000000000000000000000000000000000000000000000009' + + test({ type: 'bytes', expected: 'gavofyork', value: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000009' + '6761766f66796f726b0000000000000000000000000000000000000000000000'}); - test({ type: 'int[]', expected: [new bn(3)], value: '0000000000000000000000000000000000000000000000000000000000000001' + + test({ type: 'int[]', expected: [new bn(3)], value: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000003'}); - test({ type: 'int256[]', expected: [new bn(3)], value: '0000000000000000000000000000000000000000000000000000000000000001' + + test({ type: 'int256[]', expected: [new bn(3)], value: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000003'}); test({ type: 'int[]', expected: [new bn(1), new bn(2), new bn(3)], - value: '0000000000000000000000000000000000000000000000000000000000000003' + + value: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000003' + '0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000002' + '0000000000000000000000000000000000000000000000000000000000000003'}); + test({ type: 'bool', expected: true, value: '0000000000000000000000000000000000000000000000000000000000000001'}); + test({ type: 'bool', expected: false, value: '0000000000000000000000000000000000000000000000000000000000000000'}); + test({ type: 'real', expected: new bn(1), value: '0000000000000000000000000000000100000000000000000000000000000000'}); + test({ type: 'real', expected: new bn(2.125), value: '0000000000000000000000000000000220000000000000000000000000000000'}); + test({ type: 'real', expected: new bn(8.5), value: '0000000000000000000000000000000880000000000000000000000000000000'}); + test({ type: 'real', expected: new bn(-1), value: 'ffffffffffffffffffffffffffffffff00000000000000000000000000000000'}); + test({ type: 'ureal', expected: new bn(1), value: '0000000000000000000000000000000100000000000000000000000000000000'}); + test({ type: 'ureal', expected: new bn(2.125), value: '0000000000000000000000000000000220000000000000000000000000000000'}); + test({ type: 'ureal', expected: new bn(8.5), value: '0000000000000000000000000000000880000000000000000000000000000000'}); + test({ type: 'address', expected: '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + value: '000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1'}); }); }); @@ -53,16 +68,18 @@ describe('lib/solidity/coder', function () { '6761766f66796f726b0000000000000000000000000000000000000000000000'}); test({ types: ['int', 'bytes', 'int', 'int', 'int', 'int[]'], expected: [new bn(1), 'gavofyork', new bn(2), new bn(3), new bn(4), [new bn(5), new bn(6), new bn(7)]], - values: '0000000000000000000000000000000000000000000000000000000000000009' + - '0000000000000000000000000000000000000000000000000000000000000003' + - '0000000000000000000000000000000000000000000000000000000000000001' + - '0000000000000000000000000000000000000000000000000000000000000002' + - '0000000000000000000000000000000000000000000000000000000000000003' + - '0000000000000000000000000000000000000000000000000000000000000004' + - '6761766f66796f726b0000000000000000000000000000000000000000000000' + - '0000000000000000000000000000000000000000000000000000000000000005' + - '0000000000000000000000000000000000000000000000000000000000000006' + - '0000000000000000000000000000000000000000000000000000000000000007'}); + values: '0000000000000000000000000000000000000000000000000000000000000001' + + '00000000000000000000000000000000000000000000000000000000000000c0' + + '0000000000000000000000000000000000000000000000000000000000000002' + + '0000000000000000000000000000000000000000000000000000000000000003' + + '0000000000000000000000000000000000000000000000000000000000000004' + + '0000000000000000000000000000000000000000000000000000000000000100' + + '0000000000000000000000000000000000000000000000000000000000000009' + + '6761766f66796f726b0000000000000000000000000000000000000000000000' + + '0000000000000000000000000000000000000000000000000000000000000003' + + '0000000000000000000000000000000000000000000000000000000000000005' + + '0000000000000000000000000000000000000000000000000000000000000006' + + '0000000000000000000000000000000000000000000000000000000000000007'}); }); }); diff --git a/coder.encodeParam.js b/coder.encodeParam.js index a9e11ab9e..60d1c618e 100644 --- a/coder.encodeParam.js +++ b/coder.encodeParam.js @@ -15,20 +15,37 @@ describe('lib/solidity/coder', function () { test({ type: 'int', value: 1, expected: '0000000000000000000000000000000000000000000000000000000000000001'}); test({ type: 'int', value: 16, expected: '0000000000000000000000000000000000000000000000000000000000000010'}); test({ type: 'int', value: -1, expected: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}); + test({ type: 'int', value: 0.1, expected: '0000000000000000000000000000000000000000000000000000000000000000'}); + test({ type: 'int', value: 3.9, expected: '0000000000000000000000000000000000000000000000000000000000000003'}); test({ type: 'int256', value: 1, expected: '0000000000000000000000000000000000000000000000000000000000000001'}); test({ type: 'int256', value: 16, expected: '0000000000000000000000000000000000000000000000000000000000000010'}); test({ type: 'int256', value: -1, expected: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}); test({ type: 'bytes32', value: 'gavofyork', expected: '6761766f66796f726b0000000000000000000000000000000000000000000000'}); - test({ type: 'bytes', value: 'gavofyork', expected: '0000000000000000000000000000000000000000000000000000000000000009' + + test({ type: 'bytes', value: 'gavofyork', expected: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000009' + '6761766f66796f726b0000000000000000000000000000000000000000000000'}); - test({ type: 'int[]', value: [3], expected: '0000000000000000000000000000000000000000000000000000000000000001' + + test({ type: 'int[]', value: [3], expected: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000003'}); - test({ type: 'int256[]', value: [3], expected: '0000000000000000000000000000000000000000000000000000000000000001' + + test({ type: 'int256[]', value: [3], expected: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000003'}); - test({ type: 'int[]', value: [1,2,3], expected: '0000000000000000000000000000000000000000000000000000000000000003' + + test({ type: 'int[]', value: [1,2,3], expected: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000003' + '0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000002' + '0000000000000000000000000000000000000000000000000000000000000003'}); + test({ type: 'bool', value: true, expected: '0000000000000000000000000000000000000000000000000000000000000001'}); + test({ type: 'bool', value: false, expected: '0000000000000000000000000000000000000000000000000000000000000000'}); + test({ type: 'address', value: '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + expected: '000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1'}); + test({ type: 'real', value: 1, expected: '0000000000000000000000000000000100000000000000000000000000000000'}); + test({ type: 'real', value: 2.125, expected: '0000000000000000000000000000000220000000000000000000000000000000'}); + test({ type: 'real', value: 8.5, expected: '0000000000000000000000000000000880000000000000000000000000000000'}); + test({ type: 'real', value: -1, expected: 'ffffffffffffffffffffffffffffffff00000000000000000000000000000000'}); + test({ type: 'ureal', value: 1, expected: '0000000000000000000000000000000100000000000000000000000000000000'}); + test({ type: 'ureal', value: 2.125, expected: '0000000000000000000000000000000220000000000000000000000000000000'}); + test({ type: 'ureal', value: 8.5, expected: '0000000000000000000000000000000880000000000000000000000000000000'}); }); }); @@ -49,16 +66,29 @@ describe('lib/solidity/coder', function () { test({ types: ['int256'], values: [16], expected: '0000000000000000000000000000000000000000000000000000000000000010'}); test({ types: ['int256'], values: [-1], expected: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}); test({ types: ['bytes32'], values: ['gavofyork'], expected: '6761766f66796f726b0000000000000000000000000000000000000000000000'}); - test({ types: ['bytes'], values: ['gavofyork'], expected: '0000000000000000000000000000000000000000000000000000000000000009' + + test({ types: ['bytes'], values: ['gavofyork'], expected: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000009' + '6761766f66796f726b0000000000000000000000000000000000000000000000'}); - test({ types: ['int[]'], values: [[3]], expected: '0000000000000000000000000000000000000000000000000000000000000001' + + test({ types: ['int[]'], values: [[3]], expected: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000003'}); - test({ types: ['int256[]'], values: [[3]], expected: '0000000000000000000000000000000000000000000000000000000000000001' + + test({ types: ['int256[]'], values: [[3]], expected: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000003'}); - test({ types: ['int256[]'], values: [[1,2,3]], expected: '0000000000000000000000000000000000000000000000000000000000000003' + + test({ types: ['int256[]'], values: [[1,2,3]], expected: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000003' + '0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000002' + '0000000000000000000000000000000000000000000000000000000000000003'}); + test({ types: ['int[]', 'int[]'], values: [[1,2], [3,4]], + expected: '0000000000000000000000000000000000000000000000000000000000000040' + + '00000000000000000000000000000000000000000000000000000000000000a0' + + '0000000000000000000000000000000000000000000000000000000000000002' + + '0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000002' + + '0000000000000000000000000000000000000000000000000000000000000002' + + '0000000000000000000000000000000000000000000000000000000000000003' + + '0000000000000000000000000000000000000000000000000000000000000004'}); test({ types: ['bytes32', 'int'], values: ['gavofyork', 5], expected: '6761766f66796f726b0000000000000000000000000000000000000000000000' + '0000000000000000000000000000000000000000000000000000000000000005'}); @@ -66,25 +96,47 @@ describe('lib/solidity/coder', function () { expected: '0000000000000000000000000000000000000000000000000000000000000005' + '6761766f66796f726b0000000000000000000000000000000000000000000000'}); test({ types: ['bytes', 'int'], values: ['gavofyork', 5], - expected: '0000000000000000000000000000000000000000000000000000000000000009' + + expected: '0000000000000000000000000000000000000000000000000000000000000040' + '0000000000000000000000000000000000000000000000000000000000000005' + + '0000000000000000000000000000000000000000000000000000000000000009' + '6761766f66796f726b0000000000000000000000000000000000000000000000'}); + test({ types: ['bytes', 'bool', 'int[]'], values: ['gavofyork', true, [1, 2, 3]], + expected: '0000000000000000000000000000000000000000000000000000000000000060' + + '0000000000000000000000000000000000000000000000000000000000000001' + + '00000000000000000000000000000000000000000000000000000000000000a0' + + '0000000000000000000000000000000000000000000000000000000000000009' + + '6761766f66796f726b0000000000000000000000000000000000000000000000' + + '0000000000000000000000000000000000000000000000000000000000000003' + + '0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000002' + + '0000000000000000000000000000000000000000000000000000000000000003'}); + test({ types: ['bytes', 'int[]'], values: ['gavofyork', [1, 2, 3]], + expected: '0000000000000000000000000000000000000000000000000000000000000040' + + '0000000000000000000000000000000000000000000000000000000000000080' + + '0000000000000000000000000000000000000000000000000000000000000009' + + '6761766f66796f726b0000000000000000000000000000000000000000000000' + + '0000000000000000000000000000000000000000000000000000000000000003' + + '0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000002' + + '0000000000000000000000000000000000000000000000000000000000000003'}); test({ types: ['int', 'bytes'], values: [5, 'gavofyork'], - expected: '0000000000000000000000000000000000000000000000000000000000000009' + - '0000000000000000000000000000000000000000000000000000000000000005' + + expected: '0000000000000000000000000000000000000000000000000000000000000005' + + '0000000000000000000000000000000000000000000000000000000000000040' + + '0000000000000000000000000000000000000000000000000000000000000009' + '6761766f66796f726b0000000000000000000000000000000000000000000000'}); test({ types: ['int', 'bytes', 'int', 'int', 'int', 'int[]'], values: [1, 'gavofyork', 2, 3, 4, [5, 6, 7]], - expected: '0000000000000000000000000000000000000000000000000000000000000009' + - '0000000000000000000000000000000000000000000000000000000000000003' + - '0000000000000000000000000000000000000000000000000000000000000001' + + expected: '0000000000000000000000000000000000000000000000000000000000000001' + + '00000000000000000000000000000000000000000000000000000000000000c0' + '0000000000000000000000000000000000000000000000000000000000000002' + '0000000000000000000000000000000000000000000000000000000000000003' + '0000000000000000000000000000000000000000000000000000000000000004' + + '0000000000000000000000000000000000000000000000000000000000000100' + + '0000000000000000000000000000000000000000000000000000000000000009' + '6761766f66796f726b0000000000000000000000000000000000000000000000' + + '0000000000000000000000000000000000000000000000000000000000000003' + '0000000000000000000000000000000000000000000000000000000000000005' + '0000000000000000000000000000000000000000000000000000000000000006' + '0000000000000000000000000000000000000000000000000000000000000007'}); - }); }); diff --git a/contract.js b/contract.js index 8a2ea109d..0dcaa1003 100644 --- a/contract.js +++ b/contract.js @@ -345,6 +345,7 @@ describe('web3.eth.contract', function () { assert.equal(payload.method, 'eth_call'); assert.deepEqual(payload.params, [{ data: sha3.slice(0, 10) + + '0000000000000000000000000000000000000000000000000000000000000020' + '0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000003', to: address diff --git a/event.encode.js b/event.encode.js index c28588c2e..6d9850c00 100644 --- a/event.encode.js +++ b/event.encode.js @@ -119,6 +119,32 @@ var tests = [{ ] } }, { + abi: { + name: 'event1', + inputs: [{ + type: 'int', + name: 'a', + indexed: true + }] + }, + indexed: { + a: 1 + }, + options: { + fromBlock: 'latest', + toBlock: 'pending' + }, + expected: { + address: address, + fromBlock: 'latest', + toBlock: 'pending', + topics: [ + signature, + '0x0000000000000000000000000000000000000000000000000000000000000001' + ] + } +}, +{ abi: { name: 'event1', inputs: [{ diff --git a/formatters.inputTransactionFormatter.js b/formatters.inputTransactionFormatter.js index 2f7f8c2e5..44c3534d3 100644 --- a/formatters.inputTransactionFormatter.js +++ b/formatters.inputTransactionFormatter.js @@ -3,24 +3,62 @@ var assert = chai.assert; var formatters = require('../lib/web3/formatters.js'); var BigNumber = require('bignumber.js'); +var tests = [{ + input: { + data: '0x34234bf23bf4234', + value: new BigNumber(100), + from: '0x00000', + to: '0x00000', + nonce: 1000, + gas: 1000, + gasPrice: new BigNumber(1000) + }, + result: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00000', + to: '0x00000', + nonce: '0x3e8', + gas: '0x3e8', + gasPrice: '0x3e8' + } +},{ + input: { + data: '0x34234bf23bf4234', + value: new BigNumber(100), + from: '0x00000', + to: '0x00000', + }, + result: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00000', + to: '0x00000', + } +},{ + input: { + data: '0x34234bf23bf4234', + value: new BigNumber(100), + from: '0x00000', + to: '0x00000', + gas: '1000', + gasPrice: new BigNumber(1000) + }, + result: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00000', + to: '0x00000', + gas: '0x3e8', + gasPrice: '0x3e8' + } +}]; + describe('formatters', function () { describe('inputTransactionFormatter', function () { - it('should return the correct value', function () { - - assert.deepEqual(formatters.inputTransactionFormatter({ - data: '0x34234bf23bf4234', - value: new BigNumber(100), - from: '0x00000', - to: '0x00000', - gas: 1000, - gasPrice: new BigNumber(1000) - }), { - data: '0x34234bf23bf4234', - value: '0x64', - from: '0x00000', - to: '0x00000', - gas: '0x3e8', - gasPrice: '0x3e8' + tests.forEach(function(test){ + it('should return the correct value', function () { + assert.deepEqual(formatters.inputTransactionFormatter(test.input), test.result); }); }); }); diff --git a/web3.eth.filter.js b/web3.eth.filter.js index d8b37311a..7a355b50c 100644 --- a/web3.eth.filter.js +++ b/web3.eth.filter.js @@ -21,6 +21,21 @@ var tests = [{ result: '0xf', formattedResult: '0xf', call: 'eth_newFilter' +},{ + args: [{ + fromBlock: 'latest', + toBlock: 'latest', + address: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855' + }], + formattedArgs: [{ + fromBlock: 'latest', + toBlock: 'latest', + address: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', + topics: [] + }], + result: '0xf', + formattedResult: '0xf', + call: 'eth_newFilter' },{ args: ['pending'], formattedArgs: ['pending'], diff --git a/web3.eth.hashRate.js b/web3.eth.hashRate.js new file mode 100644 index 000000000..ec01bfad1 --- /dev/null +++ b/web3.eth.hashRate.js @@ -0,0 +1,38 @@ +var chai = require('chai'); +var assert = chai.assert; +var web3 = require('../index'); +var FakeHttpProvider = require('./helpers/FakeHttpProvider'); + +var method = 'hashrate'; + +var tests = [{ + result: '0x788a8', + formattedResult: 493736, + call: 'eth_'+ method +}]; + +describe('web3.eth', function () { + describe(method, function () { + tests.forEach(function (test, index) { + it('property test: ' + index, function () { + + // given + var provider = new FakeHttpProvider(); + web3.setProvider(provider); + provider.injectResult(test.result); + provider.injectValidation(function (payload) { + assert.equal(payload.jsonrpc, '2.0'); + assert.equal(payload.method, test.call); + assert.deepEqual(payload.params, []); + }); + + // when + var result = web3.eth[method]; + + // then + assert.strictEqual(test.formattedResult, result); + }); + }); + }); +}); + From af9dbf9520ada4155d654f445bac05612d6fc259 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 11 May 2015 14:26:27 +0200 Subject: [PATCH 37/41] reorganize inout Limits tests From ccc3d56542d76ce19ce994716e8d7afc339e7472 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 11 May 2015 13:47:21 +0200 Subject: [PATCH 38/41] bug in abi. fixed external type for return parameters --- libsolidity/SolidityABIJSON.cpp | 48 ++++++++++++++++++- libsolidity/SolidityNameAndTypeResolution.cpp | 22 +++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/libsolidity/SolidityABIJSON.cpp b/libsolidity/SolidityABIJSON.cpp index 26d0110b8..6c1025d6a 100644 --- a/libsolidity/SolidityABIJSON.cpp +++ b/libsolidity/SolidityABIJSON.cpp @@ -499,7 +499,8 @@ BOOST_AUTO_TEST_CASE(constructor_abi) { char const* sourceCode = R"( contract test { - function test(uint param1, test param2, bool param3) {} + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } + function test(uint param1, test param2, bool param3, ActionChoices param4) {} } )"; @@ -517,6 +518,51 @@ BOOST_AUTO_TEST_CASE(constructor_abi) { "name": "param3", "type": "bool" + }, + { + "name": "param4", + "type": "uint8" + } + ], + "type": "constructor" + } + ])"; + checkInterface(sourceCode, interface); +} + + +BOOST_AUTO_TEST_CASE(return_param_in_abi) +{ + // bug #1801 + char const* sourceCode = R"( + contract test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } + function test(ActionChoices param) {} + function ret() returns(ActionChoices){ + ActionChoices action = ActionChoices.GoLeft; + return action; + } + } + )"; + + char const* interface = R"([ + { + "constant" : false, + "inputs" : [], + "name" : "ret", + "outputs" : [ + { + "name" : "", + "type" : "uint8" + } + ], + "type" : "function" + }, + { + "inputs": [ + { + "name": "param", + "type": "uint8" } ], "type": "constructor" diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp index c317dad97..c59c1f56f 100644 --- a/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/libsolidity/SolidityNameAndTypeResolution.cpp @@ -508,6 +508,28 @@ BOOST_AUTO_TEST_CASE(function_external_types) } } +BOOST_AUTO_TEST_CASE(enum_external_type) +{ + // bug #1801 + ASTPointer sourceUnit; + char const* text = R"( + contract Test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } + function boo(ActionChoices enumArg) external returns (uint ret) { + ret = 5; + } + })"; + ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseTextAndResolveNames(text), "Parsing and name Resolving failed"); + for (ASTPointer const& node: sourceUnit->getNodes()) + if (ContractDefinition* contract = dynamic_cast(node.get())) + { + auto functions = contract->getDefinedFunctions(); + if (functions.empty()) + continue; + BOOST_CHECK_EQUAL("boo(uint8)", functions[0]->externalSignature()); + } +} + BOOST_AUTO_TEST_CASE(function_external_call_allowed_conversion) { char const* text = R"( From 23925040a11a7b4dad3286a9832822cae8baeb95 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 11 May 2015 16:24:04 +0200 Subject: [PATCH 39/41] updated unit test --- libsolidity/SolidityABIJSON.cpp | 55 +++++++++---------- libsolidity/SolidityNameAndTypeResolution.cpp | 2 +- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/libsolidity/SolidityABIJSON.cpp b/libsolidity/SolidityABIJSON.cpp index 6c1025d6a..fe8b791c5 100644 --- a/libsolidity/SolidityABIJSON.cpp +++ b/libsolidity/SolidityABIJSON.cpp @@ -499,8 +499,7 @@ BOOST_AUTO_TEST_CASE(constructor_abi) { char const* sourceCode = R"( contract test { - enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } - function test(uint param1, test param2, bool param3, ActionChoices param4) {} + function test(uint param1, test param2, bool param3) {} } )"; @@ -518,10 +517,6 @@ BOOST_AUTO_TEST_CASE(constructor_abi) { "name": "param3", "type": "bool" - }, - { - "name": "param4", - "type": "uint8" } ], "type": "constructor" @@ -545,29 +540,31 @@ BOOST_AUTO_TEST_CASE(return_param_in_abi) } )"; - char const* interface = R"([ - { - "constant" : false, - "inputs" : [], - "name" : "ret", - "outputs" : [ - { - "name" : "", - "type" : "uint8" - } - ], - "type" : "function" - }, - { - "inputs": [ - { - "name": "param", - "type": "uint8" - } - ], - "type": "constructor" - } - ])"; + char const* interface = R"( + [ + { + "constant" : false, + "inputs" : [], + "name" : "ret", + "outputs" : [ + { + "name" : "", + "type" : "uint8" + } + ], + "type" : "function" + }, + { + "inputs": [ + { + "name": "param", + "type": "uint8" + } + ], + "type": "constructor" + } + ] + )"; checkInterface(sourceCode, interface); } diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp index c59c1f56f..4ec7b8bda 100644 --- a/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/libsolidity/SolidityNameAndTypeResolution.cpp @@ -516,7 +516,7 @@ BOOST_AUTO_TEST_CASE(enum_external_type) contract Test { enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } function boo(ActionChoices enumArg) external returns (uint ret) { - ret = 5; + ret = 5; } })"; ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseTextAndResolveNames(text), "Parsing and name Resolving failed"); From 14b30c87ab7c043028fee1058116b63488d0e128 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 11 May 2015 17:17:50 +0200 Subject: [PATCH 40/41] Update SolidityABIJSON.cpp --- libsolidity/SolidityABIJSON.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsolidity/SolidityABIJSON.cpp b/libsolidity/SolidityABIJSON.cpp index fe8b791c5..f9bf78d0a 100644 --- a/libsolidity/SolidityABIJSON.cpp +++ b/libsolidity/SolidityABIJSON.cpp @@ -546,7 +546,7 @@ BOOST_AUTO_TEST_CASE(return_param_in_abi) "constant" : false, "inputs" : [], "name" : "ret", - "outputs" : [ + "outputs" : [ { "name" : "", "type" : "uint8" From cf23eea716f16ab05e10c8bb63978083a2cbe5a6 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 10 May 2015 18:22:45 +0300 Subject: [PATCH 41/41] Integrate KeyManager.