From af6b44fb905fccf82aa3bdb36126a385ebb70d1f Mon Sep 17 00:00:00 2001 From: winsvega Date: Sat, 28 Feb 2015 20:57:01 +0300 Subject: [PATCH 1/8] Transaction Tests A few changes --- TestHelper.cpp | 2 +- transaction.cpp | 2 +- ttTransactionTestFiller.json | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/TestHelper.cpp b/TestHelper.cpp index ea44111c9..f82b72b88 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -170,7 +170,7 @@ void ImportTest::importTransaction(json_spirit::mObject& _o) } } -void ImportTest::exportTest(bytes _output, State& _statePost) +void ImportTest::exportTest(bytes const& _output, State const& _statePost) { // export output m_TestObject["out"] = "0x" + toHex(_output); diff --git a/transaction.cpp b/transaction.cpp index c7a0e61d7..8cda18f1e 100644 --- a/transaction.cpp +++ b/transaction.cpp @@ -104,7 +104,7 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin) BOOST_AUTO_TEST_SUITE(TransactionTests) -BOOST_AUTO_TEST_CASE(TransactionTest) +BOOST_AUTO_TEST_CASE(ttTransactionTest) { dev::test::executeTests("ttTransactionTest", "/TransactionTests", dev::test::doTransactionTests); } diff --git a/ttTransactionTestFiller.json b/ttTransactionTestFiller.json index 23a384d50..96e4c78a6 100644 --- a/ttTransactionTestFiller.json +++ b/ttTransactionTestFiller.json @@ -59,6 +59,21 @@ } }, + "WrongVRSTestVOverflow" : { + "transaction" : + { + "data" : "", + "gasLimit" : "2000", + "gasPrice" : "1", + "nonce" : "0", + "to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "value" : "10", + "v" : "310", + "r" : "0x98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a", + "s" : "0x8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3" + } + }, + "WrongVRSTestIncorrectSize" : { "transaction" : { @@ -91,6 +106,22 @@ } }, + "DataTest" : { + "transaction" : + { + "data" : "0x0358ac39584bc98a7c979f984b03", + "gasLimit" : "850", + "gasPrice" : "1", + "nonce" : "0", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10", + "v" : "27", + "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", + "s" : "secretkey 45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804" + } + }, + "TransactionWithTooManyRLPElements" : { "transaction" : { From d311a82444b043de5e890309f172a656729aedf0 Mon Sep 17 00:00:00 2001 From: winsvega Date: Mon, 2 Mar 2015 18:18:28 +0300 Subject: [PATCH 2/8] Test Cases Changes userDefinedFile test now goes with --test option for all cases --- block.cpp | 144 ++++++++++++++++++++++++------------------------ state.cpp | 2 +- transaction.cpp | 4 +- vm.cpp | 4 +- 4 files changed, 78 insertions(+), 76 deletions(-) diff --git a/block.cpp b/block.cpp index fdf65affa..7c50eef4d 100644 --- a/block.cpp +++ b/block.cpp @@ -81,6 +81,76 @@ bytes createBlockRLPFromFields(mObject& _tObj) return rlpStream.out(); } +void overwriteBlockHeader(mObject& _o, BlockInfo _current_BlockHeader) +{ + if (_o.count("blockHeader")) + { + if (_o["blockHeader"].get_obj().size() != 14) + { + + BlockInfo tmp = _current_BlockHeader; + + if (_o["blockHeader"].get_obj().count("parentHash")) + tmp.parentHash = h256(_o["blockHeader"].get_obj()["parentHash"].get_str()); + + if (_o["blockHeader"].get_obj().count("uncleHash")) + tmp.sha3Uncles = h256(_o["blockHeader"].get_obj()["uncleHash"].get_str()); + + if (_o["blockHeader"].get_obj().count("coinbase")) + tmp.coinbaseAddress = Address(_o["blockHeader"].get_obj()["coinbase"].get_str()); + + if (_o["blockHeader"].get_obj().count("stateRoot")) + tmp.stateRoot = h256(_o["blockHeader"].get_obj()["stateRoot"].get_str()); + + if (_o["blockHeader"].get_obj().count("transactionsTrie")) + tmp.transactionsRoot = h256(_o["blockHeader"].get_obj()["transactionsTrie"].get_str()); + + if (_o["blockHeader"].get_obj().count("receiptTrie")) + tmp.receiptsRoot = h256(_o["blockHeader"].get_obj()["receiptTrie"].get_str()); + + if (_o["blockHeader"].get_obj().count("bloom")) + tmp.logBloom = LogBloom(_o["blockHeader"].get_obj()["bloom"].get_str()); + + if (_o["blockHeader"].get_obj().count("difficulty")) + tmp.difficulty = toInt(_o["blockHeader"].get_obj()["difficulty"]); + + if (_o["blockHeader"].get_obj().count("number")) + tmp.number = toInt(_o["blockHeader"].get_obj()["number"]); + + if (_o["blockHeader"].get_obj().count("gasLimit")) + tmp.gasLimit = toInt(_o["blockHeader"].get_obj()["gasLimit"]); + + if (_o["blockHeader"].get_obj().count("gasUsed")) + tmp.gasUsed = toInt(_o["blockHeader"].get_obj()["gasUsed"]); + + if (_o["blockHeader"].get_obj().count("timestamp")) + tmp.timestamp = toInt(_o["blockHeader"].get_obj()["timestamp"]); + + if (_o["blockHeader"].get_obj().count("extraData")) + tmp.extraData = importByteArray(_o["blockHeader"].get_obj()["extraData"].get_str()); + + // find new valid nonce + + if (tmp != _current_BlockHeader) + { + _current_BlockHeader = tmp; + cout << "new header!\n"; + ProofOfWork pow; + MineInfo ret; + while (!ProofOfWork::verify(_current_BlockHeader.headerHash(WithoutNonce), _current_BlockHeader.nonce, _current_BlockHeader.difficulty)) + tie(ret, _current_BlockHeader.nonce) = pow.mine(_current_BlockHeader.headerHash(WithoutNonce), _current_BlockHeader.difficulty, 10000, true, true); + } + } + else + { + // take the blockheader as is + const bytes c_blockRLP = createBlockRLPFromFields(_o["blockHeader"].get_obj()); + const RLP c_bRLP(c_blockRLP); + _current_BlockHeader.populateFromHeader(c_bRLP, false); + } + } +} + void doBlockTests(json_spirit::mValue& _v, bool _fillin) { for (auto& i: _v.get_obj()) @@ -214,76 +284,9 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BlockInfo current_BlockHeader = state.info(); // overwrite blockheader with (possible wrong) data from "blockheader" in filler; - - if (o.count("blockHeader")) - { - if (o["blockHeader"].get_obj().size() != 14) - { - - BlockInfo tmp = current_BlockHeader; - - if (o["blockHeader"].get_obj().count("parentHash")) - tmp.parentHash = h256(o["blockHeader"].get_obj()["parentHash"].get_str()); - - if (o["blockHeader"].get_obj().count("uncleHash")) - tmp.sha3Uncles = h256(o["blockHeader"].get_obj()["uncleHash"].get_str()); - - if (o["blockHeader"].get_obj().count("coinbase")) - tmp.coinbaseAddress = Address(o["blockHeader"].get_obj()["coinbase"].get_str()); - - if (o["blockHeader"].get_obj().count("stateRoot")) - tmp.stateRoot = h256(o["blockHeader"].get_obj()["stateRoot"].get_str()); - - if (o["blockHeader"].get_obj().count("transactionsTrie")) - tmp.transactionsRoot = h256(o["blockHeader"].get_obj()["transactionsTrie"].get_str()); - - if (o["blockHeader"].get_obj().count("receiptTrie")) - tmp.receiptsRoot = h256(o["blockHeader"].get_obj()["receiptTrie"].get_str()); - - if (o["blockHeader"].get_obj().count("bloom")) - tmp.logBloom = LogBloom(o["blockHeader"].get_obj()["bloom"].get_str()); - - if (o["blockHeader"].get_obj().count("difficulty")) - tmp.difficulty = toInt(o["blockHeader"].get_obj()["difficulty"]); - - if (o["blockHeader"].get_obj().count("number")) - tmp.number = toInt(o["blockHeader"].get_obj()["number"]); - - if (o["blockHeader"].get_obj().count("gasLimit")) - tmp.gasLimit = toInt(o["blockHeader"].get_obj()["gasLimit"]); - - if (o["blockHeader"].get_obj().count("gasUsed")) - tmp.gasUsed = toInt(o["blockHeader"].get_obj()["gasUsed"]); - - if (o["blockHeader"].get_obj().count("timestamp")) - tmp.timestamp = toInt(o["blockHeader"].get_obj()["timestamp"]); - - if (o["blockHeader"].get_obj().count("extraData")) - tmp.extraData = importByteArray(o["blockHeader"].get_obj()["extraData"].get_str()); - - // find new valid nonce - - if (tmp != current_BlockHeader) - { - current_BlockHeader = tmp; - cout << "new header!\n"; - ProofOfWork pow; - MineInfo ret; - while (!ProofOfWork::verify(current_BlockHeader.headerHash(WithoutNonce), current_BlockHeader.nonce, current_BlockHeader.difficulty)) - tie(ret, current_BlockHeader.nonce) = pow.mine(current_BlockHeader.headerHash(WithoutNonce), current_BlockHeader.difficulty, 10000, true, true); - } - } - else - { - // take the blockheader as is - const bytes c_blockRLP = createBlockRLPFromFields(o["blockHeader"].get_obj()); - const RLP c_bRLP(c_blockRLP); - current_BlockHeader.populateFromHeader(c_bRLP, false); - } - } + overwriteBlockHeader(o, current_BlockHeader); // write block header - mObject oBlockHeader; oBlockHeader["parentHash"] = toString(current_BlockHeader.parentHash); oBlockHeader["uncleHash"] = toString(current_BlockHeader.sha3Uncles); @@ -423,7 +426,6 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_CHECK_MESSAGE(blockHeaderFromFields == blockFromRlp, "However, blockHeaderFromFields != blockFromRlp!"); //Check transaction list - Transactions txsFromField; for (auto const& txObj: o["transactions"].get_array()) @@ -511,9 +513,9 @@ BOOST_AUTO_TEST_CASE(blForkBlocks) dev::test::executeTests("blForkBlocks", "/BlockTests", dev::test::doBlockTests); } -BOOST_AUTO_TEST_CASE(userDefinedFileBl) +BOOST_AUTO_TEST_CASE(userDefinedFile) { - dev::test::userDefinedTest("--bltest", dev::test::doBlockTests); + dev::test::userDefinedTest("--singletest", dev::test::doBlockTests); } BOOST_AUTO_TEST_SUITE_END() diff --git a/state.cpp b/state.cpp index 1581e4055..fe133822a 100644 --- a/state.cpp +++ b/state.cpp @@ -241,7 +241,7 @@ BOOST_AUTO_TEST_CASE(stCreateTest) BOOST_AUTO_TEST_CASE(userDefinedFileState) { - dev::test::userDefinedTest("--statetest", dev::test::doStateTests); + dev::test::userDefinedTest("--singletest", dev::test::doStateTests); } BOOST_AUTO_TEST_SUITE_END() diff --git a/transaction.cpp b/transaction.cpp index 8cda18f1e..83fd8da4d 100644 --- a/transaction.cpp +++ b/transaction.cpp @@ -167,9 +167,9 @@ BOOST_AUTO_TEST_CASE(ttCreateTest) } } -BOOST_AUTO_TEST_CASE(userDefinedFileTT) +BOOST_AUTO_TEST_CASE(userDefinedFile) { - dev::test::userDefinedTest("--ttTest", dev::test::doTransactionTests); + dev::test::userDefinedTest("--singletest", dev::test::doTransactionTests); } BOOST_AUTO_TEST_SUITE_END() diff --git a/vm.cpp b/vm.cpp index 21bea0650..16f7385a0 100644 --- a/vm.cpp +++ b/vm.cpp @@ -592,9 +592,9 @@ BOOST_AUTO_TEST_CASE(vmRandom) } } -BOOST_AUTO_TEST_CASE(userDefinedFileVM) +BOOST_AUTO_TEST_CASE(userDefinedFile) { - dev::test::userDefinedTest("--vmtest", dev::test::doVMTests); + dev::test::userDefinedTest("--singletest", dev::test::doVMTests); } BOOST_AUTO_TEST_SUITE_END() From b5693332fb66e157e135bbeb6a798e83b0f33a6a Mon Sep 17 00:00:00 2001 From: winsvega Date: Mon, 2 Mar 2015 18:21:41 +0300 Subject: [PATCH 3/8] Transaction Tests missing TestHelper.h file --- TestHelper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TestHelper.h b/TestHelper.h index c4dde1a60..3707a5fff 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -52,7 +52,7 @@ public: void importEnv(json_spirit::mObject& _o); void importState(json_spirit::mObject& _o, eth::State& _state); void importTransaction(json_spirit::mObject& _o); - void exportTest(bytes _output, eth::State& _statePost); + void exportTest(bytes const& _output, eth::State const& _statePost); eth::State m_statePre; eth::State m_statePost; From 628a07d541b209555569b875aacf349e7d9658fd Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 4 Mar 2015 01:17:08 +0100 Subject: [PATCH 4/8] Squashed 'libjsqrc/ethereumjs/' changes from 5bd166c..7d6b35a 7d6b35a Merge branch 'master' into cpp 9b3a0f0 Merge branch 'event_hash' 9887972 version 63dcee6 ignore for maxcomplexity warning 8376bfa gulp a59f3a4 Merge pull request #85 from ethers/abiString 0dd6cc4 gulp 688faec Merge pull request #81 from ethers/arraySupport 64f6630 updated README.md 4f9aaec Merge pull request #94 from ethereum/signature 91321fb removed web3 dependency from abi.js 5c7d8a7 separated event signature 81b19cc event hash ea250e6 Merge commit 'be3bfb76bef1d1f113033cd9093e03a00066d5d1' into ethereumjs_timeout c08cea1 Improvement to AZ - confirmation disabler. Fix network crash. git-subtree-dir: libjsqrc/ethereumjs git-subtree-split: 7d6b35af1c2b59feae5a01c899fae68298d71211 --- abi.inputParser.js | 203 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 162 insertions(+), 41 deletions(-) diff --git a/abi.inputParser.js b/abi.inputParser.js index 12b735153..edfc2b58f 100644 --- a/abi.inputParser.js +++ b/abi.inputParser.js @@ -29,7 +29,7 @@ describe('abi', function() { d[0].inputs = [ { type: "uint" } ]; - + // when var parser = abi.inputParser(d); @@ -37,7 +37,7 @@ describe('abi', function() { assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), + parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ); assert.equal( @@ -67,7 +67,7 @@ describe('abi', function() { assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), + parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ); assert.equal( @@ -80,7 +80,7 @@ describe('abi', function() { assert.equal(parser.test('3.9'), "0000000000000000000000000000000000000000000000000000000000000003"); }); - + it('should parse input uint256', function() { // given @@ -97,7 +97,7 @@ describe('abi', function() { assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), + parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ); assert.equal( @@ -108,7 +108,7 @@ describe('abi', function() { assert.equal(parser.test(3.9), "0000000000000000000000000000000000000000000000000000000000000003"); assert.equal(parser.test('0.1'), "0000000000000000000000000000000000000000000000000000000000000000"); assert.equal(parser.test('3.9'), "0000000000000000000000000000000000000000000000000000000000000003"); - + }); it('should parse input int', function() { @@ -119,7 +119,7 @@ describe('abi', function() { d[0].inputs = [ { type: "int" } ]; - + // when var parser = abi.inputParser(d); @@ -130,7 +130,7 @@ describe('abi', function() { assert.equal(parser.test(-2), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"); assert.equal(parser.test(-16), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"); assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), + parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ); assert.equal( @@ -162,7 +162,7 @@ describe('abi', function() { assert.equal(parser.test(-2), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"); assert.equal(parser.test(-16), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"); assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), + parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ); assert.equal( @@ -177,7 +177,7 @@ describe('abi', function() { }); it('should parse input int256', function() { - + // given var d = clone(description); @@ -195,7 +195,7 @@ describe('abi', function() { assert.equal(parser.test(-2), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"); assert.equal(parser.test(-16), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"); assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), + parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ); assert.equal( @@ -206,11 +206,11 @@ describe('abi', function() { assert.equal(parser.test(3.9), "0000000000000000000000000000000000000000000000000000000000000003"); assert.equal(parser.test('0.1'), "0000000000000000000000000000000000000000000000000000000000000000"); assert.equal(parser.test('3.9'), "0000000000000000000000000000000000000000000000000000000000000003"); - + }); it('should parse input bool', function() { - + // given var d = clone(description); @@ -235,14 +235,14 @@ describe('abi', function() { d[0].inputs = [ { type: "hash" } ]; - + // when var parser = abi.inputParser(d); // then assert.equal(parser.test("0x407d73d8a49eeb85d32cf465507dd71d507100c1"), "000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"); - }); + }); it('should parse input hash256', function() { @@ -272,7 +272,7 @@ describe('abi', function() { // when var parser = abi.inputParser(d); - + // then assert.equal(parser.test("0x407d73d8a49eeb85d32cf465507dd71d507100c1"), "000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"); }); @@ -285,17 +285,17 @@ describe('abi', function() { d[0].inputs = [ { type: "address" } ]; - + // when var parser = abi.inputParser(d) - + // then assert.equal(parser.test("0x407d73d8a49eeb85d32cf465507dd71d507100c1"), "000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"); }); it('should parse input string', function () { - + // given var d = clone(description); @@ -308,8 +308,9 @@ describe('abi', function() { // then assert.equal( - parser.test('hello'), - "000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000" + parser.test('hello'), + "0000000000000000000000000000000000000000000000000000000000000005" + + "68656c6c6f000000000000000000000000000000000000000000000000000000" ); assert.equal( parser.test('world'), @@ -317,8 +318,52 @@ describe('abi', function() { ); }); + it('should parse input int followed by a string', function () { + + // given + var d = clone(description); + + d[0].inputs = [ + { type: "int" }, + { type: "string" } + ]; + + // when + var parser = abi.inputParser(d); + + // then + assert.equal( + parser.test(9, 'hello'), + "0000000000000000000000000000000000000000000000000000000000000005" + + "0000000000000000000000000000000000000000000000000000000000000009" + + "68656c6c6f000000000000000000000000000000000000000000000000000000" + ); + }); + + it('should parse input string followed by an int', function () { + + // given + var d = clone(description); + + d[0].inputs = [ + { type: "string" }, + { type: "int" } + ]; + + // when + var parser = abi.inputParser(d); + + // then + assert.equal( + parser.test('hello', 9), + "0000000000000000000000000000000000000000000000000000000000000005" + + "0000000000000000000000000000000000000000000000000000000000000009" + + "68656c6c6f000000000000000000000000000000000000000000000000000000" + ); + }); + it('should use proper method name', function () { - + // given var d = clone(description); d[0].name = 'helloworld(int)'; @@ -334,9 +379,9 @@ describe('abi', function() { assert.equal(parser.helloworld['int'](1), "0000000000000000000000000000000000000000000000000000000000000001"); }); - + it('should parse multiple methods', function () { - + // given var d = [{ name: "test", @@ -356,14 +401,14 @@ describe('abi', function() { //then assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); assert.equal( - parser.test2('hello'), + parser.test2('hello'), "000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000" ); }); it('should parse input array of ints', function () { - + // given var d = clone(description); @@ -377,14 +422,91 @@ describe('abi', function() { // then assert.equal( parser.test([5, 6]), - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000000000000000000000000000000000000000000005" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "0000000000000000000000000000000000000000000000000000000000000005" + "0000000000000000000000000000000000000000000000000000000000000006" ); }); + it('should parse an array followed by an int', function () { + + // given + var d = clone(description); + + d[0].inputs = [ + { type: "int[]" }, + { type: "int" } + ]; + + // when + var parser = abi.inputParser(d); + + // then + assert.equal( + parser.test([5, 6], 3), + "0000000000000000000000000000000000000000000000000000000000000002" + + "0000000000000000000000000000000000000000000000000000000000000003" + + "0000000000000000000000000000000000000000000000000000000000000005" + + "0000000000000000000000000000000000000000000000000000000000000006" + ); + }); + + it('should parse an int followed by an array', function () { + + // given + var d = clone(description); + + d[0].inputs = [ + { type: "int" }, + { type: "int[]" } + ]; + + // when + var parser = abi.inputParser(d); + + // then + assert.equal( + parser.test(3, [5, 6]), + "0000000000000000000000000000000000000000000000000000000000000002" + + "0000000000000000000000000000000000000000000000000000000000000003" + + "0000000000000000000000000000000000000000000000000000000000000005" + + "0000000000000000000000000000000000000000000000000000000000000006" + ); + }); + + it('should parse mixture of arrays and ints', function () { + + // given + var d = clone(description); + + d[0].inputs = [ + { type: "int" }, + { type: "int[]" }, + { type: "int" }, + { type: "int[]" } + ]; + + // when + var parser = abi.inputParser(d); + + // then + assert.equal( + parser.test(3, [5, 6, 1, 2], 7, [8, 9]), + "0000000000000000000000000000000000000000000000000000000000000004" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "0000000000000000000000000000000000000000000000000000000000000003" + + "0000000000000000000000000000000000000000000000000000000000000007" + + "0000000000000000000000000000000000000000000000000000000000000005" + + "0000000000000000000000000000000000000000000000000000000000000006" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "0000000000000000000000000000000000000000000000000000000000000008" + + "0000000000000000000000000000000000000000000000000000000000000009" + ); + }); + it('should parse input real', function () { - + // given var d = clone(description); @@ -396,15 +518,15 @@ describe('abi', function() { var parser = abi.inputParser(d); // then - assert.equal(parser.test([1]), "0000000000000000000000000000000100000000000000000000000000000000"); - assert.equal(parser.test([2.125]), "0000000000000000000000000000000220000000000000000000000000000000"); - assert.equal(parser.test([8.5]), "0000000000000000000000000000000880000000000000000000000000000000"); - assert.equal(parser.test([-1]), "ffffffffffffffffffffffffffffffff00000000000000000000000000000000"); - + assert.equal(parser.test([1]), "0000000000000000000000000000000100000000000000000000000000000000"); + assert.equal(parser.test([2.125]), "0000000000000000000000000000000220000000000000000000000000000000"); + assert.equal(parser.test([8.5]), "0000000000000000000000000000000880000000000000000000000000000000"); + assert.equal(parser.test([-1]), "ffffffffffffffffffffffffffffffff00000000000000000000000000000000"); + }); - + it('should parse input ureal', function () { - + // given var d = clone(description); @@ -416,12 +538,11 @@ describe('abi', function() { var parser = abi.inputParser(d); // then - assert.equal(parser.test([1]), "0000000000000000000000000000000100000000000000000000000000000000"); - assert.equal(parser.test([2.125]), "0000000000000000000000000000000220000000000000000000000000000000"); - assert.equal(parser.test([8.5]), "0000000000000000000000000000000880000000000000000000000000000000"); - + assert.equal(parser.test([1]), "0000000000000000000000000000000100000000000000000000000000000000"); + assert.equal(parser.test([2.125]), "0000000000000000000000000000000220000000000000000000000000000000"); + assert.equal(parser.test([8.5]), "0000000000000000000000000000000880000000000000000000000000000000"); + }); }); }); - From 26ba1086b82497f9100c0283955c6ea4e742aee0 Mon Sep 17 00:00:00 2001 From: jhuntley Date: Fri, 16 Jan 2015 16:55:46 -0500 Subject: [PATCH 5/8] Avoid boost include order issue on windows: http://stackoverflow.com/questions/9750344/boostasio-winsock-and-winsock-2-compatibility-issue http://stackoverflow.com/questions/9750344/boostasio-winsock-and-winsock-2-compatibility-issue/16288859#16288859 Make sure boost/asio.hpp is included before windows.h. --- TestHelper.cpp | 1 + fork.cpp | 2 +- txTest.cpp | 2 +- whisperTopic.cpp | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/TestHelper.cpp b/TestHelper.cpp index f82b72b88..4ee53f88e 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include diff --git a/fork.cpp b/fork.cpp index bc6ed87bc..934583164 100644 --- a/fork.cpp +++ b/fork.cpp @@ -19,7 +19,7 @@ * @date 2014 * Tests for different forking behavior */ - +#include #include #include #include diff --git a/txTest.cpp b/txTest.cpp index 8d067f9bb..dcb2515af 100644 --- a/txTest.cpp +++ b/txTest.cpp @@ -19,7 +19,7 @@ * @date 2014 * Simple peer transaction send test. */ - +#include #include #include #include diff --git a/whisperTopic.cpp b/whisperTopic.cpp index 4609c957d..2f90b4fb9 100644 --- a/whisperTopic.cpp +++ b/whisperTopic.cpp @@ -19,6 +19,7 @@ * @date 2014 */ #include +#include #include #include #include From b6b80b020006e269c877faee85f6664a1cd925a0 Mon Sep 17 00:00:00 2001 From: jhuntley Date: Wed, 21 Jan 2015 10:59:34 -0500 Subject: [PATCH 6/8] Avoid boost include order issue on windows: http://stackoverflow.com/questions/9750344/boostasio-winsock-and-winsock-2-compatibility-issue http://stackoverflow.com/questions/9750344/boostasio-winsock-and-winsock-2-compatibility-issue/16288859#16288859 Make sure boost/asio.hpp is included before windows.h. --- TestHelper.h | 1 + checkRandomTest.cpp | 1 + createRandomTest.cpp | 1 + genesis.cpp | 6 +++++- hexPrefix.cpp | 3 ++- net.cpp | 1 + rlp.cpp | 3 ++- state.cpp | 1 + trie.cpp | 3 ++- vm.cpp | 1 + vm.h | 1 + 11 files changed, 18 insertions(+), 4 deletions(-) diff --git a/TestHelper.h b/TestHelper.h index 3707a5fff..0b80273c8 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -22,6 +22,7 @@ #pragma once #include +#include #include #include "JsonSpiritHeaders.h" #include diff --git a/checkRandomTest.cpp b/checkRandomTest.cpp index e3442d438..50c3c367d 100644 --- a/checkRandomTest.cpp +++ b/checkRandomTest.cpp @@ -20,6 +20,7 @@ * Check a random test and return 0/1 for success or failure. To be used for efficiency in the random test simulation. */ +#include #include #include #include diff --git a/createRandomTest.cpp b/createRandomTest.cpp index fa5ed7bd3..da1a028bf 100644 --- a/createRandomTest.cpp +++ b/createRandomTest.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #pragma GCC diagnostic ignored "-Wunused-parameter" diff --git a/genesis.cpp b/genesis.cpp index 7ca741ee9..a450b79fc 100644 --- a/genesis.cpp +++ b/genesis.cpp @@ -22,10 +22,14 @@ #include #include + +// Make sure boost/asio.hpp is included before windows.h. +#include +#include + #include "JsonSpiritHeaders.h" #include #include -#include #include "TestHelper.h" using namespace std; diff --git a/hexPrefix.cpp b/hexPrefix.cpp index 551983db3..c96e9e98c 100644 --- a/hexPrefix.cpp +++ b/hexPrefix.cpp @@ -21,11 +21,12 @@ */ #include +#include +#include #include "JsonSpiritHeaders.h" #include #include #include -#include #include "TestHelper.h" using namespace std; diff --git a/net.cpp b/net.cpp index 5039c5436..f842ff1a3 100644 --- a/net.cpp +++ b/net.cpp @@ -19,6 +19,7 @@ * @date 2014 */ +#include #include #include #include diff --git a/rlp.cpp b/rlp.cpp index be098d84d..c67f09665 100644 --- a/rlp.cpp +++ b/rlp.cpp @@ -22,11 +22,12 @@ #include #include +#include +#include #include #include #include #include -#include #include #include "JsonSpiritHeaders.h" #include "TestHelper.h" diff --git a/state.cpp b/state.cpp index fe133822a..99fa36fc7 100644 --- a/state.cpp +++ b/state.cpp @@ -20,6 +20,7 @@ * State test functions. */ +#include #include #include #include "JsonSpiritHeaders.h" diff --git a/trie.cpp b/trie.cpp index 39a3a59a5..a15713412 100644 --- a/trie.cpp +++ b/trie.cpp @@ -22,12 +22,13 @@ #include #include +#include +#include #include "JsonSpiritHeaders.h" #include #include #include "TrieHash.h" #include "MemTrie.h" -#include #include "TestHelper.h" using namespace std; diff --git a/vm.cpp b/vm.cpp index 16f7385a0..423d55ac8 100644 --- a/vm.cpp +++ b/vm.cpp @@ -21,6 +21,7 @@ */ #include +#include #include #include #include diff --git a/vm.h b/vm.h index 0a5b5fb45..ae28213bd 100644 --- a/vm.h +++ b/vm.h @@ -25,6 +25,7 @@ along with cpp-ethereum. If not, see . #include #include +#include #include #include #include From 5ae585f7cf21ae281f564d0edbad1251129f256d Mon Sep 17 00:00:00 2001 From: jhuntley Date: Mon, 9 Feb 2015 11:31:04 -0500 Subject: [PATCH 7/8] asio.h and windows.h build comments as per request. --- TestHelper.cpp | 3 + TestHelper.h | 3 + checkRandomTest.cpp | 2 + createRandomTest.cpp | 3 + fork.cpp | 3 + hexPrefix.cpp | 7 ++- net.cpp | 30 ++++----- rlp.cpp | 147 ++++++++++++++++++++++--------------------- state.cpp | 2 + trie.cpp | 3 + txTest.cpp | 3 + vm.cpp | 7 ++- vm.h | 3 + whisperTopic.cpp | 3 + 14 files changed, 129 insertions(+), 90 deletions(-) diff --git a/TestHelper.cpp b/TestHelper.cpp index 4ee53f88e..16f0d6d10 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -23,8 +23,11 @@ #include #include + +// Make sure boost/asio.hpp is included before windows.h. #include #include + #include #include #include diff --git a/TestHelper.h b/TestHelper.h index 0b80273c8..40294b034 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -22,8 +22,11 @@ #pragma once #include + +// Make sure boost/asio.hpp is included before windows.h. #include #include + #include "JsonSpiritHeaders.h" #include #include diff --git a/checkRandomTest.cpp b/checkRandomTest.cpp index 50c3c367d..f1daaecbf 100644 --- a/checkRandomTest.cpp +++ b/checkRandomTest.cpp @@ -20,7 +20,9 @@ * Check a random test and return 0/1 for success or failure. To be used for efficiency in the random test simulation. */ +// Make sure boost/asio.hpp is included before windows.h. #include + #include #include #include diff --git a/createRandomTest.cpp b/createRandomTest.cpp index da1a028bf..140a7fb38 100644 --- a/createRandomTest.cpp +++ b/createRandomTest.cpp @@ -23,9 +23,12 @@ #include #include #include + +// Make sure boost/asio.hpp is included before windows.h. #include #include #include + #pragma GCC diagnostic ignored "-Wunused-parameter" #include #include diff --git a/fork.cpp b/fork.cpp index 934583164..65c5dd3b5 100644 --- a/fork.cpp +++ b/fork.cpp @@ -19,9 +19,12 @@ * @date 2014 * Tests for different forking behavior */ + +// Make sure boost/asio.hpp is included before windows.h. #include #include #include + #include #include #include diff --git a/hexPrefix.cpp b/hexPrefix.cpp index c96e9e98c..5875d62f6 100644 --- a/hexPrefix.cpp +++ b/hexPrefix.cpp @@ -21,8 +21,11 @@ */ #include + +// Make sure boost/asio.hpp is included before windows.h. #include #include + #include "JsonSpiritHeaders.h" #include #include @@ -54,8 +57,8 @@ BOOST_AUTO_TEST_CASE(hexPrefix_test) for (auto& i: o["seq"].get_array()) v.push_back((byte)i.get_int()); auto e = hexPrefixEncode(v, o["term"].get_bool()); - BOOST_REQUIRE( ! o["out"].is_null() ); - BOOST_CHECK( o["out"].get_str() == toHex(e) ); + BOOST_REQUIRE( ! o["out"].is_null() ); + BOOST_CHECK( o["out"].get_str() == toHex(e) ); } } diff --git a/net.cpp b/net.cpp index f842ff1a3..fafcc1ff6 100644 --- a/net.cpp +++ b/net.cpp @@ -19,8 +19,10 @@ * @date 2014 */ +// Make sure boost/asio.hpp is included before windows.h. #include #include + #include #include #include @@ -44,7 +46,7 @@ public: void start() { startWorking(); } void doWork() { m_io.run(); } void doneWorking() { m_io.reset(); m_io.poll(); m_io.reset(); } - + protected: ba::io_service m_io; }; @@ -53,23 +55,23 @@ struct TestNodeTable: public NodeTable { /// Constructor TestNodeTable(ba::io_service& _io, KeyPair _alias, uint16_t _port = 30300): NodeTable(_io, _alias, _port) {} - + static std::vector> createTestNodes(unsigned _count) { std::vector> ret; asserts(_count < 1000); static uint16_t s_basePort = 30500; - + ret.clear(); for (unsigned i = 0; i < _count; i++) { KeyPair k = KeyPair::create(); ret.push_back(make_pair(k,s_basePort+i)); } - + return std::move(ret); } - + void pingTestNodes(std::vector> const& _testNodes) { bi::address ourIp = bi::address::from_string("127.0.0.1"); @@ -79,7 +81,7 @@ struct TestNodeTable: public NodeTable this_thread::sleep_for(chrono::milliseconds(2)); } } - + void populateTestNodes(std::vector> const& _testNodes, size_t _count = 0) { if (!_count) @@ -92,7 +94,7 @@ struct TestNodeTable: public NodeTable else break; } - + void reset() { Guard l(x_state); @@ -109,13 +111,13 @@ struct TestNodeTableHost: public TestHost ~TestNodeTableHost() { m_io.stop(); stopWorking(); } void setup() { for (auto n: testNodes) nodeTables.push_back(make_shared(m_io,n.first,n.second)); } - + void pingAll() { for (auto& t: nodeTables) t->pingTestNodes(testNodes); } - + void populateAll(size_t _count = 0) { for (auto& t: nodeTables) t->populateTestNodes(testNodes, _count); } - + void populate(size_t _count = 0) { nodeTable->populateTestNodes(testNodes, _count); } - + KeyPair m_alias; shared_ptr nodeTable; std::vector> testNodes; // keypair and port @@ -131,7 +133,7 @@ public: void onReceived(UDPSocketFace*, bi::udp::endpoint const&, bytesConstRef _packet) { if (_packet.toString() == "AAAA") success = true; } shared_ptr> m_socket; - + bool success = false; }; @@ -140,7 +142,7 @@ BOOST_AUTO_TEST_CASE(test_neighbours_packet) KeyPair k = KeyPair::create(); std::vector> testNodes(TestNodeTable::createTestNodes(16)); bi::udp::endpoint to(boost::asio::ip::address::from_string("127.0.0.1"), 30000); - + Neighbours out(to); for (auto n: testNodes) { @@ -187,7 +189,7 @@ BOOST_AUTO_TEST_CASE(kademlia) node.setup(); node.populate(); clog << "NodeTable:\n" << *node.nodeTable.get() << endl; - + node.populateAll(); clog << "NodeTable:\n" << *node.nodeTable.get() << endl; diff --git a/rlp.cpp b/rlp.cpp index c67f09665..fc4f858ed 100644 --- a/rlp.cpp +++ b/rlp.cpp @@ -22,8 +22,11 @@ #include #include + +// Make sure boost/asio.hpp is included before windows.h. #include #include + #include #include #include @@ -67,76 +70,76 @@ namespace dev testPath += "/BasicTests"; string s = asString(contents(testPath + "/rlptest.json")); - BOOST_REQUIRE_MESSAGE( s.length() > 0, - "Contents of 'rlptest.json' is empty. Have you cloned the 'tests' repo branch develop?"); + BOOST_REQUIRE_MESSAGE( s.length() > 0, + "Contents of 'rlptest.json' is empty. Have you cloned the 'tests' repo branch develop?"); js::read_string(s, v); - } + } static void checkRLPTestCase(js::mObject& o) - { - BOOST_REQUIRE( o.count("in") > 0 ); - BOOST_REQUIRE( o.count("out") > 0 ); - BOOST_REQUIRE(!o["out"].is_null()); - } + { + BOOST_REQUIRE( o.count("in") > 0 ); + BOOST_REQUIRE( o.count("out") > 0 ); + BOOST_REQUIRE(!o["out"].is_null()); + } static void checkRLPAgainstJson(js::mValue& v, RLP& u) { - if ( v.type() == js::str_type ) - { + if ( v.type() == js::str_type ) + { const std::string& expectedText = v.get_str(); - if ( !expectedText.empty() && expectedText.front() == '#' ) - { - // Deal with bigint instead of a raw string - std::string bigIntStr = expectedText.substr(1,expectedText.length()-1); - std::stringstream bintStream(bigIntStr); - bigint val; - bintStream >> val; - BOOST_CHECK( !u.isList() ); + if ( !expectedText.empty() && expectedText.front() == '#' ) + { + // Deal with bigint instead of a raw string + std::string bigIntStr = expectedText.substr(1,expectedText.length()-1); + std::stringstream bintStream(bigIntStr); + bigint val; + bintStream >> val; + BOOST_CHECK( !u.isList() ); BOOST_CHECK( !u.isNull() ); BOOST_CHECK( u ); // operator bool() - BOOST_CHECK(u == val); - } - else - { - BOOST_CHECK( !u.isList() ); - BOOST_CHECK( !u.isNull() ); - BOOST_CHECK( u.isData() ); - BOOST_CHECK( u ); - BOOST_CHECK( u.size() == expectedText.length() ); - BOOST_CHECK(u == expectedText); + BOOST_CHECK(u == val); } - } - else if ( v.type() == js::int_type ) - { - const int expectedValue = v.get_int(); - BOOST_CHECK( u.isInt() ); - BOOST_CHECK( !u.isList() ); + else + { + BOOST_CHECK( !u.isList() ); + BOOST_CHECK( !u.isNull() ); + BOOST_CHECK( u.isData() ); + BOOST_CHECK( u ); + BOOST_CHECK( u.size() == expectedText.length() ); + BOOST_CHECK(u == expectedText); + } + } + else if ( v.type() == js::int_type ) + { + const int expectedValue = v.get_int(); + BOOST_CHECK( u.isInt() ); + BOOST_CHECK( !u.isList() ); BOOST_CHECK( !u.isNull() ); BOOST_CHECK( u ); // operator bool() - BOOST_CHECK(u == expectedValue); - } - else if ( v.type() == js::array_type ) - { - BOOST_CHECK( u.isList() ); - BOOST_CHECK( !u.isInt() ); - BOOST_CHECK( !u.isData() ); - js::mArray& arr = v.get_array(); - BOOST_CHECK( u.itemCount() == arr.size() ); - unsigned i; - for( i = 0; i < arr.size(); i++ ) - { - RLP item = u[i]; - checkRLPAgainstJson(arr[i], item); - } - } - else - { + BOOST_CHECK(u == expectedValue); + } + else if ( v.type() == js::array_type ) + { + BOOST_CHECK( u.isList() ); + BOOST_CHECK( !u.isInt() ); + BOOST_CHECK( !u.isData() ); + js::mArray& arr = v.get_array(); + BOOST_CHECK( u.itemCount() == arr.size() ); + unsigned i; + for( i = 0; i < arr.size(); i++ ) + { + RLP item = u[i]; + checkRLPAgainstJson(arr[i], item); + } + } + else + { BOOST_ERROR("Invalid Javascript object!"); - } - - } + } + + } } -} +} BOOST_AUTO_TEST_SUITE(BasicTests) @@ -155,30 +158,30 @@ BOOST_AUTO_TEST_CASE(rlp_encoding_test) RLPStream s; dev::test::buildRLP(o["in"], s); - std::string expectedText(o["out"].get_str()); - std::transform(expectedText.begin(), expectedText.end(), expectedText.begin(), ::tolower ); + std::string expectedText(o["out"].get_str()); + std::transform(expectedText.begin(), expectedText.end(), expectedText.begin(), ::tolower ); - const std::string& computedText = toHex(s.out()); + const std::string& computedText = toHex(s.out()); - std::stringstream msg; + std::stringstream msg; msg << "Encoding Failed: expected: " << expectedText << std::endl; - msg << " But Computed: " << computedText; + msg << " But Computed: " << computedText; BOOST_CHECK_MESSAGE( - expectedText == computedText, + expectedText == computedText, msg.str() - ); + ); } } BOOST_AUTO_TEST_CASE(rlp_decoding_test) { - cnote << "Testing RLP decoding..."; - // Uses the same test cases as encoding but in reverse. - // We read into the string of hex values, convert to bytes, - // and then compare the output structure to the json of the - // input object. + cnote << "Testing RLP decoding..."; + // Uses the same test cases as encoding but in reverse. + // We read into the string of hex values, convert to bytes, + // and then compare the output structure to the json of the + // input object. js::mValue v; dev::test::getRLPTestCases(v); for (auto& i: v.get_obj()) @@ -186,11 +189,11 @@ BOOST_AUTO_TEST_CASE(rlp_decoding_test) js::mObject& o = i.second.get_obj(); cnote << i.first; dev::test::checkRLPTestCase(o); - - js::mValue& inputData = o["in"]; - bytes payloadToDecode = fromHex(o["out"].get_str()); - RLP payload(payloadToDecode); + js::mValue& inputData = o["in"]; + bytes payloadToDecode = fromHex(o["out"].get_str()); + + RLP payload(payloadToDecode); dev::test::checkRLPAgainstJson(inputData, payload); diff --git a/state.cpp b/state.cpp index 99fa36fc7..e2201f241 100644 --- a/state.cpp +++ b/state.cpp @@ -20,9 +20,11 @@ * State test functions. */ +// Make sure boost/asio.hpp is included before windows.h. #include #include #include + #include "JsonSpiritHeaders.h" #include #include diff --git a/trie.cpp b/trie.cpp index a15713412..312749752 100644 --- a/trie.cpp +++ b/trie.cpp @@ -22,8 +22,11 @@ #include #include + +// Make sure boost/asio.hpp is included before windows.h. #include #include + #include "JsonSpiritHeaders.h" #include #include diff --git a/txTest.cpp b/txTest.cpp index dcb2515af..3f67c0a2f 100644 --- a/txTest.cpp +++ b/txTest.cpp @@ -19,9 +19,12 @@ * @date 2014 * Simple peer transaction send test. */ + +// Make sure boost/asio.hpp is included before windows.h. #include #include #include + #include #include #include diff --git a/vm.cpp b/vm.cpp index 423d55ac8..00ba82aaf 100644 --- a/vm.cpp +++ b/vm.cpp @@ -21,8 +21,11 @@ */ #include + +// Make sure boost/asio.hpp is included before windows.h. #include #include + #include #include #include "vm.h" @@ -287,7 +290,7 @@ eth::OnOpFunc FakeExtVM::simpleTrace() /*add the storage*/ Object storage; for (auto const& i: std::get<2>(ext.addresses.find(ext.myAddress)->second)) - storage.push_back(Pair( (string)i.first , (string)i.second)); + storage.push_back(Pair( (string)i.first , (string)i.second)); /*add all the other details*/ o_step.push_back(Pair("storage", storage)); @@ -366,7 +369,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) auto argc = boost::unit_test::framework::master_test_suite().argc; auto argv = boost::unit_test::framework::master_test_suite().argv; for (auto i = 0; i < argc; ++i) - { + { if (std::string(argv[i]) == "--show-times") { auto testDuration = endTime - startTime; diff --git a/vm.h b/vm.h index ae28213bd..03b3b4e5e 100644 --- a/vm.h +++ b/vm.h @@ -25,8 +25,11 @@ along with cpp-ethereum. If not, see . #include #include + +// Make sure boost/asio.hpp is included before windows.h. #include #include + #include #include #include diff --git a/whisperTopic.cpp b/whisperTopic.cpp index 2f90b4fb9..0937ab922 100644 --- a/whisperTopic.cpp +++ b/whisperTopic.cpp @@ -19,8 +19,11 @@ * @date 2014 */ #include + +// Make sure boost/asio.hpp is included before windows.h. #include #include + #include #include #include From e229b5d291eefbf05e77988149d3ba2dc0059575 Mon Sep 17 00:00:00 2001 From: jhuntley Date: Thu, 26 Feb 2015 16:05:53 -0500 Subject: [PATCH 8/8] Revert all asio.h includes except for in 2 files, DebuggingStateWrapper.h and Transact.cpp. After enabling WIN32_LEAN_AND_MEAN, all the asio.h include issues, commit 20b6e24ffcab088e71092e07030a377d3135da3c, went away. --- TestHelper.cpp | 2 -- TestHelper.h | 2 -- checkRandomTest.cpp | 3 --- createRandomTest.cpp | 2 -- fork.cpp | 2 -- genesis.cpp | 4 +--- hexPrefix.cpp | 2 -- net.cpp | 10 ++++------ rlp.cpp | 2 -- state.cpp | 2 -- trie.cpp | 2 -- txTest.cpp | 2 -- vm.cpp | 2 -- vm.h | 2 -- whisperTopic.cpp | 32 +++++++++++++++----------------- 15 files changed, 20 insertions(+), 51 deletions(-) diff --git a/TestHelper.cpp b/TestHelper.cpp index 16f0d6d10..82add295e 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -24,8 +24,6 @@ #include #include -// Make sure boost/asio.hpp is included before windows.h. -#include #include #include diff --git a/TestHelper.h b/TestHelper.h index 40294b034..6f9143c5c 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -23,8 +23,6 @@ #include -// Make sure boost/asio.hpp is included before windows.h. -#include #include #include "JsonSpiritHeaders.h" diff --git a/checkRandomTest.cpp b/checkRandomTest.cpp index f1daaecbf..e3442d438 100644 --- a/checkRandomTest.cpp +++ b/checkRandomTest.cpp @@ -20,9 +20,6 @@ * Check a random test and return 0/1 for success or failure. To be used for efficiency in the random test simulation. */ -// Make sure boost/asio.hpp is included before windows.h. -#include - #include #include #include diff --git a/createRandomTest.cpp b/createRandomTest.cpp index 140a7fb38..55e023759 100644 --- a/createRandomTest.cpp +++ b/createRandomTest.cpp @@ -24,8 +24,6 @@ #include #include -// Make sure boost/asio.hpp is included before windows.h. -#include #include #include diff --git a/fork.cpp b/fork.cpp index 65c5dd3b5..a2eb6f4eb 100644 --- a/fork.cpp +++ b/fork.cpp @@ -20,8 +20,6 @@ * Tests for different forking behavior */ -// Make sure boost/asio.hpp is included before windows.h. -#include #include #include diff --git a/genesis.cpp b/genesis.cpp index a450b79fc..5ac3ea2a8 100644 --- a/genesis.cpp +++ b/genesis.cpp @@ -23,8 +23,6 @@ #include #include -// Make sure boost/asio.hpp is included before windows.h. -#include #include #include "JsonSpiritHeaders.h" @@ -44,7 +42,7 @@ BOOST_AUTO_TEST_CASE(emptySHA3Types) { h256 emptyListSHA3(fromHex("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347")); BOOST_REQUIRE_EQUAL(emptyListSHA3, EmptyListSHA3); - + h256 emptySHA3(fromHex("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")); BOOST_REQUIRE_EQUAL(emptySHA3, EmptySHA3); } diff --git a/hexPrefix.cpp b/hexPrefix.cpp index 5875d62f6..da294ba5b 100644 --- a/hexPrefix.cpp +++ b/hexPrefix.cpp @@ -22,8 +22,6 @@ #include -// Make sure boost/asio.hpp is included before windows.h. -#include #include #include "JsonSpiritHeaders.h" diff --git a/net.cpp b/net.cpp index fafcc1ff6..831c283e2 100644 --- a/net.cpp +++ b/net.cpp @@ -19,8 +19,6 @@ * @date 2014 */ -// Make sure boost/asio.hpp is included before windows.h. -#include #include #include @@ -192,22 +190,22 @@ BOOST_AUTO_TEST_CASE(kademlia) node.populateAll(); clog << "NodeTable:\n" << *node.nodeTable.get() << endl; - + auto nodes = node.nodeTable->nodes(); nodes.sort(); - + node.nodeTable->reset(); clog << "NodeTable:\n" << *node.nodeTable.get() << endl; node.populate(1); clog << "NodeTable:\n" << *node.nodeTable.get() << endl; - + node.nodeTable->discover(); this_thread::sleep_for(chrono::milliseconds(2000)); clog << "NodeTable:\n" << *node.nodeTable.get() << endl; BOOST_REQUIRE_EQUAL(node.nodeTable->count(), 8); - + auto netNodes = node.nodeTable->nodes(); netNodes.sort(); diff --git a/rlp.cpp b/rlp.cpp index fc4f858ed..9062b54f4 100644 --- a/rlp.cpp +++ b/rlp.cpp @@ -23,8 +23,6 @@ #include #include -// Make sure boost/asio.hpp is included before windows.h. -#include #include #include diff --git a/state.cpp b/state.cpp index e2201f241..17ebe2b77 100644 --- a/state.cpp +++ b/state.cpp @@ -20,8 +20,6 @@ * State test functions. */ -// Make sure boost/asio.hpp is included before windows.h. -#include #include #include diff --git a/trie.cpp b/trie.cpp index 312749752..dd335b4a6 100644 --- a/trie.cpp +++ b/trie.cpp @@ -23,8 +23,6 @@ #include #include -// Make sure boost/asio.hpp is included before windows.h. -#include #include #include "JsonSpiritHeaders.h" diff --git a/txTest.cpp b/txTest.cpp index 3f67c0a2f..e2a16e16c 100644 --- a/txTest.cpp +++ b/txTest.cpp @@ -20,8 +20,6 @@ * Simple peer transaction send test. */ -// Make sure boost/asio.hpp is included before windows.h. -#include #include #include diff --git a/vm.cpp b/vm.cpp index 00ba82aaf..e78753e6a 100644 --- a/vm.cpp +++ b/vm.cpp @@ -22,8 +22,6 @@ #include -// Make sure boost/asio.hpp is included before windows.h. -#include #include #include diff --git a/vm.h b/vm.h index 03b3b4e5e..f27bce50b 100644 --- a/vm.h +++ b/vm.h @@ -26,8 +26,6 @@ along with cpp-ethereum. If not, see . #include #include -// Make sure boost/asio.hpp is included before windows.h. -#include #include #include diff --git a/whisperTopic.cpp b/whisperTopic.cpp index 0937ab922..0ea681b67 100644 --- a/whisperTopic.cpp +++ b/whisperTopic.cpp @@ -20,8 +20,6 @@ */ #include -// Make sure boost/asio.hpp is included before windows.h. -#include #include #include @@ -44,10 +42,10 @@ BOOST_AUTO_TEST_CASE(topic) Host host1("Test", NetworkPreferences(30303, "127.0.0.1", false, true)); auto whost1 = host1.registerCapability(new WhisperHost()); host1.start(); - + while (!host1.isStarted()) this_thread::sleep_for(chrono::milliseconds(2)); - + bool started = false; unsigned result = 0; std::thread listener([&]() @@ -75,19 +73,19 @@ BOOST_AUTO_TEST_CASE(topic) } this_thread::sleep_for(chrono::milliseconds(50)); } - + }); - + Host host2("Test", NetworkPreferences(30300, "127.0.0.1", false, true)); auto whost2 = host2.registerCapability(new WhisperHost()); host2.start(); - + while (!host2.isStarted()) this_thread::sleep_for(chrono::milliseconds(2)); - + this_thread::sleep_for(chrono::milliseconds(100)); host2.addNode(host1.id(), "127.0.0.1", 30303, 30303); - + this_thread::sleep_for(chrono::milliseconds(500)); while (!started) @@ -111,7 +109,7 @@ BOOST_AUTO_TEST_CASE(forwarding) cnote << "Testing Whisper forwarding..."; auto oldLogVerbosity = g_logVerbosity; g_logVerbosity = 0; - + // Host must be configured not to share peers. Host host1("Listner", NetworkPreferences(30303, "", false, true)); host1.setIdealPeerCount(0); @@ -119,7 +117,7 @@ BOOST_AUTO_TEST_CASE(forwarding) host1.start(); while (!host1.isStarted()) this_thread::sleep_for(chrono::milliseconds(2)); - + unsigned result = 0; bool done = false; @@ -146,7 +144,7 @@ BOOST_AUTO_TEST_CASE(forwarding) } }); - + // Host must be configured not to share peers. Host host2("Forwarder", NetworkPreferences(30305, "", false, true)); host2.setIdealPeerCount(1); @@ -154,7 +152,7 @@ BOOST_AUTO_TEST_CASE(forwarding) host2.start(); while (!host2.isStarted()) this_thread::sleep_for(chrono::milliseconds(2)); - + Public fwderid; bool startedForwarder = false; std::thread forwarder([&]() @@ -214,7 +212,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding) unsigned result = 0; bool done = false; - + // Host must be configured not to share peers. Host host1("Forwarder", NetworkPreferences(30305, "", false, true)); host1.setIdealPeerCount(1); @@ -227,7 +225,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding) std::thread forwarder([&]() { setThreadName("forwarder"); - + this_thread::sleep_for(chrono::milliseconds(500)); // ph.addNode("127.0.0.1", 30303, 30303); @@ -249,7 +247,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding) while (!startedForwarder) this_thread::sleep_for(chrono::milliseconds(2)); - + { Host host2("Sender", NetworkPreferences(30300, "", false, true)); host2.setIdealPeerCount(1); @@ -261,7 +259,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding) while (!host2.peerCount()) this_thread::sleep_for(chrono::milliseconds(5)); - + KeyPair us = KeyPair::create(); whost2->post(us.sec(), RLPStream().append(1).out(), BuildTopic("test")); this_thread::sleep_for(chrono::milliseconds(250));