1 // Aleth: Ethereum C++ client, tools and libraries.
2 // Copyright 2014-2019 Aleth Authors.
3 // Licensed under the GNU General Public License, Version 3.
4 
5 /// @file
6 /// Unit tests for blockchain test filling/execution.
7 #include <test/tools/libtesteth/TestOutputHelper.h>
8 #include <test/tools/libtesteth/TestHelper.h>
9 #include <test/tools/jsontests/BlockChainTests.h>
10 
11 #include <boost/test/unit_test.hpp>
12 
13 using namespace dev::test;
14 
BOOST_FIXTURE_TEST_SUITE(BlockChainTestSuite,TestOutputHelperFixture)15 BOOST_FIXTURE_TEST_SUITE(BlockChainTestSuite, TestOutputHelperFixture)
16 
17 BOOST_AUTO_TEST_CASE(fillingExpectationOnMultipleNetworks)
18 {
19     std::string const s = R"(
20         {
21             "fillingExpectationOnMultipleNetworks" : {
22                 "blocks" : [
23                 ],
24                 "expect" : [
25                     {
26                         "network" : ["EIP150", "EIP158"],
27                         "result" : {
28                             "0x1000000000000000000000000000000000000000" : {
29                                 "balance" : "0x00"
30                             },
31                             "0x1000000000000000000000000000000000000001" : {
32                                 "balance" : "0x00"
33                             }
34                         }
35                     }
36                 ],
37                 "genesisBlockHeader" : {
38                     "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
39                     "coinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
40                     "difficulty" : "131072",
41                     "extraData" : "0x42",
42                     "gasLimit" : "0x7fffffffffffffff",
43                     "gasUsed" : "0",
44                     "mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
45                     "nonce" : "0x0102030405060708",
46                     "number" : "0",
47                     "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
48                     "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
49                     "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
50                     "timestamp" : "0x03b6",
51                     "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
52                     "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
53                 },
54                 "pre" : {
55                     "0x1000000000000000000000000000000000000000" : {
56                         "balance" : "0x00",
57                         "code" : "0x60004060005563ffffffff4060015567ffffffffffffffff406002556fffffffffffffffffffffffffffffffff406003557fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff40600455",
58                         "nonce" : "0x00",
59                         "storage" : {
60                         }
61                     },
62                 "0x1000000000000000000000000000000000000001" : {
63                     "balance" : "0x00",
64                     "code" : "0x60004060005563ffffffff4060015567ffffffffffffffff406002556fffffffffffffffffffffffffffffffff406003557fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff40600455",
65                     "nonce" : "0x00",
66                     "storage" : {
67                     }
68                 }
69         }
70     )";
71     json_spirit::mValue input;
72     json_spirit::read_string(s, input);
73     BlockchainValidTestSuite suite;
74     json_spirit::mValue output = suite.doTests(input, true);
75     BOOST_CHECK_MESSAGE(output.get_obj().size() == 2, "A wrong number of tests were generated.");
76 }
77 
BOOST_AUTO_TEST_CASE(fillingExpectationOnSingleNetwork)78 BOOST_AUTO_TEST_CASE(fillingExpectationOnSingleNetwork)
79 {
80     std::string const s = R"(
81         {
82             "fillingExpectationOnSingleNetwork" : {
83                 "blocks" : [
84                      {
85                        "transactions" : [
86                         {
87                             "data" : "0x",
88                             "gasLimit" : "0x030d40",
89                             "gasPrice" : "0x01",
90                             "nonce" : "0x00",
91                             "to" : "0x1baf27b88c48dd02b744999cf3522766929d2b2a",
92                             "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
93                             "value" : "0x00"
94                         }
95                         ],
96                         "uncleHeaders" : [
97                         ]
98                     }
99                 ],
100                 "expect" : [
101                     {
102                         "network" : "EIP150",
103                         "result" : {
104                             "0x1000000000000000000000000000000000000000" : {
105                                 "balance" : "0x00"
106                             },
107                             "0x1000000000000000000000000000000000000001" : {
108                                 "balance" : "0x00"
109                             },
110                             "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
111                                 "code" : "0x",
112                                 "nonce" : "1"
113                             }
114                         }
115                     }
116                 ],
117                 "sealEngine" : "NoProof",
118                 "genesisBlockHeader" : {
119                     "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
120                     "coinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
121                     "difficulty" : "131072",
122                     "extraData" : "0x42",
123                     "gasLimit" : "0x7fffffffffffffff",
124                     "gasUsed" : "0",
125                     "mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
126                     "nonce" : "0x0102030405060708",
127                     "number" : "0",
128                     "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
129                     "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
130                     "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
131                     "timestamp" : "0x03b6",
132                     "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
133                     "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
134                 },
135                 "pre" : {
136                     "0x1000000000000000000000000000000000000000" : {
137                         "balance" : "0x00",
138                         "code" : "0x60004060005563ffffffff4060015567ffffffffffffffff406002556fffffffffffffffffffffffffffffffff406003557fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff40600455",
139                         "nonce" : "0x00",
140                         "storage" : {
141                         }
142                     },
143                     "0x1000000000000000000000000000000000000001" : {
144                         "balance" : "0x00",
145                         "code" : "0x60004060005563ffffffff4060015567ffffffffffffffff406002556fffffffffffffffffffffffffffffffff406003557fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff40600455",
146                         "nonce" : "0x00",
147                         "storage" : {
148                         }
149                     },
150                     "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
151                         "balance" : "10000000000",
152                         "nonce" : "0",
153                         "code" : "",
154                         "storage": {}
155                     }
156             }
157     )";
158     json_spirit::mValue input;
159     json_spirit::read_string(s, input);
160     BlockchainValidTestSuite suite;
161     json_spirit::mValue output = suite.doTests(input, true);
162     const string testname = "fillingExpectationOnSingleNetwork_EIP150";
163     BOOST_CHECK_MESSAGE(output.get_obj().size() == 1, "A wrong number of tests were generated.");
164     BOOST_CHECK_MESSAGE(output.get_obj().count(testname) > 0, "Missing test name!");
165 
166     json_spirit::mObject const& testObject = output.get_obj().at(testname).get_obj();
167     BOOST_CHECK_MESSAGE(testObject.size() == 8, "Wrong number of objects in the filled test!");
168     BOOST_CHECK_MESSAGE(testObject.at("blocks").get_array().size() > 0, "Missing blocks in the filled test!");
169 
170     json_spirit::mObject const& testBlock = testObject.at("blocks").get_array().at(0).get_obj();
171     BOOST_CHECK_MESSAGE(testBlock.size() == 4, "Wrong number of items in filled block section!");
172     BOOST_CHECK_MESSAGE(testBlock.at("transactions").get_array().size() == 1, "Wrong number of transactions filled test!");
173 
174     json_spirit::mObject const& testTransaction = testBlock.at("transactions").get_array().at(0).get_obj();
175     BOOST_CHECK_MESSAGE(testTransaction.at("data").get_str() == "0x", "Data in the transaction must be 0x prefixed (even if empty)!");
176 }
177 
178 
179 BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(fillingWithWrongExpectation, 2)
BOOST_AUTO_TEST_CASE(fillingWithWrongExpectation)180 BOOST_AUTO_TEST_CASE(fillingWithWrongExpectation)
181 {
182     cout << "BlockChainTestSuite/fillingWithWrongExpectation test - failure is expected\n";
183 
184     std::string const s = R"(
185         {
186             "fillingWithWrongExpectation" : {
187                 "blocks" : [
188                 ],
189                 "expect" : [
190                     {
191                         "network" : ["EIP150"],
192                         "result" : {
193                             "0x1000000000000000000000000000000000000000" : {
194                                 "balance" : "0x01"
195                             },
196                             "0x1000000000000000000000000000000000000001" : {
197                                 "balance" : "0x00"
198                             }
199                         }
200                     }
201                 ],
202                 "genesisBlockHeader" : {
203                     "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
204                     "coinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
205                     "difficulty" : "131072",
206                     "extraData" : "0x42",
207                     "gasLimit" : "0x7fffffffffffffff",
208                     "gasUsed" : "0",
209                     "mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
210                     "nonce" : "0x0102030405060708",
211                     "number" : "0",
212                     "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
213                     "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
214                     "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
215                     "timestamp" : "0x03b6",
216                     "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
217                     "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
218                 },
219                 "pre" : {
220                     "0x1000000000000000000000000000000000000000" : {
221                         "balance" : "0x00",
222                         "code" : "0x60004060005563ffffffff4060015567ffffffffffffffff406002556fffffffffffffffffffffffffffffffff406003557fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff40600455",
223                         "nonce" : "0x00",
224                         "storage" : {
225                         }
226                     },
227                 "0x1000000000000000000000000000000000000001" : {
228                     "balance" : "0x00",
229                     "code" : "0x60004060005563ffffffff4060015567ffffffffffffffff406002556fffffffffffffffffffffffffffffffff406003557fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff40600455",
230                     "nonce" : "0x00",
231                     "storage" : {
232                     }
233                 }
234         }
235     )";
236     json_spirit::mValue input;
237     json_spirit::read_string(s, input);
238 
239     BlockchainValidTestSuite suite;
240     json_spirit::mValue output = suite.doTests(input, true);
241     BOOST_CHECK_MESSAGE(output.get_obj().size() == 1, "A wrong number of tests were generated.");
242 }
243 
244 BOOST_AUTO_TEST_SUITE_END()
245