Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit 75cc789

Browse files
committed
test_importRawBlock should fail when block import fails.
1 parent be6ce38 commit 75cc789

File tree

2 files changed

+77
-4
lines changed

2 files changed

+77
-4
lines changed

libethereum/ClientTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,10 @@ h256 ClientTest::importRawBlock(const string& _blockRLP)
160160
tie(ignore, moreToImport, ignore) = syncQueue(100000);
161161
this_thread::sleep_for(chrono::milliseconds(100));
162162
}
163+
164+
// check that it was really imported and not rejected as invalid
165+
if (!bc().isKnown(blockHash))
166+
BOOST_THROW_EXCEPTION(ImportBlockFailed());
167+
163168
return blockHash;
164169
}

test/unittests/libweb3jsonrpc/jsonrpc.cpp

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,33 @@ BOOST_AUTO_TEST_CASE(test_importRawBlock)
729729
Json::Value ret;
730730
Json::Reader().parse(c_genesisConfigString, ret);
731731
rpcClient->test_setChainParams(ret);
732+
732733
string blockHash = rpcClient->test_importRawBlock(
734+
"0xf90213f9020ea0c92211c9cd49036c37568feedb8e518a24a77e9f6ca959931a19dcf186a8e1e6a01dcc4de8"
735+
"dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347942adc25665018aa1fe0e6bc666dac8fc2"
736+
"697ff9baa04b4b7a0d58a2388c0e6b3b048c3c27edd6febc6f04171167ed15a77ab2e60b16a056e81f171bcc55"
737+
"a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e0"
738+
"1b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000"
739+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
740+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
741+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
742+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
743+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
744+
"00008302000001830f460f80845d1ca87c97d68094312e372e302b2b63346336646c696e7578636c61a0000000"
745+
"0000000000000000000000000000000000000000000000000000000000880000000000000000c0c0");
746+
BOOST_CHECK_EQUAL(
747+
blockHash, "0x0ef84365e15a50e7440286de7e9c1ca47f17af98b2c8d3d97503045d8f5a128b");
748+
749+
BOOST_CHECK_EQUAL(web3->ethereum()->number(), 1);
750+
}
751+
752+
BOOST_AUTO_TEST_CASE(test_importRawBlockFailsForInvalidHeader)
753+
{
754+
Json::Value ret;
755+
Json::Reader().parse(c_genesisConfigString, ret);
756+
rpcClient->test_setChainParams(ret);
757+
// invalid difficulty (below minimum)
758+
std::string block =
733759
"0xf90279f9020ea0c92211c9cd49036c37568feedb8e518a24a77e9f6ca959931a19dcf186a8e1e6a01dcc4de8"
734760
"dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347942adc25665018aa1fe0e6bc666dac8fc2"
735761
"697ff9baa0328f16ca7b0259d7617b3ddf711c107efe6d5785cbeb11a8ed1614b484a6bc3aa093ca2a18d52e7c"
@@ -740,13 +766,55 @@ BOOST_AUTO_TEST_CASE(test_importRawBlock)
740766
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
741767
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
742768
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
743-
"00008304000001830f460f82a0348203e897d68094312e342e302b2b62383163726c696e7578676e75a08e2042"
769+
"00008301000001830f460f82a0348203e897d68094312e342e302b2b62383163726c696e7578676e75a08e2042"
744770
"e00086a18e2f095bc997dc11d1c93fcf34d0540a428ee95869a4a62264883f8fd3f43a3567c3f865f863800183"
745771
"061a8094095e7baea6a6c7c4c2dfeb977efac326af552d87830186a0801ca0e94818d1f3b0c69eb37720145a5e"
746772
"ad7fbf6f8d80139dd53953b4a782301050a3a01fcf46908c01576715411be0857e30027d6be3250a3653f049b3"
747-
"ff8d74d2540cc0");
748-
BOOST_CHECK_EQUAL(
749-
blockHash, "0xedef94eddd6002ae14803b91aa5138932f948026310144fc615d52d7d5ff29c7");
773+
"ff8d74d2540cc0";
774+
BOOST_CHECK_THROW(rpcClient->test_importRawBlock(block), jsonrpc::JsonRpcException);
775+
776+
// invalid difficulty (above minimum but incorrect value)
777+
block =
778+
"0xf90279f9020ea0c92211c9cd49036c37568feedb8e518a24a77e9f6ca959931a19dcf186a8e1e6a01dcc4de8"
779+
"dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347942adc25665018aa1fe0e6bc666dac8fc2"
780+
"697ff9baa0328f16ca7b0259d7617b3ddf711c107efe6d5785cbeb11a8ed1614b484a6bc3aa093ca2a18d52e7c"
781+
"1846f7b104e2fc1e5fdc71ebe38187248f9437d39e74f43aaba0e151c94b824bded58346fa03fc91fa275bd0cf"
782+
"94caac0ea4ebb9c8d32a574644b901000000000000000000000000000000000000000000000000000000000000"
783+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
784+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
785+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
786+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
787+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
788+
"00008303000001830f460f82a0348203e897d68094312e342e302b2b62383163726c696e7578676e75a08e2042"
789+
"e00086a18e2f095bc997dc11d1c93fcf34d0540a428ee95869a4a62264883f8fd3f43a3567c3f865f863800183"
790+
"061a8094095e7baea6a6c7c4c2dfeb977efac326af552d87830186a0801ca0e94818d1f3b0c69eb37720145a5e"
791+
"ad7fbf6f8d80139dd53953b4a782301050a3a01fcf46908c01576715411be0857e30027d6be3250a3653f049b3"
792+
"ff8d74d2540cc0";
793+
BOOST_CHECK_THROW(rpcClient->test_importRawBlock(block), jsonrpc::JsonRpcException);
794+
}
795+
796+
BOOST_AUTO_TEST_CASE(test_importRawBlockFailsForInvalidBlockBody)
797+
{
798+
Json::Value ret;
799+
Json::Reader().parse(c_genesisConfigString, ret);
800+
rpcClient->test_setChainParams(ret);
801+
802+
// incorrect receipts root
803+
string block =
804+
"0xf90213f9020ea0c92211c9cd49036c37568feedb8e518a24a77e9f6ca959931a19dcf186a8e1e6a01dcc4de8"
805+
"dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347942adc25665018aa1fe0e6bc666dac8fc2"
806+
"697ff9baa04b4b7a0d58a2388c0e6b3b048c3c27edd6febc6f04171167ed15a77ab2e60b16a056e81f171bcc55"
807+
"a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e0"
808+
"1b996cadc001622fb5e363baaab901000000000000000000000000000000000000000000000000000000000000"
809+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
810+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
811+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
812+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
813+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
814+
"00008302000001830f460f80845d1ca87c97d68094312e372e302b2b63346336646c696e7578636c61a0000000"
815+
"0000000000000000000000000000000000000000000000000000000000880000000000000000c0c0";
816+
817+
BOOST_CHECK_THROW(rpcClient->test_importRawBlock(block), jsonrpc::JsonRpcException);
750818
}
751819

752820
BOOST_AUTO_TEST_CASE(call_from_parameter)

0 commit comments

Comments
 (0)