Skip to content

Commit b0a7fa5

Browse files
committed
[QA] Add tests for fbv messages signed with BLS keys
1 parent dd0fb01 commit b0a7fa5

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/test/budget_tests.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "test_pivx.h"
66

7+
#include "bls/bls_wrapper.h"
78
#include "budget/budgetmanager.h"
89
#include "masternode-payments.h"
910
#include "masternode-sync.h"
@@ -446,7 +447,62 @@ BOOST_FIXTURE_TEST_CASE(IsCoinbaseValueValid_test, TestingSetup)
446447
cbase.vout[1].nValue = budgAmt/2 + 1;
447448
BOOST_CHECK(!IsCoinbaseValueValid(MakeTransactionRef(cbase), budgAmt, state));
448449
BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-superblock-cb-amt");
450+
}
449451

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()));
450506
}
451507

452508
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)