tweaks
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||||
#include <cryptoconditions.h>
|
#include <cryptoconditions.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include "cc/betprotocol.h"
|
#include "cc/betprotocol.h"
|
||||||
#include "cc/eval.h"
|
#include "cc/eval.h"
|
||||||
#include "base58.h"
|
#include "base58.h"
|
||||||
@@ -13,16 +12,12 @@
|
|||||||
#include "primitives/transaction.h"
|
#include "primitives/transaction.h"
|
||||||
#include "script/interpreter.h"
|
#include "script/interpreter.h"
|
||||||
#include "script/serverchecker.h"
|
#include "script/serverchecker.h"
|
||||||
|
|
||||||
#include "testutils.h"
|
#include "testutils.h"
|
||||||
|
|
||||||
|
|
||||||
extern Eval* EVAL_TEST;
|
extern Eval* EVAL_TEST;
|
||||||
|
|
||||||
|
|
||||||
namespace TestBet {
|
namespace TestBet {
|
||||||
|
|
||||||
|
|
||||||
static std::vector<CKey> playerSecrets;
|
static std::vector<CKey> playerSecrets;
|
||||||
static std::vector<CPubKey> players;
|
static std::vector<CPubKey> players;
|
||||||
|
|
||||||
|
|||||||
@@ -22,30 +22,24 @@
|
|||||||
#include "script/interpreter.h"
|
#include "script/interpreter.h"
|
||||||
#include "testutils.h"
|
#include "testutils.h"
|
||||||
|
|
||||||
|
// We need to have control of Time Itself, otherwise block production can fail.
|
||||||
|
int64_t nMockTime;
|
||||||
|
extern uint32_t USE_EXTERNAL_PUBKEY;
|
||||||
|
extern std::string NOTARY_PUBKEY;
|
||||||
|
// This is a publicly burned keypair for Testing Purposes Only, lulz
|
||||||
|
// Have fun, Blockchain Analysts ;)
|
||||||
std::string notaryPubkey = "0205a8ad0c1dbc515f149af377981aab58b836af008d4d7ab21bd76faf80550b47";
|
std::string notaryPubkey = "0205a8ad0c1dbc515f149af377981aab58b836af008d4d7ab21bd76faf80550b47";
|
||||||
std::string notarySecret = "UxFWWxsf1d7w7K5TvAWSkeX4H95XQKwdwGv49DXwWUTzPTTjHBbU";
|
std::string notarySecret = "UxFWWxsf1d7w7K5TvAWSkeX4H95XQKwdwGv49DXwWUTzPTTjHBbU";
|
||||||
CKey notaryKey;
|
CKey notaryKey;
|
||||||
|
|
||||||
|
void setupChain() {
|
||||||
/*
|
|
||||||
* We need to have control of clock,
|
|
||||||
* otherwise block production can fail.
|
|
||||||
*/
|
|
||||||
int64_t nMockTime;
|
|
||||||
|
|
||||||
extern uint32_t USE_EXTERNAL_PUBKEY;
|
|
||||||
extern std::string NOTARY_PUBKEY;
|
|
||||||
|
|
||||||
void setupChain()
|
|
||||||
{
|
|
||||||
SelectParams(CBaseChainParams::REGTEST);
|
SelectParams(CBaseChainParams::REGTEST);
|
||||||
|
|
||||||
// Settings to get block reward
|
// Settings to get block reward
|
||||||
NOTARY_PUBKEY = notaryPubkey;
|
NOTARY_PUBKEY = notaryPubkey;
|
||||||
USE_EXTERNAL_PUBKEY = 1;
|
USE_EXTERNAL_PUBKEY = 1;
|
||||||
mapArgs["-mineraddress"] = "bogus";
|
mapArgs["-mineraddress"] = "bogus";
|
||||||
COINBASE_MATURITY = 1;
|
COINBASE_MATURITY = 1;
|
||||||
// Global mock time
|
// Global mock time
|
||||||
nMockTime = GetTime();
|
nMockTime = GetTime();
|
||||||
|
|
||||||
@@ -54,7 +48,7 @@ void setupChain()
|
|||||||
|
|
||||||
// Init blockchain
|
// Init blockchain
|
||||||
ClearDatadirCache();
|
ClearDatadirCache();
|
||||||
auto pathTemp = GetTempPath() / strprintf("test_komodo_%li_%i", GetTime(), GetRand(100000));
|
auto pathTemp = GetTempPath() / strprintf("test_hush_%li_%i", GetTime(), GetRand(100000));
|
||||||
if (SMART_CHAIN_SYMBOL[0])
|
if (SMART_CHAIN_SYMBOL[0])
|
||||||
pathTemp = pathTemp / strprintf("_%s", SMART_CHAIN_SYMBOL);
|
pathTemp = pathTemp / strprintf("_%s", SMART_CHAIN_SYMBOL);
|
||||||
boost::filesystem::create_directories(pathTemp);
|
boost::filesystem::create_directories(pathTemp);
|
||||||
@@ -74,7 +68,7 @@ void generateBlock(CBlock *block)
|
|||||||
params.push_back(1);
|
params.push_back(1);
|
||||||
uint256 blockId;
|
uint256 blockId;
|
||||||
|
|
||||||
SetMockTime(nMockTime+=100); // CreateNewBlock can fail if not enough time passes
|
SetMockTime(nMockTime+=100); // CreateNewBlock can fail if not enough Time Has Happened
|
||||||
|
|
||||||
try {
|
try {
|
||||||
UniValue out = generate(params, false, CPubKey());
|
UniValue out = generate(params, false, CPubKey());
|
||||||
@@ -85,21 +79,18 @@ void generateBlock(CBlock *block)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void acceptTxFail(const CTransaction tx)
|
void acceptTxFail(const CTransaction tx)
|
||||||
{
|
{
|
||||||
CValidationState state;
|
CValidationState state;
|
||||||
if (!acceptTx(tx, state)) FAIL() << state.GetRejectReason();
|
if (!acceptTx(tx, state)) FAIL() << state.GetRejectReason();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool acceptTx(const CTransaction tx, CValidationState &state)
|
bool acceptTx(const CTransaction tx, CValidationState &state)
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
return AcceptToMemoryPool(mempool, state, tx, false, NULL);
|
return AcceptToMemoryPool(mempool, state, tx, false, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CMutableTransaction spendTx(const CTransaction &txIn, int nOut)
|
CMutableTransaction spendTx(const CTransaction &txIn, int nOut)
|
||||||
{
|
{
|
||||||
CMutableTransaction mtx;
|
CMutableTransaction mtx;
|
||||||
@@ -111,7 +102,6 @@ CMutableTransaction spendTx(const CTransaction &txIn, int nOut)
|
|||||||
return mtx;
|
return mtx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<uint8_t> getSig(const CMutableTransaction mtx, CScript inputPubKey, int nIn)
|
std::vector<uint8_t> getSig(const CMutableTransaction mtx, CScript inputPubKey, int nIn)
|
||||||
{
|
{
|
||||||
uint256 hash = SignatureHash(inputPubKey, mtx, nIn, SIGHASH_ALL, 0, 0);
|
uint256 hash = SignatureHash(inputPubKey, mtx, nIn, SIGHASH_ALL, 0, 0);
|
||||||
@@ -121,7 +111,6 @@ std::vector<uint8_t> getSig(const CMutableTransaction mtx, CScript inputPubKey,
|
|||||||
return vchSig;
|
return vchSig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* In order to do tests there needs to be inputs to spend.
|
* In order to do tests there needs to be inputs to spend.
|
||||||
* This method creates a block and returns a transaction that spends the coinbase.
|
* This method creates a block and returns a transaction that spends the coinbase.
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
// Copyright (c) 2019-2020 The Hush developers
|
// Copyright (c) 2019-2020 The Hush developers
|
||||||
// Distributed under the GPLv3 software license, see the accompanying
|
// Distributed under the GPLv3 software license, see the accompanying
|
||||||
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||||
#ifndef TESTUTILS_H
|
#ifndef HUSH_TESTUTILS_H
|
||||||
#define TESTUTILS_H
|
#define HUSH_TESTUTILS_H
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
|
||||||
#define VCH(a,b) std::vector<unsigned char>(a, a + b)
|
#define VCH(a,b) std::vector<unsigned char>(a, a + b)
|
||||||
|
|
||||||
static char ccjsonerr[1000] = "\0";
|
static char ccjsonerr[1000] = "\0";
|
||||||
@@ -14,12 +13,9 @@ static char ccjsonerr[1000] = "\0";
|
|||||||
o = cc_conditionFromJSONString(s, ccjsonerr); \
|
o = cc_conditionFromJSONString(s, ccjsonerr); \
|
||||||
if (!o) FAIL() << "bad json: " << ccjsonerr;
|
if (!o) FAIL() << "bad json: " << ccjsonerr;
|
||||||
|
|
||||||
|
|
||||||
extern std::string notaryPubkey;
|
extern std::string notaryPubkey;
|
||||||
extern std::string notarySecret;
|
extern std::string notarySecret;
|
||||||
extern CKey notaryKey;
|
extern CKey notaryKey;
|
||||||
|
|
||||||
|
|
||||||
void setupChain();
|
void setupChain();
|
||||||
void generateBlock(CBlock *block=NULL);
|
void generateBlock(CBlock *block=NULL);
|
||||||
bool acceptTx(const CTransaction tx, CValidationState &state);
|
bool acceptTx(const CTransaction tx, CValidationState &state);
|
||||||
@@ -28,5 +24,4 @@ void getInputTx(CScript scriptPubKey, CTransaction &txIn);
|
|||||||
CMutableTransaction spendTx(const CTransaction &txIn, int nOut=0);
|
CMutableTransaction spendTx(const CTransaction &txIn, int nOut=0);
|
||||||
std::vector<uint8_t> getSig(const CMutableTransaction mtx, CScript inputPubKey, int nIn=0);
|
std::vector<uint8_t> getSig(const CMutableTransaction mtx, CScript inputPubKey, int nIn=0);
|
||||||
|
|
||||||
|
#endif /* HUSH_TESTUTILS_H */
|
||||||
#endif /* TESTUTILS_H */
|
|
||||||
|
|||||||
Reference in New Issue
Block a user