You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
2.0 KiB
56 lines
2.0 KiB
#!/usr/bin/env python |
|
from __future__ import print_function |
|
from commontest import DummyBlockchainInterface |
|
import pytest |
|
|
|
from jmclient import (load_program_config, jm_single) |
|
from jmclient.commitment_utils import get_utxo_info, validate_utxo_data |
|
|
|
|
|
def test_get_utxo_info(): |
|
load_program_config() |
|
jm_single().config.set("BLOCKCHAIN", "network", "mainnet") |
|
dbci = DummyBlockchainInterface() |
|
privkey = "L1RrrnXkcKut5DEMwtDthjwRcTTwED36thyL1DebVrKuwvohjMNi" |
|
#to verify use from_wif_privkey and privkey_to_address |
|
iaddr = "1LDsjB43N2NAQ1Vbc2xyHca4iBBciN8iwC" |
|
fakeutxo = "aa"*32+":08" |
|
|
|
fake_query_results = [{'value': 200000000, |
|
'address': iaddr, |
|
'utxo': fakeutxo, |
|
'confirms': 20}] |
|
dbci.insert_fake_query_results(fake_query_results) |
|
jm_single().bc_interface = dbci |
|
u, priv = get_utxo_info(fakeutxo + "," + privkey) |
|
assert u == fakeutxo |
|
assert priv == privkey |
|
#invalid format |
|
with pytest.raises(Exception) as e_info: |
|
u, priv = get_utxo_info(fakeutxo + privkey) |
|
#invalid index |
|
fu2 = "ab"*32 + ":00004" |
|
with pytest.raises(Exception) as e_info: |
|
u, priv = get_utxo_info(fu2 + "," + privkey) |
|
#invalid privkey |
|
p2 = privkey[:-1] + 'j' |
|
with pytest.raises(Exception) as e_info: |
|
u, priv = get_utxo_info(fakeutxo + "," + p2) |
|
|
|
utxodatas = [(fakeutxo, privkey)] |
|
retval = validate_utxo_data(utxodatas, False) |
|
assert retval |
|
#try to retrieve |
|
retval = validate_utxo_data(utxodatas, True) |
|
assert retval[0] == (fakeutxo, 200000000) |
|
fake_query_results[0]['address'] = "fakeaddress" |
|
dbci.insert_fake_query_results(fake_query_results) |
|
#validate should fail for wrong address |
|
retval = validate_utxo_data(utxodatas, False) |
|
assert not retval |
|
#remove fake query result and trigger not found |
|
dbci.fake_query_results = None |
|
dbci.setQUSFail(True) |
|
retval = validate_utxo_data(utxodatas, False) |
|
assert not retval |
|
dbci.setQUSFail(False)
|
|
|