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/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp
index f248a5a07..301cc06ef 100644
--- a/SolidityEndToEndTest.cpp
+++ b/SolidityEndToEndTest.cpp
@@ -959,6 +959,24 @@ BOOST_AUTO_TEST_CASE(complex_accessors)
BOOST_CHECK(callContractFunction("to_multiple_map(uint256,uint256)", 42, 23) == encodeArgs(31));
}
+BOOST_AUTO_TEST_CASE(struct_accessor)
+{
+ char const* sourceCode = R"(
+ contract test {
+ struct Data { uint a; uint8 b; mapping(uint => uint) c; bool d; }
+ mapping(uint => Data) public data;
+ function test() {
+ data[7].a = 1;
+ data[7].b = 2;
+ data[7].c[0] = 3;
+ data[7].d = true;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("data(uint256)", 7) == encodeArgs(1, 2, true));
+}
+
BOOST_AUTO_TEST_CASE(balance)
{
char const* sourceCode = "contract test {\n"
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()
}
diff --git a/natspec.cpp b/natspec.cpp
new file mode 100644
index 000000000..827f96625
--- /dev/null
+++ b/natspec.cpp
@@ -0,0 +1,112 @@
+/*
+ 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)
+{
+ // given
+ NatspecExpressionEvaluator e;
+ // when
+ string result = e.evalExpression("`typeof evaluateExpression`").toStdString();
+ // then
+ BOOST_CHECK_EQUAL(result, "function");
+}
+
+BOOST_AUTO_TEST_CASE(natspec_js_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)
+{
+ // 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)
+{
+ // 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)
+{
+ // 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_CASE(natspec_js_eval_error)
+{
+ // given
+ NatspecExpressionEvaluator e;
+ // when
+ string result = e.evalExpression("`test(`").toStdString();
+ // then
+ BOOST_CHECK_EQUAL(result, "`test(`");
+}
+
+BOOST_AUTO_TEST_SUITE_END()
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" : ""
+ }
+ }
}
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",
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",
diff --git a/vmSha3TestFiller.json b/vmSha3TestFiller.json
index 7ed729520..851b7aab9 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 0x1000000 2)}",
+ "storage": {}
+ }
+ },
+ "exec" : {
+ "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
+ "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+ "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+ "value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+ "data" : "",
+ "gasPrice" : "1",
+ "gas" : "0x100000000"
+ }
}
}