From a82385d5418bfb9efa59fffe4f47848451501597 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 4 Feb 2015 11:24:10 +0100 Subject: [PATCH 1/6] Squashed 'libjsqrc/ethereumjs/' changes from a0cfa3c..f3e1797 f3e1797 fixed jsonrpc response 0 not handled properly git-subtree-dir: libjsqrc/ethereumjs git-subtree-split: f3e1797153ebf5b19ca3e154cf1240be738e4f08 --- jsonrpc.isValidResponse.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/jsonrpc.isValidResponse.js b/jsonrpc.isValidResponse.js index 2fe200496..920b5f3a9 100644 --- a/jsonrpc.isValidResponse.js +++ b/jsonrpc.isValidResponse.js @@ -124,5 +124,20 @@ describe('jsonrpc', function () { assert.equal(valid, true); }); + it('should validate jsonrpc response with result field === 0', function () { + + // given + var response = { + jsonrpc: '2.0', + id: 1, + result: 0 + }; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, true); + }); }); }); From 9f5d8342a6e89117a0f72e89ecf7f6ed2f7d26b9 Mon Sep 17 00:00:00 2001 From: Lu Guanqun Date: Thu, 5 Feb 2015 00:06:35 +0800 Subject: [PATCH 2/6] add a test case for disorder named args --- SolidityEndToEndTest.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index d0d501677..f248a5a07 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -102,6 +102,16 @@ BOOST_AUTO_TEST_CASE(named_args) BOOST_CHECK(callContractFunction("b()", bytes()) == toBigEndian(u256(123))); } +BOOST_AUTO_TEST_CASE(disorder_named_args) +{ + char const* sourceCode = "contract test {\n" + " function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n" + " function b() returns (uint r) { r = a({c: 3, a: 1, b: 2}); }\n" + "}\n"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("b()", bytes()) == toBigEndian(u256(123))); +} + BOOST_AUTO_TEST_CASE(while_loop) { char const* sourceCode = "contract test {\n" From bade3d98e91fe3e3a20dafba61a975a5638554b7 Mon Sep 17 00:00:00 2001 From: Lu Guanqun Date: Thu, 5 Feb 2015 00:06:54 +0800 Subject: [PATCH 3/6] add two test cases parser error for named args --- SolidityParser.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/SolidityParser.cpp b/SolidityParser.cpp index 4ccdcd57a..9ba38a4a1 100644 --- a/SolidityParser.cpp +++ b/SolidityParser.cpp @@ -124,6 +124,24 @@ BOOST_AUTO_TEST_CASE(single_function_param) BOOST_CHECK_NO_THROW(parseText(text)); } +BOOST_AUTO_TEST_CASE(missing_parameter_name_in_named_args) +{ + char const* text = "contract test {\n" + " function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n" + " function b() returns (uint r) { r = a({: 1, : 2, : 3}); }\n" + "}\n"; + BOOST_CHECK_THROW(parseText(text), ParserError); +} + +BOOST_AUTO_TEST_CASE(missing_argument_in_named_args) +{ + char const* text = "contract test {\n" + " function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n" + " function b() returns (uint r) { r = a({a: , b: , c: }); }\n" + "}\n"; + BOOST_CHECK_THROW(parseText(text), ParserError); +} + BOOST_AUTO_TEST_CASE(function_natspec_documentation) { ASTPointer contract; From 7eece799f2aefa521d0cee7e7773e8c4235a0b1c Mon Sep 17 00:00:00 2001 From: Lu Guanqun Date: Thu, 5 Feb 2015 00:58:20 +0800 Subject: [PATCH 4/6] add several type error test cases --- SolidityNameAndTypeResolution.cpp | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index 1a087592c..ae6c374b4 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -868,6 +868,42 @@ BOOST_AUTO_TEST_CASE(access_to_protected_state_variable) BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); } +BOOST_AUTO_TEST_CASE(error_count_in_named_args) +{ + char const* sourceCode = "contract test {\n" + " function a(uint a, uint b) returns (uint r) { r = a + b; }\n" + " function b() returns (uint r) { r = a({a: 1}); }\n" + "}\n"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + +BOOST_AUTO_TEST_CASE(empty_in_named_args) +{ + char const* sourceCode = "contract test {\n" + " function a(uint a, uint b) returns (uint r) { r = a + b; }\n" + " function b() returns (uint r) { r = a({}); }\n" + "}\n"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + +BOOST_AUTO_TEST_CASE(duplicate_parameter_names_in_named_args) +{ + char const* sourceCode = "contract test {\n" + " function a(uint a, uint b) returns (uint r) { r = a + b; }\n" + " function b() returns (uint r) { r = a({a: 1, a: 2}); }\n" + "}\n"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + +BOOST_AUTO_TEST_CASE(invalid_parameter_names_in_named_args) +{ + char const* sourceCode = "contract test {\n" + " function a(uint a, uint b) returns (uint r) { r = a + b; }\n" + " function b() returns (uint r) { r = a({a: 1, c: 2}); }\n" + "}\n"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + BOOST_AUTO_TEST_SUITE_END() } From 4dc5909072fd87f29716c0429ecdd40eddeedf5a Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 4 Feb 2015 10:29:56 -0800 Subject: [PATCH 5/6] Split canon blockchain and basic blockchain. --- fork.cpp | 2 +- genesis.cpp | 8 ++++---- state.cpp | 2 +- stateOriginal.cpp | 4 ++-- txTest.cpp | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fork.cpp b/fork.cpp index 1cdb8822c..bc6ed87bc 100644 --- a/fork.cpp +++ b/fork.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include "TestHelper.h" using namespace std; diff --git a/genesis.cpp b/genesis.cpp index 8cdb84024..7ca741ee9 100644 --- a/genesis.cpp +++ b/genesis.cpp @@ -24,7 +24,7 @@ #include #include "JsonSpiritHeaders.h" #include -#include +#include #include #include "TestHelper.h" @@ -58,9 +58,9 @@ BOOST_AUTO_TEST_CASE(genesis_tests) js::mObject o = v.get_obj(); - BOOST_CHECK_EQUAL(BlockChain::genesis().stateRoot, h256(o["genesis_state_root"].get_str())); - BOOST_CHECK_EQUAL(toHex(BlockChain::createGenesisBlock()), toHex(fromHex(o["genesis_rlp_hex"].get_str()))); - BOOST_CHECK_EQUAL(BlockInfo::headerHash(BlockChain::createGenesisBlock()), h256(o["genesis_hash"].get_str())); + BOOST_CHECK_EQUAL(CanonBlockChain::genesis().stateRoot, h256(o["genesis_state_root"].get_str())); + BOOST_CHECK_EQUAL(toHex(CanonBlockChain::createGenesisBlock()), toHex(fromHex(o["genesis_rlp_hex"].get_str()))); + BOOST_CHECK_EQUAL(BlockInfo::headerHash(CanonBlockChain::createGenesisBlock()), h256(o["genesis_hash"].get_str())); } BOOST_AUTO_TEST_SUITE_END() diff --git a/state.cpp b/state.cpp index 100634be3..fb54a62ae 100644 --- a/state.cpp +++ b/state.cpp @@ -24,7 +24,7 @@ #include #include "JsonSpiritHeaders.h" #include -#include +#include #include #include #include diff --git a/stateOriginal.cpp b/stateOriginal.cpp index b1a7c0d8e..65ff5084f 100644 --- a/stateOriginal.cpp +++ b/stateOriginal.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include using namespace std; @@ -40,7 +40,7 @@ int stateTest() Defaults::setDBPath(boost::filesystem::temp_directory_path().string()); OverlayDB stateDB = State::openDB(); - BlockChain bc; + CanonBlockChain bc; State s(myMiner.address(), stateDB); cout << bc; diff --git a/txTest.cpp b/txTest.cpp index cc78c26a2..8d067f9bb 100644 --- a/txTest.cpp +++ b/txTest.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include "TestHelper.h" using namespace std; From 969366f46b83c57461fc5399fff76bd07738b6f2 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 4 Feb 2015 11:26:58 -0800 Subject: [PATCH 6/6] Move CommonJS to libethcore. Split it up ready for refactoring into libdevcore/libdevcrypto. --- commonjs.cpp | 5 +++-- jsonrpc.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/commonjs.cpp b/commonjs.cpp index 860b713dd..041a14f68 100644 --- a/commonjs.cpp +++ b/commonjs.cpp @@ -20,7 +20,8 @@ */ #include -#include +#include +#include BOOST_AUTO_TEST_SUITE(commonjs) using namespace std; @@ -41,7 +42,7 @@ BOOST_AUTO_TEST_CASE(jsToAddress) cnote << "Testing jsToPublic..."; KeyPair kp = KeyPair::create(); string string = toJS(kp.address()); - Address address = dev::jsToAddress(string); + Address address = dev::eth::jsToAddress(string); BOOST_CHECK_EQUAL(kp.address(), address); } diff --git a/jsonrpc.cpp b/jsonrpc.cpp index 1f0a466b2..eaa9edc45 100644 --- a/jsonrpc.cpp +++ b/jsonrpc.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include