functional_tests: add wallet address/subaddress RPC tests

This commit is contained in:
moneromooo-monero 2019-03-14 23:41:11 +00:00
parent 8dcd4d3d11
commit 98e280fcb8
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
2 changed files with 259 additions and 0 deletions

View file

@ -118,3 +118,110 @@ class Wallet(object):
'id': '0'
}
return self.rpc.send_json_rpc_request(sweep_all)
def get_address(self, account_index = 0, subaddresses = []):
get_address = {
'method': 'get_address',
'params' : {
'account_index' : account_index,
'address_index': subaddresses
},
'jsonrpc': '2.0',
'id': '0'
}
return self.rpc.send_json_rpc_request(get_address)
def create_account(self, label = ""):
create_account = {
'method': 'create_account',
'params' : {
'label': label
},
'jsonrpc': '2.0',
'id': '0'
}
return self.rpc.send_json_rpc_request(create_account)
def create_address(self, account_index = 0, label = ""):
create_address = {
'method': 'create_address',
'params' : {
'account_index': account_index,
'label': label
},
'jsonrpc': '2.0',
'id': '0'
}
return self.rpc.send_json_rpc_request(create_address)
def label_address(self, subaddress_index, label):
label_address = {
'method': 'label_address',
'params' : {
'index': { 'major': subaddress_index[0], 'minor': subaddress_index[1]},
'label': label
},
'jsonrpc': '2.0',
'id': '0'
}
return self.rpc.send_json_rpc_request(label_address)
def label_account(self, account_index, label):
label_account = {
'method': 'label_account',
'params' : {
'account_index': account_index,
'label': label
},
'jsonrpc': '2.0',
'id': '0'
}
return self.rpc.send_json_rpc_request(label_account)
def get_address_index(self, address):
get_address_index = {
'method': 'get_address_index',
'params' : {
'address': address
},
'jsonrpc': '2.0',
'id': '0'
}
return self.rpc.send_json_rpc_request(get_address_index)
def query_key(self, key_type):
query_key = {
'method': 'query_key',
'params' : {
'key_type': key_type
},
'jsonrpc': '2.0',
'id': '0'
}
return self.rpc.send_json_rpc_request(query_key)
def restore_deterministic_wallet(self, seed = '', seed_offset = '', filename = '', restore_height = 0, password = '', language = ''):
restore_deterministic_wallet = {
'method': 'restore_deterministic_wallet',
'params' : {
'restore_height': restore_height,
'filename': filename,
'seed': seed,
'seed_offset': seed_offset,
'password': password,
'language': language
},
'jsonrpc': '2.0',
'id': '0'
}
return self.rpc.send_json_rpc_request(restore_deterministic_wallet)
def close_wallet(self):
close_wallet = {
'method': 'close_wallet',
'params' : {
},
'jsonrpc': '2.0',
'id': '0'
}
return self.rpc.send_json_rpc_request(close_wallet)

View file

@ -0,0 +1,152 @@
#!/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.
import time
"""Test transaction creation RPC calls
Test the following RPCs:
- [TODO: many tests still need to be written]
"""
from test_framework.wallet import Wallet
class WalletAddressTest():
def run_test(self):
self.create()
self.check_main_address()
self.check_keys()
self.create_subaddresses()
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 check_main_address(self):
print 'Getting address'
wallet = Wallet()
res = wallet.get_address()
assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', res
assert len(res.addresses) == 1
assert res.addresses[0].address == res.address
assert res.addresses[0].address_index == 0
assert res.addresses[0].used == False
def check_keys(self):
print 'Checking keys'
wallet = Wallet()
res = wallet.query_key('view_key')
assert res.key == '49774391fa5e8d249fc2c5b45dadef13534bf2483dede880dac88f061e809100'
res = wallet.query_key('spend_key')
assert res.key == '148d78d2aba7dbca5cd8f6abcfb0b3c009ffbdbea1ff373d50ed94d78286640e'
res = wallet.query_key('mnemonic')
assert res.key == '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'
def create_subaddresses(self):
print 'Creating subaddresses'
wallet = Wallet()
res = wallet.create_account("idx1")
assert res.account_index == 1, res
assert res.address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf', res
res = wallet.create_account("idx2")
assert res.account_index == 2, res
assert res.address == '8Bdb75y2MhvbkvaBnG7vYP6DCNneLWcXqNmfPmyyDkavAUUgrHQEAhTNK3jEq69kGPDrd3i5inPivCwTvvA12eQ4SJk9iyy', res
res = wallet.get_address(0, 0)
assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', res
assert len(res.addresses) == 1
assert res.addresses[0].address_index == 0, res
res = wallet.get_address(1, 0)
assert res.address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf', res
assert len(res.addresses) == 1
assert res.addresses[0].label == 'idx1', res
assert res.addresses[0].address_index == 0, res
res = wallet.get_address(2, 0)
assert res.address == '8Bdb75y2MhvbkvaBnG7vYP6DCNneLWcXqNmfPmyyDkavAUUgrHQEAhTNK3jEq69kGPDrd3i5inPivCwTvvA12eQ4SJk9iyy', res
assert len(res.addresses) == 1
assert res.addresses[0].label == 'idx2', res
assert res.addresses[0].address_index == 0, res
res = wallet.create_address(0, "sub_0_1")
res = wallet.create_address(1, "sub_1_1")
res = wallet.create_address(1, "sub_1_2")
res = wallet.get_address(0, [1])
assert len(res.addresses) == 1
assert res.addresses[0].address == '84QRUYawRNrU3NN1VpFRndSukeyEb3Xpv8qZjjsoJZnTYpDYceuUTpog13D7qPxpviS7J29bSgSkR11hFFoXWk2yNdsR9WF'
assert res.addresses[0].label == 'sub_0_1'
res = wallet.get_address(1, [1])
assert len(res.addresses) == 1
assert res.addresses[0].address == '87qyoPVaEcWikVBmG1TaP1KumZ3hB3Q5f4wZRjuppNdwYjWzs2RgbLYQgtpdu2YdoTT3EZhiUGaPJQt2FsykeFZbCtaGXU4'
assert res.addresses[0].label == 'sub_1_1'
res = wallet.get_address(1, [2])
assert len(res.addresses) == 1
assert res.addresses[0].address == '87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB'
assert res.addresses[0].label == 'sub_1_2'
res = wallet.get_address(1, [0, 1, 2])
assert len(res.addresses) == 3
assert res.addresses[0].address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf'
assert res.addresses[0].label == 'idx1'
assert res.addresses[1].address == '87qyoPVaEcWikVBmG1TaP1KumZ3hB3Q5f4wZRjuppNdwYjWzs2RgbLYQgtpdu2YdoTT3EZhiUGaPJQt2FsykeFZbCtaGXU4'
assert res.addresses[1].label == 'sub_1_1'
assert res.addresses[2].address == '87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB'
assert res.addresses[2].label == 'sub_1_2'
res = wallet.label_address((1, 2), "sub_1_2_new")
res = wallet.get_address(1, [2])
assert len(res.addresses) == 1
assert res.addresses[0].address == '87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB'
assert res.addresses[0].label == 'sub_1_2_new'
res = wallet.label_account(1, "idx1_new")
res = wallet.get_address(1, [0])
assert len(res.addresses) == 1
assert res.addresses[0].address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf'
assert res.addresses[0].label == 'idx1_new'
res = wallet.get_address_index('87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB')
assert res.index == {'major': 1, 'minor': 2}
res = wallet.get_address_index('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm')
assert res.index == {'major': 0, 'minor': 0}
res = wallet.get_address_index('84QRUYawRNrU3NN1VpFRndSukeyEb3Xpv8qZjjsoJZnTYpDYceuUTpog13D7qPxpviS7J29bSgSkR11hFFoXWk2yNdsR9WF')
assert res.index == {'major': 0, 'minor': 1}
res = wallet.get_address_index('82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf')
assert res.index == {'major': 1, 'minor': 0}
if __name__ == '__main__':
WalletAddressTest().run_test()