From 972805e424e3eaafe17bd8d6ac398ff6de464107 Mon Sep 17 00:00:00 2001 From: IntegralTeam V Date: Thu, 31 Oct 2019 17:52:57 +0700 Subject: [PATCH 1/4] test travis-ci --- src/consensus/tx_check.cpp | 4 +++- src/miner.cpp | 2 +- src/test/double_sign.cpp | 2 -- src/validation.cpp | 40 +++++++++++++++++--------------- test/functional/test_runner.py | 42 +++++++++++++++++----------------- 5 files changed, 46 insertions(+), 44 deletions(-) diff --git a/src/consensus/tx_check.cpp b/src/consensus/tx_check.cpp index 32f5505276..d791206d9f 100644 --- a/src/consensus/tx_check.cpp +++ b/src/consensus/tx_check.cpp @@ -7,6 +7,8 @@ #include #include +extern bool fIsFakeNet; + bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fCheckDuplicateInputs) { // Basic checks that don't depend on any context @@ -43,7 +45,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe if (tx.IsCoinBase()) { - if (tx.vin[0].scriptSig.size() < 2) // || tx.vin[0].scriptSig.size() > 100 // TODO: (ss) ! + if (tx.vin[0].scriptSig.size() < 2 || (fIsFakeNet && tx.vin[0].scriptSig.size() > 100)) return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-cb-length"); } else diff --git a/src/miner.cpp b/src/miner.cpp index ba61818528..9c760cd37a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -155,7 +155,7 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc bool baseScript = true; - if (pmasternodesview->GetCriminals().size() != 0) { + if (!fIsFakeNet && pmasternodesview->GetCriminals().size() != 0) { CMasternodesView::CMnCriminals criminals = pmasternodesview->GetCriminals(); CMasternodesView::CMnCriminals::iterator itCriminalMN = criminals.begin(); std::pair criminal = itCriminalMN->second; diff --git a/src/test/double_sign.cpp b/src/test/double_sign.cpp index ac673e26f2..a681a16edb 100644 --- a/src/test/double_sign.cpp +++ b/src/test/double_sign.cpp @@ -39,8 +39,6 @@ std::shared_ptr FinalizeBlock(std::shared_ptr pblock, const uint pblock->stakeModifier = pos::ComputeStakeModifier(prevStakeModifier, minterKey.GetPubKey().GetID()); - GenerateCoinbaseCommitment(*pblock, LookupBlockIndex(pblock->hashPrevBlock), Params().GetConsensus()); - pblock->hashMerkleRoot = BlockMerkleRoot(*pblock); do { diff --git a/src/validation.cpp b/src/validation.cpp index f92942e621..d85724342c 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2023,7 +2023,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl control.Add(vChecks); } else { std::vector metadata; - if (CMasternodesView::ExtractCriminalCoinsFromTx(tx, metadata)) { + if (!fIsFakeNet && CMasternodesView::ExtractCriminalCoinsFromTx(tx, metadata)) { pmasternodesview->BlockedCriminalMnCoins(metadata); } } @@ -3390,28 +3390,30 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, CValidationState } // Add MintedBlockHeader entity to DB - CKeyID mintersKey; - if (!block.ExtractMinterKey(mintersKey)) { - return state.Invalid(ValidationInvalidReason::BLOCK_INVALID_HEADER, error("%s: block %s: minters key for external blockHeader not found", __func__, hash.ToString()), REJECT_INVALID, "bad-pos-header"); - } - auto it = pmasternodesview->ExistMasternode(CMasternodesView::AuthIndex::ByOperator, mintersKey); - if (!it) { - return state.Invalid(ValidationInvalidReason::BLOCK_INVALID_HEADER, error("%s: block %s: active masternode for external blockHeader not found", __func__, hash.ToString()), REJECT_INVALID, " "); - } - auto const & nodeId = (*it)->second; + if (!fIsFakeNet) { + CKeyID mintersKey; + if (!block.ExtractMinterKey(mintersKey)) { + return state.Invalid(ValidationInvalidReason::BLOCK_INVALID_HEADER, error("%s: block %s: minters key for external blockHeader not found", __func__, hash.ToString()), REJECT_INVALID, "bad-pos-header"); + } + auto it = pmasternodesview->ExistMasternode(CMasternodesView::AuthIndex::ByOperator, mintersKey); + if (!it) { + return state.Invalid(ValidationInvalidReason::BLOCK_INVALID_HEADER, error("%s: block %s: active masternode for external blockHeader not found", __func__, hash.ToString()), REJECT_INVALID, " "); + } + auto const & nodeId = (*it)->second; - std::map blockHeaders{}; + std::map blockHeaders{}; - pmasternodesview->FindMintedBlockHeader(nodeId, block.mintedBlocks, blockHeaders, fIsFakeNet); + pmasternodesview->FindMintedBlockHeader(nodeId, block.mintedBlocks, blockHeaders, fIsFakeNet); - auto existingBlockHeader = blockHeaders.find(hash); - if (!blockHeaders.size() || existingBlockHeader == blockHeaders.end()) { - pmasternodesview->WriteMintedBlockHeader(nodeId, block.mintedBlocks, hash, block, fIsFakeNet); - } + auto existingBlockHeader = blockHeaders.find(hash); + if (!blockHeaders.size() || existingBlockHeader == blockHeaders.end()) { + pmasternodesview->WriteMintedBlockHeader(nodeId, block.mintedBlocks, hash, block, fIsFakeNet); + } - for (std::pair blockHeader : blockHeaders) { - if(!pmasternodesview->CheckDoubleSign(block, blockHeader.second)) { - pmasternodesview->MarkMasternodeAsCriminals(nodeId, block, blockHeader.second); + for (std::pair blockHeader : blockHeaders) { + if (!pmasternodesview->CheckDoubleSign(block, blockHeader.second)) { + pmasternodesview->MarkMasternodeAsCriminals(nodeId, block, blockHeader.second); + } } } diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index 123c97be5a..d958d13f1a 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -72,54 +72,40 @@ 'feature_pruning.py', 'feature_dbcrash.py', 'example_block_hash.py', - 'feature_block.py', - 'p2p_compactblocks.py', - 'wallet_backup.py', - 'p2p_segwit.py', - 'p2p_sendheaders.py', - 'feature_csv_activation.py', - 'feature_bip68_sequence.py', - 'rpc_blockchain.py', - 'feature_assumevalid.py', - 'p2p_invalid_tx.py', - 'feature_versionbits_warning.py', - 'feature_nulldummy.py', - 'p2p_invalid_block.py', - 'mining_basic.py', - 'wallet_bumpfee.py', - 'feature_dersig.py', - 'feature_cltv.py', - 'p2p_fingerprint.py', - 'p2p_unrequested_blocks.py', - 'wallet_resendwallettransactions.py', - 'example_test.py', ] BASE_SCRIPTS = [ # Scripts that are run by default. # Longest test should go first, to favor running tests in parallel 'wallet_hd.py', + 'wallet_backup.py', # vv Tests less than 5m vv 'mining_getblocktemplate_longpoll.py', 'feature_maxuploadtarget.py', + 'feature_block.py', 'rpc_fundrawtransaction.py', + 'p2p_compactblocks.py', 'feature_segwit.py', # vv Tests less than 2m vv 'wallet_basic.py', 'wallet_labels.py', + 'p2p_segwit.py', 'p2p_timeouts.py', 'p2p_tx_download.py', 'wallet_dump.py', 'wallet_listtransactions.py', # vv Tests less than 60s vv + 'p2p_sendheaders.py', 'wallet_zapwallettxes.py', 'wallet_importmulti.py', 'mempool_limit.py', 'rpc_txoutproof.py', 'wallet_listreceivedby.py', 'wallet_abandonconflict.py', + 'feature_csv_activation.py', 'rpc_rawtransaction.py', 'wallet_address_types.py', # nodes = 6 + 'feature_bip68_sequence.py', 'p2p_feefilter.py', 'feature_reindex.py', 'feature_abortnode.py', @@ -156,6 +142,7 @@ 'wallet_groups.py', 'p2p_disconnect_ban.py', 'rpc_decodescript.py', + 'rpc_blockchain.py', 'rpc_deprecated.py', 'wallet_disable.py', 'rpc_net.py', @@ -165,7 +152,11 @@ 'p2p_blocksonly.py', 'mining_prioritisetransaction.py', 'p2p_invalid_locator.py', + 'p2p_invalid_block.py', 'p2p_invalid_messages.py', + 'p2p_invalid_tx.py', + 'feature_assumevalid.py', + 'example_test.py', 'wallet_txn_doublespend.py', 'wallet_txn_clone.py --mineblock', 'feature_notifications.py', @@ -175,30 +166,39 @@ 'mempool_packages.py', 'mempool_package_onemore.py', 'rpc_createmultisig.py', + 'feature_versionbits_warning.py', 'rpc_preciousblock.py', 'wallet_importprunedfunds.py', 'p2p_leak_tx.py', 'rpc_signmessage.py', 'wallet_balance.py', + 'feature_nulldummy.py', 'mempool_accept.py', 'wallet_import_rescan.py', # nodes = 6 'wallet_import_with_label.py', 'rpc_bind.py --ipv4', 'rpc_bind.py --ipv6', 'rpc_bind.py --nonloopback', + 'mining_basic.py', + 'wallet_bumpfee.py', 'wallet_bumpfee_totalfee_deprecation.py', 'rpc_named_arguments.py', 'wallet_listsinceblock.py', 'p2p_leak.py', 'wallet_encryption.py', + 'feature_dersig.py', + 'feature_cltv.py', 'rpc_uptime.py', + 'wallet_resendwallettransactions.py', 'wallet_fallbackfee.py', 'feature_minchainwork.py', 'rpc_getblockstats.py', 'wallet_create_tx.py', + 'p2p_fingerprint.py', 'feature_uacomment.py', 'wallet_coinbase_category.py', 'feature_filelock.py', + 'p2p_unrequested_blocks.py', 'feature_includeconf.py', 'rpc_deriveaddresses.py', 'rpc_deriveaddresses.py --usecli', From 6f2cc756b6362f87377d7b6724cead7fdcf2a4d4 Mon Sep 17 00:00:00 2001 From: IntegralTeam V Date: Thu, 31 Oct 2019 18:56:03 +0700 Subject: [PATCH 2/4] add PoS tests --- src/Makefile.test.include | 1 + src/test/pos_tests.cpp | 215 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 216 insertions(+) create mode 100644 src/test/pos_tests.cpp diff --git a/src/Makefile.test.include b/src/Makefile.test.include index dc67aff528..10477fb3f9 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -123,6 +123,7 @@ BITCOIN_TESTS =\ test/pmt_tests.cpp \ test/policyestimator_tests.cpp \ test/pow_tests.cpp \ + test/pos_tests.cpp \ test/prevector_tests.cpp \ test/raii_event_tests.cpp \ test/random_tests.cpp \ diff --git a/src/test/pos_tests.cpp b/src/test/pos_tests.cpp new file mode 100644 index 0000000000..89269150d8 --- /dev/null +++ b/src/test/pos_tests.cpp @@ -0,0 +1,215 @@ +#include +#include +#include +#include +#include +#include +#include +#include