mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 14:08:40 +01:00
test: simplify tests by using the pre-mined chain
This commit is contained in:
@@ -12,7 +12,6 @@ definable expiry timeout via the '-mempoolexpiry=<n>' command line argument
|
|||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from test_framework.blocktools import COINBASE_MATURITY
|
|
||||||
from test_framework.messages import DEFAULT_MEMPOOL_EXPIRY_HOURS
|
from test_framework.messages import DEFAULT_MEMPOOL_EXPIRY_HOURS
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import (
|
from test_framework.util import (
|
||||||
@@ -27,17 +26,11 @@ CUSTOM_MEMPOOL_EXPIRY = 10 # hours
|
|||||||
class MempoolExpiryTest(BitcoinTestFramework):
|
class MempoolExpiryTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
self.num_nodes = 1
|
self.num_nodes = 1
|
||||||
self.setup_clean_chain = True
|
|
||||||
|
|
||||||
def test_transaction_expiry(self, timeout):
|
def test_transaction_expiry(self, timeout):
|
||||||
"""Tests that a transaction expires after the expiry timeout and its
|
"""Tests that a transaction expires after the expiry timeout and its
|
||||||
children are removed as well."""
|
children are removed as well."""
|
||||||
node = self.nodes[0]
|
node = self.nodes[0]
|
||||||
self.wallet = MiniWallet(node)
|
|
||||||
|
|
||||||
# Add enough mature utxos to the wallet so that all txs spend confirmed coins.
|
|
||||||
self.generate(self.wallet, 4)
|
|
||||||
self.generate(node, COINBASE_MATURITY)
|
|
||||||
|
|
||||||
# Send a parent transaction that will expire.
|
# Send a parent transaction that will expire.
|
||||||
parent_txid = self.wallet.send_self_transfer(from_node=node)['txid']
|
parent_txid = self.wallet.send_self_transfer(from_node=node)['txid']
|
||||||
@@ -97,6 +90,8 @@ class MempoolExpiryTest(BitcoinTestFramework):
|
|||||||
assert_equal(half_expiry_time, node.getmempoolentry(independent_txid)['time'])
|
assert_equal(half_expiry_time, node.getmempoolentry(independent_txid)['time'])
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
|
self.wallet = MiniWallet(self.nodes[0])
|
||||||
|
|
||||||
self.log.info('Test default mempool expiry timeout of %d hours.' %
|
self.log.info('Test default mempool expiry timeout of %d hours.' %
|
||||||
DEFAULT_MEMPOOL_EXPIRY_HOURS)
|
DEFAULT_MEMPOOL_EXPIRY_HOURS)
|
||||||
self.test_transaction_expiry(DEFAULT_MEMPOOL_EXPIRY_HOURS)
|
self.test_transaction_expiry(DEFAULT_MEMPOOL_EXPIRY_HOURS)
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
"""Test resurrection of mined transactions when the blockchain is re-organized."""
|
"""Test resurrection of mined transactions when the blockchain is re-organized."""
|
||||||
|
|
||||||
from test_framework.blocktools import COINBASE_MATURITY
|
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import assert_equal
|
from test_framework.util import assert_equal
|
||||||
from test_framework.wallet import MiniWallet
|
from test_framework.wallet import MiniWallet
|
||||||
@@ -13,16 +12,11 @@ from test_framework.wallet import MiniWallet
|
|||||||
class MempoolCoinbaseTest(BitcoinTestFramework):
|
class MempoolCoinbaseTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
self.num_nodes = 1
|
self.num_nodes = 1
|
||||||
self.setup_clean_chain = True
|
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
node = self.nodes[0]
|
node = self.nodes[0]
|
||||||
wallet = MiniWallet(node)
|
wallet = MiniWallet(node)
|
||||||
|
|
||||||
# Add enough mature utxos to the wallet so that all txs spend confirmed coins
|
|
||||||
self.generate(wallet, 3)
|
|
||||||
self.generate(node, COINBASE_MATURITY)
|
|
||||||
|
|
||||||
# Spend block 1/2/3's coinbase transactions
|
# Spend block 1/2/3's coinbase transactions
|
||||||
# Mine a block
|
# Mine a block
|
||||||
# Create three more transactions, spending the spends
|
# Create three more transactions, spending the spends
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ from decimal import Decimal
|
|||||||
from itertools import product
|
from itertools import product
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from test_framework.blocktools import COINBASE_MATURITY
|
|
||||||
import test_framework.messages
|
import test_framework.messages
|
||||||
from test_framework.p2p import (
|
from test_framework.p2p import (
|
||||||
P2PInterface,
|
P2PInterface,
|
||||||
@@ -43,7 +42,6 @@ def assert_net_servicesnames(servicesflag, servicenames):
|
|||||||
|
|
||||||
class NetTest(BitcoinTestFramework):
|
class NetTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
self.setup_clean_chain = True
|
|
||||||
self.num_nodes = 2
|
self.num_nodes = 2
|
||||||
self.extra_args = [["-minrelaytxfee=0.00001000"], ["-minrelaytxfee=0.00000500"]]
|
self.extra_args = [["-minrelaytxfee=0.00001000"], ["-minrelaytxfee=0.00000500"]]
|
||||||
self.supports_cli = False
|
self.supports_cli = False
|
||||||
@@ -51,9 +49,6 @@ class NetTest(BitcoinTestFramework):
|
|||||||
def run_test(self):
|
def run_test(self):
|
||||||
# We need miniwallet to make a transaction
|
# We need miniwallet to make a transaction
|
||||||
self.wallet = MiniWallet(self.nodes[0])
|
self.wallet = MiniWallet(self.nodes[0])
|
||||||
self.generate(self.wallet, 1)
|
|
||||||
# Get out of IBD for the minfeefilter and getpeerinfo tests.
|
|
||||||
self.generate(self.nodes[0], COINBASE_MATURITY + 1)
|
|
||||||
|
|
||||||
# By default, the test framework sets up an addnode connection from
|
# By default, the test framework sets up an addnode connection from
|
||||||
# node 1 --> node0. By connecting node0 --> node 1, we're left with
|
# node 1 --> node0. By connecting node0 --> node 1, we're left with
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ from collections import OrderedDict
|
|||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from itertools import product
|
from itertools import product
|
||||||
|
|
||||||
from test_framework.blocktools import COINBASE_MATURITY
|
|
||||||
from test_framework.messages import (
|
from test_framework.messages import (
|
||||||
MAX_BIP125_RBF_SEQUENCE,
|
MAX_BIP125_RBF_SEQUENCE,
|
||||||
CTransaction,
|
CTransaction,
|
||||||
@@ -59,7 +58,6 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||||||
self.add_wallet_options(parser, descriptors=False)
|
self.add_wallet_options(parser, descriptors=False)
|
||||||
|
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
self.setup_clean_chain = True
|
|
||||||
self.num_nodes = 3
|
self.num_nodes = 3
|
||||||
self.extra_args = [
|
self.extra_args = [
|
||||||
["-txindex"],
|
["-txindex"],
|
||||||
@@ -77,9 +75,6 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
self.wallet = MiniWallet(self.nodes[0])
|
self.wallet = MiniWallet(self.nodes[0])
|
||||||
self.log.info("Prepare some coins for multiple *rawtransaction commands")
|
|
||||||
self.generate(self.wallet, 10)
|
|
||||||
self.generate(self.nodes[0], COINBASE_MATURITY + 1)
|
|
||||||
|
|
||||||
self.getrawtransaction_tests()
|
self.getrawtransaction_tests()
|
||||||
self.getrawtransaction_verbosity_tests()
|
self.getrawtransaction_verbosity_tests()
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
"""Test gettxoutproof and verifytxoutproof RPCs."""
|
"""Test gettxoutproof and verifytxoutproof RPCs."""
|
||||||
|
|
||||||
from test_framework.blocktools import COINBASE_MATURITY
|
|
||||||
from test_framework.messages import (
|
from test_framework.messages import (
|
||||||
CMerkleBlock,
|
CMerkleBlock,
|
||||||
from_hex,
|
from_hex,
|
||||||
@@ -20,7 +19,6 @@ from test_framework.wallet import MiniWallet
|
|||||||
class MerkleBlockTest(BitcoinTestFramework):
|
class MerkleBlockTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
self.num_nodes = 2
|
self.num_nodes = 2
|
||||||
self.setup_clean_chain = True
|
|
||||||
self.extra_args = [
|
self.extra_args = [
|
||||||
[],
|
[],
|
||||||
["-txindex"],
|
["-txindex"],
|
||||||
@@ -28,12 +26,9 @@ class MerkleBlockTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
miniwallet = MiniWallet(self.nodes[0])
|
miniwallet = MiniWallet(self.nodes[0])
|
||||||
# Add enough mature utxos to the wallet, so that all txs spend confirmed coins
|
|
||||||
self.generate(miniwallet, 5)
|
|
||||||
self.generate(self.nodes[0], COINBASE_MATURITY)
|
|
||||||
|
|
||||||
chain_height = self.nodes[1].getblockcount()
|
chain_height = self.nodes[1].getblockcount()
|
||||||
assert_equal(chain_height, 105)
|
assert_equal(chain_height, 200)
|
||||||
|
|
||||||
txid1 = miniwallet.send_self_transfer(from_node=self.nodes[0])['txid']
|
txid1 = miniwallet.send_self_transfer(from_node=self.nodes[0])['txid']
|
||||||
txid2 = miniwallet.send_self_transfer(from_node=self.nodes[0])['txid']
|
txid2 = miniwallet.send_self_transfer(from_node=self.nodes[0])['txid']
|
||||||
|
|||||||
Reference in New Issue
Block a user