mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-16 13:01:19 +02:00
Merge #563: Some more standard pegout testing
30eb323e9ensure pak wallet is returning right kind of addresses (Gregory Sanders)9e56c87echave validateaddress give useful parent chain addr info (Gregory Sanders)894d76e7ctest all single-key pegout address types (Gregory Sanders)40a62a151DestinationEncoder: don't assert when a parent destination is unblinded (Gregory Sanders) Pull request description: Added more utility to `validateaddress` for parent addresses by returning an additional object `parent_address_info`, then used it to enhance various tests. Tree-SHA512: 941ef1dc8b7469c3274a50907ea788fe520398809d5c4ac901ef057dfa688f63b45f0be298de14c07c250015d02de8f2f4687e430da121fba759e3879823947f
This commit is contained in:
commit
6c4f6efb64
4 changed files with 45 additions and 9 deletions
|
|
@ -33,7 +33,6 @@ public:
|
|||
std::string operator()(const PKHash& id) const
|
||||
{
|
||||
if (id.blinding_pubkey.IsFullyValid()) {
|
||||
assert(!for_parent);
|
||||
std::vector<unsigned char> data = m_params.Base58Prefix(CChainParams::BLINDED_ADDRESS);
|
||||
// Blinded addresses have the actual address type prefix inside the payload.
|
||||
std::vector<unsigned char> prefix = m_params.Base58Prefix(CChainParams::PUBKEY_ADDRESS);
|
||||
|
|
@ -52,7 +51,6 @@ public:
|
|||
std::string operator()(const ScriptHash& id) const
|
||||
{
|
||||
if (id.blinding_pubkey.IsFullyValid()) {
|
||||
assert(!for_parent);
|
||||
std::vector<unsigned char> data = m_params.Base58Prefix(CChainParams::BLINDED_ADDRESS);
|
||||
// Blinded addresses have the actual address type prefix inside the payload.
|
||||
std::vector<unsigned char> prefix = m_params.Base58Prefix(CChainParams::SCRIPT_ADDRESS);
|
||||
|
|
|
|||
|
|
@ -56,6 +56,12 @@ static UniValue validateaddress(const JSONRPCRequest& request)
|
|||
" \"witness_program\" : \"hex\" (string, optional) The hex value of the witness program\n"
|
||||
" \"confidential_key\" : \"hex\", (string) The hex value of the raw blinding public key for that address, if any. \"\" if none.\n"
|
||||
" \"unconfidential\" : \"address\", (string) The address without confidentiality key.\n"
|
||||
" \"parent_address_info\": (obj) If the address isvalid_parent, this object contains details about the parent address type.\n"
|
||||
" {\n"
|
||||
" \"address\" : \"address\",\n"
|
||||
" \"scriptPubKey\" : \"hex\",\n"
|
||||
" ...\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
|
||||
|
|
@ -82,6 +88,20 @@ static UniValue validateaddress(const JSONRPCRequest& request)
|
|||
UniValue blind_detail = DescribeBlindAddress(dest);
|
||||
ret.pushKVs(blind_detail);
|
||||
}
|
||||
if (is_valid_parent) {
|
||||
UniValue parent_info(UniValue::VOBJ);
|
||||
std::string currentAddress = EncodeParentDestination(parent_dest);
|
||||
parent_info.pushKV("address", currentAddress);
|
||||
|
||||
CScript scriptPubKey = GetScriptForDestination(parent_dest);
|
||||
parent_info.pushKV("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end()));
|
||||
|
||||
UniValue detail = DescribeAddress(parent_dest);
|
||||
parent_info.pushKVs(detail);
|
||||
UniValue blind_detail = DescribeBlindAddress(parent_dest);
|
||||
parent_info.pushKVs(blind_detail);
|
||||
ret.pushKV("parent_address_info", parent_info);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ from test_framework.util import (
|
|||
)
|
||||
from decimal import Decimal
|
||||
|
||||
def get_new_unconfidential_address(node):
|
||||
addr = node.getnewaddress()
|
||||
def get_new_unconfidential_address(node, addr_type="p2sh-segwit"):
|
||||
addr = node.getnewaddress("", addr_type)
|
||||
val_addr = node.getaddressinfo(addr)
|
||||
if 'unconfidential' in val_addr:
|
||||
return val_addr['unconfidential']
|
||||
|
|
@ -153,6 +153,8 @@ class FedPegTest(BitcoinTestFramework):
|
|||
pegout_tested = True
|
||||
break
|
||||
assert pegout_tested
|
||||
sidechain.generatetoaddress(1, sidechain.getnewaddress())
|
||||
assert_equal(sidechain.gettransaction(pegout_txid)["confirmations"], 1)
|
||||
|
||||
def run_test(self):
|
||||
parent = self.nodes[0]
|
||||
|
|
@ -294,8 +296,10 @@ class FedPegTest(BitcoinTestFramework):
|
|||
if "confirmations" not in tx or tx["confirmations"] == 0:
|
||||
raise Exception("Peg-in confirmation has failed.")
|
||||
|
||||
print("Test pegout")
|
||||
self.test_pegout(get_new_unconfidential_address(parent), sidechain)
|
||||
print("Test pegouts")
|
||||
self.test_pegout(get_new_unconfidential_address(parent, "legacy"), sidechain)
|
||||
self.test_pegout(get_new_unconfidential_address(parent, "p2sh-segwit"), sidechain)
|
||||
self.test_pegout(get_new_unconfidential_address(parent, "bech32"), sidechain)
|
||||
|
||||
print("Test pegout P2SH")
|
||||
parent_chain_addr = get_new_unconfidential_address(parent)
|
||||
|
|
|
|||
|
|
@ -33,9 +33,8 @@ pak2 = [("03767a74373b7207c5ae1214295197a88ec2abdf92e9e2a29daf024c322fae9fcb", "
|
|||
("02f4a7445f9c48ee8590a930d3fc4f0f5763e3d1d003fdf5fc822e7ba18f380632", "036b3786f029751ada9f02f519a86c7e02fb2963a7013e7e668eb5f7ec069b9e7e")]
|
||||
|
||||
# Args that will be re-used in slightly different ways across runs
|
||||
# TODO remove lol once parent chain hrp default is changed
|
||||
args = [["-acceptnonstdtxn=0", "-initialfreecoins=100000000", "-parent_bech32_hrp=lol"]] \
|
||||
+ [["-acceptnonstdtxn=0", "-enforce_pak=1", "-initialfreecoins=100000000", "-parent_bech32_hrp=lol"]]*4
|
||||
args = [["-acceptnonstdtxn=0", "-initialfreecoins=100000000", "-parent_bech32_hrp=lol", "-pubkeyprefix=112", "-scriptprefix=197"]] \
|
||||
+ [["-acceptnonstdtxn=0", "-enforce_pak=1", "-initialfreecoins=100000000", "-parent_bech32_hrp=lol", "-pubkeyprefix=112", "-scriptprefix=197"]]*4
|
||||
args[i_reject] = args[i_reject] + ['-pak=reject']
|
||||
# Novalidate has pak entry, should not act on it ever
|
||||
args[i_novalidate] = args[i_novalidate] + pak_to_option(pak1)
|
||||
|
|
@ -220,6 +219,11 @@ class PAKTest (BitcoinTestFramework):
|
|||
assert_equal(init_results[i]["liquid_pak_address"], info_results[i]["liquid_pak_address"])
|
||||
assert_equal(info_results[i]["bitcoin_descriptor"], xpub_desc)
|
||||
assert_equal(info_results[i]["bip32_counter"], "0")
|
||||
validata = self.nodes[i].validateaddress(init_results[i]["address_lookahead"][0])
|
||||
assert not validata["isvalid"]
|
||||
assert validata["isvalid_parent"]
|
||||
assert not validata["parent_address_info"]["isscript"]
|
||||
assert not validata["parent_address_info"]["iswitness"]
|
||||
|
||||
# Use custom derivation counter values, check if stored correctly,
|
||||
# address lookahead looks correct and that new liquid_pak was chosen
|
||||
|
|
@ -349,12 +353,20 @@ class PAKTest (BitcoinTestFramework):
|
|||
validata = self.nodes[i_pak1].validateaddress(wpkh_stmc["bitcoin_address"])
|
||||
assert(not validata["isvalid"])
|
||||
assert(validata["isvalid_parent"])
|
||||
assert(not validata["parent_address_info"]["isscript"])
|
||||
assert(validata["parent_address_info"]["iswitness"])
|
||||
assert_equal(wpkh_pak_info["bip32_counter"], wpkh_stmc["bip32_counter"])
|
||||
assert_equal(wpkh_pak_info["bitcoin_descriptor"], wpkh_stmc["bitcoin_descriptor"])
|
||||
|
||||
sh_wpkh_desc = "sh(wpkh("+xpub+"/0/1/*))"
|
||||
sh_wpkh_info = self.nodes[i_pak1].initpegoutwallet(sh_wpkh_desc)
|
||||
|
||||
validata = self.nodes[i_pak1].validateaddress(sh_wpkh_info["address_lookahead"][0])
|
||||
assert(not validata["isvalid"])
|
||||
assert(validata["isvalid_parent"])
|
||||
assert(validata["parent_address_info"]["isscript"])
|
||||
assert(not validata["parent_address_info"]["iswitness"])
|
||||
|
||||
# Add to pak list for pak1, restart
|
||||
self.stop_nodes()
|
||||
extra_args = copy.deepcopy(args)
|
||||
|
|
@ -396,5 +408,7 @@ class PAKTest (BitcoinTestFramework):
|
|||
raise Exception("Found unexpected peg-out output")
|
||||
assert(peg_out_found)
|
||||
|
||||
# TODO: create rawsendtomainchain to do transaction surgery for testing
|
||||
|
||||
if __name__ == '__main__':
|
||||
PAKTest ().main ()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue