fix bugs in tests

This commit is contained in:
Jude Nelson
2018-05-01 10:44:47 -04:00
parent f8b66f576d
commit aebac2db8d
8 changed files with 48 additions and 29 deletions

View File

@@ -183,7 +183,7 @@ def scenario( wallets, **kw ):
name_cost_2 = name_rec_2['op_fee']
# namespace should NOT have gotten the fee for foo_fail. It should only have gotten it for foo.test
if new_namespace_balance - namespace_balance != 4*name_cost + 3*5500:
if new_namespace_balance - namespace_balance != 4*name_cost + 11250:
print 'address {} got credited after fee capture period'.format(namespace_rec['address'])
print '{} != {} + 4*{}'.format(new_namespace_balance, namespace_balance, name_cost)
return False

View File

@@ -134,7 +134,7 @@ def scenario( wallets, **kw ):
name_cost_2 = name_rec_2['op_fee']
# namespace should NOT have gotten the fee for foo_fail. It should only have gotten it for foo.test
if new_namespace_balance - namespace_balance != name_cost + 5500:
if new_namespace_balance - namespace_balance != name_cost + 250:
print 'address {} got credited after fee capture period'.format(namespace_rec['address'])
print '{} != {} + {}'.format(new_namespace_balance, namespace_balance, name_cost)
return False

View File

@@ -66,7 +66,14 @@ def scenario( wallets, **kw ):
testlib.next_block( **kw )
testlib.expect_snv_fail_at('foo26.test', testlib.get_current_block(**kw))
# safety checks should prohibit this
resp = testlib.blockstack_name_preorder( "bar.test", wallets[2].privkey, wallets[3].addr )
if 'error' not in resp:
print 'safety check failure on preorder'
print json.dumps( resp, indent=4 )
return False
resp = testlib.blockstack_name_preorder( "bar.test", wallets[2].privkey, wallets[3].addr, safety_checks=False)
if 'error' in resp:
print json.dumps( resp, indent=4 )
return False
@@ -74,13 +81,10 @@ def scenario( wallets, **kw ):
testlib.next_block( **kw )
# safety checks should prohibit this
# TODO: they don't
'''
resp = testlib.blockstack_name_register( "bar.test", wallets[2].privkey, wallets[3].addr)
if 'error' not in resp:
print 'safety check failure'
return False
'''
# should fail
resp = testlib.blockstack_name_register( "bar.test", wallets[2].privkey, wallets[3].addr, safety_checks=False )

View File

@@ -227,12 +227,12 @@ def scenario( wallets, **kw ):
did_rec = res
old_rec = name_recs[name]
if old_rec['revoked'] and 'error' not in did_rec:
print 'revoked did is sitll valid: {}'.format(dids[i])
if old_rec.get('revoked') and 'error' not in did_rec:
print 'revoked did is still valid: {}'.format(dids[i])
print did_rec
return False
elif not name_rec_equal(did_rec, old_rec):
elif not name_rec_equal(did_rec, old_rec) and 'error' not in did_rec and 'error' not in old_rec:
print 'old record mismatch'
print json.dumps(did_rec, sort_keys=True)
print json.dumps(old_rec, sort_keys=True)

View File

@@ -232,7 +232,7 @@ def scenario( wallets, **kw ):
did_rec = res
old_rec = name_recs[name]
if old_rec['revoked'] and 'error' not in did_rec:
if old_rec.get('revoked') and 'error' not in did_rec:
print 'revoked did is sitll valid: {}'.format(dids[i])
print did_rec
return False

View File

@@ -55,59 +55,59 @@ def scenario( wallets, **kw ):
preorder_block = testlib.get_current_block( **kw ) + 1
testlib.next_block(**kw)
resp = testlib.blockstack_cli_namespace_reveal('test', "abcd", wallets[1].privkey, 52595, 250, 4, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 10)
resp = testlib.blockstack_cli_namespace_reveal('test', "abcd", wallets[1].privkey, 52595, 250, 4, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 10, expect_fail=True)
if 'error' not in resp:
print json.dumps(resp, indent=4, sort_keys=True)
return False
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, "abcd", 52595, 250, 4, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 10)
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, "abcd", 52595, 250, 4, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 10, expect_fail=True)
if 'error' not in resp:
print json.dumps(resp, indent=4, sort_keys=True)
return False
# NOTE: there's nothing bad we can put for lifetime, since < 0 or > 2**32-1 will be "infinite"
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, 256, 4, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 10)
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, 256, 4, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 10, expect_fail=True)
if 'error' not in resp:
print json.dumps(resp, indent=4, sort_keys=True)
return False
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, -1, 4, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 10)
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, -1, 4, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 10, expect_fail=True)
if 'error' not in resp:
print json.dumps(resp, indent=4, sort_keys=True)
return False
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, 250, -1, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 10)
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, 250, -1, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 10, expect_fail=True)
if 'error' not in resp:
print json.dumps(resp, indent=4, sort_keys=True)
return False
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, 250, 4, '16,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 10)
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, 250, 4, '16,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 10, expect_fail=True)
if 'error' not in resp:
print json.dumps(resp, indent=4, sort_keys=True)
return False
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, 250, 4, '-1,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 10)
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, 250, 4, '-1,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 10, expect_fail=True)
if 'error' not in resp:
print json.dumps(resp, indent=4, sort_keys=True)
return False
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, 250, 4, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 0, 10)
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, 250, 4, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 0, 10, expect_fail=True)
if 'error' not in resp:
print json.dumps(resp, indent=4, sort_keys=True)
return False
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, 250, 4, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 16, 10)
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, 250, 4, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 16, 10, expect_fail=True)
if 'error' not in resp:
print json.dumps(resp, indent=4, sort_keys=True)
return False
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, 250, 4, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 0)
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, 250, 4, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 0, expect_fail=True)
if 'error' not in resp:
print json.dumps(resp, indent=4, sort_keys=True)
return False
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, 250, 4, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 16)
resp = testlib.blockstack_cli_namespace_reveal('test', wallets[0].privkey, wallets[1].privkey, 52595, 250, 4, '6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0', 10, 16, expect_fail=True)
if 'error' not in resp:
print json.dumps(resp, indent=4, sort_keys=True)
return False

View File

@@ -826,15 +826,23 @@ def blockstack_namespace_preorder( namespace_id, register_addr, privatekey, cons
return resp
def blockstack_namespace_reveal( namespace_id, register_addr, lifetime, coeff, base, bucket_exponents, nonalpha_discount, no_vowel_discount, privatekey, version_bits=1, safety_checks=True, tx_only=False, config_path=None, use_cli=True):
def blockstack_namespace_reveal( namespace_id, register_addr, lifetime, coeff, base, bucket_exponents, nonalpha_discount, no_vowel_discount, privatekey, version_bits=1, safety_checks=True, tx_only=False, config_path=None, use_cli=True, expect_fail=False):
global api_call_history
resp = None
register_addr = virtualchain.address_reencode(register_addr)
if use_cli and has_nodejs_cli() and virtualchain.is_singlesig(privatekey):
txid = nodejs_cli('namespace_reveal', namespace_id, register_addr, '{}'.format(version_bits), '{}'.format(lifetime), '{}'.format(coeff), '{}'.format(base),
','.join(['{}'.format(bucket) for bucket in bucket_exponents]), '{}'.format(nonalpha_discount), '{}'.format(no_vowel_discount), privatekey, safety_checks=safety_checks, pattern='^[0-9a-f]{64}$', tx_only=tx_only)
txid = {}
try:
txid = nodejs_cli('namespace_reveal', namespace_id, register_addr, '{}'.format(version_bits), '{}'.format(lifetime), '{}'.format(coeff), '{}'.format(base),
','.join(['{}'.format(bucket) for bucket in bucket_exponents]), '{}'.format(nonalpha_discount), '{}'.format(no_vowel_discount), privatekey, safety_checks=safety_checks, pattern='^[0-9a-f]{64}$', tx_only=tx_only)
except:
if expect_fail:
txid = {'error': 'command failed'}
else:
raise
if 'error' in txid:
return txid
@@ -976,16 +984,23 @@ def blockstack_cli_namespace_preorder( namespace_id, payment_privkey, reveal_pri
return blockstack_namespace_preorder(namespace_id, virtualchain.get_privkey_address(reveal_privkey), payment_privkey, use_cli=use_cli)
def blockstack_cli_namespace_reveal( namespace_id, payment_privkey, reveal_privkey, lifetime, coeff, base, buckets, nonalpha_disc, no_vowel_disc, preorder_txid=None, config_path=None, version_bits=None, expect_fail=False):
def blockstack_cli_namespace_reveal( namespace_id, payment_privkey, reveal_privkey, lifetime, coeff, base, buckets, nonalpha_disc, no_vowel_disc, preorder_txid=None, config_path=None, version_bits=1, expect_fail=False):
"""
reveal a namespace
"""
use_cli = True
if not virtualchain.is_singlesig(payment_privkey) or not virtualchain.is_singlesig(reveal_privkey):
use_cli = False
try:
use_cli = True
if not virtualchain.is_singlesig(payment_privkey) or not virtualchain.is_singlesig(reveal_privkey):
use_cli = False
buckets = [int(x) for x in buckets.split(',')]
return blockstack_namespace_reveal(namespace_id, virtualchain.get_privkey_address(reveal_privkey), lifetime, coeff, base, buckets, nonalpha_disc, no_vowel_disc, payment_privkey, version_bits=version_bits, use_cli=use_cli, expect_fail=expect_fail)
buckets = [int(x) for x in buckets.split(',')]
return blockstack_namespace_reveal(namespace_id, virtualchain.address_reencode(virtualchain.get_privkey_address(reveal_privkey)),
lifetime, coeff, base, buckets, nonalpha_disc, no_vowel_disc, payment_privkey, version_bits=version_bits, use_cli=use_cli, expect_fail=expect_fail)
except:
if expect_fail:
return {'error': 'failed to call into CLI to reveal namespace'}
else:
raise
def blockstack_cli_namespace_ready( namespace_id, reveal_privkey, config_path=None ):