From ed2b4cff41a23e81e706c47b0187a18f5c7ea8d2 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 19 Jan 2015 11:02:13 +0100 Subject: [PATCH 01/13] test with sha3 and gas = 2**32 --- vmSha3TestFiller.json | 86 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/vmSha3TestFiller.json b/vmSha3TestFiller.json index 7ed729520..d594d4fe9 100644 --- a/vmSha3TestFiller.json +++ b/vmSha3TestFiller.json @@ -193,5 +193,89 @@ "gasPrice" : "100000000000000", "gas" : "10000" } - } + }, + + "sha3_bigSize": { + "env" : { + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", + "currentNumber" : "0", + "currentGasLimit" : "1000000", + "currentDifficulty" : "256", + "currentTimestamp" : 1, + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "nonce" : 0, + "code" : "{ [[ 0 ]] (SHA3 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)}", + "storage": {} + } + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "data" : "", + "gasPrice" : "1", + "gas" : "0x10000000000" + } + }, + + "sha3_bigOffset": { + "env" : { + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", + "currentNumber" : "0", + "currentGasLimit" : "1000000", + "currentDifficulty" : "256", + "currentTimestamp" : 1, + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "nonce" : 0, + "code" : "{ [[ 0 ]] (SHA3 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 2)}", + "storage": {} + } + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "data" : "", + "gasPrice" : "1", + "gas" : "0x10000000000" + } + }, + + "sha3_bigOffset2": { + "env" : { + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", + "currentNumber" : "0", + "currentGasLimit" : "1000000", + "currentDifficulty" : "256", + "currentTimestamp" : 1, + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "nonce" : 0, + "code" : "{ [[ 0 ]] (SHA3 0x100000000 2)}", + "storage": {} + } + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "data" : "", + "gasPrice" : "1", + "gas" : "0x10000000000" + } + } } From cbfd094a17212da0d81d10b99416e240c5e7c625 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 3 Feb 2015 01:25:41 +0100 Subject: [PATCH 02/13] add refundoverflow test --- stRefundTestFiller.json | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/stRefundTestFiller.json b/stRefundTestFiller.json index 6b2b2fc15..6749fd3dd 100644 --- a/stRefundTestFiller.json +++ b/stRefundTestFiller.json @@ -303,6 +303,34 @@ "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", "data" : "" } - } + }, + "RefundOverflow" : { + "env" : { + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "45678256", + "currentGasLimit" : "115792089237316195423570985008687907853269984665640564039457584007913129639935", + "currentNumber" : "0", + "currentTimestamp" : 1, + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "400", + "code" : "0x", + "nonce" : "0", + "storage" : { + } + } + }, + "transaction" : { + "data" : "", + "gasLimit" : "5789604461865809771178549250434395392663499233282028201972879200395656482016", + "gasPrice" : "20", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "value" : "" + } + } } From 19c92ee1d2d488179daec6bfdd5ed48764e2c19e Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Wed, 4 Feb 2015 22:02:35 +0100 Subject: [PATCH 03/13] Tests for ether subdenominations. Work in progress --- SolidityExpressionCompiler.cpp | 33 ++++++++++++++++++++++++++++++++- SolidityParser.cpp | 19 +++++++++++++++++++ SolidityScanner.cpp | 9 +++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/SolidityExpressionCompiler.cpp b/SolidityExpressionCompiler.cpp index a0cca3a3a..71f40bd25 100644 --- a/SolidityExpressionCompiler.cpp +++ b/SolidityExpressionCompiler.cpp @@ -91,7 +91,16 @@ bytes compileFirstExpression(const string& _sourceCode, vector> _ { Parser parser; ASTPointer sourceUnit; - BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared(CharStream(_sourceCode)))); + try + { + sourceUnit = parser.parse(make_shared(CharStream(_sourceCode))); + } + catch(boost::exception const& _e) + { + auto msg = std::string("Parsing source code failed with: \n") + boost::diagnostic_information(_e); + BOOST_FAIL(msg); + } + // BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared(CharStream(_sourceCode)))); vector declarations; declarations.reserve(_globalDeclarations.size() + 1); @@ -177,6 +186,28 @@ BOOST_AUTO_TEST_CASE(int_literal) BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); } +BOOST_AUTO_TEST_CASE(int_literals_with_ether_subdenominations) +{ + char const* sourceCode = R"( + contract c { + function c () + { + a = 1 wei; + // b = 2 szabo; + // c = 3 finney; +// b = 4 ether; + } + uint256 a; + uint256 b; + uint256 c; + uint256 d; + })"; + bytes code = compileFirstExpression(sourceCode); + + bytes expectation({byte(eth::Instruction::PUSH5), 0x38, 0xd4, 0xa5, 0x10, 0x00}); + BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); +} + BOOST_AUTO_TEST_CASE(comparison) { char const* sourceCode = "contract test {\n" diff --git a/SolidityParser.cpp b/SolidityParser.cpp index 9ba38a4a1..b6837866c 100644 --- a/SolidityParser.cpp +++ b/SolidityParser.cpp @@ -660,6 +660,25 @@ BOOST_AUTO_TEST_CASE(multiple_visibility_specifiers) BOOST_CHECK_THROW(parseText(text), ParserError); } +BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations) +{ + char const* text = R"( + contract c { + function c () + { + a = 1 wei; + b = 2 szabo; + c = 3 finney; + b = 4 ether; + } + uint256 a; + uint256 b; + uint256 c; + uint256 d; + })"; + BOOST_CHECK_NO_THROW(parseTextExplainError(text)); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/SolidityScanner.cpp b/SolidityScanner.cpp index 7dc9ef482..5bd897ab4 100644 --- a/SolidityScanner.cpp +++ b/SolidityScanner.cpp @@ -255,6 +255,15 @@ BOOST_AUTO_TEST_CASE(comments_mixed_in_sequence) BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "documentation comment "); } +BOOST_AUTO_TEST_CASE(ether_subdenominations) +{ + Scanner scanner(CharStream("wei szabo finney ether")); + BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::ETH_SUB_WEI); + BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_SZABO); + BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_FINNEY); + BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_ETHER); +} + BOOST_AUTO_TEST_SUITE_END() } From 5b8deb986605e6b6adfc6cc3bce5d38455e113e3 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 5 Feb 2015 13:48:02 +0100 Subject: [PATCH 04/13] Tests and fixes for ether subdenominations --- SolidityExpressionCompiler.cpp | 63 +++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/SolidityExpressionCompiler.cpp b/SolidityExpressionCompiler.cpp index 71f40bd25..3c3ea1baa 100644 --- a/SolidityExpressionCompiler.cpp +++ b/SolidityExpressionCompiler.cpp @@ -100,7 +100,6 @@ bytes compileFirstExpression(const string& _sourceCode, vector> _ auto msg = std::string("Parsing source code failed with: \n") + boost::diagnostic_information(_e); BOOST_FAIL(msg); } - // BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared(CharStream(_sourceCode)))); vector declarations; declarations.reserve(_globalDeclarations.size() + 1); @@ -186,25 +185,63 @@ BOOST_AUTO_TEST_CASE(int_literal) BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); } -BOOST_AUTO_TEST_CASE(int_literals_with_ether_subdenominations) +BOOST_AUTO_TEST_CASE(int_with_wei_ether_subdenomination) { char const* sourceCode = R"( - contract c { - function c () + contract test { + function test () { - a = 1 wei; - // b = 2 szabo; - // c = 3 finney; -// b = 4 ether; + var x = 1 wei; } - uint256 a; - uint256 b; - uint256 c; - uint256 d; })"; bytes code = compileFirstExpression(sourceCode); - bytes expectation({byte(eth::Instruction::PUSH5), 0x38, 0xd4, 0xa5, 0x10, 0x00}); + bytes expectation({byte(eth::Instruction::PUSH1), 0x1}); + BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); +} + +BOOST_AUTO_TEST_CASE(int_with_szabo_ether_subdenomination) +{ + char const* sourceCode = R"( + contract test { + function test () + { + var x = 1 szabo; + } + })"; + bytes code = compileFirstExpression(sourceCode); + + bytes expectation({byte(eth::Instruction::PUSH5), 0xe8, 0xd4, 0xa5, 0x10, 0x00}); + BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); +} + +BOOST_AUTO_TEST_CASE(int_with_finney_ether_subdenomination) +{ + char const* sourceCode = R"( + contract test { + function test () + { + var x = 1 finney; + } + })"; + bytes code = compileFirstExpression(sourceCode); + + bytes expectation({byte(eth::Instruction::PUSH7), 0x3, 0x8d, 0x7e, 0xa4, 0xc6, 0x80, 0x00}); + BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); +} + +BOOST_AUTO_TEST_CASE(int_with_ether_ether_subdenomination) +{ + char const* sourceCode = R"( + contract test { + function test () + { + var x = 1 ether; + } + })"; + bytes code = compileFirstExpression(sourceCode); + + bytes expectation({byte(eth::Instruction::PUSH8), 0xd, 0xe0, 0xb6, 0xb3, 0xa7, 0x64, 0x00, 0x00}); BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); } From d3dd2972c169eb368be43d77a2db7c2540e5a3ce Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 5 Feb 2015 15:45:13 +0100 Subject: [PATCH 05/13] separated libnatspec --- CMakeLists.txt | 1 + natspec.cpp | 124 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 natspec.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 764bf928e..36876eea6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ target_link_libraries(testeth ethcore) target_link_libraries(testeth secp256k1) target_link_libraries(testeth solidity) target_link_libraries(testeth webthree) +target_link_libraries(testeth natspec) if (JSONRPC) target_link_libraries(testeth web3jsonrpc) diff --git a/natspec.cpp b/natspec.cpp new file mode 100644 index 000000000..9ce8e39c6 --- /dev/null +++ b/natspec.cpp @@ -0,0 +1,124 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . + */ +/** @file natspec.cpp + * @author Marek Kotewicz + * @date 2015 + */ + +#include +#include +#include + +using namespace std; + +BOOST_AUTO_TEST_SUITE(natspec) + +BOOST_AUTO_TEST_CASE(natspec_eval_function_exists) +{ + cnote << "testing existance of evaluateExpression function"; + + // given + NatspecExpressionEvaluator e; + + // when + string result = e.evalExpression("`typeof evaluateExpression`").toStdString(); + + // then + BOOST_CHECK_EQUAL(result, "function"); +} + +BOOST_AUTO_TEST_CASE(natspec_js_eval) +{ + cnote << "testing natspec basic eval"; + + // given + NatspecExpressionEvaluator e; + + // when + string result = e.evalExpression("`1 + 2`").toStdString(); + + // then + BOOST_CHECK_EQUAL(result, "3"); +} + +BOOST_AUTO_TEST_CASE(natspec_create_custom_function) +{ + cnote << "testing creation and usage of custom js function"; + + // given + NatspecExpressionEvaluator e; + + + // when + auto x = e.evalExpression("`test = function (x) { return x + 'ok'; }`"); // ommit var, make it global + string result = e.evalExpression("`test(5)`").toStdString(); + string result2 = e.evalExpression("`typeof test`").toStdString(); + + // then + BOOST_CHECK_EQUAL(result, "5ok"); + BOOST_CHECK_EQUAL(result2, "function"); +} + +BOOST_AUTO_TEST_CASE(natspec_js_eval_separated_expressions) +{ + cnote << "testing natspec evaluation of separated expresioons"; + + // given + NatspecExpressionEvaluator e; + + // when + string result = e.evalExpression("`x = 1` + `y = 2` will be equal `x + y`").toStdString(); + + // then + BOOST_CHECK_EQUAL(result, "1 + 2 will be equal 3"); +} + +BOOST_AUTO_TEST_CASE(natspec_js_eval_input_params) +{ + cnote << "testing natspec evaluation of input params"; + + // given + char const* abi = R"([ + { + "name": "f", + "constant": false, + "type": "function", + "inputs": [ + { + "name": "a", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "d", + "type": "uint256" + } + ] + } + ])"; + + NatspecExpressionEvaluator e(abi, "'f'", "[4]"); + + // when + string result = e.evalExpression("Will multiply `a` by 7 and return `a * 7`.").toStdString(); + + // then + BOOST_CHECK_EQUAL(result, "Will multiply 4 by 7 and return 28."); +} + +BOOST_AUTO_TEST_SUITE_END() From 1954c0686d05c26e98c3da2cc009f93c3a6f8af2 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 5 Feb 2015 18:45:37 +0100 Subject: [PATCH 06/13] fixed natspec evaluator result on error --- natspec.cpp | 51 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/natspec.cpp b/natspec.cpp index 9ce8e39c6..73e70fc59 100644 --- a/natspec.cpp +++ b/natspec.cpp @@ -1,16 +1,16 @@ /* This file is part of cpp-ethereum. - + cpp-ethereum is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + cpp-ethereum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with cpp-ethereum. If not, see . */ @@ -30,13 +30,13 @@ BOOST_AUTO_TEST_SUITE(natspec) BOOST_AUTO_TEST_CASE(natspec_eval_function_exists) { cnote << "testing existance of evaluateExpression function"; - + // given NatspecExpressionEvaluator e; - + // when string result = e.evalExpression("`typeof evaluateExpression`").toStdString(); - + // then BOOST_CHECK_EQUAL(result, "function"); } @@ -44,13 +44,13 @@ BOOST_AUTO_TEST_CASE(natspec_eval_function_exists) BOOST_AUTO_TEST_CASE(natspec_js_eval) { cnote << "testing natspec basic eval"; - + // given NatspecExpressionEvaluator e; - + // when string result = e.evalExpression("`1 + 2`").toStdString(); - + // then BOOST_CHECK_EQUAL(result, "3"); } @@ -58,16 +58,15 @@ BOOST_AUTO_TEST_CASE(natspec_js_eval) BOOST_AUTO_TEST_CASE(natspec_create_custom_function) { cnote << "testing creation and usage of custom js function"; - + // given NatspecExpressionEvaluator e; - - + // when auto x = e.evalExpression("`test = function (x) { return x + 'ok'; }`"); // ommit var, make it global string result = e.evalExpression("`test(5)`").toStdString(); string result2 = e.evalExpression("`typeof test`").toStdString(); - + // then BOOST_CHECK_EQUAL(result, "5ok"); BOOST_CHECK_EQUAL(result2, "function"); @@ -76,13 +75,13 @@ BOOST_AUTO_TEST_CASE(natspec_create_custom_function) BOOST_AUTO_TEST_CASE(natspec_js_eval_separated_expressions) { cnote << "testing natspec evaluation of separated expresioons"; - + // given NatspecExpressionEvaluator e; - + // when string result = e.evalExpression("`x = 1` + `y = 2` will be equal `x + y`").toStdString(); - + // then BOOST_CHECK_EQUAL(result, "1 + 2 will be equal 3"); } @@ -90,7 +89,7 @@ BOOST_AUTO_TEST_CASE(natspec_js_eval_separated_expressions) BOOST_AUTO_TEST_CASE(natspec_js_eval_input_params) { cnote << "testing natspec evaluation of input params"; - + // given char const* abi = R"([ { @@ -111,9 +110,9 @@ BOOST_AUTO_TEST_CASE(natspec_js_eval_input_params) ] } ])"; - + NatspecExpressionEvaluator e(abi, "'f'", "[4]"); - + // when string result = e.evalExpression("Will multiply `a` by 7 and return `a * 7`.").toStdString(); @@ -121,4 +120,18 @@ BOOST_AUTO_TEST_CASE(natspec_js_eval_input_params) BOOST_CHECK_EQUAL(result, "Will multiply 4 by 7 and return 28."); } +BOOST_AUTO_TEST_CASE(natspec_js_eval_error) +{ + cnote << "testing natspec evaluation of incorrect input"; + + // given + NatspecExpressionEvaluator e; + + // when + string result = e.evalExpression("`test(`").toStdString(); + + // then + BOOST_CHECK_EQUAL(result, "`test(`"); +} + BOOST_AUTO_TEST_SUITE_END() From fb55f4f24dc1fee6e35e828ba0454c328d14f7ca Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 5 Feb 2015 22:38:07 +0100 Subject: [PATCH 07/13] Minor Style fixes --- SolidityScanner.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SolidityScanner.cpp b/SolidityScanner.cpp index 5bd897ab4..8088b4d4b 100644 --- a/SolidityScanner.cpp +++ b/SolidityScanner.cpp @@ -258,10 +258,10 @@ BOOST_AUTO_TEST_CASE(comments_mixed_in_sequence) BOOST_AUTO_TEST_CASE(ether_subdenominations) { Scanner scanner(CharStream("wei szabo finney ether")); - BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::ETH_SUB_WEI); - BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_SZABO); - BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_FINNEY); - BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_ETHER); + BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::SubWei); + BOOST_CHECK_EQUAL(scanner.next(), Token::SubSzabo); + BOOST_CHECK_EQUAL(scanner.next(), Token::SubFinney); + BOOST_CHECK_EQUAL(scanner.next(), Token::SubEther); } BOOST_AUTO_TEST_SUITE_END() From 630681094e84f46f54660dc5895fb4576865077f Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Thu, 5 Feb 2015 22:42:17 +0100 Subject: [PATCH 08/13] test block gas limit --- stTransactionTestFiller.json | 64 +++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/stTransactionTestFiller.json b/stTransactionTestFiller.json index cd42af795..a5092b60b 100644 --- a/stTransactionTestFiller.json +++ b/stTransactionTestFiller.json @@ -169,7 +169,7 @@ }, "pre" : { - "b94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { "balance" : "1000", "code" : "", "nonce" : "0", @@ -189,6 +189,68 @@ } }, + "TransactionFromCoinbaseHittingBlockGasLimit" : { + "env" : { + "currentCoinbase" : "a94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "currentDifficulty" : "45678256", + "currentGasLimit" : "1100", + "currentNumber" : "0", + "currentTimestamp" : 1, + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "pre" : + { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "1000000", + "code" : "", + "nonce" : "0", + "storage" : { + } + } + }, + "transaction" : + { + "data" : "", + "gasLimit" : "1100", + "gasPrice" : "1", + "nonce" : "", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "value" : "10" + } + }, + + "TransactionFromCoinbaseHittingBlockGasLimit1" : { + "env" : { + "currentCoinbase" : "a94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "currentDifficulty" : "45678256", + "currentGasLimit" : "1100", + "currentNumber" : "0", + "currentTimestamp" : 1, + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "pre" : + { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "100000", + "code" : "", + "nonce" : "0", + "storage" : { + } + } + }, + "transaction" : + { + "data" : "", + "gasLimit" : "1101", + "gasPrice" : "1", + "nonce" : "", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "value" : "10" + } + }, + "ContractStoreClearsSuccess" : { "env" : { "currentCoinbase" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b", From bd41622341b7dd4acbe7dcbf56b77bbcd751bc2f Mon Sep 17 00:00:00 2001 From: Lu Guanqun Date: Fri, 6 Feb 2015 07:44:38 +0800 Subject: [PATCH 09/13] disallow declaration of void type https://www.pivotaltracker.com/n/projects/1189488/stories/86318578 --- SolidityNameAndTypeResolution.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index ae6c374b4..742d2ee2a 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -904,6 +904,12 @@ BOOST_AUTO_TEST_CASE(invalid_parameter_names_in_named_args) BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); } +BOOST_AUTO_TEST_CASE(disallow_declaration_of_void_type) +{ + char const* sourceCode = "contract c { function f() { var x = f(); } }"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + BOOST_AUTO_TEST_SUITE_END() } From aea7de95565260c9f09c65007ea5e9629080b566 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Fri, 6 Feb 2015 13:38:28 +0100 Subject: [PATCH 10/13] removed output messages in tests && spaces --- natspec.cpp | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/natspec.cpp b/natspec.cpp index 73e70fc59..827f96625 100644 --- a/natspec.cpp +++ b/natspec.cpp @@ -29,44 +29,32 @@ BOOST_AUTO_TEST_SUITE(natspec) BOOST_AUTO_TEST_CASE(natspec_eval_function_exists) { - cnote << "testing existance of evaluateExpression function"; - // given NatspecExpressionEvaluator e; - // when string result = e.evalExpression("`typeof evaluateExpression`").toStdString(); - // then BOOST_CHECK_EQUAL(result, "function"); } BOOST_AUTO_TEST_CASE(natspec_js_eval) { - cnote << "testing natspec basic eval"; - // given NatspecExpressionEvaluator e; - // when string result = e.evalExpression("`1 + 2`").toStdString(); - // then BOOST_CHECK_EQUAL(result, "3"); } BOOST_AUTO_TEST_CASE(natspec_create_custom_function) { - cnote << "testing creation and usage of custom js function"; - // given NatspecExpressionEvaluator e; - // when auto x = e.evalExpression("`test = function (x) { return x + 'ok'; }`"); // ommit var, make it global string result = e.evalExpression("`test(5)`").toStdString(); string result2 = e.evalExpression("`typeof test`").toStdString(); - // then BOOST_CHECK_EQUAL(result, "5ok"); BOOST_CHECK_EQUAL(result2, "function"); @@ -74,22 +62,16 @@ BOOST_AUTO_TEST_CASE(natspec_create_custom_function) BOOST_AUTO_TEST_CASE(natspec_js_eval_separated_expressions) { - cnote << "testing natspec evaluation of separated expresioons"; - // given NatspecExpressionEvaluator e; - // when string result = e.evalExpression("`x = 1` + `y = 2` will be equal `x + y`").toStdString(); - // then BOOST_CHECK_EQUAL(result, "1 + 2 will be equal 3"); } BOOST_AUTO_TEST_CASE(natspec_js_eval_input_params) { - cnote << "testing natspec evaluation of input params"; - // given char const* abi = R"([ { @@ -110,26 +92,19 @@ BOOST_AUTO_TEST_CASE(natspec_js_eval_input_params) ] } ])"; - NatspecExpressionEvaluator e(abi, "'f'", "[4]"); - // when string result = e.evalExpression("Will multiply `a` by 7 and return `a * 7`.").toStdString(); - // then BOOST_CHECK_EQUAL(result, "Will multiply 4 by 7 and return 28."); } BOOST_AUTO_TEST_CASE(natspec_js_eval_error) { - cnote << "testing natspec evaluation of incorrect input"; - // given NatspecExpressionEvaluator e; - // when string result = e.evalExpression("`test(`").toStdString(); - // then BOOST_CHECK_EQUAL(result, "`test(`"); } From 5bedf7f81612767f2f60ea57a1c38c34973465ec Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 6 Feb 2015 13:38:10 +0100 Subject: [PATCH 11/13] Some fixes for the ether units parser. --- SolidityNameAndTypeResolution.cpp | 22 ++++++++++++++++++++++ SolidityParser.cpp | 13 +++++++++++++ 2 files changed, 35 insertions(+) diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index 742d2ee2a..05ce6ed66 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -910,6 +910,28 @@ BOOST_AUTO_TEST_CASE(disallow_declaration_of_void_type) BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); } +BOOST_AUTO_TEST_CASE(overflow_caused_by_ether_units) +{ + char const* sourceCodeFine = R"( + contract c { + function c () + { + a = 115792089237316195423570985008687907853269984665640564039458; + } + uint256 a; + })"; + BOOST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCodeFine)); + char const* sourceCode = R"( + contract c { + function c () + { + a = 115792089237316195423570985008687907853269984665640564039458 ether; + } + uint256 a; + })"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/SolidityParser.cpp b/SolidityParser.cpp index b6837866c..7af99567b 100644 --- a/SolidityParser.cpp +++ b/SolidityParser.cpp @@ -679,6 +679,19 @@ BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations) BOOST_CHECK_NO_THROW(parseTextExplainError(text)); } +BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations_in_expressions) +{ + char const* text = R"( + contract c { + function c () + { + a = 1 wei * 100 wei + 7 szabo - 3; + } + uint256 a; + })"; + BOOST_CHECK_NO_THROW(parseTextExplainError(text)); +} + BOOST_AUTO_TEST_SUITE_END() } From 6b803670103018d08f3d4cf6c9a4d27e21964582 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 6 Feb 2015 15:40:07 +0100 Subject: [PATCH 12/13] failing tests from random simulation as state tests and transaction tests --- stSystemOperationsTestFiller.json | 70 +++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/stSystemOperationsTestFiller.json b/stSystemOperationsTestFiller.json index 253ba0a8a..6a4b83e34 100644 --- a/stSystemOperationsTestFiller.json +++ b/stSystemOperationsTestFiller.json @@ -33,6 +33,76 @@ } }, + "testRandomTest": { + "env" : { + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "115792089237316195423570985008687907853269984665640564039457584007913129639935", + "currentGasLimit" : "1000000", + "currentNumber" : "300", + "currentTimestamp" : "2", + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "code" : "0x424443444243434383f0155af055", + "nonce" : "0", + "storage" : { + } + }, + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "1000000000000000000", + "code" : "0x", + "nonce" : "0", + "storage" : { + } + } + }, + "transaction" : { + "data" : "", + "gasLimit" : "10000", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "value" : "100000" + } + }, + + "createWithInvalidOpcode": { + "env" : { + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "115792089237316195423570985008687907853269984665640564039457584007913129639935", + "currentGasLimit" : "1000000", + "currentNumber" : "300", + "currentTimestamp" : "2", + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "pre" : { + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "1000000000000000000", + "nonce" : 0, + "code" : "0x444242424245434253f0", + "storage": {} + }, + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "1000000000000000000", + "nonce" : 0, + "code" : "", + "storage": {} + } + }, + "transaction" : { + "nonce" : "0", + "gasPrice" : "1", + "gasLimit" : "10000", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "100000", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "data" : "" + } + }, + "createNameRegistratorOOG_MemExpansionInsufficientBalance": { "env" : { "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", From d78e171ef44db2cfa141ca1c4b3873b2d6d84cf5 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 6 Feb 2015 17:37:56 +0100 Subject: [PATCH 13/13] sha3 performance test --- vmSha3TestFiller.json | 50 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/vmSha3TestFiller.json b/vmSha3TestFiller.json index d594d4fe9..851b7aab9 100644 --- a/vmSha3TestFiller.json +++ b/vmSha3TestFiller.json @@ -251,31 +251,31 @@ } }, - "sha3_bigOffset2": { - "env" : { - "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", - "currentNumber" : "0", - "currentGasLimit" : "1000000", - "currentDifficulty" : "256", - "currentTimestamp" : 1, - "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" - }, - "pre" : { - "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { - "balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "nonce" : 0, - "code" : "{ [[ 0 ]] (SHA3 0x100000000 2)}", - "storage": {} - } - }, - "exec" : { - "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", - "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", - "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", - "value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "data" : "", - "gasPrice" : "1", - "gas" : "0x10000000000" + "sha3_bigOffset2": { + "env" : { + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", + "currentNumber" : "0", + "currentGasLimit" : "1000000", + "currentDifficulty" : "256", + "currentTimestamp" : 1, + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "nonce" : 0, + "code" : "{ [[ 0 ]] (SHA3 0x1000000 2)}", + "storage": {} } + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "data" : "", + "gasPrice" : "1", + "gas" : "0x100000000" } + } }