Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test MultiChain #3

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*.tar.gz

*.gch
*.exe
src/bitcoin
src/bitcoind
Expand Down
6 changes: 6 additions & 0 deletions src/chainparams/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
#ifndef GLOBALS_H
#define GLOBALS_H


#if defined(UNIT_TESTING_MULTICHAIN)
#include "structs/amount.h"
#include "chainparams/state.h"
#endif // defined

mc_State* mc_gState;
unsigned int MIN_RELAY_TX_FEE = 1000; // new
unsigned int MAX_OP_RETURN_RELAY = 40; // standard.h
Expand Down
4 changes: 3 additions & 1 deletion src/keys/pubkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ bool CPubKey::IsFullyValid() const {

//Validate the key
CryptoPP::AutoSeededRandomPool rnd;
if(!pubKey.Validate(rnd, 3)) {
try {
pubKey.Validate(rnd, 3);
} catch (CryptoPP::Exception& ex) {
std::cout << "Non valid public key in IsFullyValid()\n";
return false;
}
Expand Down
8 changes: 6 additions & 2 deletions src/keys/pubkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ class CPubKey
if (len && len == (pend - pbegin)) {
memcpy(vch, (unsigned char*)&pbegin[0], len);
//Initialize public key from vch
pubKey.Initialize(CryptoPP::ASN1::brainpoolP320r1(), CryptoPP::ECP::Element());
pubKey.Load(CryptoPP::StringStore((const byte*) vch,(size_t) CRYPTOPP_PUBLIC_KEY_SIZE).Ref());
try {
pubKey.Initialize(CryptoPP::ASN1::brainpoolP320r1(), CryptoPP::ECP::Element());
pubKey.Load(CryptoPP::StringStore((const byte*) vch,(size_t) CRYPTOPP_PUBLIC_KEY_SIZE).Ref());
} catch(CryptoPP::Exception& ex) {
Invalidate();
}
}
else
Invalidate();
Expand Down
2 changes: 2 additions & 0 deletions src/test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data/
!Makefile
50 changes: 50 additions & 0 deletions src/test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
HEADERS = test1.o catch.hpp ../structs/amount.h ../keys/key.h ../keys/pubkey.h \
../structs/hash.h ../crypto/ripemd160.h ../crypto/sha256.h \
../utils/serialize.h ../structs/uint256.h ../version/bcversion.h \
../utils/allocators.h ../crypto/common.h ../crypto/hmac_sha512.h \
../crypto/sha512.h ../utils/utilstrencodings.h ../utils/random.h \
../utils/util.h ../utils/utiltime.h ../chainparams/chainparamsbase.h \
../chainparams/params.h \
../version/version.h ../multichain/multichain.h \
../primitives/block.h ../chainparams/globals.h ../utils/streams.h \
../version/clientversion.h

SOURCES =../keys/pubkey.cpp \
../keys/key.cpp ../crypto/sha256.cpp ../structs/hash.cpp ../crypto/ripemd160.cpp \
../structs/uint256.cpp ../utils/allocators.cpp ../crypto/hmac_sha512.cpp \
../crypto/sha512.cpp ../utils/utilstrencodings.cpp ../utils/random.cpp \
../utils/util.cpp ../utils/utiltime.cpp ../chainparams/chainparamsbase.cpp \
../utils/utilwrapper.cpp ../utils/tools.cpp ../chainparams/params.cpp \
../utils/utility.cpp ../utils/systemdependent.cpp ../version/version.cpp \
../structs/amount.cpp



COV=-fprofile-arcs -ftest-coverage

LIB=-lcryptopp -lcrypto \
-lboost_thread -lboost_filesystem \
-lboost_system -lboost_program_options -lpthread
INC=-I../ \
-I../secp256k1/ \
-I../secp256k1/include/


FLAGS=-DHAVE_DECL_STRNLEN -DHAVE_WORKING_BOOST_SLEEP_FOR -DUNIT_TESTING_MULTICHAIN

STATIC_LIBS = ../secp256k1/.libs/libsecp256k1.a


NAME=tst.o


default : comp go

#test: test1.cpp
# g++ -c test1.cpp -I../ -lcryptopp -o $(NAME)

comp: test1.cpp
g++ -c test1.cpp -I../ $(COV)

go: test1.cpp
g++ $(FLAGS) $(COV) $(HEADERS) $(SOURCES) $(LIB) $(INC) $(STATIC_LIBS)
8 changes: 8 additions & 0 deletions src/test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Install notes

First install all dependencies of MultiChain, see the readme in the main folder.

Then install `gcovr` with `pip install gcovr`, this allows us to see the percentage of coverage.

# Execute tests
Run `sh test.sh`, this will build the tests and run it. A html file is created with as content the coverage of the files. This html file can be found in `test/data/coverage.html`.
Loading