Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-schnorr.py
Show First 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
tip = self.getbestblock(node) | tip = self.getbestblock(node) | ||||
self.log.info("Create some blocks with OP_1 coinbase for spending.") | self.log.info("Create some blocks with OP_1 coinbase for spending.") | ||||
blocks = [] | blocks = [] | ||||
for _ in range(10): | for _ in range(10): | ||||
tip = self.build_block(tip) | tip = self.build_block(tip) | ||||
blocks.append(tip) | blocks.append(tip) | ||||
node.p2p.send_blocks_and_test(blocks, node, success=True) | node.p2p.send_blocks_and_test(blocks, node, success=True) | ||||
out = [block.vtx[0] for block in blocks] | spendable_outputs = [block.vtx[0] for block in blocks] | ||||
self.log.info("Mature the blocks and get out of IBD.") | self.log.info("Mature the blocks and get out of IBD.") | ||||
node.generate(100) | node.generate(100) | ||||
tip = self.getbestblock(node) | tip = self.getbestblock(node) | ||||
self.log.info("Setting up spends to test and mining the fundings.") | self.log.info("Setting up spends to test and mining the fundings.") | ||||
fundings = [] | |||||
# Generate a key pair | # Generate a key pair | ||||
privkeybytes = b"Schnorr!" * 4 | privkeybytes = b"Schnorr!" * 4 | ||||
private_key = CECKey() | private_key = CECKey() | ||||
private_key.set_secretbytes(privkeybytes) | private_key.set_secretbytes(privkeybytes) | ||||
# get uncompressed public key serialization | # get uncompressed public key serialization | ||||
public_key = private_key.get_pubkey() | public_key = private_key.get_pubkey() | ||||
def create_fund_and_spend_tx(spend, multi=False, sig='schnorr'): | def create_fund_and_spend_tx(multi=False, sig='schnorr'): | ||||
spendfrom = spendable_outputs.pop() | |||||
if multi: | if multi: | ||||
script = CScript([OP_1, public_key, OP_1, OP_CHECKMULTISIG]) | script = CScript([OP_1, public_key, OP_1, OP_CHECKMULTISIG]) | ||||
else: | else: | ||||
script = CScript([public_key, OP_CHECKSIG]) | script = CScript([public_key, OP_CHECKSIG]) | ||||
value = spend.vout[0].nValue | value = spendfrom.vout[0].nValue | ||||
# Fund transaction | # Fund transaction | ||||
txfund = create_transaction(spend, 0, b'', value, script) | txfund = create_transaction(spendfrom, 0, b'', value, script) | ||||
txfund.rehash() | txfund.rehash() | ||||
fundings.append(txfund) | |||||
# Spend transaction | # Spend transaction | ||||
txspend = CTransaction() | txspend = CTransaction() | ||||
txspend.vout.append( | txspend.vout.append( | ||||
CTxOut(value-1000, CScript([OP_TRUE]))) | CTxOut(value-1000, CScript([OP_TRUE]))) | ||||
txspend.vin.append( | txspend.vin.append( | ||||
CTxIn(COutPoint(txfund.sha256, 0), b'')) | CTxIn(COutPoint(txfund.sha256, 0), b'')) | ||||
Show All 9 Lines | def run_test(self): | ||||
elif isinstance(sig, bytes): | elif isinstance(sig, bytes): | ||||
txsig = sig + hashbyte | txsig = sig + hashbyte | ||||
if multi: | if multi: | ||||
txspend.vin[0].scriptSig = CScript([b'', txsig]) | txspend.vin[0].scriptSig = CScript([b'', txsig]) | ||||
else: | else: | ||||
txspend.vin[0].scriptSig = CScript([txsig]) | txspend.vin[0].scriptSig = CScript([txsig]) | ||||
txspend.rehash() | txspend.rehash() | ||||
return txfund, txspend | return txspend | ||||
def send_transaction_to_mempool(tx): | def send_transaction_to_mempool(tx): | ||||
tx_id = node.sendrawtransaction(ToHex(tx)) | tx_id = node.sendrawtransaction(ToHex(tx)) | ||||
assert(tx_id in set(node.getrawmempool())) | assert(tx_id in set(node.getrawmempool())) | ||||
return tx_id | return tx_id | ||||
# Check we are disconnected when sending a txn that node_ban rejects. | # Check we are disconnected when sending a txn that node_ban rejects. | ||||
# (Can't actually get banned, since bitcoind won't ban local peers.) | # (Can't actually get banned, since bitcoind won't ban local peers.) | ||||
def check_for_ban_on_rejected_tx(tx): | def check_for_ban_on_rejected_tx(tx): | ||||
self.nodes[0].p2p.send_txs_and_test( | self.nodes[0].p2p.send_txs_and_test( | ||||
[tx], self.nodes[0], success=False, expect_disconnect=True) | [tx], self.nodes[0], success=False, expect_disconnect=True) | ||||
self.reconnect_p2p() | self.reconnect_p2p() | ||||
# Setup fundings | schnorrchecksigtx = create_fund_and_spend_tx() | ||||
fundings = [] | schnorrmultisigtx = create_fund_and_spend_tx(multi=True) | ||||
fund, schnorrchecksigtx = create_fund_and_spend_tx(out[0]) | ecdsachecksigtx = create_fund_and_spend_tx(sig='ecdsa') | ||||
fundings.append(fund) | sig64checksigtx = create_fund_and_spend_tx(sig=sig64) | ||||
fund, schnorrmultisigtx = create_fund_and_spend_tx(out[1], multi=True) | sig64multisigtx = create_fund_and_spend_tx(multi=True, sig=sig64) | ||||
fundings.append(fund) | |||||
fund, ecdsachecksigtx = create_fund_and_spend_tx(out[2], sig='ecdsa') | |||||
fundings.append(fund) | |||||
fund, sig64checksigtx = create_fund_and_spend_tx( | |||||
out[5], sig=sig64) | |||||
fundings.append(fund) | |||||
fund, sig64multisigtx = create_fund_and_spend_tx( | |||||
out[6], multi=True, sig=sig64) | |||||
fundings.append(fund) | |||||
tip = self.build_block(tip, fundings) | tip = self.build_block(tip, fundings) | ||||
node.p2p.send_blocks_and_test([tip], node) | node.p2p.send_blocks_and_test([tip], node) | ||||
self.log.info("Typical ECDSA and Schnorr CHECKSIG are valid.") | self.log.info("Typical ECDSA and Schnorr CHECKSIG are valid.") | ||||
schnorr_tx_id = send_transaction_to_mempool(schnorrchecksigtx) | schnorr_tx_id = send_transaction_to_mempool(schnorrchecksigtx) | ||||
ecdsa_tx_id = send_transaction_to_mempool(ecdsachecksigtx) | ecdsa_tx_id = send_transaction_to_mempool(ecdsachecksigtx) | ||||
# It can also be mined | # It can also be mined | ||||
Show All 33 Lines |