| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
"""Test basic wallet functionality |
| 33 |
""" |
| 34 |
|
| 35 |
from __future__ import print_function |
| 36 |
import sys |
| 37 |
import util_resources |
| 38 |
|
| 39 |
from framework.wallet import Wallet |
| 40 |
from framework.daemon import Daemon |
| 41 |
|
| 42 |
class WalletTest(): |
| 43 |
def run_test(self): |
| 44 |
self.reset() |
| 45 |
self.create() |
| 46 |
self.check_main_address() |
| 47 |
self.check_keys() |
| 48 |
self.create_subaddresses() |
| 49 |
self.tags() |
| 50 |
self.attributes() |
| 51 |
self.open_close() |
| 52 |
self.languages() |
| 53 |
self.change_password() |
| 54 |
self.store() |
| 55 |
|
| 56 |
def reset(self): |
| 57 |
print('Resetting blockchain') |
| 58 |
daemon = Daemon() |
| 59 |
res = daemon.get_height() |
| 60 |
daemon.pop_blocks(res.height - 1) |
| 61 |
daemon.flush_txpool() |
| 62 |
|
| 63 |
def create(self): |
| 64 |
print('Creating wallet') |
| 65 |
wallet = Wallet() |
| 66 |
|
| 67 |
try: wallet.close_wallet() |
| 68 |
except: pass |
| 69 |
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' |
| 70 |
res = wallet.restore_deterministic_wallet(seed = seed) |
| 71 |
assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' |
| 72 |
assert res.seed == seed |
| 73 |
|
| 74 |
def check_main_address(self): |
| 75 |
print('Getting address') |
| 76 |
wallet = Wallet() |
| 77 |
res = wallet.get_address() |
| 78 |
assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', res |
| 79 |
assert len(res.addresses) == 1 |
| 80 |
assert res.addresses[0].address == res.address |
| 81 |
assert res.addresses[0].address_index == 0 |
| 82 |
assert res.addresses[0].used == False |
| 83 |
|
| 84 |
def check_keys(self): |
| 85 |
print('Checking keys') |
| 86 |
wallet = Wallet() |
| 87 |
res = wallet.query_key('view_key') |
| 88 |
assert res.key == '49774391fa5e8d249fc2c5b45dadef13534bf2483dede880dac88f061e809100' |
| 89 |
res = wallet.query_key('spend_key') |
| 90 |
assert res.key == '148d78d2aba7dbca5cd8f6abcfb0b3c009ffbdbea1ff373d50ed94d78286640e' |
| 91 |
res = wallet.query_key('mnemonic') |
| 92 |
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' |
| 93 |
|
| 94 |
def create_subaddresses(self): |
| 95 |
print('Creating subaddresses') |
| 96 |
wallet = Wallet() |
| 97 |
res = wallet.create_account("idx1") |
| 98 |
assert res.account_index == 1, res |
| 99 |
assert res.address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf', res |
| 100 |
res = wallet.create_account("idx2") |
| 101 |
assert res.account_index == 2, res |
| 102 |
assert res.address == '8Bdb75y2MhvbkvaBnG7vYP6DCNneLWcXqNmfPmyyDkavAUUgrHQEAhTNK3jEq69kGPDrd3i5inPivCwTvvA12eQ4SJk9iyy', res |
| 103 |
|
| 104 |
res = wallet.get_address(0, 0) |
| 105 |
assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', res |
| 106 |
assert len(res.addresses) == 1 |
| 107 |
assert res.addresses[0].address_index == 0, res |
| 108 |
res = wallet.get_address(1, 0) |
| 109 |
assert res.address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf', res |
| 110 |
assert len(res.addresses) == 1 |
| 111 |
assert res.addresses[0].label == 'idx1', res |
| 112 |
assert res.addresses[0].address_index == 0, res |
| 113 |
res = wallet.get_address(2, 0) |
| 114 |
assert res.address == '8Bdb75y2MhvbkvaBnG7vYP6DCNneLWcXqNmfPmyyDkavAUUgrHQEAhTNK3jEq69kGPDrd3i5inPivCwTvvA12eQ4SJk9iyy', res |
| 115 |
assert len(res.addresses) == 1 |
| 116 |
assert res.addresses[0].label == 'idx2', res |
| 117 |
assert res.addresses[0].address_index == 0, res |
| 118 |
|
| 119 |
res = wallet.create_address(0, "sub_0_1") |
| 120 |
res = wallet.create_address(1, "sub_1_1") |
| 121 |
res = wallet.create_address(1, "sub_1_2") |
| 122 |
|
| 123 |
res = wallet.get_address(0, [1]) |
| 124 |
assert len(res.addresses) == 1 |
| 125 |
assert res.addresses[0].address == '84QRUYawRNrU3NN1VpFRndSukeyEb3Xpv8qZjjsoJZnTYpDYceuUTpog13D7qPxpviS7J29bSgSkR11hFFoXWk2yNdsR9WF' |
| 126 |
assert res.addresses[0].label == 'sub_0_1' |
| 127 |
res = wallet.get_address(1, [1]) |
| 128 |
assert len(res.addresses) == 1 |
| 129 |
assert res.addresses[0].address == '87qyoPVaEcWikVBmG1TaP1KumZ3hB3Q5f4wZRjuppNdwYjWzs2RgbLYQgtpdu2YdoTT3EZhiUGaPJQt2FsykeFZbCtaGXU4' |
| 130 |
assert res.addresses[0].label == 'sub_1_1' |
| 131 |
res = wallet.get_address(1, [2]) |
| 132 |
assert len(res.addresses) == 1 |
| 133 |
assert res.addresses[0].address == '87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB' |
| 134 |
assert res.addresses[0].label == 'sub_1_2' |
| 135 |
res = wallet.get_address(1, [0, 1, 2]) |
| 136 |
assert len(res.addresses) == 3 |
| 137 |
assert res.addresses[0].address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf' |
| 138 |
assert res.addresses[0].label == 'idx1' |
| 139 |
assert res.addresses[1].address == '87qyoPVaEcWikVBmG1TaP1KumZ3hB3Q5f4wZRjuppNdwYjWzs2RgbLYQgtpdu2YdoTT3EZhiUGaPJQt2FsykeFZbCtaGXU4' |
| 140 |
assert res.addresses[1].label == 'sub_1_1' |
| 141 |
assert res.addresses[2].address == '87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB' |
| 142 |
assert res.addresses[2].label == 'sub_1_2' |
| 143 |
|
| 144 |
res = wallet.label_address((1, 2), "sub_1_2_new") |
| 145 |
res = wallet.get_address(1, [2]) |
| 146 |
assert len(res.addresses) == 1 |
| 147 |
assert res.addresses[0].address == '87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB' |
| 148 |
assert res.addresses[0].label == 'sub_1_2_new' |
| 149 |
|
| 150 |
res = wallet.label_account(1, "idx1_new") |
| 151 |
res = wallet.get_address(1, [0]) |
| 152 |
assert len(res.addresses) == 1 |
| 153 |
assert res.addresses[0].address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf' |
| 154 |
assert res.addresses[0].label == 'idx1_new' |
| 155 |
|
| 156 |
res = wallet.get_address_index('87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB') |
| 157 |
assert res.index == {'major': 1, 'minor': 2} |
| 158 |
res = wallet.get_address_index('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm') |
| 159 |
assert res.index == {'major': 0, 'minor': 0} |
| 160 |
res = wallet.get_address_index('84QRUYawRNrU3NN1VpFRndSukeyEb3Xpv8qZjjsoJZnTYpDYceuUTpog13D7qPxpviS7J29bSgSkR11hFFoXWk2yNdsR9WF') |
| 161 |
assert res.index == {'major': 0, 'minor': 1} |
| 162 |
res = wallet.get_address_index('82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf') |
| 163 |
assert res.index == {'major': 1, 'minor': 0} |
| 164 |
|
| 165 |
res = wallet.label_account(0, "main") |
| 166 |
|
| 167 |
def tags(self): |
| 168 |
print('Testing tags') |
| 169 |
wallet = Wallet() |
| 170 |
res = wallet.get_account_tags() |
| 171 |
assert not 'account_tags' in res or len(res.account_tags) == 0 |
| 172 |
ok = False |
| 173 |
try: res = wallet.get_accounts('tag') |
| 174 |
except: ok = True |
| 175 |
assert ok or not 'subaddress_accounts' in res or res.subaddress_accounts == 0 |
| 176 |
wallet.tag_accounts('tag0', [1]) |
| 177 |
res = wallet.get_account_tags() |
| 178 |
assert len(res.account_tags) == 1 |
| 179 |
assert res.account_tags[0].tag == 'tag0' |
| 180 |
assert res.account_tags[0].label == '' |
| 181 |
assert res.account_tags[0].accounts == [1] |
| 182 |
res = wallet.get_accounts('tag0') |
| 183 |
assert len(res.subaddress_accounts) == 1 |
| 184 |
assert res.subaddress_accounts[0].account_index == 1 |
| 185 |
assert res.subaddress_accounts[0].base_address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf' |
| 186 |
assert res.subaddress_accounts[0].balance == 0 |
| 187 |
assert res.subaddress_accounts[0].unlocked_balance == 0 |
| 188 |
assert res.subaddress_accounts[0].label == 'idx1_new' |
| 189 |
assert res.subaddress_accounts[0].tag == 'tag0' |
| 190 |
wallet.untag_accounts([0]) |
| 191 |
res = wallet.get_account_tags() |
| 192 |
assert len(res.account_tags) == 1 |
| 193 |
assert res.account_tags[0].tag == 'tag0' |
| 194 |
assert res.account_tags[0].label == '' |
| 195 |
assert res.account_tags[0].accounts == [1] |
| 196 |
wallet.untag_accounts([1]) |
| 197 |
res = wallet.get_account_tags() |
| 198 |
assert not 'account_tags' in res or len(res.account_tags) == 0 |
| 199 |
wallet.tag_accounts('tag0', [0]) |
| 200 |
wallet.tag_accounts('tag1', [1]) |
| 201 |
res = wallet.get_account_tags() |
| 202 |
assert len(res.account_tags) == 2 |
| 203 |
x = [x for x in res.account_tags if x.tag == 'tag0'] |
| 204 |
assert len(x) == 1 |
| 205 |
assert x[0].tag == 'tag0' |
| 206 |
assert x[0].label == '' |
| 207 |
assert x[0].accounts == [0] |
| 208 |
x = [x for x in res.account_tags if x.tag == 'tag1'] |
| 209 |
assert len(x) == 1 |
| 210 |
assert x[0].tag == 'tag1' |
| 211 |
assert x[0].label == '' |
| 212 |
assert x[0].accounts == [1] |
| 213 |
wallet.tag_accounts('tagA', [0, 1]) |
| 214 |
res = wallet.get_account_tags() |
| 215 |
assert len(res.account_tags) == 1 |
| 216 |
assert res.account_tags[0].tag == 'tagA' |
| 217 |
assert res.account_tags[0].label == '' |
| 218 |
assert res.account_tags[0].accounts == [0, 1] |
| 219 |
wallet.tag_accounts('tagB', [1, 0]) |
| 220 |
res = wallet.get_account_tags() |
| 221 |
assert len(res.account_tags) == 1 |
| 222 |
assert res.account_tags[0].tag == 'tagB' |
| 223 |
assert res.account_tags[0].label == '' |
| 224 |
assert res.account_tags[0].accounts == [0, 1] |
| 225 |
wallet.set_account_tag_description('tagB', 'tag B') |
| 226 |
res = wallet.get_account_tags() |
| 227 |
assert len(res.account_tags) == 1 |
| 228 |
assert res.account_tags[0].tag == 'tagB' |
| 229 |
assert res.account_tags[0].label == 'tag B' |
| 230 |
assert res.account_tags[0].accounts == [0, 1] |
| 231 |
res = wallet.get_accounts('tagB') |
| 232 |
assert len(res.subaddress_accounts) == 2 |
| 233 |
subaddress_accounts = [] |
| 234 |
for x in res.subaddress_accounts: |
| 235 |
assert x.balance == 0 |
| 236 |
assert x.unlocked_balance == 0 |
| 237 |
subaddress_accounts.append((x.account_index, x.base_address, x.label)) |
| 238 |
assert sorted(subaddress_accounts) == [(0, '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 'main'), (1, '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf', 'idx1_new')] |
| 239 |
|
| 240 |
def attributes(self): |
| 241 |
print('Testing attributes') |
| 242 |
wallet = Wallet() |
| 243 |
|
| 244 |
ok = False |
| 245 |
try: res = wallet.get_attribute('foo') |
| 246 |
except: ok = True |
| 247 |
assert ok |
| 248 |
res = wallet.set_attribute('foo', 'bar') |
| 249 |
res = wallet.get_attribute('foo') |
| 250 |
assert res.value == 'bar' |
| 251 |
res = wallet.set_attribute('foo', 'いっしゅん') |
| 252 |
res = wallet.get_attribute('foo') |
| 253 |
assert res.value == u'いっしゅん' |
| 254 |
ok = False |
| 255 |
try: res = wallet.get_attribute('いちりゅう') |
| 256 |
except: ok = True |
| 257 |
assert ok |
| 258 |
res = wallet.set_attribute('いちりゅう', 'いっぽう') |
| 259 |
res = wallet.get_attribute('いちりゅう') |
| 260 |
assert res.value == u'いっぽう' |
| 261 |
|
| 262 |
def open_close(self): |
| 263 |
print('Testing open/close') |
| 264 |
wallet = Wallet() |
| 265 |
|
| 266 |
res = wallet.get_address() |
| 267 |
assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' |
| 268 |
|
| 269 |
wallet.close_wallet() |
| 270 |
ok = False |
| 271 |
try: res = wallet.get_address() |
| 272 |
except: ok = True |
| 273 |
assert ok |
| 274 |
|
| 275 |
wallet.restore_deterministic_wallet(seed = 'peeled mixture ionic radar utopia puddle buying illness nuns gadget river spout cavernous bounced paradise drunk looking cottage jump tequila melting went winter adjust spout') |
| 276 |
res = wallet.get_address() |
| 277 |
assert res.address == '44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW' |
| 278 |
|
| 279 |
wallet.close_wallet() |
| 280 |
ok = False |
| 281 |
try: wallet.get_address() |
| 282 |
except: ok = True |
| 283 |
assert ok |
| 284 |
|
| 285 |
wallet.restore_deterministic_wallet(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') |
| 286 |
res = wallet.get_address() |
| 287 |
assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' |
| 288 |
|
| 289 |
def languages(self): |
| 290 |
print('Testing languages') |
| 291 |
wallet = Wallet() |
| 292 |
res = wallet.get_languages() |
| 293 |
assert 'English' in res.languages |
| 294 |
assert 'English' in res.languages_local |
| 295 |
assert 'Dutch' in res.languages |
| 296 |
assert 'Nederlands' in res.languages_local |
| 297 |
assert 'Japanese' in res.languages |
| 298 |
assert u'日本語' in res.languages_local |
| 299 |
try: wallet.close_wallet() |
| 300 |
except: pass |
| 301 |
languages = res.languages |
| 302 |
languages_local = res.languages_local |
| 303 |
for language in languages + languages_local: |
| 304 |
sys.stdout.write('Creating ' + language + ' wallet\n') |
| 305 |
wallet.create_wallet(filename = '', language = language) |
| 306 |
res = wallet.query_key('mnemonic') |
| 307 |
wallet.close_wallet() |
| 308 |
|
| 309 |
def change_password(self): |
| 310 |
print('Testing password change') |
| 311 |
wallet = Wallet() |
| 312 |
|
| 313 |
|
| 314 |
try: wallet.close_wallet() |
| 315 |
except: pass |
| 316 |
|
| 317 |
util_resources.remove_wallet_files('test1') |
| 318 |
|
| 319 |
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' |
| 320 |
res = wallet.restore_deterministic_wallet(seed = seed, filename = 'test1') |
| 321 |
assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' |
| 322 |
assert res.seed == seed |
| 323 |
|
| 324 |
wallet.close_wallet() |
| 325 |
res = wallet.open_wallet('test1', password = '') |
| 326 |
res = wallet.get_address() |
| 327 |
assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' |
| 328 |
|
| 329 |
res = wallet.change_wallet_password(old_password = '', new_password = 'foo') |
| 330 |
wallet.close_wallet() |
| 331 |
|
| 332 |
ok = False |
| 333 |
try: res = wallet.open_wallet('test1', password = '') |
| 334 |
except: ok = True |
| 335 |
assert ok |
| 336 |
|
| 337 |
res = wallet.open_wallet('test1', password = 'foo') |
| 338 |
res = wallet.get_address() |
| 339 |
assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' |
| 340 |
|
| 341 |
wallet.close_wallet() |
| 342 |
|
| 343 |
util_resources.remove_wallet_files('test1') |
| 344 |
|
| 345 |
def store(self): |
| 346 |
print('Testing store') |
| 347 |
wallet = Wallet() |
| 348 |
|
| 349 |
|
| 350 |
try: wallet.close_wallet() |
| 351 |
except: pass |
| 352 |
|
| 353 |
util_resources.remove_wallet_files('test1') |
| 354 |
|
| 355 |
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' |
| 356 |
res = wallet.restore_deterministic_wallet(seed = seed, filename = 'test1') |
| 357 |
assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' |
| 358 |
assert res.seed == seed |
| 359 |
|
| 360 |
util_resources.remove_file('test1') |
| 361 |
assert util_resources.file_exists('test1.keys') |
| 362 |
assert not util_resources.file_exists('test1') |
| 363 |
wallet.store() |
| 364 |
assert util_resources.file_exists('test1.keys') |
| 365 |
assert util_resources.file_exists('test1') |
| 366 |
|
| 367 |
wallet.close_wallet() |
| 368 |
|
| 369 |
wallet.open_wallet(filename = 'test1', password = '') |
| 370 |
wallet.close_wallet() |
| 371 |
|
| 372 |
util_resources.remove_wallet_files('test1') |
| 373 |
|
| 374 |
|
| 375 |
if __name__ == '__main__': |
| 376 |
WalletTest().run_test() |