townforge/tests/functional_tests/validate_address.py
2020-05-29 23:20:49 +00:00

92 lines
4.5 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright (c) 2019 The Monero Project
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Test address validation RPC calls
"""
from __future__ import print_function
from framework.wallet import Wallet
class AddressValidationTest():
def run_test(self):
self.create()
self.check_bad_addresses()
self.check_good_addresses()
self.check_openalias_addresses()
def create(self):
print('Creating wallet')
seed = 'teardrop owls later width skater gadget different pegs yard ahead onslaught dynamite thorn espionage dwelt rural eels aimless shipped toaster shocking rounded maverick mystery thorn'
address = 'TF1MMEY5v2dN49XKNCKCdBqmTMM6GdZZA5UBbDgTewaUd3c2jDazN5yKrG1BBHX3UyPqKD9hrh3DpPTDmWiCmsuRpePT1MTaPxm'
self.wallet = Wallet()
# close the wallet if any, will throw if none is loaded
try: self.wallet.close_wallet()
except: pass
res = self.wallet.restore_deterministic_wallet(seed = seed)
assert res.address == address
assert res.seed == seed
def check_bad_addresses(self):
print('Validating bad addresses')
bad_addresses = ['', 'a', 'TF1MMEY5v2dN49XKNCKCdBqmTMM6GdZZA5UBbDgTewaUd3c2jDazN5yKrG1BBHX3UyPqKD9hrh3DpPTDmWiCmsuRpePT1MTaPx9', ' ', '@', 'TF1MME']
for address in bad_addresses:
res = self.wallet.validate_address(address, any_net_type = False)
assert not res.valid
res = self.wallet.validate_address(address, any_net_type = True)
assert not res.valid
def check_good_addresses(self):
print('Validating good addresses')
addresses = [
[ 'mainnet', '', 'TF1MMEY5v2dN49XKNCKCdBqmTMM6GdZZA5UBbDgTewaUd3c2jDazN5yKrG1BBHX3UyPqKD9hrh3DpPTDmWiCmsuRpePT1MTaPxm' ],
#[ 'testnet', '', '9ujeXrjzf7bfeK3KZdCqnYaMwZVFuXemPU8Ubw335rj2FN1CdMiWNyFV3ksEfMFvRp9L9qum5UxkP5rN9aLcPxbH1au4WAB' ],
#[ 'stagenet', '', '53teqCAESLxeJ1REzGMAat1ZeHvuajvDiXqboEocPaDRRmqWoVPzy46GLo866qRFjbNhfkNckyhST3WEvBviDwpUDd7DSzB' ],
[ 'mainnet', 's', 'TF2MMFPZA4h7z4MFGWsXXS6YSt67ZAjQxFWhQecUjAXWGKtT3z4yh12HxLMBinKw2Ng99DDvMncWF7xjS8qM43mdWPiWDaDkZ2m' ],
#[ 'testnet', 's', 'BdKg9udkvckC5T58a8Nmtb6BNsgRAxs7uA2D49sWNNX5HPW5Us6Wxu8QMXrnSx3xPBQQ2iu9kwEcRGAoiz6EPmcZKbF62GS' ],
#[ 'stagenet', 's', '73LhUiix4DVFMcKhsPRG51QmCsv8dYYbL6GcQoLwEEFvPvkVvc7BhebfA4pnEFF9Lq66hwvLqBvpHjTcqvpJMHmmNjPPBqa' ],
]
for any_net_type in [True, False]:
for address in addresses:
res = self.wallet.validate_address(address[2], any_net_type = any_net_type)
if any_net_type or address[0] == 'mainnet':
assert res.valid
assert res.subaddress == (address[1] == 's')
assert res.nettype == address[0]
assert res.openalias_address == ''
else:
assert not res.valid
def check_openalias_addresses(self):
pass
if __name__ == '__main__':
AddressValidationTest().run_test()