Skip to content

Commit

Permalink
Merge #563: Some more standard pegout testing
Browse files Browse the repository at this point in the history
30eb323 ensure pak wallet is returning right kind of addresses (Gregory Sanders)
9e56c87 have validateaddress give useful parent chain addr info (Gregory Sanders)
894d76e test all single-key pegout address types (Gregory Sanders)
40a62a1 DestinationEncoder: 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
  • Loading branch information
stevenroose committed Apr 12, 2019
2 parents 8fd8a45 + 30eb323 commit 6c4f6ef
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
2 changes: 0 additions & 2 deletions src/key_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class DestinationEncoder : public boost::static_visitor<std::string>
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);
Expand All @@ -52,7 +51,6 @@ class DestinationEncoder : public boost::static_visitor<std::string>
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);
Expand Down
20 changes: 20 additions & 0 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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\"")
Expand All @@ -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;
}

Expand Down
12 changes: 8 additions & 4 deletions test/functional/feature_fedpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
)
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']
Expand Down Expand Up @@ -153,6 +153,8 @@ def test_pegout(self, parent_chain_addr, sidechain):
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]
Expand Down Expand Up @@ -294,8 +296,10 @@ def run_test(self):
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)
Expand Down
20 changes: 17 additions & 3 deletions test/functional/feature_pak.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ def pak_to_option(pak):
("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)
Expand Down Expand Up @@ -220,6 +219,11 @@ def compare(actual, expected):
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
Expand Down Expand Up @@ -349,12 +353,20 @@ def compare(actual, expected):
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)
Expand Down Expand Up @@ -396,5 +408,7 @@ def compare(actual, expected):
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 ()

0 comments on commit 6c4f6ef

Please sign in to comment.