|
4 | 4 |
|
5 | 5 | #include "test_pivx.h" |
6 | 6 |
|
| 7 | +#include "bls/bls_wrapper.h" |
7 | 8 | #include "budget/budgetmanager.h" |
8 | 9 | #include "masternode-payments.h" |
9 | 10 | #include "masternode-sync.h" |
@@ -446,7 +447,62 @@ BOOST_FIXTURE_TEST_CASE(IsCoinbaseValueValid_test, TestingSetup) |
446 | 447 | cbase.vout[1].nValue = budgAmt/2 + 1; |
447 | 448 | BOOST_CHECK(!IsCoinbaseValueValid(MakeTransactionRef(cbase), budgAmt, state)); |
448 | 449 | BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-superblock-cb-amt"); |
| 450 | +} |
449 | 451 |
|
| 452 | +BOOST_AUTO_TEST_CASE(fbv_signverify_bls) |
| 453 | +{ |
| 454 | + CBLSSecretKey sk1, sk2; |
| 455 | + sk1.MakeNewKey(); |
| 456 | + sk2.MakeNewKey(); |
| 457 | + BOOST_ASSERT(sk1 != sk2); |
| 458 | + |
| 459 | + CTxIn vin(COutPoint(uint256S("0000000000000000000000000000000000000000000000000000000000000002"), 0)); |
| 460 | + CTxIn vin2(COutPoint(uint256S("000000000000000000000000000000000000000000000000000000000000003"), 0)); |
| 461 | + CTxIn vin3(COutPoint(uint256S("0000000000000000000000000000000000000000000000000000000000000002"), 1)); |
| 462 | + |
| 463 | + uint256 budgetHash1 = uint256S("0000000000000000000000000000000000000000000000000000000000000001"); |
| 464 | + uint256 budgetHash2 = uint256S("0000000000000000000000000000000000010000000000000000000000000001"); |
| 465 | + |
| 466 | + // Create serialized finalbudgetvote for budgetHash1, signed with sk1 |
| 467 | + CFinalizedBudgetVote vote(vin, budgetHash1); |
| 468 | + BOOST_CHECK(vote.Sign(sk1)); |
| 469 | + CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); |
| 470 | + ss << vote; |
| 471 | + |
| 472 | + // Verify received message on pk1 |
| 473 | + CFinalizedBudgetVote _vote; |
| 474 | + ss >> _vote; |
| 475 | + BOOST_CHECK(_vote.CheckSignature(sk1.GetPublicKey())); |
| 476 | + |
| 477 | + // Failing verification on pk2 |
| 478 | + BOOST_CHECK(!_vote.CheckSignature(sk2.GetPublicKey())); |
| 479 | + |
| 480 | + std::vector<unsigned char> sig = _vote.GetVchSig(); |
| 481 | + |
| 482 | + // Failing with different time |
| 483 | + CFinalizedBudgetVote vote1(_vote); |
| 484 | + vote1.SetTime(vote1.GetTime()+1); |
| 485 | + BOOST_CHECK(!vote1.CheckSignature(sk1.GetPublicKey())); |
| 486 | + |
| 487 | + // Failing with different budget hash |
| 488 | + CFinalizedBudgetVote vote2(vin, budgetHash2); |
| 489 | + vote2.SetTime(_vote.GetTime()); |
| 490 | + vote2.SetVchSig(sig); |
| 491 | + BOOST_CHECK(!vote2.CheckSignature(sk1.GetPublicKey())); |
| 492 | + |
| 493 | + // Failing with different vins: different txid (vin2) or voutn (vin3) |
| 494 | + CFinalizedBudgetVote vote3_1(vin, budgetHash1); |
| 495 | + CFinalizedBudgetVote vote3_2(vin2, budgetHash1); |
| 496 | + CFinalizedBudgetVote vote3_3(vin3, budgetHash1); |
| 497 | + vote3_1.SetTime(_vote.GetTime()); |
| 498 | + vote3_2.SetTime(_vote.GetTime()); |
| 499 | + vote3_3.SetTime(_vote.GetTime()); |
| 500 | + vote3_1.SetVchSig(sig); |
| 501 | + vote3_2.SetVchSig(sig); |
| 502 | + vote3_3.SetVchSig(sig); |
| 503 | + BOOST_CHECK(vote3_1.CheckSignature(sk1.GetPublicKey())); // vote3_1 == _vote |
| 504 | + BOOST_CHECK(!vote3_2.CheckSignature(sk1.GetPublicKey())); |
| 505 | + BOOST_CHECK(!vote3_3.CheckSignature(sk1.GetPublicKey())); |
450 | 506 | } |
451 | 507 |
|
452 | 508 | BOOST_AUTO_TEST_SUITE_END() |
0 commit comments