Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F12945065
D2324.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
23 KB
Subscribers
None
D2324.diff
View Options
diff --git a/test/functional/abc-checkdatasig-activation.py b/test/functional/abc-checkdatasig-activation.py
deleted file mode 100755
--- a/test/functional/abc-checkdatasig-activation.py
+++ /dev/null
@@ -1,174 +0,0 @@
-#!/usr/bin/env python3
-# Copyright (c) 2018 The Bitcoin developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
-"""
-This test checks activation of OP_CHECKDATASIG
-"""
-
-from test_framework.test_framework import ComparisonTestFramework
-from test_framework.util import satoshi_round, assert_equal, assert_raises_rpc_error
-from test_framework.comptool import TestManager, TestInstance, RejectResult
-from test_framework.blocktools import *
-from test_framework.script import *
-
-# far into the future
-MAGNETIC_ANOMALY_START_TIME = 2000000000
-
-# Error due to invalid opcodes
-BAD_OPCODE_ERROR = b'mandatory-script-verify-flag-failed (Opcode missing or not understood)'
-RPC_BAD_OPCODE_ERROR = "16: " + \
- BAD_OPCODE_ERROR.decode("utf-8")
-
-
-class PreviousSpendableOutput():
-
- def __init__(self, tx=CTransaction(), n=-1):
- self.tx = tx
- self.n = n # the output we're spending
-
-
-class CheckDataSigActivationTest(ComparisonTestFramework):
-
- def set_test_params(self):
- self.num_nodes = 1
- self.setup_clean_chain = True
- self.extra_args = [['-whitelist=127.0.0.1',
- "-magneticanomalyactivationtime=%d" % MAGNETIC_ANOMALY_START_TIME,
- "-replayprotectionactivationtime=%d" % (2 * MAGNETIC_ANOMALY_START_TIME)]]
-
- def create_checkdatasig_tx(self, count):
- node = self.nodes[0]
- utxos = node.listunspent()
- assert(len(utxos) > 0)
- utxo = utxos[0]
- tx = CTransaction()
- value = int(satoshi_round(utxo["amount"]) * COIN) // count
- tx.vin = [CTxIn(COutPoint(int(utxo["txid"], 16), utxo["vout"]))]
- tx.vout = []
- signature = bytearray.fromhex(
- '30440220256c12175e809381f97637933ed6ab97737d263eaaebca6add21bced67fd12a402205ce29ecc1369d6fc1b51977ed38faaf41119e3be1d7edfafd7cfaf0b6061bd07')
- message = bytearray.fromhex('')
- pubkey = bytearray.fromhex(
- '038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508')
- for _ in range(count):
- tx.vout.append(CTxOut(value, CScript(
- [signature, message, pubkey, OP_CHECKDATASIG])))
- tx.vout[0].nValue -= node.calculate_fee(tx)
- tx_signed = node.signrawtransaction(ToHex(tx))["hex"]
- return tx_signed
-
- def run_test(self):
- self.test = TestManager(self, self.options.tmpdir)
- self.test.add_all_connections(self.nodes)
- # Start up network handling in another thread
- NetworkThread().start()
- self.test.run()
-
- def get_tests(self):
- node = self.nodes[0]
-
- # First, we generate some coins to spend.
- node.generate(125)
-
- # Create various outputs using the OP_CHECKDATASIG
- # to check for activation.
- tx_hex = self.create_checkdatasig_tx(25)
- txid = node.sendrawtransaction(tx_hex)
- assert(txid in set(node.getrawmempool()))
-
- node.generate(1)
- assert(txid not in set(node.getrawmempool()))
-
- # register the spendable outputs.
- tx = FromHex(CTransaction(), tx_hex)
- tx.rehash()
- spendable_checkdatasigs = [PreviousSpendableOutput(tx, i)
- for i in range(len(tx.vout))]
-
- def spend_checkdatasig():
- outpoint = spendable_checkdatasigs.pop()
- out = outpoint.tx.vout[outpoint.n]
- tx = CTransaction()
- tx.vin = [CTxIn(COutPoint(outpoint.tx.sha256, outpoint.n))]
- tx.vout = [CTxOut(out.nValue, CScript([])),
- CTxOut(0, CScript([random.getrandbits(800), OP_RETURN]))]
- tx.vout[0].nValue -= node.calculate_fee(tx)
- tx.rehash()
- return tx
-
- # Check that transactions using checkdatasig are not accepted yet.
- self.log.info("Try to use the checkdatasig opcodes before activation")
-
- tx0 = spend_checkdatasig()
- tx0_hex = ToHex(tx0)
- assert_raises_rpc_error(-26, RPC_BAD_OPCODE_ERROR,
- node.sendrawtransaction, tx0_hex)
-
- # Push MTP forward just before activation.
- self.log.info("Pushing MTP just before the activation and check again")
- node.setmocktime(MAGNETIC_ANOMALY_START_TIME)
-
- # returns a test case that asserts that the current tip was accepted
- def accepted(tip):
- return TestInstance([[tip, True]])
-
- # returns a test case that asserts that the current tip was rejected
- def rejected(tip, reject=None):
- if reject is None:
- return TestInstance([[tip, False]])
- else:
- return TestInstance([[tip, reject]])
-
- def next_block(block_time):
- # get block height
- blockchaininfo = node.getblockchaininfo()
- height = int(blockchaininfo['blocks'])
-
- # create the block
- coinbase = create_coinbase(height)
- coinbase.rehash()
- block = create_block(
- int(node.getbestblockhash(), 16), coinbase, block_time)
-
- # Do PoW, which is cheap on regnet
- block.solve()
- return block
-
- for i in range(6):
- b = next_block(MAGNETIC_ANOMALY_START_TIME + i - 1)
- yield accepted(b)
-
- # Check again just before the activation time
- assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'],
- MAGNETIC_ANOMALY_START_TIME - 1)
- assert_raises_rpc_error(-26, RPC_BAD_OPCODE_ERROR,
- node.sendrawtransaction, tx0_hex)
-
- def add_tx(block, tx):
- block.vtx.append(tx)
- block.hashMerkleRoot = block.calc_merkle_root()
- block.solve()
-
- b = next_block(MAGNETIC_ANOMALY_START_TIME + 6)
- add_tx(b, tx0)
- yield rejected(b, RejectResult(16, b'blk-bad-inputs'))
-
- self.log.info("Activates checkdatasig")
- fork_block = next_block(MAGNETIC_ANOMALY_START_TIME + 6)
- yield accepted(fork_block)
-
- assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'],
- MAGNETIC_ANOMALY_START_TIME)
-
- tx0id = node.sendrawtransaction(tx0_hex)
- assert(tx0id in set(node.getrawmempool()))
-
- # Transactions can also be included in blocks.
- magneticanomalyblock = next_block(MAGNETIC_ANOMALY_START_TIME + 7)
- add_tx(magneticanomalyblock, tx0)
- yield accepted(magneticanomalyblock)
-
-
-if __name__ == '__main__':
- CheckDataSigActivationTest().main()
diff --git a/test/functional/abc-magnetic-anomaly-activation.py b/test/functional/abc-magnetic-anomaly-activation.py
deleted file mode 100755
--- a/test/functional/abc-magnetic-anomaly-activation.py
+++ /dev/null
@@ -1,277 +0,0 @@
-#!/usr/bin/env python3
-# Copyright (c) 2018 The Bitcoin developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
-"""
-This test checks that simple features of the magnetic anomaly fork
-activates properly. More complex features are given their own tests.
-"""
-
-from test_framework.test_framework import ComparisonTestFramework
-from test_framework.util import assert_equal, assert_raises_rpc_error
-from test_framework.comptool import TestManager, TestInstance, RejectResult
-from test_framework.blocktools import create_coinbase, create_block
-from test_framework.mininode import *
-from test_framework.script import *
-from test_framework.cdefs import MIN_TX_SIZE
-from collections import deque
-
-# far into the future
-MAGNETIC_ANOMALY_START_TIME = 2000000000
-RPC_VERIFY_REJECTED = -26
-
-
-class PreviousSpendableOutput():
-
- def __init__(self, tx=CTransaction(), n=-1):
- self.tx = tx
- self.n = n # the output we're spending
-
-
-class MagneticAnomalyActivationTest(ComparisonTestFramework):
-
- def set_test_params(self):
- self.num_nodes = 1
- self.setup_clean_chain = True
- self.block_heights = {}
- self.tip = None
- self.blocks = {}
- self.extra_args = [['-whitelist=127.0.0.1',
- "-magneticanomalyactivationtime=%d" % MAGNETIC_ANOMALY_START_TIME,
- "-replayprotectionactivationtime=%d" % (2 * MAGNETIC_ANOMALY_START_TIME)]]
-
- def run_test(self):
- self.test = TestManager(self, self.options.tmpdir)
- self.test.add_all_connections(self.nodes)
- # Start up network handling in another thread
- NetworkThread().start()
- # Set the blocksize to 2MB as initial condition
- self.nodes[0].setmocktime(MAGNETIC_ANOMALY_START_TIME)
- self.test.run()
-
- def add_transactions_to_block(self, block, tx_list):
- [tx.rehash() for tx in tx_list]
- block.vtx.extend(tx_list)
-
- def new_transaction(self, spend, tx_size=0, pushonly=True, cleanstack=True):
- tx = CTransaction()
- # Make sure we have plenty enough to spend going forward.
- spendable_outputs = deque([spend])
-
- # Spend from one of the spendable outputs
- spend = spendable_outputs.popleft()
- tx.vin.append(CTxIn(COutPoint(spend.tx.sha256, spend.n)))
- extra_ops = []
- if pushonly == False:
- extra_ops += [OP_TRUE, OP_DROP]
- if cleanstack == False:
- extra_ops += [OP_TRUE]
- tx.vin[0].scriptSig = CScript(extra_ops)
-
- # Add spendable outputs
- for i in range(2):
- tx.vout.append(CTxOut(0, CScript([OP_TRUE])))
- spendable_outputs.append(PreviousSpendableOutput(tx, i))
-
- # Put some random data into the transaction in order to randomize ids.
- if tx_size == 0:
- tx.vout.append(
- CTxOut(0, CScript([random.getrandbits(8), OP_RETURN])))
- else:
- # Create an input to pad the transaction.
- tx.vout.append(CTxOut(0, CScript([OP_RETURN])))
-
- # Estimate the size of the padding.
- push_size = tx_size - len(tx.serialize()) - 1
-
- # Because several field are of variable size, we grow the push slowly
- # up to the requested size.
- while len(tx.serialize()) < tx_size:
- # Ensure the padding has a left most bit on, so it's
- # exactly the correct number of bits.
- padding = random.randrange(
- 1 << 8 * push_size - 2, 1 << 8 * push_size - 1)
- tx.vout[2] = CTxOut(0, CScript([padding, OP_RETURN]))
- push_size += 1
-
- assert_equal(len(tx.serialize()), tx_size)
-
- tx.rehash()
- return tx
-
- def next_block(self, number, spend_tx=None):
- if self.tip == None:
- base_block_hash = self.genesis_hash
- import time
- block_time = int(time.time()) + 1
- else:
- base_block_hash = self.tip.sha256
- block_time = self.tip.nTime + 1
- # First create the coinbase
- height = self.block_heights[base_block_hash] + 1
- coinbase = create_coinbase(height)
- coinbase.rehash()
- if spend_tx == None:
- # We need to have something to spend to fill the block.
- block = create_block(base_block_hash, coinbase, block_time)
- else:
- # All but one satoshi to fees
- #coinbase.vout[0].nValue += spend.tx.vout[spend.n].nValue - 1
- coinbase.vout[0].nValue += spend_tx.vin[0].prevout.n - 1
- coinbase.rehash()
- block = create_block(base_block_hash, coinbase, block_time)
-
- # Add the transaction to the block
- self.add_transactions_to_block(block, [spend_tx])
-
- # Now that we added a bunch of transactions, we need to recompute
- # the merkle root.
- block.hashMerkleRoot = block.calc_merkle_root()
-
- # Do PoW, which is cheap on regnet
- block.solve()
- self.tip = block
- self.block_heights[block.sha256] = height
- assert number not in self.blocks
- self.blocks[number] = block
- return block
-
- def get_tests(self):
- node = self.nodes[0]
- self.genesis_hash = int(node.getbestblockhash(), 16)
- self.block_heights[self.genesis_hash] = 0
- spendable_outputs = []
-
- # save the current tip so it can be spent by a later block
- def save_spendable_output():
- spendable_outputs.append(self.tip)
-
- # get an output that we previously marked as spendable
- def get_spendable_output():
- return PreviousSpendableOutput(spendable_outputs.pop(0).vtx[0], 0)
-
- # returns a test case that asserts that the current tip was accepted
- def accepted():
- return TestInstance([[self.tip, True]])
-
- # returns a test case that asserts that the current tip was rejected
- def rejected(reject=None):
- if reject is None:
- return TestInstance([[self.tip, False]])
- else:
- return TestInstance([[self.tip, reject]])
-
- # move the tip back to a previous block
- def tip(number):
- self.tip = self.blocks[number]
-
- # adds transactions to the block and updates state
- def update_block(block_number, new_transactions=[]):
- block = self.blocks[block_number]
- self.add_transactions_to_block(block, new_transactions)
- old_sha256 = block.sha256
- block.hashMerkleRoot = block.calc_merkle_root()
- block.solve()
- # Update the internal state just like in next_block
- self.tip = block
- if block.sha256 != old_sha256:
- self.block_heights[block.sha256] = self.block_heights[old_sha256]
- del self.block_heights[old_sha256]
- self.blocks[block_number] = block
- return block
-
- # shorthand for functions
- block = self.next_block
- transaction = self.new_transaction
-
- # Create a new block
- block(0)
- save_spendable_output()
- yield accepted()
-
- # Now we need that block to mature so we can spend the coinbase.
- test = TestInstance(sync_every_block=False)
- for i in range(99):
- block(5000 + i)
- test.blocks_and_transactions.append([self.tip, True])
- save_spendable_output()
- yield test
-
- # collect spendable outputs now to avoid cluttering the code later on
- out = []
- for i in range(100):
- out.append(get_spendable_output())
-
- # Let's build some blocks and test them.
- for i in range(15):
- n = i + 1
- block(n)
- yield accepted()
-
- # Start moving MTP forward
- bfork = block(5555)
- bfork.nTime = MAGNETIC_ANOMALY_START_TIME - 1
- update_block(5555)
- yield accepted()
-
- # Get to one block of the Nov 15, 2018 HF activation
- for i in range(5):
- block(5100 + i)
- test.blocks_and_transactions.append([self.tip, True])
- yield test
-
- # Check that the MTP is just before the configured fork point.
- assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'],
- MAGNETIC_ANOMALY_START_TIME - 1)
-
- # Check that block with small transactions, non push only signatures and
- # non clean stack are still accepted.
- small_tx_block = block(4444,
- transaction(out[0], MIN_TX_SIZE - 1, pushonly=False, cleanstack=False))
- assert_equal(len(small_tx_block.vtx[1].serialize()), MIN_TX_SIZE - 1)
- yield accepted()
-
- # Now MTP is exactly the fork time. Small transaction are now rejected.
- assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'],
- MAGNETIC_ANOMALY_START_TIME)
-
- # Now that the for activated, it is not possible to have
- # small transactions anymore.
- small_tx_block = block(4445, transaction(out[1], MIN_TX_SIZE - 1))
- assert_equal(len(small_tx_block.vtx[1].serialize()), MIN_TX_SIZE - 1)
- yield rejected(RejectResult(16, b'bad-txns-undersize'))
-
- # Rewind bad block.
- tip(4444)
-
- # Now that the for activated, it is not possible to have
- # non push only transactions.
- non_pushonly_tx_block = block(4446,
- transaction(out[1], MIN_TX_SIZE, pushonly=False))
- yield rejected(RejectResult(16, b'blk-bad-inputs'))
-
- # Rewind bad block.
- tip(4444)
-
- # Now that the for activated, it is not possible to have
- # non clean stack transactions.
- non_cleanstack_tx_block = block(4447,
- transaction(out[1], MIN_TX_SIZE, cleanstack=False))
- yield rejected(RejectResult(16, b'blk-bad-inputs'))
-
- # Rewind bad block.
- tip(4444)
-
- # Verfiy that ATMP doesn't accept undersize transactions
- undersized_tx = transaction(out[1], MIN_TX_SIZE - 1)
- assert_raises_rpc_error(RPC_VERIFY_REJECTED, "bad-txns-undersize",
- node.sendrawtransaction, ToHex(undersized_tx), True)
-
- # But large transactions are still ok.
- large_tx_block = block(3333, transaction(out[1], MIN_TX_SIZE))
- assert_equal(len(large_tx_block.vtx[1].serialize()), MIN_TX_SIZE)
- yield accepted()
-
-
-if __name__ == '__main__':
- MagneticAnomalyActivationTest().main()
diff --git a/test/functional/abc-magnetic-anomaly-mining.py b/test/functional/abc-magnetic-anomaly-mining.py
--- a/test/functional/abc-magnetic-anomaly-mining.py
+++ b/test/functional/abc-magnetic-anomaly-mining.py
@@ -28,7 +28,6 @@
self.mocktime = int(time.time()) - 600 * 100
extra_arg = ['-spendzeroconfchange=0', '-whitelist=127.0.0.1',
- "-magneticanomalyactivationtime=%d" % self.mocktime,
"-replayprotectionactivationtime=%d" % (10 * self.mocktime)]
self.extra_args = [extra_arg, extra_arg]
diff --git a/test/functional/abc-replay-protection.py b/test/functional/abc-replay-protection.py
--- a/test/functional/abc-replay-protection.py
+++ b/test/functional/abc-replay-protection.py
@@ -19,7 +19,6 @@
# far into the future
REPLAY_PROTECTION_START_TIME = 2000000000
-MAGNETIC_ANOMALY_START_TIME = 4000000000
# Error due to invalid signature
INVALID_SIGNATURE_ERROR = b'mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)'
@@ -43,7 +42,6 @@
self.tip = None
self.blocks = {}
self.extra_args = [['-whitelist=127.0.0.1',
- "-magneticanomalyactivationtime=%d" % MAGNETIC_ANOMALY_START_TIME,
"-replayprotectionactivationtime=%d" % REPLAY_PROTECTION_START_TIME]]
def run_test(self):
@@ -109,6 +107,7 @@
block = self.blocks[block_number]
block.vtx.extend(new_transactions)
old_sha256 = block.sha256
+ make_conform_to_ctor(block)
block.hashMerkleRoot = block.calc_merkle_root()
block.solve()
# Update the internal state just like in next_block
diff --git a/test/functional/abc-transaction-ordering.py b/test/functional/abc-transaction-ordering.py
--- a/test/functional/abc-transaction-ordering.py
+++ b/test/functional/abc-transaction-ordering.py
@@ -17,7 +17,7 @@
from collections import deque
# far into the future
-MAGNETIC_ANOMALY_START_TIME = 2000000000
+REPLAY_PROTECTION_START_TIME = 2000000000
class PreviousSpendableOutput():
@@ -41,8 +41,7 @@
self.blocks = {}
self.extra_args = [['-whitelist=127.0.0.1',
'-relaypriority=0',
- "-magneticanomalyactivationtime=%d" % MAGNETIC_ANOMALY_START_TIME,
- "-replayprotectionactivationtime=%d" % (2 * MAGNETIC_ANOMALY_START_TIME)]]
+ "-replayprotectionactivationtime={}".format(REPLAY_PROTECTION_START_TIME)]]
def run_test(self):
self.test = TestManager(self, self.options.tmpdir)
@@ -50,7 +49,6 @@
# Start up network handling in another thread
NetworkThread().start()
# Set the blocksize to 2MB as initial condition
- self.nodes[0].setmocktime(MAGNETIC_ANOMALY_START_TIME)
self.test.run()
def add_transactions_to_block(self, block, tx_list):
@@ -192,35 +190,14 @@
out.append(get_spendable_output())
# Let's build some blocks and test them.
- for i in range(15):
+ for i in range(17):
n = i + 1
block(n)
yield accepted()
- # Start moving MTP forward
- bfork = block(5555)
- bfork.nTime = MAGNETIC_ANOMALY_START_TIME - 1
- update_block(5555)
+ block(5556)
yield accepted()
- # Get to one block of the Nov 15, 2018 HF activation
- for i in range(5):
- block(5100 + i)
- test.blocks_and_transactions.append([self.tip, True])
- yield test
-
- # Check that the MTP is just before the configured fork point.
- assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'],
- MAGNETIC_ANOMALY_START_TIME - 1)
-
- # Activate the Nov 15, 2018 HF
- block(5556, out[16], tx_count=16)
- yield accepted()
-
- # Now MTP is exactly the fork time. Transactions are expected to be ordered now.
- assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'],
- MAGNETIC_ANOMALY_START_TIME)
-
# Block with regular ordering are now rejected.
block(5557, out[17], tx_count=16)
yield rejected(RejectResult(16, b'tx-ordering'))
@@ -231,7 +208,7 @@
# After we activate the Nov 15, 2018 HF, transaction order is enforced.
def ordered_block(block_number, spend):
b = block(block_number, spend=spend, tx_count=16)
- b.vtx = [b.vtx[0]] + sorted(b.vtx[1:], key=lambda tx: tx.get_id())
+ make_conform_to_ctor(b)
update_block(block_number)
return b
@@ -239,26 +216,6 @@
ordered_block(4445, out[17])
yield accepted()
- # Invalidate the best block and make sure we are back at the fork point.
- ctorblockhash = node.getbestblockhash()
- node.invalidateblock(ctorblockhash)
- forkblockhash = node.getbestblockhash()
- assert(forkblockhash != ctorblockhash)
- assert_equal(node.getblockheader(forkblockhash)[
- 'mediantime'], MAGNETIC_ANOMALY_START_TIME)
-
- assert_equal(len(node.getrawmempool()), 15)
- node.generate(1)
- generatedblockhash = node.getbestblockhash()
- assert(forkblockhash != generatedblockhash)
-
- # Reconstruct tip.
- tip_hash = node.getbestblockhash()
- self.tip = CBlock()
- self.tip.sha256 = int(tip_hash, 16)
- self.tip.nTime = timestamp = node.getblock(tip_hash)['time']
- self.block_heights[self.tip.sha256] = node.getblock(tip_hash)['height']
-
ordered_block(4446, out[18])
yield accepted()
diff --git a/test/functional/timing.json b/test/functional/timing.json
--- a/test/functional/timing.json
+++ b/test/functional/timing.json
@@ -3,10 +3,6 @@
"name": "abandonconflict.py",
"time": 18
},
- {
- "name": "abc-checkdatasig-activation.py",
- "time": 5
- },
{
"name": "abc-cmdline.py",
"time": 8
@@ -19,10 +15,6 @@
"name": "abc-high_priority_transaction.py",
"time": 16
},
- {
- "name": "abc-magnetic-anomaly-activation.py",
- "time": 8
- },
{
"name": "abc-magnetic-anomaly-mining.py",
"time": 19
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Feb 6, 17:40 (18 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5082794
Default Alt Text
D2324.diff (23 KB)
Attached To
D2324: Remove -magneticanomalyactivationtime from functional tests
Event Timeline
Log In to Comment