From f18c2aa378fd60a977649480bb3cd9fa80e77ddc Mon Sep 17 00:00:00 2001 From: winsvega Date: Thu, 12 Feb 2015 22:26:10 +0300 Subject: [PATCH 01/11] New Tests Solidity test Transaction test update --- test/stSolidityTestFiller.json | 237 ++++++++++++++++++++++++++++++ test/state.cpp | 5 + test/ttTransactionTestFiller.json | 70 ++++++--- 3 files changed, 292 insertions(+), 20 deletions(-) create mode 100644 test/stSolidityTestFiller.json diff --git a/test/stSolidityTestFiller.json b/test/stSolidityTestFiller.json new file mode 100644 index 000000000..fc0770c5e --- /dev/null +++ b/test/stSolidityTestFiller.json @@ -0,0 +1,237 @@ +{ + "SolidityTest" : { + "env" : { + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "45678256", + "currentGasLimit" : "1000000000000000000000", + "currentNumber" : "120", + "currentTimestamp" : 1, + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "pre" : + { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000000000", + "code" : "", + "nonce" : "0", + "storage" : { + } + }, + + "d94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "100000", + "//" : " ", + "//" : "contract TestContract ", + "//" : "{ ", + "//" : " function testMethod() returns (int res) ", + "//" : " { ", + "//" : " return 225; ", + "//" : " } ", + "//" : " ", + "//" : " function destroy(address sendFoundsTo) ", + "//" : " { ", + "//" : " suicide(sendFoundsTo); ", + "//" : " } ", + "//" : "} ", + "//" : " ", + "//" : "contract TestSolidityContracts ", + "//" : "{ ", + "//" : "struct StructTest ", + "//" : " { ", + "//" : " address addr; ", + "//" : " int amount; ", + "//" : " string32 str; ", + "//" : " mapping (uint => address) funders; ", + "//" : " } ", + "//" : " ", + "//" : " int globalValue; ", + "//" : " StructTest globalData; ", + "//" : " function runSolidityTests() returns (hash res) ", + "//" : " { ", + "//" : " //res is a mask of failing tests given the first byte is first test ", + "//" : " res = 0x0000000000000000000000000000000000000000000000000000000000000000; ", + "//" : " ", + "//" : " createContractFromMethod(); ", + "//" : " ", + "//" : " if (!testKeywords()) ", + "//" : " res = hash(int(res) + int(0xf000000000000000000000000000000000000000000000000000000000000000)); ", + "//" : " ", + "//" : " if (!testContractInteraction()) ", + "//" : " res = hash(int(res) + int(0x0f00000000000000000000000000000000000000000000000000000000000000)); ", + "//" : " ", + "//" : " if (!testContractSuicide()) ", + "//" : " res = hash(int(res) + int(0x00f0000000000000000000000000000000000000000000000000000000000000)); ", + "//" : " ", + "//" : " if (!testBlockAndTransactionProperties()) ", + "//" : " res = hash(int(res) + int(0x000f000000000000000000000000000000000000000000000000000000000000)); ", + "//" : " ", + "//" : " globalValue = 255; ", + "//" : " globalData.addr = 0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b; ", + "//" : " globalData.amount = 255; ", + "//" : " globalData.str = 'global data 32 length string'; ", + "//" : " globalData.funders[0] = 0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b; ", + "//" : " if (!testStructuresAndVariabless()) ", + "//" : " res = hash(int(res) + int(0x0000f00000000000000000000000000000000000000000000000000000000000)); ", + "//" : " ", + "//" : " //Tested 27.01.2015 ", + "//" : " //should run out of gas ", + "//" : " //if (!testInfiniteLoop()) ", + "//" : " // res = hash(int(res) + int(0x000f000000000000000000000000000000000000000000000000000000000000)); ", + "//" : " // ", + "//" : " //should run out of gas ", + "//" : " //if (!testRecursiveMethods()) ", + "//" : " // res = hash(int(res) + int(0x0000000000000000000000000000000000000000000000000000000000000000)); ", + "//" : " } ", + "//" : " ", + "//" : " function testStructuresAndVariabless() returns (bool res) ", + "//" : " { ", + "//" : " res = true; ", + "//" : " if (globalValue != 255) ", + "//" : " return false; ", + "//" : " ", + "//" : " if (globalValue != globalData.amount) ", + "//" : " return false; ", + "//" : " ", + "//" : " if (globalData.addr != 0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b) ", + "//" : " return false; ", + "//" : " ", + "//" : " if (globalData.str != 'global data 32 length string') ", + "//" : " return false; ", + "//" : " ", + "//" : " if (globalData.funders[0] != 0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b) ", + "//" : " return false; ", + "//" : " } ", + "//" : " ", + "//" : " function testBlockAndTransactionProperties() returns (bool res) ", + "//" : " { ", + "//" : " res = true; ", + "//" : " if (block.coinbase != 0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba) ", + "//" : " return false; ", + "//" : " ", + "//" : " if (block.difficulty != 45678256) ", + "//" : " return false; ", + "//" : " ", + "//" : " //for some reason does not work 27.01.2015 ", + "//" : " //if (block.gaslimit != 1000000000000000000000) ", + "//" : " // return false; ", + "//" : " ", + "//" : " if (block.number != 120) ", + "//" : " return false; ", + "//" : " ", + "//" : " //try to call this ", + "//" : " block.blockhash(120); ", + "//" : " block.timestamp; ", + "//" : " msg.gas; ", + "//" : " ", + "//" : " if (msg.sender != 0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b) ", + "//" : " return false; ", + "//" : " ", + "//" : " if (msg.value != 100) ", + "//" : " return false; ", + "//" : " ", + "//" : " if (tx.gasprice != 1) ", + "//" : " return false; ", + "//" : " ", + "//" : " if (tx.origin != 0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b) ", + "//" : " return false; ", + "//" : " ", + "//" : " } ", + "//" : " ", + "//" : " function testInfiniteLoop() returns (bool res) ", + "//" : " { ", + "//" : " res = false; ", + "//" : " while(true){} ", + "//" : " return true; ", + "//" : " } ", + "//" : " ", + "//" : " function testRecursiveMethods() returns (bool res) ", + "//" : " { ", + "//" : " res = false; ", + "//" : " testRecursiveMethods2(); ", + "//" : " return true; ", + "//" : " } ", + "//" : " function testRecursiveMethods2() ", + "//" : " { ", + "//" : " testRecursiveMethods(); ", + "//" : "} ", + "//" : " ", + "//" : " ", + "//" : " function testContractSuicide() returns (bool res) ", + "//" : " { ", + "//" : " TestContract a = new TestContract(); ", + "//" : " a.destroy(block.coinbase); ", + "//" : " if (a.testMethod() == 225) //we should be able to call a contract ", + "//" : " return true; ", + "//" : " return false; ", + "//" : " } ", + "//" : " ", + "//" : " function testContractInteraction() returns (bool res) ", + "//" : " { ", + "//" : " TestContract a = new TestContract(); ", + "//" : " if (a.testMethod() == 225) ", + "//" : " return true; ", + "//" : " return false; ", + "//" : " } ", + "//" : " ", + "//" : " function testKeywords() returns (bool res) ", + "//" : " { ", + "//" : " //some simple checks for the if statemnt ", + "//" : " //if, else, while, for, break, continue, return ", + "//" : " int i = 0; ", + "//" : " res = false; ", + "//" : " ", + "//" : " if (i == 0) ", + "//" : " { ", + "//" : " if( i <= -25) ", + "//" : " { ", + "//" : " return false; ", + "//" : " } ", + "//" : " else ", + "//" : " { ", + "//" : " while(i < 10) ", + "//" : " i++; ", + "//" : " ", + "//" : " if (i == 10) ", + "//" : " { ", + "//" : " for(var j=10; j>0; j--) ", + "//" : " { ", + "//" : " i--; ", + "//" : " } ", + "//" : " } ", + "//" : " } ", + "//" : " } ", + "//" : " ", + "//" : " ", + "//" : " if (i == 0) ", + "//" : " return true; ", + "//" : " ", + "//" : " return false; ", + "//" : " } ", + "//" : " ", + "//" : " function createContractFromMethod() returns (TestContract a) ", + "//" : " { ", + "//" : " a = new TestContract(); ", + "//" : " } ", + "//" : "} ", + "code" : "0x60e060020a6000350480630c4c9a8014610078578063296df0df1461008a5780632a9afb831461009c578063380e4396146100ae5780634893d88a146100c05780637ee17e12146100ce578063981a3165146100dc578063a60eedda146100ee578063e97384dc14610100578063ed973fe91461011257005b610080610431565b8060005260206000f35b6100926103f7565b8060005260206000f35b6100a46105d1565b8060005260206000f35b6100b6610220565b8060005260206000f35b6100c8610426565b60006000f35b6100d66102df565b60006000f35b6100e4610411565b8060005260206000f35b6100f6610124565b8060005260206000f35b6101086102f5565b8060005260206000f35b61011a6101be565b8060005260206000f35b60006000605f6106be600039605f60006000f0905080600160a060020a031662f55d9d8060e060020a0260005241600160a060020a0316600452600060006024600060008660155a03f150505080600160a060020a031663b9c3d0a58060e060020a02600052602060006004600060008660155a03f150505060005160e1146101ac576101b5565b600191506101ba565b600091505b5090565b60006000605f6106be600039605f60006000f0905080600160a060020a031663b9c3d0a58060e060020a02600052602060006004600060008660155a03f150505060005160e11461020e57610217565b6001915061021c565b600091505b5090565b60006000600060009150600092508160001461023b576102bf565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe78213156102b5575b600a82121561027a578180600101925050610264565b81600a14610287576102b0565b600a90505b60008160ff1611156102af5781806001900392505080806001900391505061028c565b5b6102be565b600092506102da565b5b816000146102cc576102d5565b600192506102da565b600092505b505090565b6000605f6106be600039605f60006000f0905090565b60006001905041600160a060020a0316732adc25665018aa1fe0e6bc666dac8fc2697ff9ba14156103255761032e565b600090506103f4565b446302b8feb0141561033f57610348565b600090506103f4565b43607814156103565761035f565b600090506103f4565b33600160a060020a031673a94f5374fce5edbc8e2a8697c15331677e6ebf0b141561038957610392565b600090506103f4565b34606414156103a0576103a9565b600090506103f4565b3a600114156103b7576103c0565b600090506103f4565b32600160a060020a031673a94f5374fce5edbc8e2a8697c15331677e6ebf0b14156103ea576103f3565b600090506103f4565b5b90565b6000600090505b60011561040a576103fe565b6001905090565b60006000905061041f610426565b6001905090565b61042e610411565b50565b60006000905061043f6102df565b50610448610220565b1561045257610478565b7ff000000000000000000000000000000000000000000000000000000000000000810190505b6104806101be565b1561048a576104b0565b7f0f00000000000000000000000000000000000000000000000000000000000000810190505b6104b8610124565b156104c2576104e7565b7ef0000000000000000000000000000000000000000000000000000000000000810190505b6104ef6102f5565b156104f95761051e565b7e0f000000000000000000000000000000000000000000000000000000000000810190505b60ff60008190555073a94f5374fce5edbc8e2a8697c15331677e6ebf0b60018190555060ff6002819055507f676c6f62616c2064617461203332206c656e67746820737472696e670000000060038190555073a94f5374fce5edbc8e2a8697c15331677e6ebf0b600460006000526020526040600020819055506105a06105d1565b156105aa576105ce565b7df00000000000000000000000000000000000000000000000000000000000810190505b90565b60006001905060005460ff14156105e7576105f0565b600090506106ba565b60025460005414156106015761060a565b600090506106ba565b600154600160a060020a031673a94f5374fce5edbc8e2a8697c15331677e6ebf0b14156106365761063f565b600090506106ba565b6003547f676c6f62616c2064617461203332206c656e67746820737472696e6700000000141561066e57610677565b600090506106ba565b60046000600052602052604060002054600160a060020a031673a94f5374fce5edbc8e2a8697c15331677e6ebf0b14156106b0576106b9565b600090506106ba565b5b905600605380600c6000396000f30060e060020a600035048062f55d9d14601d578063b9c3d0a514602c57005b60266004356045565b60006000f35b6032603c565b8060005260206000f35b600060e1905090565b80600160a060020a0316ff5056", + "nonce" : "0", + "storage" : { + } + } + }, + + "transaction" : + { + "//" : "createContractFromMethod()", + "data" : "0x7ee17e12", + "//" : "runSolidityTests()", + "data" : "0x0c4c9a80", + "gasLimit" : "465224", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "d94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "value" : "100" + } + } +} diff --git a/test/state.cpp b/test/state.cpp index fb54a62ae..03f01d0fb 100644 --- a/test/state.cpp +++ b/test/state.cpp @@ -159,6 +159,11 @@ BOOST_AUTO_TEST_CASE(stBlockHashTest) dev::test::executeTests("stBlockHashTest", "/StateTests", dev::test::doStateTests); } +BOOST_AUTO_TEST_CASE(stSolidityTest) +{ + dev::test::executeTests("stSolidityTest", "/StateTests", dev::test::doStateTests); +} + BOOST_AUTO_TEST_CASE(stCreateTest) { for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) diff --git a/test/ttTransactionTestFiller.json b/test/ttTransactionTestFiller.json index 49831261a..e9ae27188 100644 --- a/test/ttTransactionTestFiller.json +++ b/test/ttTransactionTestFiller.json @@ -44,6 +44,21 @@ } }, + "WrongVRSTestIncorrectSize" : { + "transaction" : + { + "data" : "", + "gasLimit" : "2000", + "gasPrice" : "1", + "nonce" : "0", + "to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "value" : "10", + "v" : "28", + "r" : "0x98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a02c3", + "s" : "0x8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a302c3" + } + }, + "SenderTest" : { "//" : "sender a94f5374fce5edbc8e2a8697c15331677e6ebf0b", "transaction" : @@ -196,33 +211,18 @@ } }, - "RLPElementsWithZeros" : { + "AddressMoreThan20PrefixedBy0" : { "transaction" : { - "data" : "0x0000011222333", - "gasLimit" : "1000", - "gasPrice" : "00123", - "nonce" : "0054", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "00000011", - "v" : "27", - "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", - "s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804" - } - }, - - "RLPWrongHexElements" : { - "transaction" : - { - "data" : "0x0000000012", + "data" : "0x12", "gasLimit" : "1000", "gasPrice" : "123", "nonce" : "54", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "to" : "0x0000000000000000095e7baea6a6c7c4c2dfeb977efac326af552d87", "value" : "11", "v" : "27", - "r" : "0x0048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", - "s" : "0x00efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804" + "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", + "s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804" } }, @@ -299,5 +299,35 @@ "r" : "0x98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a", "s" : "0x8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3" } + }, + + "ValuesAsHex" : { + "transaction" : + { + "data" : "", + "gasLimit" : "0xadc053", + "gasPrice" : "1", + "nonce" : "0xffdc5", + "to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "value" : "0xfffdc12c", + "v" : "28", + "r" : "0x98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a", + "s" : "0x8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3" + } + }, + + "ValuesAsDec" : { + "transaction" : + { + "data" : "", + "gasLimit" : "11386963", + "gasPrice" : "1", + "nonce" : "1048005", + "to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "value" : "4501151495864620", + "v" : "28", + "r" : "0x98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a", + "s" : "0x8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3" + } } } From 29abb4fb551f17442955e56160ff86ea4a622892 Mon Sep 17 00:00:00 2001 From: winsvega Date: Thu, 12 Feb 2015 23:43:57 +0300 Subject: [PATCH 02/11] New Tests Transaction with RLP object and catching exceptions from importByteArray --- test/TestHelper.cpp | 2 +- test/stTransactionTestFiller.json | 152 +++++++++++++++++++++++++++++- test/transaction.cpp | 11 ++- 3 files changed, 157 insertions(+), 8 deletions(-) diff --git a/test/TestHelper.cpp b/test/TestHelper.cpp index 8a00a5462..5e7472105 100644 --- a/test/TestHelper.cpp +++ b/test/TestHelper.cpp @@ -247,7 +247,7 @@ byte toByte(json_spirit::mValue const& _v) bytes importByteArray(std::string const& _str) { - return fromHex(_str.substr(0, 2) == "0x" ? _str.substr(2) : _str); + return fromHex(_str.substr(0, 2) == "0x" ? _str.substr(2) : _str, ThrowType::Throw); } bytes importData(json_spirit::mObject& _o) diff --git a/test/stTransactionTestFiller.json b/test/stTransactionTestFiller.json index e5369f0cd..214a0ae7c 100644 --- a/test/stTransactionTestFiller.json +++ b/test/stTransactionTestFiller.json @@ -189,6 +189,53 @@ } }, + "InternalCallHittingGasLimit" : { + "env" : { + "currentCoinbase" : "a94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "currentDifficulty" : "45678256", + "currentGasLimit" : "1100", + "currentNumber" : "0", + "currentTimestamp" : 1, + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "pre" : + { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "1000000", + "code" : "", + "nonce" : "0", + "storage" : { + } + }, + + "b94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "1000000", + "code" : "{ (CALL 5000 0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b 1 0 0 0 0) }", + "nonce" : "0", + "storage" : { + } + }, + + "c94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "0", + "code" : "{[[1]]55}", + "nonce" : "0", + "storage" : { + } + } + }, + "transaction" : + { + "data" : "", + "gasLimit" : "1100", + "gasPrice" : "1", + "nonce" : "", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "value" : "10" + } + }, + "TransactionFromCoinbaseHittingBlockGasLimit" : { "env" : { "currentCoinbase" : "a94f5374fce5edbc8e2a8697c15331677e6ebf0b", @@ -623,7 +670,7 @@ "balance" : "100000", "code" : "", "nonce" : "115792089237316195423570985008687907853269984665640564039457584007913129639935", - "nonce" : "10000000", + "nonce" : "10000", "storage" : { } } @@ -634,7 +681,7 @@ "gasLimit" : "1000", "gasPrice" : "1", "nonce" : "115792089237316195423570985008687907853269984665640564039457584007913129639935", - "nonce" : "10000000", + "nonce" : "10000", "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", "to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b", "value" : "100" @@ -864,5 +911,106 @@ "to" : "0xffffffffffffffffffffffffffffffffffffffff", "value" : "100" } + }, + + "CreateTransactionReverted" : { + "env" : { + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "45678256", + "currentGasLimit" : "1000000000000", + "currentNumber" : "0", + "currentTimestamp" : 1, + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "pre" : + { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000", + "code" : "", + "nonce" : "0", + "storage" : { + } + } + }, + "transaction" : + { + "data" : "0x602280600c6000396000f30060e060020a600035048063f8a8fd6d14601457005b601a6020565b60006000f35b56", + "gasLimit" : "882", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "", + "value" : "" + } + }, + + "CreateTransactionWorking" : { + "env" : { + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "45678256", + "currentGasLimit" : "1000000000000", + "currentNumber" : "0", + "currentTimestamp" : 1, + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "pre" : + { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000", + "code" : "", + "nonce" : "0", + "storage" : { + } + } + }, + "transaction" : + { + "data" : "0x602280600c6000396000f30060e060020a600035048063f8a8fd6d14601457005b601a6020565b60006000f35b56", + "gasLimit" : "883", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "", + "value" : "100" + } + }, + + "CreateMessageReverted" : { + "env" : { + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "45678256", + "currentGasLimit" : "1000000000000", + "currentNumber" : "0", + "currentTimestamp" : 1, + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "pre" : + { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000", + "code" : "", + "nonce" : "0", + "storage" : { + } + }, + + "b94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "0", + "code" : "{(MSTORE 0 0x600c600055) (CREATE 0 27 5)}", + "nonce" : "0", + "storage" : { + } + } + }, + "transaction" : + { + "data" : "", + "gasLimit" : "882", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "value" : "100" + } } } diff --git a/test/transaction.cpp b/test/transaction.cpp index b51494d84..9f9429534 100644 --- a/test/transaction.cpp +++ b/test/transaction.cpp @@ -64,7 +64,7 @@ RLPStream createRLPStreamFromTransactionFields(mObject& _tObj) rlpStream << bigint(_tObj["r"].get_str()); if (_tObj.count("s") > 0) - rlpStream << bigint(_tObj["s"].get_str()); + rlpStream << bigint(_tObj["s"].get_str()); if (_tObj.count("extrafield") > 0) rlpStream << bigint(_tObj["extrafield"].get_str()); @@ -82,18 +82,18 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin) if (_fillin == false) { BOOST_REQUIRE(o.count("rlp") > 0); - bytes rlpReaded = importByteArray(o["rlp"].get_str()); Transaction txFromRlp; - try { - txFromRlp = Transaction(rlpReaded, CheckSignature::Sender); + bytes stream = importByteArray(o["rlp"].get_str()); + RLP rlp(stream); + txFromRlp = Transaction(rlp.data(), CheckSignature::Sender); if (!txFromRlp.signature().isValid()) BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("transaction from RLP signature is invalid") ); } catch(...) { - BOOST_CHECK_MESSAGE(o.count("transaction") == 0, "A transction object should not be defined because the RLP is invalid!"); + BOOST_CHECK_MESSAGE(o.count("transaction") == 0, "A transaction object should not be defined because the RLP is invalid!"); return; } @@ -115,6 +115,7 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin) Address addressReaded = Address(o["sender"].get_str()); BOOST_CHECK_MESSAGE(txFromFields.sender() == addressReaded || txFromRlp.sender() == addressReaded, "Signature address of sender does not match given sender address!"); + } else { From e1666c85e5ccbfaa7d2cd757fb5172b4feb8511d Mon Sep 17 00:00:00 2001 From: arkpar Date: Thu, 12 Feb 2015 21:52:30 +0100 Subject: [PATCH 03/11] Ctrl+C/Cmd+C to copy data from debug panes --- mix/qml/DebugInfoList.qml | 11 ++++++++++- mix/qml/Debugger.qml | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/mix/qml/DebugInfoList.qml b/mix/qml/DebugInfoList.qml index c1ab11596..ae7e6fabe 100644 --- a/mix/qml/DebugInfoList.qml +++ b/mix/qml/DebugInfoList.qml @@ -8,7 +8,7 @@ ColumnLayout { property string title property variant listModel; property bool collapsible; - property bool enableSelection; + property bool enableSelection: false; property real storedHeight: 0; property Component itemDelegate signal rowActivated(int index) @@ -116,6 +116,15 @@ ColumnLayout { } } onActivated: rowActivated(row); + Keys.onPressed: { + if ((event.modifiers & Qt.ControlModifier) && event.key === Qt.Key_C && currentRow >=0 && currentRow < listModel.length) { + var str = ""; + for (var i = 0; i < listModel.length; i++) + str += listModel[i] + "\n"; + appContext.toClipboard(str); + } + } + TableViewColumn { role: "modelData" width: parent.width diff --git a/mix/qml/Debugger.qml b/mix/qml/Debugger.qml index 61bf5e8cc..df91aa1c4 100644 --- a/mix/qml/Debugger.qml +++ b/mix/qml/Debugger.qml @@ -529,7 +529,7 @@ Rectangle { Text { anchors.leftMargin: 5 width: parent.width - 5 - wrapMode: Text.Wrap + wrapMode: Text.NoWrap anchors.left: parent.left font.family: "monospace" anchors.verticalCenter: parent.verticalCenter @@ -600,7 +600,7 @@ Rectangle { Text { anchors.leftMargin: 5 width: parent.width - 5 - wrapMode: Text.Wrap + wrapMode: Text.NoWrap anchors.left: parent.left font.family: "monospace" anchors.verticalCenter: parent.verticalCenter From 1ffdd5d7ff32558437a6c1277a9b33b6daad2e88 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 13 Feb 2015 01:29:21 +0100 Subject: [PATCH 04/11] Copying calldata directly to memory. --- libsolidity/CompilerUtils.cpp | 63 ++++++++++++++++++++--------------- test/SolidityEndToEndTest.cpp | 15 +++++++++ 2 files changed, 51 insertions(+), 27 deletions(-) diff --git a/libsolidity/CompilerUtils.cpp b/libsolidity/CompilerUtils.cpp index 73be38176..dda1736d6 100644 --- a/libsolidity/CompilerUtils.cpp +++ b/libsolidity/CompilerUtils.cpp @@ -76,35 +76,44 @@ void CompilerUtils::storeInMemoryDynamic(Type const& _type, bool _padToWordBound if (_type.getCategory() == Type::Category::ByteArray) { auto const& type = dynamic_cast(_type); - solAssert(type.getLocation() == ByteArrayType::Location::Storage, "Non-storage byte arrays not yet implemented."); - m_context << eth::Instruction::DUP1 << eth::Instruction::SLOAD; - // stack here: memory_offset storage_offset length_bytes - // jump to end if length is zero - m_context << eth::Instruction::DUP1 << eth::Instruction::ISZERO; - eth::AssemblyItem loopEnd = m_context.newTag(); - m_context.appendConditionalJumpTo(loopEnd); - // compute memory end offset - m_context << eth::Instruction::DUP3 << eth::Instruction::ADD << eth::Instruction::SWAP2; - // actual array data is stored at SHA3(storage_offset) - m_context << eth::Instruction::SWAP1; - CompilerUtils(m_context).computeHashStatic(); - m_context << eth::Instruction::SWAP1; + if (type.getLocation() == ByteArrayType::Location::CallData) + { + m_context << eth::Instruction::CALLDATASIZE << u256(0) << eth::Instruction::DUP3 + << eth::Instruction::CALLDATACOPY + << eth::Instruction::CALLDATASIZE << eth::Instruction::ADD; + } + else + { + solAssert(type.getLocation() == ByteArrayType::Location::Storage, "Memory byte arrays not yet implemented."); + m_context << eth::Instruction::DUP1 << eth::Instruction::SLOAD; + // stack here: memory_offset storage_offset length_bytes + // jump to end if length is zero + m_context << eth::Instruction::DUP1 << eth::Instruction::ISZERO; + eth::AssemblyItem loopEnd = m_context.newTag(); + m_context.appendConditionalJumpTo(loopEnd); + // compute memory end offset + m_context << eth::Instruction::DUP3 << eth::Instruction::ADD << eth::Instruction::SWAP2; + // actual array data is stored at SHA3(storage_offset) + m_context << eth::Instruction::SWAP1; + CompilerUtils(m_context).computeHashStatic(); + m_context << eth::Instruction::SWAP1; - // stack here: memory_end_offset storage_data_offset memory_offset - eth::AssemblyItem loopStart = m_context.newTag(); - m_context << loopStart - // load and store - << eth::Instruction::DUP2 << eth::Instruction::SLOAD - << eth::Instruction::DUP2 << eth::Instruction::MSTORE - // increment storage_data_offset by 1 - << eth::Instruction::SWAP1 << u256(1) << eth::Instruction::ADD - // increment memory offset by 32 - << eth::Instruction::SWAP1 << u256(32) << eth::Instruction::ADD - // check for loop condition - << eth::Instruction::DUP1 << eth::Instruction::DUP4 << eth::Instruction::GT; - m_context.appendConditionalJumpTo(loopStart); - m_context << loopEnd << eth::Instruction::POP << eth::Instruction::POP; + // stack here: memory_end_offset storage_data_offset memory_offset + eth::AssemblyItem loopStart = m_context.newTag(); + m_context << loopStart + // load and store + << eth::Instruction::DUP2 << eth::Instruction::SLOAD + << eth::Instruction::DUP2 << eth::Instruction::MSTORE + // increment storage_data_offset by 1 + << eth::Instruction::SWAP1 << u256(1) << eth::Instruction::ADD + // increment memory offset by 32 + << eth::Instruction::SWAP1 << u256(32) << eth::Instruction::ADD + // check for loop condition + << eth::Instruction::DUP1 << eth::Instruction::DUP4 << eth::Instruction::GT; + m_context.appendConditionalJumpTo(loopStart); + m_context << loopEnd << eth::Instruction::POP << eth::Instruction::POP; + } } else { diff --git a/test/SolidityEndToEndTest.cpp b/test/SolidityEndToEndTest.cpp index abfc97b73..259123db6 100644 --- a/test/SolidityEndToEndTest.cpp +++ b/test/SolidityEndToEndTest.cpp @@ -2273,6 +2273,21 @@ BOOST_AUTO_TEST_CASE(store_bytes) BOOST_CHECK(callContractFunction("save()", "abcdefg") == encodeArgs(24)); } +BOOST_AUTO_TEST_CASE(bytes_from_calldata_to_memory) +{ + char const* sourceCode = R"( + contract C { + function() returns (hash) { + return sha3("abc", msg.data); + } + } + )"; + compileAndRun(sourceCode); + bytes calldata = bytes(61, 0x22) + bytes(12, 0x12); + sendMessage(calldata, false); + BOOST_CHECK(m_output == encodeArgs(dev::sha3(bytes{'a', 'b', 'c'} + calldata))); +} + BOOST_AUTO_TEST_CASE(call_forward_bytes) { char const* sourceCode = R"( From 483ce3a2ea136f840ae6f1eac9dbf7fd0258a8e9 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 13 Feb 2015 09:00:51 +0100 Subject: [PATCH 05/11] performance test --- test/vm.cpp | 28 +++++++++++++++++++++++ test/vmPerformanceTestFiller.json | 38 +++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 test/vmPerformanceTestFiller.json diff --git a/test/vm.cpp b/test/vm.cpp index f15dc048a..af946777f 100644 --- a/test/vm.cpp +++ b/test/vm.cpp @@ -32,6 +32,8 @@ using namespace dev; using namespace dev::eth; using namespace dev::test; +using Millisecs = chrono::duration; + FakeExtVM::FakeExtVM(eth::BlockInfo const& _previousBlock, eth::BlockInfo const& _currentBlock, unsigned _depth): /// TODO: XXX: remove the default argument & fix. ExtVMFace(Address(), Address(), Address(), 0, 1, bytesConstRef(), bytes(), _previousBlock, _currentBlock, test::lastHashes(_currentBlock.number), _depth) {} @@ -513,13 +515,39 @@ BOOST_AUTO_TEST_CASE(vmSystemOperationsTest) dev::test::executeTests("vmSystemOperationsTest", "/VMTests", dev::test::doVMTests); } +BOOST_AUTO_TEST_CASE(vmPerformanceTest) +{ + for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) + { + string arg = boost::unit_test::framework::master_test_suite().argv[i]; + if (arg == "--performance") + { + chrono::steady_clock::time_point start = chrono::steady_clock::now(); + + dev::test::executeTests("vmPerformanceTest", "/VMTests", dev::test::doVMTests); + + chrono::steady_clock::time_point end = chrono::steady_clock::now(); + Millisecs duration(chrono::duration_cast(end - start)); + cnote << "test duration: " << duration.count() << " milliseconds.\n"; + } + } +} + BOOST_AUTO_TEST_CASE(vmInputLimitsTest1) { for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) { string arg = boost::unit_test::framework::master_test_suite().argv[i]; if (arg == "--inputlimits") + { + chrono::steady_clock::time_point start = chrono::steady_clock::now(); + dev::test::executeTests("vmInputLimitsTest1", "/VMTests", dev::test::doVMTests); + + chrono::steady_clock::time_point end = chrono::steady_clock::now(); + Millisecs duration(chrono::duration_cast(end - start)); + cnote << "test duration: " << duration.count() << " milliseconds.\n"; + } } } diff --git a/test/vmPerformanceTestFiller.json b/test/vmPerformanceTestFiller.json new file mode 100644 index 000000000..7979bfbdb --- /dev/null +++ b/test/vmPerformanceTestFiller.json @@ -0,0 +1,38 @@ +{ + "ackermann33": { + "env" : { + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", + "currentNumber" : "0", + "currentGasLimit" : "100000000000", + "currentDifficulty" : "256", + "currentTimestamp" : "1", + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "nonce" : "0", + "//" : "contract PerformanceTester {", + "//" : " function ackermann(uint m, uint n) returns (uint) {", + "//" : " if (m == 0)", + "//" : " return n + 1;", + "//" : " if (n == 0)", + "//" : " return ackermann(m - 1, 1);", + "//" : " return ackermann(m - 1, ackermann(m, n - 1));", + "//" : " }", + "//" : "}", + "code" : "0x60e060020a6000350480632839e92814601457005b6020600435602435602a565b8060005260206000f35b6000826000146037576041565b8160010190506076565b81600014604c57605e565b6058600184036001602a565b90506076565b607360018403606f8560018603602a565b602a565b90505b9291505056", + "storage": {} + } + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000", + "data" : "0x2839e92800000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003", + "gasPrice" : "100000000000000", + "gas" : "100000000000" + } + } +} From 0520e0f4db7fa8b49b6c294135b689b1fdce4427 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Fri, 13 Feb 2015 09:03:03 +0100 Subject: [PATCH 06/11] fixed issue with including wrong json/json.h file --- alethzero/CMakeLists.txt | 4 ++-- libsolidity/CMakeLists.txt | 4 ++-- lllc/CMakeLists.txt | 4 ++-- mix/CMakeLists.txt | 3 ++- solc/CMakeLists.txt | 4 ++-- test/CMakeLists.txt | 5 +++-- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/alethzero/CMakeLists.txt b/alethzero/CMakeLists.txt index ed2d8fa5e..c18a76c36 100644 --- a/alethzero/CMakeLists.txt +++ b/alethzero/CMakeLists.txt @@ -10,9 +10,9 @@ endif() set(CMAKE_INCLUDE_CURRENT_DIR ON) aux_source_directory(. SRC_LIST) -include_directories(${JSON_RPC_CPP_INCLUDE_DIRS}) -include_directories(${JSONCPP_INCLUDE_DIRS}) include_directories(..) +include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS}) +include_directories(${JSON_RPC_CPP_INCLUDE_DIRS}) qt5_wrap_ui(ui_Main.h Main.ui) diff --git a/libsolidity/CMakeLists.txt b/libsolidity/CMakeLists.txt index 9c0b50775..cccc5e165 100644 --- a/libsolidity/CMakeLists.txt +++ b/libsolidity/CMakeLists.txt @@ -11,9 +11,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB") aux_source_directory(. SRC_LIST) -include_directories(${Boost_INCLUDE_DIRS}) -include_directories(${JSONCPP_INCLUDE_DIRS}) include_directories(..) +include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS}) +include_directories(${Boost_INCLUDE_DIRS}) set(EXECUTABLE solidity) diff --git a/lllc/CMakeLists.txt b/lllc/CMakeLists.txt index 5aaca0ccc..2157fea74 100644 --- a/lllc/CMakeLists.txt +++ b/lllc/CMakeLists.txt @@ -3,9 +3,9 @@ set(CMAKE_AUTOMOC OFF) aux_source_directory(. SRC_LIST) -include_directories(${Boost_INCLUDE_DIRS}) -include_directories(${JSONCPP_INCLUDE_DIRS}) include_directories(..) +include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS}) +include_directories(${Boost_INCLUDE_DIRS}) set(EXECUTABLE lllc) diff --git a/mix/CMakeLists.txt b/mix/CMakeLists.txt index 755f3df04..4390a4eb0 100644 --- a/mix/CMakeLists.txt +++ b/mix/CMakeLists.txt @@ -10,8 +10,9 @@ endif() set(CMAKE_INCLUDE_CURRENT_DIR ON) aux_source_directory(. SRC_LIST) -include_directories(${JSONCPP_INCLUDE_DIRS}) + include_directories(..) +include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS}) find_package (Qt5WebEngine QUIET) qt5_add_resources(UI_RESOURCES res.qrc) diff --git a/solc/CMakeLists.txt b/solc/CMakeLists.txt index 2a7bd7b6d..747effad0 100644 --- a/solc/CMakeLists.txt +++ b/solc/CMakeLists.txt @@ -3,9 +3,9 @@ set(CMAKE_AUTOMOC OFF) aux_source_directory(. SRC_LIST) -include_directories(${Boost_INCLUDE_DIRS}) -include_directories(${JSONCPP_INCLUDE_DIRS}) include_directories(..) +include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS}) +include_directories(${Boost_INCLUDE_DIRS}) set(EXECUTABLE solc) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ab8afcd70..6ba07f280 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,11 +4,12 @@ aux_source_directory(. SRC_LIST) list(REMOVE_ITEM SRC_LIST "./createRandomTest.cpp") list(REMOVE_ITEM SRC_LIST "./checkRandomTest.cpp") +include_directories(..) +include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS}) include_directories(${Boost_INCLUDE_DIRS}) include_directories(${CRYPTOPP_INCLUDE_DIRS}) -include_directories(${JSONCPP_INCLUDE_DIRS}) include_directories(${JSON_RPC_CPP_INCLUDE_DIRS}) -include_directories(..) + file(GLOB HEADERS "*.h") add_executable(testeth ${SRC_LIST} ${HEADERS}) From d892a39cb21a9fcd871977d61ceecf8e23c0e052 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 13 Feb 2015 09:07:07 +0100 Subject: [PATCH 07/11] style fix --- test/vmPerformanceTestFiller.json | 64 +++++++++++++++---------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/test/vmPerformanceTestFiller.json b/test/vmPerformanceTestFiller.json index 7979bfbdb..7cfe659d5 100644 --- a/test/vmPerformanceTestFiller.json +++ b/test/vmPerformanceTestFiller.json @@ -1,38 +1,38 @@ { "ackermann33": { - "env" : { - "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", - "currentNumber" : "0", - "currentGasLimit" : "100000000000", - "currentDifficulty" : "256", - "currentTimestamp" : "1", - "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" - }, - "pre" : { - "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { - "balance" : "1000000000000000000", - "nonce" : "0", - "//" : "contract PerformanceTester {", - "//" : " function ackermann(uint m, uint n) returns (uint) {", - "//" : " if (m == 0)", - "//" : " return n + 1;", - "//" : " if (n == 0)", - "//" : " return ackermann(m - 1, 1);", - "//" : " return ackermann(m - 1, ackermann(m, n - 1));", - "//" : " }", - "//" : "}", - "code" : "0x60e060020a6000350480632839e92814601457005b6020600435602435602a565b8060005260206000f35b6000826000146037576041565b8160010190506076565b81600014604c57605e565b6058600184036001602a565b90506076565b607360018403606f8560018603602a565b602a565b90505b9291505056", - "storage": {} - } - }, + "env" : { + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", + "currentNumber" : "0", + "currentGasLimit" : "100000000000", + "currentDifficulty" : "256", + "currentTimestamp" : "1", + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "nonce" : "0", + "//" : "contract PerformanceTester {", + "//" : " function ackermann(uint m, uint n) returns (uint) {", + "//" : " if (m == 0)", + "//" : " return n + 1;", + "//" : " if (n == 0)", + "//" : " return ackermann(m - 1, 1);", + "//" : " return ackermann(m - 1, ackermann(m, n - 1));", + "//" : " }", + "//" : "}", + "code" : "0x60e060020a6000350480632839e92814601457005b6020600435602435602a565b8060005260206000f35b6000826000146037576041565b8160010190506076565b81600014604c57605e565b6058600184036001602a565b90506076565b607360018403606f8560018603602a565b602a565b90505b9291505056", + "storage": {} + } + }, "exec" : { - "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", - "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", - "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", - "value" : "1000000000000000000", + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000", "data" : "0x2839e92800000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003", - "gasPrice" : "100000000000000", + "gasPrice" : "100000000000000", "gas" : "100000000000" - } - } + } + } } From 0696ee87da8d34d09fd1286cc7d08e535b514ce3 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 13 Feb 2015 10:25:56 +0100 Subject: [PATCH 08/11] Windows compile fix. --- libp2p/Host.cpp | 2 +- libp2p/Session.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libp2p/Host.cpp b/libp2p/Host.cpp index f09468e0d..f117df37a 100644 --- a/libp2p/Host.cpp +++ b/libp2p/Host.cpp @@ -54,7 +54,7 @@ Host::Host(std::string const& _clientVersion, NetworkPreferences const& _n, byte m_ioService(2), m_tcp4Acceptor(m_ioService), m_alias(networkAlias(_restoreNetwork)), - m_lastPing(chrono::time_point::min()) + m_lastPing(chrono::steady_clock::time_point::min()) { for (auto address: m_ifAddresses) if (address.is_v4()) diff --git a/libp2p/Session.cpp b/libp2p/Session.cpp index cb7225f0f..6ff765cf6 100644 --- a/libp2p/Session.cpp +++ b/libp2p/Session.cpp @@ -40,10 +40,10 @@ Session::Session(Host* _s, bi::tcp::socket _socket, std::shared_ptr const& m_server(_s), m_socket(std::move(_socket)), m_peer(_n), - m_info({NodeId(), "?", m_socket.remote_endpoint().address().to_string(), 0, std::chrono::steady_clock::duration(0), CapDescSet(), 0, map()}), - m_ping(chrono::time_point::max()) + m_info({NodeId(), "?", m_socket.remote_endpoint().address().to_string(), 0, chrono::steady_clock::duration(0), CapDescSet(), 0, map()}), + m_ping(chrono::steady_clock::time_point::max()) { - m_lastReceived = m_connect = std::chrono::steady_clock::now(); + m_lastReceived = m_connect = chrono::steady_clock::now(); } Session::~Session() From f5022ee58f2262624b991487006e3fd56991ce07 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 13 Feb 2015 10:27:38 +0100 Subject: [PATCH 09/11] use auto for steady clock and chrono::milliseconds --- test/vm.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/test/vm.cpp b/test/vm.cpp index af946777f..faab48129 100644 --- a/test/vm.cpp +++ b/test/vm.cpp @@ -32,8 +32,6 @@ using namespace dev; using namespace dev::eth; using namespace dev::test; -using Millisecs = chrono::duration; - FakeExtVM::FakeExtVM(eth::BlockInfo const& _previousBlock, eth::BlockInfo const& _currentBlock, unsigned _depth): /// TODO: XXX: remove the default argument & fix. ExtVMFace(Address(), Address(), Address(), 0, 1, bytesConstRef(), bytes(), _previousBlock, _currentBlock, test::lastHashes(_currentBlock.number), _depth) {} @@ -522,12 +520,12 @@ BOOST_AUTO_TEST_CASE(vmPerformanceTest) string arg = boost::unit_test::framework::master_test_suite().argv[i]; if (arg == "--performance") { - chrono::steady_clock::time_point start = chrono::steady_clock::now(); + auto start = chrono::steady_clock::now(); dev::test::executeTests("vmPerformanceTest", "/VMTests", dev::test::doVMTests); - chrono::steady_clock::time_point end = chrono::steady_clock::now(); - Millisecs duration(chrono::duration_cast(end - start)); + auto end = chrono::steady_clock::now(); + chrono::milliseconds duration(chrono::duration_cast(end - start)); cnote << "test duration: " << duration.count() << " milliseconds.\n"; } } @@ -540,12 +538,12 @@ BOOST_AUTO_TEST_CASE(vmInputLimitsTest1) string arg = boost::unit_test::framework::master_test_suite().argv[i]; if (arg == "--inputlimits") { - chrono::steady_clock::time_point start = chrono::steady_clock::now(); + auto start = chrono::steady_clock::now(); dev::test::executeTests("vmInputLimitsTest1", "/VMTests", dev::test::doVMTests); - chrono::steady_clock::time_point end = chrono::steady_clock::now(); - Millisecs duration(chrono::duration_cast(end - start)); + auto end = chrono::steady_clock::now(); + chrono::milliseconds duration(chrono::duration_cast(end - start)); cnote << "test duration: " << duration.count() << " milliseconds.\n"; } } From 5d15c00aba00bacac7748b7dbf9b6c814018d131 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 13 Feb 2015 10:43:46 +0100 Subject: [PATCH 10/11] Windows warning fix. --- libp2p/NodeTable.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libp2p/NodeTable.h b/libp2p/NodeTable.h index 04e8d009c..0217c700e 100644 --- a/libp2p/NodeTable.h +++ b/libp2p/NodeTable.h @@ -163,7 +163,7 @@ public: std::list snapshot() const; /// Returns true if node id is in node table. - bool haveNode(NodeId const& _id) { Guard l(x_nodes); return m_nodes.count(_id); } + bool haveNode(NodeId const& _id) { Guard l(x_nodes); return m_nodes.count(_id) > 0; } /// Returns the Node to the corresponding node id or the empty Node if that id is not found. Node node(NodeId const& _id); @@ -418,4 +418,4 @@ struct NodeTableEgress: public LogChannel { static const char* name() { return " struct NodeTableIngress: public LogChannel { static const char* name() { return "< Date: Fri, 13 Feb 2015 11:24:14 +0100 Subject: [PATCH 11/11] auto reccommendations. --- CodingStandards.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CodingStandards.txt b/CodingStandards.txt index f883c9147..8acea78ae 100644 --- a/CodingStandards.txt +++ b/CodingStandards.txt @@ -96,12 +96,18 @@ e. Always pass non-trivial parameters with a const& suffix. f. If a function returns multiple values, use std::tuple (std::pair acceptable). Prefer not using */& arguments, except where efficiency requires. g. Never use a macro where adequate non-preprocessor C++ can be written. h. Prefer "using NewType = OldType" to "typedef OldType NewType". +i. Make use of auto whenever type is clear or unimportant: +- Always avoid doubly-stating the type. +- Use to avoid vast and unimportant type declarations + (WRONG) const double d = 0; int i, j; char *s; float meanAndSigma(std::vector _v, float* _sigma); +Derived* x(dynamic_cast(base)); +for (map::iterator i = l.begin(); i != l.end(); ++l) {} (CORRECT) double const d = 0; @@ -109,7 +115,8 @@ int i; int j; char* s; std::tuple meanAndSigma(std::vector const& _v); - +auto x = dynamic_cast(base); +for (auto i = x.begin(); i != x.end(); ++i) {} 7. Structs & classes