Skip to content

Commit 0253ea7

Browse files
committed
[QA] Add test for BLS sign/verify message and sethexstr
1 parent c4c6efe commit 0253ea7

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

src/Makefile.test.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ BITCOIN_TESTS =\
9999
test/base64_tests.cpp \
100100
test/bech32_tests.cpp \
101101
test/bip32_tests.cpp \
102+
test/bls_tests.cpp \
102103
test/budget_tests.cpp \
103104
test/checkblock_tests.cpp \
104105
test/Checkpoints_tests.cpp \

src/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ set(BITCOIN_TESTS
118118
${CMAKE_CURRENT_SOURCE_DIR}/bech32_tests.cpp
119119
${CMAKE_CURRENT_SOURCE_DIR}/budget_tests.cpp
120120
${CMAKE_CURRENT_SOURCE_DIR}/bip32_tests.cpp
121+
${CMAKE_CURRENT_SOURCE_DIR}/bls_tests.cpp
121122
${CMAKE_CURRENT_SOURCE_DIR}/checkblock_tests.cpp
122123
${CMAKE_CURRENT_SOURCE_DIR}/Checkpoints_tests.cpp
123124
${CMAKE_CURRENT_SOURCE_DIR}/coins_tests.cpp

src/test/bls_tests.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) 2019-2020 The Dash Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include "test/test_pivx.h"
6+
#include "bls/bls_wrapper.h"
7+
8+
#include <boost/test/unit_test.hpp>
9+
10+
BOOST_FIXTURE_TEST_SUITE(bls_tests, BasicTestingSetup)
11+
12+
BOOST_AUTO_TEST_CASE(bls_sethexstr_tests)
13+
{
14+
CBLSSecretKey sk;
15+
std::string strValidSecret = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f";
16+
// Note: invalid string passed to SetHexStr() should cause it to fail and reset key internal data
17+
BOOST_CHECK(sk.SetHexStr(strValidSecret));
18+
BOOST_CHECK(!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1g")); // non-hex
19+
BOOST_CHECK(!sk.IsValid());
20+
BOOST_CHECK(sk == CBLSSecretKey());
21+
// Try few more invalid strings
22+
BOOST_CHECK(sk.SetHexStr(strValidSecret));
23+
BOOST_CHECK(!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e")); // hex but too short
24+
BOOST_CHECK(!sk.IsValid());
25+
BOOST_CHECK(sk.SetHexStr(strValidSecret));
26+
BOOST_CHECK(!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20")); // hex but too long
27+
BOOST_CHECK(!sk.IsValid());
28+
}
29+
30+
BOOST_AUTO_TEST_CASE(bls_sig_tests)
31+
{
32+
CBLSSecretKey sk1, sk2;
33+
sk1.MakeNewKey();
34+
sk2.MakeNewKey();
35+
36+
uint256 msgHash1 = uint256S("0000000000000000000000000000000000000000000000000000000000000001");
37+
uint256 msgHash2 = uint256S("0000000000000000000000000000000000000000000000000000000000000002");
38+
39+
auto sig1 = sk1.Sign(msgHash1);
40+
auto sig2 = sk2.Sign(msgHash1);
41+
42+
BOOST_CHECK(sig1.VerifyInsecure(sk1.GetPublicKey(), msgHash1));
43+
BOOST_CHECK(!sig1.VerifyInsecure(sk1.GetPublicKey(), msgHash2));
44+
45+
BOOST_CHECK(sig2.VerifyInsecure(sk2.GetPublicKey(), msgHash1));
46+
BOOST_CHECK(!sig2.VerifyInsecure(sk2.GetPublicKey(), msgHash2));
47+
48+
BOOST_CHECK(!sig1.VerifyInsecure(sk2.GetPublicKey(), msgHash1));
49+
BOOST_CHECK(!sig1.VerifyInsecure(sk2.GetPublicKey(), msgHash2));
50+
BOOST_CHECK(!sig2.VerifyInsecure(sk1.GetPublicKey(), msgHash1));
51+
BOOST_CHECK(!sig2.VerifyInsecure(sk1.GetPublicKey(), msgHash2));
52+
}
53+
54+
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)