Merge #14296: [wallet] Remove addwitnessaddress
2b91e42ece
[docs] Add release note for removing getwitnessaddress (John Newbery)ebec90ac97
[wallet] Remove deprecated addwitnessaddress RPC method (John Newbery)07e3f585ab
[test] Remove deprecated addwitnessaddress from feature_segwit.py (John Newbery)82f2fa03a5
[test] Remove deprecated addwitnessaddress from wallet_bumpfee.py (John Newbery)9d7ee187a3
[test] Remove deprecated addwitnessaddress from p2p_compactblocks.py (John Newbery)3cf77f0b3e
[tests] Remove deprecated addwitnessaddress call from wallet_dump.py (John Newbery)bdefc9705d
[tests] Remove deprecated addwitnessaddress call from feature_nulldummy (John Newbery)67d7d67cf3
[test] Fix flake8 warnings in tests (John Newbery) Pull request description: Fully removes the `addwitnessaddress` RPC method, which was deprecated in V0.17 Tree-SHA512: 8fa8a2a721a81262fbdedbe1cef031e6a07aa6abbc9760dbc62738fc4f688b44bd737d0f3cdb1aec046866a6395befbfecde0f34e76a99e11d3cf566cad1d0de
This commit is contained in:
commit
9dda5fdf64
8 changed files with 130 additions and 306 deletions
5
doc/release-notes-14296.md
Normal file
5
doc/release-notes-14296.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
addwitnessaddress RPC method removed
|
||||||
|
------------------------------------
|
||||||
|
|
||||||
|
The `addwitnessaddress` RPC was added for segwit testing in version 0.13.0. It
|
||||||
|
was deprecated in version 0.16.0. This version fully removes the RPC method.
|
|
@ -147,7 +147,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
||||||
{ "logging", 0, "include" },
|
{ "logging", 0, "include" },
|
||||||
{ "logging", 1, "exclude" },
|
{ "logging", 1, "exclude" },
|
||||||
{ "disconnectnode", 1, "nodeid" },
|
{ "disconnectnode", 1, "nodeid" },
|
||||||
{ "addwitnessaddress", 1, "p2sh" },
|
|
||||||
// Echo with conversion (For testing only)
|
// Echo with conversion (For testing only)
|
||||||
{ "echojson", 0, "arg0" },
|
{ "echojson", 0, "arg0" },
|
||||||
{ "echojson", 1, "arg1" },
|
{ "echojson", 1, "arg1" },
|
||||||
|
|
|
@ -982,131 +982,6 @@ static UniValue addmultisigaddress(const JSONRPCRequest& request)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Witnessifier : public boost::static_visitor<bool>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CWallet * const pwallet;
|
|
||||||
CTxDestination result;
|
|
||||||
bool already_witness;
|
|
||||||
|
|
||||||
explicit Witnessifier(CWallet *_pwallet) : pwallet(_pwallet), already_witness(false) {}
|
|
||||||
|
|
||||||
bool operator()(const CKeyID &keyID) {
|
|
||||||
if (pwallet) {
|
|
||||||
CScript basescript = GetScriptForDestination(keyID);
|
|
||||||
CScript witscript = GetScriptForWitness(basescript);
|
|
||||||
if (!IsSolvable(*pwallet, witscript)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return ExtractDestination(witscript, result);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator()(const CScriptID &scriptID) {
|
|
||||||
CScript subscript;
|
|
||||||
if (pwallet && pwallet->GetCScript(scriptID, subscript)) {
|
|
||||||
int witnessversion;
|
|
||||||
std::vector<unsigned char> witprog;
|
|
||||||
if (subscript.IsWitnessProgram(witnessversion, witprog)) {
|
|
||||||
ExtractDestination(subscript, result);
|
|
||||||
already_witness = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
CScript witscript = GetScriptForWitness(subscript);
|
|
||||||
if (!IsSolvable(*pwallet, witscript)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return ExtractDestination(witscript, result);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator()(const WitnessV0KeyHash& id)
|
|
||||||
{
|
|
||||||
already_witness = true;
|
|
||||||
result = id;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator()(const WitnessV0ScriptHash& id)
|
|
||||||
{
|
|
||||||
already_witness = true;
|
|
||||||
result = id;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool operator()(const T& dest) { return false; }
|
|
||||||
};
|
|
||||||
|
|
||||||
static UniValue addwitnessaddress(const JSONRPCRequest& request)
|
|
||||||
{
|
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
|
||||||
CWallet* const pwallet = wallet.get();
|
|
||||||
|
|
||||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
|
|
||||||
return NullUniValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
|
|
||||||
{
|
|
||||||
std::string msg = "addwitnessaddress \"address\" ( p2sh )\n"
|
|
||||||
"\nDEPRECATED: set the address_type argument of getnewaddress, or option -addresstype=[bech32|p2sh-segwit] instead.\n"
|
|
||||||
"Add a witness address for a script (with pubkey or redeemscript known). Requires a new wallet backup.\n"
|
|
||||||
"It returns the witness script.\n"
|
|
||||||
|
|
||||||
"\nArguments:\n"
|
|
||||||
"1. \"address\" (string, required) An address known to the wallet\n"
|
|
||||||
"2. p2sh (bool, optional, default=true) Embed inside P2SH\n"
|
|
||||||
|
|
||||||
"\nResult:\n"
|
|
||||||
"\"witnessaddress\", (string) The value of the new address (P2SH or BIP173).\n"
|
|
||||||
"}\n"
|
|
||||||
;
|
|
||||||
throw std::runtime_error(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!IsDeprecatedRPCEnabled("addwitnessaddress")) {
|
|
||||||
throw JSONRPCError(RPC_METHOD_DEPRECATED, "addwitnessaddress is deprecated and will be fully removed in v0.17. "
|
|
||||||
"To use addwitnessaddress in v0.16, restart bitcoind with -deprecatedrpc=addwitnessaddress.\n"
|
|
||||||
"Projects should transition to using the address_type argument of getnewaddress, or option -addresstype=[bech32|p2sh-segwit] instead.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
CTxDestination dest = DecodeDestination(request.params[0].get_str());
|
|
||||||
if (!IsValidDestination(dest)) {
|
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool p2sh = true;
|
|
||||||
if (!request.params[1].isNull()) {
|
|
||||||
p2sh = request.params[1].get_bool();
|
|
||||||
}
|
|
||||||
|
|
||||||
Witnessifier w(pwallet);
|
|
||||||
bool ret = boost::apply_visitor(w, dest);
|
|
||||||
if (!ret) {
|
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "Public key or redeemscript not known to wallet, or the key is uncompressed");
|
|
||||||
}
|
|
||||||
|
|
||||||
CScript witprogram = GetScriptForDestination(w.result);
|
|
||||||
|
|
||||||
if (p2sh) {
|
|
||||||
w.result = CScriptID(witprogram);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (w.already_witness) {
|
|
||||||
if (!(dest == w.result)) {
|
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "Cannot convert between witness address types");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pwallet->AddCScript(witprogram); // Implicit for single-key now, but necessary for multisig and for compatibility with older software
|
|
||||||
pwallet->SetAddressBook(w.result, "", "receive");
|
|
||||||
}
|
|
||||||
|
|
||||||
return EncodeDestination(w.result);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct tallyitem
|
struct tallyitem
|
||||||
{
|
{
|
||||||
CAmount nAmount;
|
CAmount nAmount;
|
||||||
|
@ -4097,7 +3972,6 @@ static const CRPCCommand commands[] =
|
||||||
{ // category name actor (function) argNames
|
{ // category name actor (function) argNames
|
||||||
// --------------------- ------------------------ ----------------------- ----------
|
// --------------------- ------------------------ ----------------------- ----------
|
||||||
{ "generating", "generate", &generate, {"nblocks","maxtries"} },
|
{ "generating", "generate", &generate, {"nblocks","maxtries"} },
|
||||||
{ "hidden", "addwitnessaddress", &addwitnessaddress, {"address","p2sh"} },
|
|
||||||
{ "hidden", "resendwallettransactions", &resendwallettransactions, {} },
|
{ "hidden", "resendwallettransactions", &resendwallettransactions, {} },
|
||||||
{ "rawtransactions", "fundrawtransaction", &fundrawtransaction, {"hexstring","options","iswitness"} },
|
{ "rawtransactions", "fundrawtransaction", &fundrawtransaction, {"hexstring","options","iswitness"} },
|
||||||
{ "wallet", "abandontransaction", &abandontransaction, {"txid"} },
|
{ "wallet", "abandontransaction", &abandontransaction, {"txid"} },
|
||||||
|
|
|
@ -12,6 +12,7 @@ Generate 427 more blocks.
|
||||||
[Consensus] Check that the new NULLDUMMY rules are not enforced on the 431st block.
|
[Consensus] Check that the new NULLDUMMY rules are not enforced on the 431st block.
|
||||||
[Policy/Consensus] Check that the new NULLDUMMY rules are enforced on the 432nd block.
|
[Policy/Consensus] Check that the new NULLDUMMY rules are enforced on the 432nd block.
|
||||||
"""
|
"""
|
||||||
|
import time
|
||||||
|
|
||||||
from test_framework.blocktools import create_coinbase, create_block, create_transaction, add_witness_commitment
|
from test_framework.blocktools import create_coinbase, create_block, create_transaction, add_witness_commitment
|
||||||
from test_framework.messages import CTransaction
|
from test_framework.messages import CTransaction
|
||||||
|
@ -19,8 +20,6 @@ from test_framework.script import CScript
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str
|
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str
|
||||||
|
|
||||||
import time
|
|
||||||
|
|
||||||
NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero) (code 64)"
|
NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero) (code 64)"
|
||||||
|
|
||||||
def trueDummy(tx):
|
def trueDummy(tx):
|
||||||
|
@ -42,7 +41,7 @@ class NULLDUMMYTest(BitcoinTestFramework):
|
||||||
self.setup_clean_chain = True
|
self.setup_clean_chain = True
|
||||||
# This script tests NULLDUMMY activation, which is part of the 'segwit' deployment, so we go through
|
# This script tests NULLDUMMY activation, which is part of the 'segwit' deployment, so we go through
|
||||||
# normal segwit activation here (and don't use the default always-on behaviour).
|
# normal segwit activation here (and don't use the default always-on behaviour).
|
||||||
self.extra_args = [['-whitelist=127.0.0.1', '-vbparams=segwit:0:999999999999', '-addresstype=legacy', "-deprecatedrpc=addwitnessaddress"]]
|
self.extra_args = [['-whitelist=127.0.0.1', '-vbparams=segwit:0:999999999999', '-addresstype=legacy']]
|
||||||
|
|
||||||
def skip_test_if_missing_module(self):
|
def skip_test_if_missing_module(self):
|
||||||
self.skip_if_no_wallet()
|
self.skip_if_no_wallet()
|
||||||
|
@ -50,7 +49,7 @@ class NULLDUMMYTest(BitcoinTestFramework):
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
self.address = self.nodes[0].getnewaddress()
|
self.address = self.nodes[0].getnewaddress()
|
||||||
self.ms_address = self.nodes[0].addmultisigaddress(1, [self.address])['address']
|
self.ms_address = self.nodes[0].addmultisigaddress(1, [self.address])['address']
|
||||||
self.wit_address = self.nodes[0].addwitnessaddress(self.address)
|
self.wit_address = self.nodes[0].getnewaddress(address_type='p2sh-segwit')
|
||||||
self.wit_ms_address = self.nodes[0].addmultisigaddress(1, [self.address], '', 'p2sh-segwit')['address']
|
self.wit_ms_address = self.nodes[0].addmultisigaddress(1, [self.address], '', 'p2sh-segwit')['address']
|
||||||
|
|
||||||
self.coinbase_blocks = self.nodes[0].generate(2) # Block 2
|
self.coinbase_blocks = self.nodes[0].generate(2) # Block 2
|
||||||
|
@ -99,7 +98,6 @@ class NULLDUMMYTest(BitcoinTestFramework):
|
||||||
self.nodes[0].sendrawtransaction(bytes_to_hex_str(i.serialize_with_witness()), True)
|
self.nodes[0].sendrawtransaction(bytes_to_hex_str(i.serialize_with_witness()), True)
|
||||||
self.block_submit(self.nodes[0], test6txs, True, True)
|
self.block_submit(self.nodes[0], test6txs, True, True)
|
||||||
|
|
||||||
|
|
||||||
def block_submit(self, node, txs, witness=False, accept=False):
|
def block_submit(self, node, txs, witness=False, accept=False):
|
||||||
block = create_block(self.tip, create_coinbase(self.lastblockheight + 1), self.lastblocktime + 1)
|
block = create_block(self.tip, create_coinbase(self.lastblockheight + 1), self.lastblocktime + 1)
|
||||||
block.nVersion = 4
|
block.nVersion = 4
|
||||||
|
|
|
@ -5,11 +5,10 @@
|
||||||
"""Test the SegWit changeover logic."""
|
"""Test the SegWit changeover logic."""
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
from test_framework.address import (
|
from test_framework.address import (
|
||||||
key_to_p2pkh,
|
key_to_p2pkh,
|
||||||
key_to_p2sh_p2wpkh,
|
|
||||||
key_to_p2wpkh,
|
|
||||||
program_to_witness,
|
program_to_witness,
|
||||||
script_to_p2sh,
|
script_to_p2sh,
|
||||||
script_to_p2sh_p2wsh,
|
script_to_p2sh_p2wsh,
|
||||||
|
@ -21,8 +20,6 @@ from test_framework.script import CScript, OP_HASH160, OP_CHECKSIG, OP_0, hash16
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, connect_nodes, hex_str_to_bytes, sync_blocks, try_rpc
|
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, connect_nodes, hex_str_to_bytes, sync_blocks, try_rpc
|
||||||
|
|
||||||
from io import BytesIO
|
|
||||||
|
|
||||||
NODE_0 = 0
|
NODE_0 = 0
|
||||||
NODE_2 = 2
|
NODE_2 = 2
|
||||||
WIT_V0 = 0
|
WIT_V0 = 0
|
||||||
|
@ -51,20 +48,17 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
"-rpcserialversion=0",
|
"-rpcserialversion=0",
|
||||||
"-vbparams=segwit:0:999999999999",
|
"-vbparams=segwit:0:999999999999",
|
||||||
"-addresstype=legacy",
|
"-addresstype=legacy",
|
||||||
"-deprecatedrpc=addwitnessaddress",
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"-blockversion=4",
|
"-blockversion=4",
|
||||||
"-rpcserialversion=1",
|
"-rpcserialversion=1",
|
||||||
"-vbparams=segwit:0:999999999999",
|
"-vbparams=segwit:0:999999999999",
|
||||||
"-addresstype=legacy",
|
"-addresstype=legacy",
|
||||||
"-deprecatedrpc=addwitnessaddress",
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"-blockversion=536870915",
|
"-blockversion=536870915",
|
||||||
"-vbparams=segwit:0:999999999999",
|
"-vbparams=segwit:0:999999999999",
|
||||||
"-addresstype=legacy",
|
"-addresstype=legacy",
|
||||||
"-deprecatedrpc=addwitnessaddress",
|
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -91,7 +85,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
def fail_accept(self, node, error_msg, txid, sign, redeem_script=""):
|
def fail_accept(self, node, error_msg, txid, sign, redeem_script=""):
|
||||||
assert_raises_rpc_error(-26, error_msg, send_to_witness, use_p2wsh=1, node=node, utxo=getutxo(txid), pubkey=self.pubkey[0], encode_p2sh=False, amount=Decimal("49.998"), sign=sign, insert_redeem_script=redeem_script)
|
assert_raises_rpc_error(-26, error_msg, send_to_witness, use_p2wsh=1, node=node, utxo=getutxo(txid), pubkey=self.pubkey[0], encode_p2sh=False, amount=Decimal("49.998"), sign=sign, insert_redeem_script=redeem_script)
|
||||||
|
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
self.nodes[0].generate(161) # block 161
|
self.nodes[0].generate(161) # block 161
|
||||||
|
|
||||||
|
@ -119,12 +112,8 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
newaddress = self.nodes[i].getnewaddress()
|
newaddress = self.nodes[i].getnewaddress()
|
||||||
self.pubkey.append(self.nodes[i].getaddressinfo(newaddress)["pubkey"])
|
self.pubkey.append(self.nodes[i].getaddressinfo(newaddress)["pubkey"])
|
||||||
multiscript = CScript([OP_1, hex_str_to_bytes(self.pubkey[-1]), OP_1, OP_CHECKMULTISIG])
|
multiscript = CScript([OP_1, hex_str_to_bytes(self.pubkey[-1]), OP_1, OP_CHECKMULTISIG])
|
||||||
p2sh_addr = self.nodes[i].addwitnessaddress(newaddress)
|
|
||||||
bip173_addr = self.nodes[i].addwitnessaddress(newaddress, False)
|
|
||||||
p2sh_ms_addr = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]], '', 'p2sh-segwit')['address']
|
p2sh_ms_addr = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]], '', 'p2sh-segwit')['address']
|
||||||
bip173_ms_addr = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]], '', 'bech32')['address']
|
bip173_ms_addr = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]], '', 'bech32')['address']
|
||||||
assert_equal(p2sh_addr, key_to_p2sh_p2wpkh(self.pubkey[-1]))
|
|
||||||
assert_equal(bip173_addr, key_to_p2wpkh(self.pubkey[-1]))
|
|
||||||
assert_equal(p2sh_ms_addr, script_to_p2sh_p2wsh(multiscript))
|
assert_equal(p2sh_ms_addr, script_to_p2sh_p2wsh(multiscript))
|
||||||
assert_equal(bip173_ms_addr, script_to_p2wsh(multiscript))
|
assert_equal(bip173_ms_addr, script_to_p2wsh(multiscript))
|
||||||
p2sh_ids.append([])
|
p2sh_ids.append([])
|
||||||
|
@ -264,7 +253,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
# Mine a block to clear the gbt cache again.
|
# Mine a block to clear the gbt cache again.
|
||||||
self.nodes[0].generate(1)
|
self.nodes[0].generate(1)
|
||||||
|
|
||||||
self.log.info("Verify behaviour of importaddress, addwitnessaddress and listunspent")
|
self.log.info("Verify behaviour of importaddress and listunspent")
|
||||||
|
|
||||||
# Some public keys to be used later
|
# Some public keys to be used later
|
||||||
pubkeys = [
|
pubkeys = [
|
||||||
|
@ -282,8 +271,8 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
uncompressed_spendable_address = ["mvozP4UwyGD2mGZU4D2eMvMLPB9WkMmMQu"]
|
uncompressed_spendable_address = ["mvozP4UwyGD2mGZU4D2eMvMLPB9WkMmMQu"]
|
||||||
self.nodes[0].importprivkey("cNC8eQ5dg3mFAVePDX4ddmPYpPbw41r9bm2jd1nLJT77e6RrzTRR")
|
self.nodes[0].importprivkey("cNC8eQ5dg3mFAVePDX4ddmPYpPbw41r9bm2jd1nLJT77e6RrzTRR")
|
||||||
compressed_spendable_address = ["mmWQubrDomqpgSYekvsU7HWEVjLFHAakLe"]
|
compressed_spendable_address = ["mmWQubrDomqpgSYekvsU7HWEVjLFHAakLe"]
|
||||||
assert ((self.nodes[0].getaddressinfo(uncompressed_spendable_address[0])['iscompressed'] == False))
|
assert not self.nodes[0].getaddressinfo(uncompressed_spendable_address[0])['iscompressed']
|
||||||
assert ((self.nodes[0].getaddressinfo(compressed_spendable_address[0])['iscompressed'] == True))
|
assert self.nodes[0].getaddressinfo(compressed_spendable_address[0])['iscompressed']
|
||||||
|
|
||||||
self.nodes[0].importpubkey(pubkeys[0])
|
self.nodes[0].importpubkey(pubkeys[0])
|
||||||
compressed_solvable_address = [key_to_p2pkh(pubkeys[0])]
|
compressed_solvable_address = [key_to_p2pkh(pubkeys[0])]
|
||||||
|
@ -305,7 +294,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
uncompressed_solvable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_spendable_address[0], uncompressed_solvable_address[0]])['address'])
|
uncompressed_solvable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_spendable_address[0], uncompressed_solvable_address[0]])['address'])
|
||||||
compressed_solvable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_spendable_address[0], compressed_solvable_address[0]])['address'])
|
compressed_solvable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_spendable_address[0], compressed_solvable_address[0]])['address'])
|
||||||
compressed_solvable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_solvable_address[0], compressed_solvable_address[1]])['address'])
|
compressed_solvable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_solvable_address[0], compressed_solvable_address[1]])['address'])
|
||||||
unknown_address = ["mtKKyoHabkk6e4ppT7NaM7THqPUt7AzPrT", "2NDP3jLWAFT8NDAiUa9qiE6oBt2awmMq7Dx"]
|
|
||||||
|
|
||||||
# Test multisig_without_privkey
|
# Test multisig_without_privkey
|
||||||
# We have 2 public keys without private keys, use addmultisigaddress to add to wallet.
|
# We have 2 public keys without private keys, use addmultisigaddress to add to wallet.
|
||||||
|
@ -386,7 +374,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
op1 = CScript([OP_1])
|
op1 = CScript([OP_1])
|
||||||
op0 = CScript([OP_0])
|
op0 = CScript([OP_0])
|
||||||
# 2N7MGY19ti4KDMSzRfPAssP6Pxyuxoi6jLe is the P2SH(P2PKH) version of mjoE3sSrb8ByYEvgnC3Aox86u1CHnfJA4V
|
# 2N7MGY19ti4KDMSzRfPAssP6Pxyuxoi6jLe is the P2SH(P2PKH) version of mjoE3sSrb8ByYEvgnC3Aox86u1CHnfJA4V
|
||||||
unsolvable_address = ["mjoE3sSrb8ByYEvgnC3Aox86u1CHnfJA4V", "2N7MGY19ti4KDMSzRfPAssP6Pxyuxoi6jLe", script_to_p2sh(op1), script_to_p2sh(op0)]
|
|
||||||
unsolvable_address_key = hex_str_to_bytes("02341AEC7587A51CDE5279E0630A531AEA2615A9F80B17E8D9376327BAEAA59E3D")
|
unsolvable_address_key = hex_str_to_bytes("02341AEC7587A51CDE5279E0630A531AEA2615A9F80B17E8D9376327BAEAA59E3D")
|
||||||
unsolvablep2pkh = CScript([OP_DUP, OP_HASH160, hash160(unsolvable_address_key), OP_EQUALVERIFY, OP_CHECKSIG])
|
unsolvablep2pkh = CScript([OP_DUP, OP_HASH160, hash160(unsolvable_address_key), OP_EQUALVERIFY, OP_CHECKSIG])
|
||||||
unsolvablep2wshp2pkh = CScript([OP_0, sha256(unsolvablep2pkh)])
|
unsolvablep2wshp2pkh = CScript([OP_0, sha256(unsolvablep2pkh)])
|
||||||
|
@ -440,19 +427,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
self.mine_and_test_listunspent(unsolvable_after_importaddress, 1)
|
self.mine_and_test_listunspent(unsolvable_after_importaddress, 1)
|
||||||
self.mine_and_test_listunspent(unseen_anytime, 0)
|
self.mine_and_test_listunspent(unseen_anytime, 0)
|
||||||
|
|
||||||
# addwitnessaddress should refuse to return a witness address if an uncompressed key is used
|
|
||||||
# note that no witness address should be returned by unsolvable addresses
|
|
||||||
for i in uncompressed_spendable_address + uncompressed_solvable_address + unknown_address + unsolvable_address:
|
|
||||||
assert_raises_rpc_error(-4, "Public key or redeemscript not known to wallet, or the key is uncompressed", self.nodes[0].addwitnessaddress, i)
|
|
||||||
|
|
||||||
# addwitnessaddress should return a witness addresses even if keys are not in the wallet
|
|
||||||
self.nodes[0].addwitnessaddress(multisig_without_privkey_address)
|
|
||||||
|
|
||||||
for i in compressed_spendable_address + compressed_solvable_address:
|
|
||||||
witaddress = self.nodes[0].addwitnessaddress(i)
|
|
||||||
# addwitnessaddress should return the same address if it is a known P2SH-witness address
|
|
||||||
assert_equal(witaddress, self.nodes[0].addwitnessaddress(witaddress))
|
|
||||||
|
|
||||||
spendable_txid.append(self.mine_and_test_listunspent(spendable_anytime + spendable_after_importaddress, 2))
|
spendable_txid.append(self.mine_and_test_listunspent(spendable_anytime + spendable_after_importaddress, 2))
|
||||||
solvable_txid.append(self.mine_and_test_listunspent(solvable_anytime + solvable_after_importaddress, 1))
|
solvable_txid.append(self.mine_and_test_listunspent(solvable_anytime + solvable_after_importaddress, 1))
|
||||||
self.mine_and_test_listunspent(unsolvable_after_importaddress, 1)
|
self.mine_and_test_listunspent(unsolvable_after_importaddress, 1)
|
||||||
|
@ -470,8 +444,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
self.nodes[0].importpubkey(pubkeys[6])
|
self.nodes[0].importpubkey(pubkeys[6])
|
||||||
uncompressed_solvable_address = [key_to_p2pkh(pubkeys[6])]
|
uncompressed_solvable_address = [key_to_p2pkh(pubkeys[6])]
|
||||||
|
|
||||||
spendable_after_addwitnessaddress = [] # These outputs should be seen after importaddress
|
|
||||||
solvable_after_addwitnessaddress=[] # These outputs should be seen after importaddress but not spendable
|
|
||||||
unseen_anytime = [] # These outputs should never be seen
|
unseen_anytime = [] # These outputs should never be seen
|
||||||
solvable_anytime = [] # These outputs should be solvable after importpubkey
|
solvable_anytime = [] # These outputs should be solvable after importpubkey
|
||||||
unseen_anytime = [] # These outputs should never be seen
|
unseen_anytime = [] # These outputs should never be seen
|
||||||
|
@ -488,8 +460,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
v = self.nodes[0].getaddressinfo(i)
|
v = self.nodes[0].getaddressinfo(i)
|
||||||
if (v['isscript']):
|
if (v['isscript']):
|
||||||
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
||||||
# P2WSH and P2SH(P2WSH) multisig with compressed keys are spendable after addwitnessaddress
|
|
||||||
spendable_after_addwitnessaddress.extend([p2wsh, p2sh_p2wsh])
|
|
||||||
premature_witaddress.append(script_to_p2sh(p2wsh))
|
premature_witaddress.append(script_to_p2sh(p2wsh))
|
||||||
else:
|
else:
|
||||||
[p2wpkh, p2sh_p2wpkh, p2pk, p2pkh, p2sh_p2pk, p2sh_p2pkh, p2wsh_p2pk, p2wsh_p2pkh, p2sh_p2wsh_p2pk, p2sh_p2wsh_p2pkh] = self.p2pkh_address_to_script(v)
|
[p2wpkh, p2sh_p2wpkh, p2pk, p2pkh, p2sh_p2pk, p2sh_p2pkh, p2wsh_p2pk, p2wsh_p2pkh, p2sh_p2wsh_p2pk, p2sh_p2wsh_p2pkh] = self.p2pkh_address_to_script(v)
|
||||||
|
@ -510,9 +480,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
for i in compressed_solvable_address:
|
for i in compressed_solvable_address:
|
||||||
v = self.nodes[0].getaddressinfo(i)
|
v = self.nodes[0].getaddressinfo(i)
|
||||||
if (v['isscript']):
|
if (v['isscript']):
|
||||||
# P2WSH multisig without private key are seen after addwitnessaddress
|
|
||||||
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
||||||
solvable_after_addwitnessaddress.extend([p2wsh, p2sh_p2wsh])
|
|
||||||
premature_witaddress.append(script_to_p2sh(p2wsh))
|
premature_witaddress.append(script_to_p2sh(p2wsh))
|
||||||
else:
|
else:
|
||||||
[p2wpkh, p2sh_p2wpkh, p2pk, p2pkh, p2sh_p2pk, p2sh_p2pkh, p2wsh_p2pk, p2wsh_p2pkh, p2sh_p2wsh_p2pk, p2sh_p2wsh_p2pkh] = self.p2pkh_address_to_script(v)
|
[p2wpkh, p2sh_p2wpkh, p2pk, p2pkh, p2sh_p2pk, p2sh_p2pkh, p2wsh_p2pk, p2wsh_p2pkh, p2sh_p2wsh_p2pk, p2sh_p2wsh_p2pkh] = self.p2pkh_address_to_script(v)
|
||||||
|
@ -521,24 +489,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
|
|
||||||
self.mine_and_test_listunspent(spendable_anytime, 2)
|
self.mine_and_test_listunspent(spendable_anytime, 2)
|
||||||
self.mine_and_test_listunspent(solvable_anytime, 1)
|
self.mine_and_test_listunspent(solvable_anytime, 1)
|
||||||
self.mine_and_test_listunspent(spendable_after_addwitnessaddress + solvable_after_addwitnessaddress + unseen_anytime, 0)
|
|
||||||
|
|
||||||
# addwitnessaddress should refuse to return a witness address if an uncompressed key is used
|
|
||||||
# note that a multisig address returned by addmultisigaddress is not solvable until it is added with importaddress
|
|
||||||
# premature_witaddress are not accepted until the script is added with addwitnessaddress first
|
|
||||||
for i in uncompressed_spendable_address + uncompressed_solvable_address + premature_witaddress:
|
|
||||||
# This will raise an exception
|
|
||||||
assert_raises_rpc_error(-4, "Public key or redeemscript not known to wallet, or the key is uncompressed", self.nodes[0].addwitnessaddress, i)
|
|
||||||
|
|
||||||
# after importaddress it should pass addwitnessaddress
|
|
||||||
v = self.nodes[0].getaddressinfo(compressed_solvable_address[1])
|
|
||||||
self.nodes[0].importaddress(v['hex'],"",False,True)
|
|
||||||
for i in compressed_spendable_address + compressed_solvable_address + premature_witaddress:
|
|
||||||
witaddress = self.nodes[0].addwitnessaddress(i)
|
|
||||||
assert_equal(witaddress, self.nodes[0].addwitnessaddress(witaddress))
|
|
||||||
|
|
||||||
spendable_txid.append(self.mine_and_test_listunspent(spendable_after_addwitnessaddress + spendable_anytime, 2))
|
|
||||||
solvable_txid.append(self.mine_and_test_listunspent(solvable_after_addwitnessaddress + solvable_anytime, 1))
|
|
||||||
self.mine_and_test_listunspent(unseen_anytime, 0)
|
self.mine_and_test_listunspent(unseen_anytime, 0)
|
||||||
|
|
||||||
# Check that createrawtransaction/decoderawtransaction with non-v0 Bech32 works
|
# Check that createrawtransaction/decoderawtransaction with non-v0 Bech32 works
|
||||||
|
@ -599,7 +549,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
for i in self.nodes[0].listunspent():
|
for i in self.nodes[0].listunspent():
|
||||||
if (i['txid'] == txid):
|
if (i['txid'] == txid):
|
||||||
watchcount += 1
|
watchcount += 1
|
||||||
if (i['spendable'] == True):
|
if i['spendable']:
|
||||||
spendcount += 1
|
spendcount += 1
|
||||||
if (ismine == 2):
|
if (ismine == 2):
|
||||||
assert_equal(spendcount, len(script_list))
|
assert_equal(spendcount, len(script_list))
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
Version 1 compact blocks are pre-segwit (txids)
|
Version 1 compact blocks are pre-segwit (txids)
|
||||||
Version 2 compact blocks are post-segwit (wtxids)
|
Version 2 compact blocks are post-segwit (wtxids)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
@ -99,7 +98,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||||
self.num_nodes = 2
|
self.num_nodes = 2
|
||||||
# This test was written assuming SegWit is activated using BIP9 at height 432 (3x confirmation window).
|
# This test was written assuming SegWit is activated using BIP9 at height 432 (3x confirmation window).
|
||||||
# TODO: Rewrite this test to support SegWit being always active.
|
# TODO: Rewrite this test to support SegWit being always active.
|
||||||
self.extra_args = [["-vbparams=segwit:0:0"], ["-vbparams=segwit:0:999999999999", "-txindex", "-deprecatedrpc=addwitnessaddress"]]
|
self.extra_args = [["-vbparams=segwit:0:0"], ["-vbparams=segwit:0:999999999999", "-txindex"]]
|
||||||
self.utxos = []
|
self.utxos = []
|
||||||
|
|
||||||
def skip_test_if_missing_module(self):
|
def skip_test_if_missing_module(self):
|
||||||
|
@ -265,7 +264,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||||
if use_witness_address:
|
if use_witness_address:
|
||||||
# Want at least one segwit spend, so move all funds to
|
# Want at least one segwit spend, so move all funds to
|
||||||
# a witness address.
|
# a witness address.
|
||||||
address = node.addwitnessaddress(address)
|
address = node.getnewaddress(address_type='bech32')
|
||||||
value_to_send = node.getbalance()
|
value_to_send = node.getbalance()
|
||||||
node.sendtoaddress(address, satoshi_round(value_to_send - Decimal(0.1)))
|
node.sendtoaddress(address, satoshi_round(value_to_send - Decimal(0.1)))
|
||||||
node.generate(1)
|
node.generate(1)
|
||||||
|
@ -279,7 +278,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||||
segwit_tx_generated = True
|
segwit_tx_generated = True
|
||||||
|
|
||||||
if use_witness_address:
|
if use_witness_address:
|
||||||
assert(segwit_tx_generated) # check that our test is not broken
|
assert segwit_tx_generated # check that our test is not broken
|
||||||
|
|
||||||
# Wait until we've seen the block announcement for the resulting tip
|
# Wait until we've seen the block announcement for the resulting tip
|
||||||
tip = int(node.getbestblockhash(), 16)
|
tip = int(node.getbestblockhash(), 16)
|
||||||
|
@ -403,8 +402,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||||
coinbase_hash = block.vtx[0].sha256
|
coinbase_hash = block.vtx[0].sha256
|
||||||
if version == 2:
|
if version == 2:
|
||||||
coinbase_hash = block.vtx[0].calc_sha256(True)
|
coinbase_hash = block.vtx[0].calc_sha256(True)
|
||||||
comp_block.shortids = [
|
comp_block.shortids = [calculate_shortid(k0, k1, coinbase_hash)]
|
||||||
calculate_shortid(k0, k1, coinbase_hash) ]
|
|
||||||
test_node.send_and_ping(msg_cmpctblock(comp_block.to_p2p()))
|
test_node.send_and_ping(msg_cmpctblock(comp_block.to_p2p()))
|
||||||
assert_equal(int(node.getbestblockhash(), 16), block.hashPrevBlock)
|
assert_equal(int(node.getbestblockhash(), 16), block.hashPrevBlock)
|
||||||
# Expect a getblocktxn message.
|
# Expect a getblocktxn message.
|
||||||
|
|
|
@ -13,26 +13,22 @@ can be disabled or reordered if needed for debugging. If new test cases are
|
||||||
added in the future, they should try to follow the same convention and not
|
added in the future, they should try to follow the same convention and not
|
||||||
make assumptions about execution order.
|
make assumptions about execution order.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
import io
|
||||||
|
|
||||||
from test_framework.blocktools import add_witness_commitment, create_block, create_coinbase, send_to_witness
|
from test_framework.blocktools import add_witness_commitment, create_block, create_coinbase, send_to_witness
|
||||||
from test_framework.messages import BIP125_SEQUENCE_NUMBER, CTransaction
|
from test_framework.messages import BIP125_SEQUENCE_NUMBER, CTransaction
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import assert_equal, assert_greater_than, assert_raises_rpc_error, bytes_to_hex_str, connect_nodes_bi, hex_str_to_bytes, sync_mempools
|
from test_framework.util import assert_equal, assert_greater_than, assert_raises_rpc_error, bytes_to_hex_str, connect_nodes_bi, hex_str_to_bytes, sync_mempools
|
||||||
|
|
||||||
import io
|
|
||||||
|
|
||||||
WALLET_PASSPHRASE = "test"
|
WALLET_PASSPHRASE = "test"
|
||||||
WALLET_PASSPHRASE_TIMEOUT = 3600
|
WALLET_PASSPHRASE_TIMEOUT = 3600
|
||||||
|
|
||||||
|
|
||||||
class BumpFeeTest(BitcoinTestFramework):
|
class BumpFeeTest(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.setup_clean_chain = True
|
||||||
self.extra_args = [[
|
self.extra_args = [[
|
||||||
"-deprecatedrpc=addwitnessaddress",
|
|
||||||
"-walletrbf={}".format(i),
|
"-walletrbf={}".format(i),
|
||||||
"-mintxfee=0.00002",
|
"-mintxfee=0.00002",
|
||||||
] for i in range(self.num_nodes)]
|
] for i in range(self.num_nodes)]
|
||||||
|
@ -107,8 +103,7 @@ def test_segwit_bumpfee_succeeds(rbf_node, dest_address):
|
||||||
# which spends it, and make sure bumpfee can be called on it.
|
# which spends it, and make sure bumpfee can be called on it.
|
||||||
|
|
||||||
segwit_in = next(u for u in rbf_node.listunspent() if u["amount"] == Decimal("0.001"))
|
segwit_in = next(u for u in rbf_node.listunspent() if u["amount"] == Decimal("0.001"))
|
||||||
segwit_out = rbf_node.getaddressinfo(rbf_node.getnewaddress())
|
segwit_out = rbf_node.getaddressinfo(rbf_node.getnewaddress(address_type='p2sh-segwit'))
|
||||||
rbf_node.addwitnessaddress(segwit_out["address"])
|
|
||||||
segwitid = send_to_witness(
|
segwitid = send_to_witness(
|
||||||
use_p2wsh=False,
|
use_p2wsh=False,
|
||||||
node=rbf_node,
|
node=rbf_node,
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
# Distributed under the MIT software license, see the accompanying
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
"""Test the dumpwallet RPC."""
|
"""Test the dumpwallet RPC."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
|
@ -19,11 +18,12 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
|
||||||
Also check that the old hd_master is inactive
|
Also check that the old hd_master is inactive
|
||||||
"""
|
"""
|
||||||
with open(file_name, encoding='utf8') as inputfile:
|
with open(file_name, encoding='utf8') as inputfile:
|
||||||
found_addr = 0
|
found_legacy_addr = 0
|
||||||
|
found_p2sh_segwit_addr = 0
|
||||||
|
found_bech32_addr = 0
|
||||||
found_script_addr = 0
|
found_script_addr = 0
|
||||||
found_addr_chg = 0
|
found_addr_chg = 0
|
||||||
found_addr_rsv = 0
|
found_addr_rsv = 0
|
||||||
witness_addr_ret = None
|
|
||||||
hd_master_addr_ret = None
|
hd_master_addr_ret = None
|
||||||
for line in inputfile:
|
for line in inputfile:
|
||||||
# only read non comment lines
|
# only read non comment lines
|
||||||
|
@ -60,14 +60,14 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
|
||||||
# count key types
|
# count key types
|
||||||
for addrObj in addrs:
|
for addrObj in addrs:
|
||||||
if addrObj['address'] == addr.split(",")[0] and addrObj['hdkeypath'] == keypath and keytype == "label=":
|
if addrObj['address'] == addr.split(",")[0] and addrObj['hdkeypath'] == keypath and keytype == "label=":
|
||||||
# a labeled entry in the wallet should contain both a native address
|
if addr.startswith('m') or addr.startswith('n'):
|
||||||
# and the p2sh-p2wpkh address that was added at wallet setup
|
# P2PKH address
|
||||||
if len(addr.split(",")) == 2:
|
found_legacy_addr += 1
|
||||||
addr_list = addr.split(",")
|
elif addr.startswith('2'):
|
||||||
# the entry should be of the first key in the wallet
|
# P2SH-segwit address
|
||||||
assert_equal(addrs[0]['address'], addr_list[0])
|
found_p2sh_segwit_addr += 1
|
||||||
witness_addr_ret = addr_list[1]
|
elif addr.startswith('bcrt1'):
|
||||||
found_addr += 1
|
found_bech32_addr += 1
|
||||||
break
|
break
|
||||||
elif keytype == "change=1":
|
elif keytype == "change=1":
|
||||||
found_addr_chg += 1
|
found_addr_chg += 1
|
||||||
|
@ -82,13 +82,13 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
|
||||||
found_script_addr += 1
|
found_script_addr += 1
|
||||||
break
|
break
|
||||||
|
|
||||||
return found_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_ret, witness_addr_ret
|
return found_legacy_addr, found_p2sh_segwit_addr, found_bech32_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_ret
|
||||||
|
|
||||||
|
|
||||||
class WalletDumpTest(BitcoinTestFramework):
|
class WalletDumpTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
self.num_nodes = 1
|
self.num_nodes = 1
|
||||||
self.extra_args = [["-keypool=90", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"]]
|
self.extra_args = [["-keypool=90", "-addresstype=legacy"]]
|
||||||
self.rpc_timeout = 120
|
self.rpc_timeout = 120
|
||||||
|
|
||||||
def skip_test_if_missing_module(self):
|
def skip_test_if_missing_module(self):
|
||||||
|
@ -102,34 +102,38 @@ class WalletDumpTest(BitcoinTestFramework):
|
||||||
wallet_unenc_dump = os.path.join(self.nodes[0].datadir, "wallet.unencrypted.dump")
|
wallet_unenc_dump = os.path.join(self.nodes[0].datadir, "wallet.unencrypted.dump")
|
||||||
wallet_enc_dump = os.path.join(self.nodes[0].datadir, "wallet.encrypted.dump")
|
wallet_enc_dump = os.path.join(self.nodes[0].datadir, "wallet.encrypted.dump")
|
||||||
|
|
||||||
# generate 20 addresses to compare against the dump
|
# generate 30 addresses to compare against the dump
|
||||||
# but since we add a p2sh-p2wpkh address for the first pubkey in the
|
# - 10 legacy P2PKH
|
||||||
# wallet, we will expect 21 addresses in the dump
|
# - 10 P2SH-segwit
|
||||||
test_addr_count = 20
|
# - 10 bech32
|
||||||
|
test_addr_count = 10
|
||||||
addrs = []
|
addrs = []
|
||||||
|
for address_type in ['legacy', 'p2sh-segwit', 'bech32']:
|
||||||
for i in range(0, test_addr_count):
|
for i in range(0, test_addr_count):
|
||||||
addr = self.nodes[0].getnewaddress()
|
addr = self.nodes[0].getnewaddress(address_type=address_type)
|
||||||
vaddr = self.nodes[0].getaddressinfo(addr) # required to get hd keypath
|
vaddr = self.nodes[0].getaddressinfo(addr) # required to get hd keypath
|
||||||
addrs.append(vaddr)
|
addrs.append(vaddr)
|
||||||
# Should be a no-op:
|
|
||||||
self.nodes[0].keypoolrefill()
|
|
||||||
|
|
||||||
# Test scripts dump by adding a P2SH witness and a 1-of-1 multisig address
|
# Test scripts dump by adding a 1-of-1 multisig address
|
||||||
witness_addr = self.nodes[0].addwitnessaddress(addrs[0]["address"], True)
|
|
||||||
multisig_addr = self.nodes[0].addmultisigaddress(1, [addrs[1]["address"]])["address"]
|
multisig_addr = self.nodes[0].addmultisigaddress(1, [addrs[1]["address"]])["address"]
|
||||||
script_addrs = [witness_addr, multisig_addr]
|
|
||||||
|
# Refill the keypool. getnewaddress() refills the keypool *before* taking a key from
|
||||||
|
# the keypool, so the final call to getnewaddress leaves the keypool with one key below
|
||||||
|
# its capacity
|
||||||
|
self.nodes[0].keypoolrefill()
|
||||||
|
|
||||||
# dump unencrypted wallet
|
# dump unencrypted wallet
|
||||||
result = self.nodes[0].dumpwallet(wallet_unenc_dump)
|
result = self.nodes[0].dumpwallet(wallet_unenc_dump)
|
||||||
assert_equal(result['filename'], wallet_unenc_dump)
|
assert_equal(result['filename'], wallet_unenc_dump)
|
||||||
|
|
||||||
found_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc, witness_addr_ret = \
|
found_legacy_addr, found_p2sh_segwit_addr, found_bech32_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc = \
|
||||||
read_dump(wallet_unenc_dump, addrs, script_addrs, None)
|
read_dump(wallet_unenc_dump, addrs, [multisig_addr], None)
|
||||||
assert_equal(found_addr, test_addr_count) # all keys must be in the dump
|
assert_equal(found_legacy_addr, test_addr_count) # all keys must be in the dump
|
||||||
assert_equal(found_script_addr, 2) # all scripts must be in the dump
|
assert_equal(found_p2sh_segwit_addr, test_addr_count) # all keys must be in the dump
|
||||||
|
assert_equal(found_bech32_addr, test_addr_count) # all keys must be in the dump
|
||||||
|
assert_equal(found_script_addr, 1) # all scripts must be in the dump
|
||||||
assert_equal(found_addr_chg, 0) # 0 blocks where mined
|
assert_equal(found_addr_chg, 0) # 0 blocks where mined
|
||||||
assert_equal(found_addr_rsv, 90 * 2) # 90 keys plus 100% internal keys
|
assert_equal(found_addr_rsv, 90 * 2) # 90 keys plus 100% internal keys
|
||||||
assert_equal(witness_addr_ret, witness_addr) # p2sh-p2wsh address added to the first key
|
|
||||||
|
|
||||||
# encrypt wallet, restart, unlock and dump
|
# encrypt wallet, restart, unlock and dump
|
||||||
self.nodes[0].encryptwallet('test')
|
self.nodes[0].encryptwallet('test')
|
||||||
|
@ -138,13 +142,14 @@ class WalletDumpTest(BitcoinTestFramework):
|
||||||
self.nodes[0].keypoolrefill()
|
self.nodes[0].keypoolrefill()
|
||||||
self.nodes[0].dumpwallet(wallet_enc_dump)
|
self.nodes[0].dumpwallet(wallet_enc_dump)
|
||||||
|
|
||||||
found_addr, found_script_addr, found_addr_chg, found_addr_rsv, _, witness_addr_ret = \
|
found_legacy_addr, found_p2sh_segwit_addr, found_bech32_addr, found_script_addr, found_addr_chg, found_addr_rsv, _ = \
|
||||||
read_dump(wallet_enc_dump, addrs, script_addrs, hd_master_addr_unenc)
|
read_dump(wallet_enc_dump, addrs, [multisig_addr], hd_master_addr_unenc)
|
||||||
assert_equal(found_addr, test_addr_count)
|
assert_equal(found_legacy_addr, test_addr_count) # all keys must be in the dump
|
||||||
assert_equal(found_script_addr, 2)
|
assert_equal(found_p2sh_segwit_addr, test_addr_count) # all keys must be in the dump
|
||||||
|
assert_equal(found_bech32_addr, test_addr_count) # all keys must be in the dump
|
||||||
|
assert_equal(found_script_addr, 1)
|
||||||
assert_equal(found_addr_chg, 90 * 2) # old reserve keys are marked as change now
|
assert_equal(found_addr_chg, 90 * 2) # old reserve keys are marked as change now
|
||||||
assert_equal(found_addr_rsv, 90 * 2)
|
assert_equal(found_addr_rsv, 90 * 2)
|
||||||
assert_equal(witness_addr_ret, witness_addr)
|
|
||||||
|
|
||||||
# Overwriting should fail
|
# Overwriting should fail
|
||||||
assert_raises_rpc_error(-8, "already exists", lambda: self.nodes[0].dumpwallet(wallet_enc_dump))
|
assert_raises_rpc_error(-8, "already exists", lambda: self.nodes[0].dumpwallet(wallet_enc_dump))
|
||||||
|
@ -155,13 +160,13 @@ class WalletDumpTest(BitcoinTestFramework):
|
||||||
|
|
||||||
# Make sure the address is not IsMine before import
|
# Make sure the address is not IsMine before import
|
||||||
result = self.nodes[0].getaddressinfo(multisig_addr)
|
result = self.nodes[0].getaddressinfo(multisig_addr)
|
||||||
assert(result['ismine'] == False)
|
assert not result['ismine']
|
||||||
|
|
||||||
self.nodes[0].importwallet(wallet_unenc_dump)
|
self.nodes[0].importwallet(wallet_unenc_dump)
|
||||||
|
|
||||||
# Now check IsMine is true
|
# Now check IsMine is true
|
||||||
result = self.nodes[0].getaddressinfo(multisig_addr)
|
result = self.nodes[0].getaddressinfo(multisig_addr)
|
||||||
assert(result['ismine'] == True)
|
assert result['ismine']
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
WalletDumpTest().main()
|
WalletDumpTest().main()
|
||||||
|
|
Loading…
Reference in a new issue