forked from dashpay/dash
-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[QA] Add test for BLS sign/verify message and sethexstr
- Loading branch information
1 parent
8915b60
commit 9f087cd
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) 2019-2020 The Dash Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include "test/test_pivx.h" | ||
#include "bls/bls_wrapper.h" | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
BOOST_FIXTURE_TEST_SUITE(bls_tests, BasicTestingSetup) | ||
|
||
BOOST_AUTO_TEST_CASE(bls_sethexstr_tests) | ||
{ | ||
CBLSSecretKey sk; | ||
std::string strValidSecret = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"; | ||
// Note: invalid string passed to SetHexStr() should cause it to fail and reset key internal data | ||
BOOST_CHECK(sk.SetHexStr(strValidSecret)); | ||
BOOST_CHECK(!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1g")); // non-hex | ||
BOOST_CHECK(!sk.IsValid()); | ||
BOOST_CHECK(sk == CBLSSecretKey()); | ||
// Try few more invalid strings | ||
BOOST_CHECK(sk.SetHexStr(strValidSecret)); | ||
BOOST_CHECK(!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e")); // hex but too short | ||
BOOST_CHECK(!sk.IsValid()); | ||
BOOST_CHECK(sk.SetHexStr(strValidSecret)); | ||
BOOST_CHECK(!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20")); // hex but too long | ||
BOOST_CHECK(!sk.IsValid()); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(bls_sig_tests) | ||
{ | ||
CBLSSecretKey sk1, sk2; | ||
sk1.MakeNewKey(); | ||
sk2.MakeNewKey(); | ||
|
||
uint256 msgHash1 = uint256S("0000000000000000000000000000000000000000000000000000000000000001"); | ||
uint256 msgHash2 = uint256S("0000000000000000000000000000000000000000000000000000000000000002"); | ||
|
||
auto sig1 = sk1.Sign(msgHash1); | ||
auto sig2 = sk2.Sign(msgHash1); | ||
|
||
BOOST_CHECK(sig1.VerifyInsecure(sk1.GetPublicKey(), msgHash1)); | ||
BOOST_CHECK(!sig1.VerifyInsecure(sk1.GetPublicKey(), msgHash2)); | ||
|
||
BOOST_CHECK(sig2.VerifyInsecure(sk2.GetPublicKey(), msgHash1)); | ||
BOOST_CHECK(!sig2.VerifyInsecure(sk2.GetPublicKey(), msgHash2)); | ||
|
||
BOOST_CHECK(!sig1.VerifyInsecure(sk2.GetPublicKey(), msgHash1)); | ||
BOOST_CHECK(!sig1.VerifyInsecure(sk2.GetPublicKey(), msgHash2)); | ||
BOOST_CHECK(!sig2.VerifyInsecure(sk1.GetPublicKey(), msgHash1)); | ||
BOOST_CHECK(!sig2.VerifyInsecure(sk1.GetPublicKey(), msgHash2)); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |