commit
a1736a9429
@ -0,0 +1,304 @@
|
||||
#!/usr/bin/env python3
|
||||
#encoding=utf-8
|
||||
|
||||
# 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 wallet address book RPC
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
from framework.wallet import Wallet
|
||||
|
||||
class AddressBookTest():
|
||||
def run_test(self):
|
||||
self.create()
|
||||
self.test_address_book()
|
||||
|
||||
def create(self):
|
||||
print('Creating wallet')
|
||||
wallet = Wallet()
|
||||
# close the wallet if any, will throw if none is loaded
|
||||
try: wallet.close_wallet()
|
||||
except: pass
|
||||
seed = 'velvet lymph giddy number token physics poetry unquoted nibs useful sabotage limits benches lifestyle eden nitrogen anvil fewest avoid batch vials washing fences goat unquoted'
|
||||
res = wallet.restore_deterministic_wallet(seed = seed)
|
||||
assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
|
||||
assert res.seed == seed
|
||||
|
||||
def test_address_book(self):
|
||||
print('Testing address book')
|
||||
wallet = Wallet()
|
||||
|
||||
# empty at start
|
||||
res = wallet.get_address_book()
|
||||
assert not 'entries' in res or (res.entries) == 0
|
||||
ok = False
|
||||
try: wallet.get_address_book([0])
|
||||
except: ok = True
|
||||
assert ok
|
||||
ok = False
|
||||
try: wallet.delete_address_book(0)
|
||||
except: ok = True
|
||||
assert ok
|
||||
ok = False
|
||||
try: wallet.edit_address_book(0, description = '')
|
||||
except: ok = True
|
||||
assert ok
|
||||
|
||||
# add one
|
||||
res = wallet.add_address_book('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', description = 'self')
|
||||
assert res.index == 0
|
||||
for get_all in [True, False]:
|
||||
res = wallet.get_address_book() if get_all else wallet.get_address_book([0])
|
||||
assert len(res.entries) == 1
|
||||
e = res.entries[0]
|
||||
assert e.index == 0
|
||||
assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
|
||||
assert e.payment_id == '' or e.payment_id == '0' * 16 or e.payment_id == '0' * 64
|
||||
assert e.description == 'self'
|
||||
|
||||
# add a duplicate
|
||||
res = wallet.add_address_book('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', description = 'self')
|
||||
assert res.index == 1
|
||||
res = wallet.get_address_book()
|
||||
assert len(res.entries) == 2
|
||||
assert res.entries[0].index == 0
|
||||
assert res.entries[1].index == 1
|
||||
assert res.entries[0].address == res.entries[1].address
|
||||
assert res.entries[0].payment_id == res.entries[1].payment_id
|
||||
assert res.entries[0].description == res.entries[1].description
|
||||
e = res.entries[1]
|
||||
res = wallet.get_address_book([1])
|
||||
assert len(res.entries) == 1
|
||||
assert e == res.entries[0]
|
||||
|
||||
# request (partially) out of range
|
||||
ok = False
|
||||
try: res = wallet.get_address_book[4, 2]
|
||||
except: ok = True
|
||||
assert ok
|
||||
ok = False
|
||||
try: res = wallet.get_address_book[0, 2]
|
||||
except: ok = True
|
||||
assert ok
|
||||
ok = False
|
||||
try: res = wallet.get_address_book[2, 0]
|
||||
except: ok = True
|
||||
assert ok
|
||||
|
||||
# delete first
|
||||
res = wallet.delete_address_book(0)
|
||||
res = wallet.get_address_book()
|
||||
assert len(res.entries) == 1
|
||||
assert res.entries[0].index == 0
|
||||
assert res.entries[0].address == e.address
|
||||
assert res.entries[0].payment_id == e.payment_id
|
||||
assert res.entries[0].description == e.description
|
||||
|
||||
# delete (new) first
|
||||
res = wallet.delete_address_book(0)
|
||||
res = wallet.get_address_book()
|
||||
assert not 'entries' in res or (res.entries) == 0
|
||||
|
||||
# add non-addresses
|
||||
errors = 0
|
||||
try: wallet.add_address_book('', description = 'bad')
|
||||
except: errors += 1
|
||||
try: wallet.add_address_book('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm ', description = 'bad')
|
||||
except: errors += 1
|
||||
try: wallet.add_address_book('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDn', description = 'bad')
|
||||
except: errors += 1
|
||||
try: wallet.add_address_book('9ujeXrjzf7bfeK3KZdCqnYaMwZVFuXemPU8Ubw335rj2FN1CdMiWNyFV3ksEfMFvRp9L9qum5UxkP5rN9aLcPxbH1au4WAB', description = 'bad')
|
||||
except: errors += 1
|
||||
try: wallet.add_address_book('donate@example.com', description = 'bad')
|
||||
except: errors += 1
|
||||
assert errors == 5
|
||||
res = wallet.get_address_book()
|
||||
assert not 'entries' in res or len(res.entries) == 0
|
||||
|
||||
# openalias
|
||||
res = wallet.add_address_book('donate@getmonero.org', description = 'dev fund')
|
||||
assert res.index == 0
|
||||
res = wallet.get_address_book()
|
||||
assert len(res.entries) == 1
|
||||
e = res.entries[0]
|
||||
assert e.address == '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A'
|
||||
assert e.description == 'dev fund'
|
||||
|
||||
# UTF-8
|
||||
res = wallet.add_address_book('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', description = u'あまやかす')
|
||||
assert res.index == 1
|
||||
res = wallet.get_address_book([1])
|
||||
assert len(res.entries) == 1
|
||||
assert res.entries[0].description == u'あまやかす'
|
||||
e = res.entries[0]
|
||||
|
||||
# duplicate request
|
||||
res = wallet.get_address_book([1, 1])
|
||||
assert len(res.entries) == 2
|
||||
assert res.entries[0] == e
|
||||
assert res.entries[1] == e
|
||||
|
||||
# payment IDs
|
||||
res = wallet.add_address_book('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', payment_id = '0' * 64)
|
||||
assert res.index == 2
|
||||
ok = False
|
||||
try: res = wallet.add_address_book('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', payment_id = 'x' * 64)
|
||||
except: ok = True
|
||||
assert ok
|
||||
ok = False
|
||||
try: res = wallet.add_address_book('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', payment_id = '0' * 65)
|
||||
except: ok = True
|
||||
assert ok
|
||||
ok = False
|
||||
try: res = wallet.add_address_book('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', payment_id = '0' * 63)
|
||||
except: ok = True
|
||||
assert ok
|
||||
ok = False
|
||||
try: res = wallet.add_address_book('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', payment_id = '0' * 16)
|
||||
except: ok = True
|
||||
assert ok
|
||||
|
||||
# various address types
|
||||
res = wallet.make_integrated_address()
|
||||
integrated_address = res.integrated_address
|
||||
integrated_address_payment_id = res.payment_id
|
||||
ok = False
|
||||
try: res = wallet.add_address_book(integrated_address, payment_id = '0' * 64)
|
||||
except: ok = True
|
||||
assert ok
|
||||
res = wallet.add_address_book(integrated_address)
|
||||
assert res.index == 3
|
||||
res = wallet.add_address_book('87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB')
|
||||
assert res.index == 4
|
||||
|
||||
# get them back
|
||||
res = wallet.get_address_book([0])
|
||||
assert len(res.entries) == 1
|
||||
assert res.entries[0].address == '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A'
|
||||
assert res.entries[0].description == 'dev fund'
|
||||
res = wallet.get_address_book([1])
|
||||
assert len(res.entries) == 1
|
||||
assert res.entries[0].address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
|
||||
assert res.entries[0].description == u'あまやかす'
|
||||
res = wallet.get_address_book([2])
|
||||
assert len(res.entries) == 1
|
||||
assert res.entries[0].address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
|
||||
res = wallet.get_address_book([3])
|
||||
assert len(res.entries) == 1
|
||||
if False: # for now, the address book splits integrated addresses
|
||||
assert res.entries[0].address == integrated_address
|
||||
else:
|
||||
assert res.entries[0].address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
|
||||
assert res.entries[0].payment_id == integrated_address_payment_id + '0' * 48
|
||||
res = wallet.get_address_book([4])
|
||||
assert len(res.entries) == 1
|
||||
assert res.entries[0].address == '87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB'
|
||||
|
||||
# edit
|
||||
res = wallet.get_address_book([1])
|
||||
assert len(res.entries) == 1
|
||||
e = res.entries[0]
|
||||
assert e.index == 1
|
||||
assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
|
||||
assert e.payment_id == '0' * 64
|
||||
assert e.description == u'あまやかす'
|
||||
res = wallet.edit_address_book(1, payment_id = '1' * 64)
|
||||
res = wallet.get_address_book([1])
|
||||
assert len(res.entries) == 1
|
||||
e = res.entries[0]
|
||||
assert e.index == 1
|
||||
assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
|
||||
assert e.payment_id == '1' * 64
|
||||
assert e.description == u'あまやかす'
|
||||
res = wallet.edit_address_book(1, description = '')
|
||||
res = wallet.get_address_book([1])
|
||||
assert len(res.entries) == 1
|
||||
e = res.entries[0]
|
||||
assert e.index == 1
|
||||
assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
|
||||
assert e.payment_id == '1' * 64
|
||||
assert e.description == ''
|
||||
res = wallet.edit_address_book(1, description = 'えんしゅう')
|
||||
res = wallet.get_address_book([1])
|
||||
assert len(res.entries) == 1
|
||||
e = res.entries[0]
|
||||
assert e.index == 1
|
||||
assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
|
||||
assert e.payment_id == '1' * 64
|
||||
assert e.description == u'えんしゅう'
|
||||
res = wallet.edit_address_book(1, address = '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A')
|
||||
res = wallet.get_address_book([1])
|
||||
assert len(res.entries) == 1
|
||||
e = res.entries[0]
|
||||
assert e.index == 1
|
||||
assert e.address == '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A'
|
||||
assert e.payment_id == '1' * 64
|
||||
assert e.description == u'えんしゅう'
|
||||
res = wallet.edit_address_book(1, payment_id = '')
|
||||
res = wallet.get_address_book([1])
|
||||
assert len(res.entries) == 1
|
||||
e = res.entries[0]
|
||||
assert e.index == 1
|
||||
assert e.address == '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A'
|
||||
assert e.payment_id == '0' * 64
|
||||
assert e.description == u'えんしゅう'
|
||||
ok = False
|
||||
try: res = wallet.edit_address_book(1, address = '')
|
||||
except: ok = True
|
||||
assert ok
|
||||
ok = False
|
||||
try: res = wallet.edit_address_book(1, payment_id = 'asdnd')
|
||||
except: ok = True
|
||||
assert ok
|
||||
ok = False
|
||||
try: res = wallet.edit_address_book(1, address = 'address')
|
||||
except: ok = True
|
||||
assert ok
|
||||
res = wallet.edit_address_book(1)
|
||||
res = wallet.get_address_book([1])
|
||||
assert len(res.entries) == 1
|
||||
assert e == res.entries[0]
|
||||
|
||||
# empty
|
||||
wallet.delete_address_book(4)
|
||||
wallet.delete_address_book(0)
|
||||
res = wallet.get_address_book([0]) # entries above the deleted one collapse one slot up
|
||||
assert len(res.entries) == 1
|
||||
assert res.entries[0].address == '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A'
|
||||
assert res.entries[0].description == u'えんしゅう'
|
||||
wallet.delete_address_book(2)
|
||||
wallet.delete_address_book(0)
|
||||
wallet.delete_address_book(0)
|
||||
res = wallet.get_address_book()
|
||||
assert not 'entries' in res or len(res.entries) == 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
AddressBookTest().run_test()
|
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
import re
|
||||
|
||||
USAGE = 'usage: check_untested_methods.py <rootdir>'
|
||||
try:
|
||||
rootdir = sys.argv[1]
|
||||
except:
|
||||
print(USAGE)
|
||||
sys.exit(1)
|
||||
|
||||
sys.path.insert(0, rootdir + '/utils/python-rpc')
|
||||
|
||||
from framework import daemon
|
||||
from framework import wallet
|
||||
|
||||
modules = [
|
||||
{
|
||||
'name': 'daemon',
|
||||
'object': daemon.Daemon(),
|
||||
'path': rootdir + '/src/rpc/core_rpc_server.h',
|
||||
'ignore': []
|
||||
},
|
||||
{
|
||||
'name': 'wallet',
|
||||
'object': wallet.Wallet(),
|
||||
'path': rootdir + '/src/wallet/wallet_rpc_server.h',
|
||||
'ignore': []
|
||||
}
|
||||
]
|
||||
|
||||
error = False
|
||||
for module in modules:
|
||||
for line in open(module['path']).readlines():
|
||||
if 'MAP_URI_AUTO_JON2' in line or 'MAP_JON_RPC' in line:
|
||||
match = re.search('.*\"(.*)\".*', line)
|
||||
name = match.group(1)
|
||||
if name in module['ignore'] or name.endswith('.bin'):
|
||||
continue
|
||||
if 'MAP_URI_AUTO_JON2' in line:
|
||||
if not name.startswith('/'):
|
||||
print('Error: %s does not start with /' % name)
|
||||
error = True
|
||||
name = name[1:]
|
||||
if not hasattr(module['object'], name):
|
||||
print('Error: %s API method %s does not have a matching function' % (module['name'], name))
|
||||
|
||||
sys.exit(1 if error else 0)
|
@ -0,0 +1,234 @@
|
||||
#!/usr/bin/env python3
|
||||
#encoding=utf-8
|
||||
|
||||
# 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 URI RPC
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
try:
|
||||
from urllib import quote as urllib_quote
|
||||
except:
|
||||
from urllib.parse import quote as urllib_quote
|
||||
|
||||
from framework.wallet import Wallet
|
||||
|
||||
class URITest():
|
||||
def run_test(self):
|
||||
self.create()
|
||||
self.test_monero_uri()
|
||||
|
||||
def create(self):
|
||||
print('Creating wallet')
|
||||
wallet = Wallet()
|
||||
# close the wallet if any, will throw if none is loaded
|
||||
try: wallet.close_wallet()
|
||||
except: pass
|
||||
seed = 'velvet lymph giddy number token physics poetry unquoted nibs useful sabotage limits benches lifestyle eden nitrogen anvil fewest avoid batch vials washing fences goat unquoted'
|
||||
res = wallet.restore_deterministic_wallet(seed = seed)
|
||||
assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
|
||||
assert res.seed == seed
|
||||
|
||||
def test_monero_uri(self):
|
||||
print('Testing monero: URI')
|
||||
wallet = Wallet()
|
||||
|
||||
utf8string = [u'えんしゅう', u'あまやかす']
|
||||
quoted_utf8string = [urllib_quote(x.encode('utf8')) for x in utf8string]
|
||||
|
||||
ok = False
|
||||
try: res = wallet.make_uri()
|
||||
except: ok = True
|
||||
assert ok
|
||||
ok = False
|
||||
try: res = wallet.make_uri(address = '')
|
||||
except: ok = True
|
||||
assert ok
|
||||
ok = False
|
||||
try: res = wallet.make_uri(address = 'kjshdkj')
|
||||
except: ok = True
|
||||
assert ok
|
||||
|
||||
for address in [
|
||||
'42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm',
|
||||
'4BxSHvcgTwu25WooY4BVmgdcKwZu5EksVZSZkDd6ooxSVVqQ4ubxXkhLF6hEqtw96i9cf3cVfLw8UWe95bdDKfRQeYtPwLm1Jiw7AKt2LY',
|
||||
'8AsN91rznfkBGTY8psSNkJBg9SZgxxGGRUhGwRptBhgr5XSQ1XzmA9m8QAnoxydecSh5aLJXdrgXwTDMMZ1AuXsN1EX5Mtm'
|
||||
]:
|
||||
res = wallet.make_uri(address = address)
|
||||
assert res.uri == 'monero:' + address
|
||||
res = wallet.parse_uri(res.uri)
|
||||
assert res.uri.address == address
|
||||
assert res.uri.payment_id == ''
|
||||
assert res.uri.amount == 0
|
||||
assert res.uri.tx_description == ''
|
||||
assert res.uri.recipient_name == ''
|
||||
assert not 'unknown_parameters' in res or len(res.unknown_parameters) == 0
|
||||
res = wallet.make_uri(address = address, amount = 11000000000)
|
||||
assert res.uri == 'monero:' + address + '?tx_amount=0.011' or res.uri == 'monero:' + address + '?tx_amount=0.011000000000'
|
||||
res = wallet.parse_uri(res.uri)
|
||||
assert res.uri.address == address
|
||||
assert res.uri.payment_id == ''
|
||||
assert res.uri.amount == 11000000000
|
||||
assert res.uri.tx_description == ''
|
||||
assert res.uri.recipient_name == ''
|
||||
assert not 'unknown_parameters' in res or len(res.unknown_parameters) == 0
|
||||
|
||||
address = '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
|
||||
|
||||
res = wallet.make_uri(address = address, tx_description = utf8string[0])
|
||||
assert res.uri == 'monero:' + address + '?tx_description=' + quoted_utf8string[0]
|
||||
res = wallet.parse_uri(res.uri)
|
||||
assert res.uri.address == address
|
||||
assert res.uri.payment_id == ''
|
||||
assert res.uri.amount == 0
|
||||
assert res.uri.tx_description == utf8string[0]
|
||||
assert res.uri.recipient_name == ''
|
||||
assert not 'unknown_parameters' in res or len(res.unknown_parameters) == 0
|
||||
|
||||
res = wallet.make_uri(address = address, recipient_name = utf8string[0])
|
||||
assert res.uri == 'monero:' + address + '?recipient_name=' + quoted_utf8string[0]
|
||||
res = wallet.parse_uri(res.uri)
|
||||
assert res.uri.address == address
|
||||
assert res.uri.payment_id == ''
|
||||
assert res.uri.amount == 0
|
||||
assert res.uri.tx_description == ''
|
||||
assert res.uri.recipient_name == utf8string[0]
|
||||
assert not 'unknown_parameters' in res or len(res.unknown_parameters) == 0
|
||||
|
||||
res = wallet.make_uri(address = address, recipient_name = utf8string[0], tx_description = utf8string[1])
|
||||
assert res.uri == 'monero:' + address + '?recipient_name=' + quoted_utf8string[0] + '&tx_description=' + quoted_utf8string[1]
|
||||
res = wallet.parse_uri(res.uri)
|
||||
assert res.uri.address == address
|
||||
assert res.uri.payment_id == ''
|
||||
assert res.uri.amount == 0
|
||||
assert res.uri.tx_description == utf8string[1]
|
||||
assert res.uri.recipient_name == utf8string[0]
|
||||
assert not 'unknown_parameters' in res or len(res.unknown_parameters) == 0
|
||||
|
||||
res = wallet.make_uri(address = address, recipient_name = utf8string[0], tx_description = utf8string[1], amount = 1000000000000)
|
||||
assert res.uri == 'monero:' + address + '?tx_amount=1.000000000000&recipient_name=' + quoted_utf8string[0] + '&tx_description=' + quoted_utf8string[1]
|
||||
res = wallet.parse_uri(res.uri)
|
||||
assert res.uri.address == address
|
||||
assert res.uri.payment_id == ''
|
||||
assert res.uri.amount == 1000000000000
|
||||
assert res.uri.tx_description == utf8string[1]
|
||||
assert res.uri.recipient_name == utf8string[0]
|
||||
assert not 'unknown_parameters' in res or len(res.unknown_parameters) == 0
|
||||
|
||||
res = wallet.make_uri(address = address, recipient_name = utf8string[0], tx_description = utf8string[1], amount = 1000000000000, payment_id = '1' * 64)
|
||||
assert res.uri == 'monero:' + address + '?tx_payment_id=' + '1' * 64 + '&tx_amount=1.000000000000&recipient_name=' + quoted_utf8string[0] + '&tx_description=' + quoted_utf8string[1]
|
||||
res = wallet.parse_uri(res.uri)
|
||||
assert res.uri.address == address
|
||||
assert res.uri.payment_id == '1' * 64
|
||||
assert res.uri.amount == 1000000000000
|
||||
assert res.uri.tx_description == utf8string[1]
|
||||
assert res.uri.recipient_name == utf8string[0]
|
||||
assert not 'unknown_parameters' in res or len(res.unknown_parameters) == 0
|
||||
|
||||
# spaces must be encoded as %20
|
||||
res = wallet.make_uri(address = address, tx_description = ' ' + utf8string[1] + ' ' + utf8string[0] + ' ', amount = 1000000000000)
|
||||
assert res.uri == 'monero:' + address + '?tx_amount=1.000000000000&tx_description=%20' + quoted_utf8string[1] + '%20' + quoted_utf8string[0] + '%20'
|
||||
res = wallet.parse_uri(res.uri)
|
||||
assert res.uri.address == address
|
||||
assert res.uri.payment_id == ''
|
||||
assert res.uri.amount == 1000000000000
|
||||
assert res.uri.tx_description == ' ' + utf8string[1] + ' ' + utf8string[0] + ' '
|
||||
assert res.uri.recipient_name == ''
|
||||
assert not 'unknown_parameters' in res or len(res.unknown_parameters) == 0
|
||||
|
||||
# the example from the docs
|
||||
res = wallet.parse_uri('monero:46BeWrHpwXmHDpDEUmZBWZfoQpdc6HaERCNmx1pEYL2rAcuwufPN9rXHHtyUA4QVy66qeFQkn6sfK8aHYjA3jk3o1Bv16em?tx_amount=239.39014&tx_description=donation')
|
||||
assert res.uri.address == '46BeWrHpwXmHDpDEUmZBWZfoQpdc6HaERCNmx1pEYL2rAcuwufPN9rXHHtyUA4QVy66qeFQkn6sfK8aHYjA3jk3o1Bv16em'
|
||||
assert res.uri.amount == 239390140000000
|
||||
assert res.uri.tx_description == 'donation'
|
||||
assert res.uri.recipient_name == ''
|
||||
assert res.uri.payment_id == ''
|
||||
assert not 'unknown_parameters' in res or len(res.unknown_parameters) == 0
|
||||
|
||||
# malformed/invalid
|
||||
for uri in [
|
||||
'',
|
||||
':',
|
||||
'monero',
|
||||
'notmonero:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm',
|
||||
'MONERO:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm',
|
||||
'MONERO::42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm',
|
||||
'monero:',
|
||||
'monero:badaddress',
|
||||
'monero:tx_amount=10',
|
||||
'monero:?tx_amount=10',
|
||||
'monero:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_amount=-1',
|
||||
'monero:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_amount=1e12',
|
||||
'monero:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_amount=+12',
|
||||
'monero:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_amount=1+2',
|
||||
'monero:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_amount=A',
|
||||
'monero:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_amount=0x2',
|
||||
'monero:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_amount=222222222222222222222',
|
||||
'monero:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDn?tx_amount=10',
|
||||
'monero:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm&',
|
||||
'monero:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm&tx_amount',
|
||||
'monero:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm&tx_amount=',
|
||||
'monero:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm&tx_amount=10=',
|
||||
'monero:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm&tx_amount=10=&',
|
||||
'monero:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm&tx_amount=10=&foo=bar',
|
||||
'monero:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_amount=10&tx_amount=20',
|
||||
'monero:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_payment_id=1111111111111111',
|
||||
'monero:4BxSHvcgTwu25WooY4BVmgdcKwZu5EksVZSZkDd6ooxSVVqQ4ubxXkhLF6hEqtw96i9cf3cVfLw8UWe95bdDKfRQeYtPwLm1Jiw7AKt2LY?tx_payment_id=' + '1' * 64,
|
||||
'monero:9ujeXrjzf7bfeK3KZdCqnYaMwZVFuXemPU8Ubw335rj2FN1CdMiWNyFV3ksEfMFvRp9L9qum5UxkP5rN9aLcPxbH1au4WAB',
|
||||
'monero:5K8mwfjumVseCcQEjNbf59Um6R9NfVUNkHTLhhPCmNvgDLVS88YW5tScnm83rw9mfgYtchtDDTW5jEfMhygi27j1QYphX38hg6m4VMtN29',
|
||||
'monero:7A1Hr63MfgUa8pkWxueD5xBqhQczkusYiCMYMnJGcGmuQxa7aDBxN1G7iCuLCNB3VPeb2TW7U9FdxB27xKkWKfJ8VhUZthF',
|
||||
]:
|
||||
ok = False
|
||||
try: res = wallet.parse_uri(uri)
|
||||
except: ok = True
|
||||
assert ok, res
|
||||
|
||||
# unknown parameters but otherwise valid
|
||||
res = wallet.parse_uri('monero:' + address + '?tx_amount=239.39014&foo=bar')
|
||||
assert res.uri.address == address
|
||||
assert res.uri.amount == 239390140000000
|
||||
assert res.unknown_parameters == ['foo=bar'], res
|
||||
res = wallet.parse_uri('monero:' + address + '?tx_amount=239.39014&foo=bar&baz=quux')
|
||||
assert res.uri.address == address
|
||||
assert res.uri.amount == 239390140000000
|
||||
assert res.unknown_parameters == ['foo=bar', 'baz=quux'], res
|
||||
res = wallet.parse_uri('monero:' + address + '?tx_amount=239.39014&%20=%20')
|
||||
assert res.uri.address == address
|
||||
assert res.uri.amount == 239390140000000
|
||||
assert res.unknown_parameters == ['%20=%20'], res
|
||||
res = wallet.parse_uri('monero:' + address + '?tx_amount=239.39014&unknown=' + quoted_utf8string[0])
|
||||
assert res.uri.address == address
|
||||
assert res.uri.amount == 239390140000000
|
||||
assert res.unknown_parameters == [u'unknown=' + quoted_utf8string[0]], res
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
URITest().run_test()
|
Loading…
Reference in new issue