def scenario(wallets, **kw): testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) # derive importer keys and do imports # NOTE: breaks consensus trace from 0.14.0 private_keychain = keychain.PrivateKeychain.from_private_key( wallets[1].privkey) private_keys = [ wallets[1].privkey ] # NOTE: always start with the reveal key, then use children for i in xrange(0, 3): import_key = private_keychain.child(i).private_key() print "fund {} (child {})".format(import_key, i) res = testlib.send_funds( wallets[1].privkey, 100000000, virtualchain.BitcoinPrivateKey(import_key).public_key().address()) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) return False testlib.next_block(**kw) private_keys.append(import_key) resp = testlib.ysi_name_import( "foo.test", addr_reencode("1BKufFedDrueBBFBXtiATB2PSdsBGZxf3N"), "11" * 20, wallets[1].privkey) # master if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_name_import( "foo.test", addr_reencode("1ARVjrtKnUVWt2GNrpuFLnNCL2WGUhKdkW"), "33" * 20, private_keys[2]) # derived child 2 if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_name_import( "foo.test", addr_reencode("1PYu4vKB3g2QLDFdurxqYSJ9aJSed7tne1"), "22" * 20, private_keys[1]) # derived child 1 if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) testlib.ysi_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw)
def scenario( wallets, **kw ): global import_block_1, import_block_2 # make a test namespace resp = testlib.ysi_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 10, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.ysi_name_import( "foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) import_block_1 = testlib.get_current_block( **kw ) testlib.next_block( **kw ) resp = testlib.ysi_name_import( "foo.test", wallets[4].addr, "22" * 20, wallets[1].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) import_block_2 = testlib.get_current_block( **kw ) testlib.next_block( **kw ) resp = testlib.ysi_namespace_ready( "test", wallets[1].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) # wait for expiration (with multipler)... for i in xrange(0, 10 * NAMESPACE_LIFETIME_MULTIPLIER): testlib.next_block( **kw ) # re-register testlib.ysi_name_preorder( "foo.test", wallets[7].privkey, wallets[8].addr ) testlib.next_block( **kw ) testlib.ysi_name_register( "foo.test", wallets[7].privkey, wallets[8].addr ) testlib.next_block( **kw )
def scenario(wallets, **kw): # make a test namespace resp = testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_name_import("foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_namespace_ready("test", wallets[1].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # revoke it resp = testlib.ysi_name_revoke("foo.test", wallets[3].privkey) testlib.next_block(**kw)
def scenario( wallets, **kw ): testlib.ysi_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 2, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey, version_bits=2) testlib.next_block( **kw ) resp = testlib.ysi_name_import( "foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) return False testlib.next_block( **kw ) testlib.ysi_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) # expire it for i in xrange(0, 4): testlib.next_block(**kw) whois = testlib.ysi_cli_whois('foo.test') if 'error' not in whois: print whois return False namespace_rec = testlib.ysi_cli_get_namespace_blockchain_record("test") if 'error' in namespace_rec: print namespace_rec return False namespace_balance = testlib.get_balance(namespace_rec['address']) res = testlib.ysi_name_preorder( "foo.test", wallets[2].privkey, wallets[4].addr ) if 'error' in res: print res return False testlib.next_block( **kw ) res = testlib.ysi_name_register( "foo.test", wallets[2].privkey, wallets[4].addr, zonefile_hash='22' * 20 ) if 'error' in res: print res return False testlib.next_block( **kw ) new_namespace_balance = testlib.get_balance(namespace_rec['address']) name_rec = testlib.get_name_blockchain_record('foo.test') name_cost = name_rec['op_fee'] if new_namespace_balance - namespace_balance != name_cost: print 'address {} did not get credited'.format(namespace_rec['address']) print '{} != {} + {}'.format(new_namespace_balance, namespace_balance, name_cost) return False if name_rec['value_hash'] != '22' * 20: print 'wrong value hash' return False
def scenario( wallets, **kw ): global update_block # make a test namespace resp = testlib.ysi_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 6, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.ysi_name_import( "foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.ysi_namespace_ready( "test", wallets[1].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) # wait for a bit... for i in xrange(0, 6): testlib.next_block( **kw ) resp = testlib.ysi_name_renew( "foo.test", wallets[3].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) # update resp = testlib.ysi_name_update( "foo.test", "22" * 20, wallets[3].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) update_block = testlib.get_current_block( **kw ) # expire for i in xrange(0, 6 * NAMESPACE_LIFETIME_MULTIPLIER): testlib.next_block( **kw ) # re-register testlib.ysi_name_preorder( "foo.test", wallets[7].privkey, wallets[8].addr ) testlib.next_block( **kw ) testlib.ysi_name_register( "foo.test", wallets[7].privkey, wallets[8].addr ) testlib.next_block( **kw )
def scenario(wallets, **kw): # make a test namespace resp = testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_name_import("foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_namespace_ready("test", wallets[1].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_name_update("foo.test", "22" * 20, wallets[3].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_name_transfer("foo.test", wallets[4].addr, True, wallets[3].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # wait for a bit... for i in xrange(0, 10): testlib.next_block(**kw) resp = testlib.ysi_name_renew("foo.test", wallets[4].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) testlib.next_block(**kw)
def scenario( wallets, **kw ): resp = testlib.ysi_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block( **kw ) # reveal it testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) # import some names testlib.ysi_name_import( "foo.test", wallets[2].addr, "11" * 20, wallets[1].privkey ) testlib.ysi_name_import( "bar.test", wallets[3].addr, "22" * 20, wallets[1].privkey ) testlib.ysi_name_import( "baz.test", wallets[4].addr, "33" * 20, wallets[1].privkey ) testlib.next_block( **kw ) # expire it (1 day later) for i in xrange(0, 145): testlib.next_block( **kw ) # try to ready it (should fail) resp = testlib.ysi_namespace_ready( "test", wallets[1].privkey ) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block( **kw ) testlib.expect_snv_fail_at("test", testlib.get_current_block(**kw)) testlib.next_block( **kw )
def scenario(wallets, **kw): testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) resp = testlib.ysi_name_import("foo.test", wallets[2].addr, "11" * 20, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_name_import("foo.test", wallets[3].addr, "22" * 20, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_name_import("foo.test", wallets[4].addr, "44" * 20, wallets[1].privkey) resp = testlib.ysi_name_import("foo.test", wallets[4].addr, "55" * 20, wallets[1].privkey) resp = testlib.ysi_name_import("foo.test", wallets[4].addr, "33" * 20, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) testlib.ysi_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw)
def scenario(wallets, **kw): print '\nactivating segwit\n' virtualchain.set_features("segwit", True) print '\nsegwit state: {}\n'.format(virtualchain.get_features('segwit')) # make a test namespace resp = testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_name_import("foo.test", wallets[9].addr, "11" * 20, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_namespace_ready("test", wallets[1].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_name_update("foo.test", "22" * 20, wallets[9].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_name_transfer("foo.test", wallets[10].addr, True, wallets[9].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw)
def scenario(wallets, **kw): global first_name_block # make a test namespace resp = testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_name_import("foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) first_name_block = testlib.get_current_block(**kw) resp = testlib.ysi_namespace_ready("test", wallets[1].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # wait for a bit... for i in xrange(0, 10): testlib.next_block(**kw) # renew; expect different fee resp = testlib.ysi_name_renew("foo.test", wallets[3].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) testlib.next_block(**kw)
def scenario( wallets, **kw ): testlib.ysi_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 2, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey, version_bits=2) testlib.next_block( **kw ) resp = testlib.ysi_name_import( "foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) return False testlib.ysi_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) namespace_rec = testlib.ysi_cli_get_namespace_blockchain_record("test") if 'error' in namespace_rec: print namespace_rec return False namespace_balance = testlib.get_balance(namespace_rec['address']) testlib.ysi_name_renew("foo.test", wallets[3].privkey) testlib.next_block(**kw) new_namespace_balance = testlib.get_balance(namespace_rec['address']) name_rec = testlib.get_name_blockchain_record('foo.test') name_cost = name_rec['op_fee'] if new_namespace_balance - namespace_balance != name_cost: print 'address {} did not get credited'.format(namespace_rec['address']) print '{} != {} + {}'.format(new_namespace_balance, namespace_balance, name_cost) return False testlib.ysi_name_renew("foo.test", wallets[3].privkey, recipient_addr=wallets[4].addr, zonefile_hash='22' * 20) testlib.next_block(**kw) new_namespace_balance = testlib.get_balance(namespace_rec['address']) name_rec = testlib.get_name_blockchain_record('foo.test') name_cost = name_rec['op_fee'] if new_namespace_balance - namespace_balance != 2*name_cost: print 'address {} did not get credited'.format(namespace_rec['address']) print '{} != {} + {}'.format(new_namespace_balance, namespace_balance, 2*name_cost) return False
def scenario( wallets, **kw ): testlib.ysi_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.ysi_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) # can't import once ready resp = testlib.ysi_name_import( "foo.test", wallets[1].addr, "11" * 20, wallets[0].privkey, safety_checks=False ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) testlib.expect_snv_fail("foo.test" )
def scenario( wallets, **kw ): global last_consensus, snv_block_id # make a test namespace resp = testlib.ysi_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.ysi_name_import( "foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) snv_block_id = testlib.get_current_block() resp = testlib.ysi_namespace_ready( "test", wallets[1].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.ysi_name_transfer( "foo.test", wallets[4].addr, True, wallets[3].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.ysi_name_update( "foo.test", "22" * 20, wallets[4].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) last_consensus = testlib.get_consensus_at( testlib.get_current_block() )
def scenario(wallets, **kw): testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.ysi_name_import("foo.test", wallets[2].addr, "11" * 20, wallets[1].privkey) testlib.ysi_name_import("bar.test", wallets[3].addr, "22" * 20, wallets[1].privkey) testlib.ysi_name_import("baz.test", wallets[4].addr, "33" * 20, wallets[1].privkey) testlib.ysi_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw)
def scenario( wallets, **kw ): testlib.ysi_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) resp = testlib.ysi_name_import( "foo.test", wallets[2].addr, "11" * 20, wallets[1].privkey ) if 'error' in resp: print json.dumps(resp, indent=4 ) return False testlib.next_block( **kw ) print "\nImport 25 names for %s" % wallets[3].addr # try to exceed quota (currently 25): order 25, and try to register a 26th for i in xrange(0, 25): resp = testlib.ysi_name_import( "foo%s.test" % i, wallets[3].addr, "22" * 20, wallets[1].privkey ) if 'error' in resp: print json.dumps(resp, indent=4 ) return False if i % 2 == 1: testlib.next_block( **kw ) testlib.next_block( **kw ) print "\nImport 26 names for %s" % wallets[4].addr # try to exceed quota (currently 25): order 26, and try to update one of them (and try to transfer one too). for i in xrange(0, 26): resp = testlib.ysi_name_import( "bar%s.test" % i, wallets[4].addr, "33" * 20, wallets[1].privkey, safety_checks=False ) if 'error' in resp: print json.dumps(resp, indent=4 ) return False if i % 2 == 1: testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.ysi_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) print wallets[3].privkey resp = testlib.ysi_name_preorder( "foofail.test", wallets[3].privkey, wallets[1].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) # should fail resp = testlib.ysi_name_register( "foofail.test",wallets[3].privkey, wallets[1].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) testlib.expect_snv_fail_at( "foofail.test", testlib.get_current_block(**kw)) # should succeed resp = testlib.ysi_name_update( "foo0.test", '55' * 20, wallets[3].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.ysi_name_preorder( "barfail.test", wallets[4].privkey, wallets[2].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) # should fail (exceeded quota) resp = testlib.ysi_name_register( "barfail.test", wallets[4].privkey, wallets[2].addr, safety_checks=False ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) testlib.expect_snv_fail_at( "barfail.test", testlib.get_current_block(**kw)) # should fail (exceeded quota--have to revoke or give names away) resp = testlib.ysi_name_update( "bar0.test", '44' * 20, wallets[4].privkey, safety_checks=False ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) testlib.expect_snv_fail_at( "bar0.test", testlib.get_current_block(**kw)) # should succeed (give a name away) resp = testlib.ysi_name_transfer( "bar0.test", wallets[1].addr, True, wallets[4].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) # should fail (exceeded quota--have to revoke or give names away) resp = testlib.ysi_name_update( "bar0.test", '44' * 20, wallets[4].privkey, safety_checks=False ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) testlib.expect_snv_fail_at( "bar0.test", testlib.get_current_block(**kw)) # should succeed (revoke a name) resp = testlib.ysi_name_revoke( "bar2.test", wallets[4].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) # should succeed (now under quota) resp = testlib.ysi_name_update( "bar1.test", '66' * 20, wallets[4].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) testlib.expect_snv_fail( "foofail.test" ) testlib.expect_snv_fail( "barfail.test" )
def scenario( wallets, **kw ): testlib.ysi_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) # will all be rejected trivially, since the first import must come from the importer's address testlib.ysi_name_import( "foo.test", wallets[4].addr, "11" * 20, wallets[2].privkey, safety_checks=False ) testlib.ysi_name_import( "bar.test", wallets[2].addr, "22" * 20, wallets[3].privkey, safety_checks=False ) testlib.ysi_name_import( "baz.test", wallets[3].addr, "33" * 20, wallets[4].privkey, safety_checks=False) testlib.next_block( **kw ) # will be accepted testlib.ysi_name_import( "goo.test", wallets[2].addr, "11" * 20, wallets[1].privkey ) # will all be rejected because they weren't sent from a importer-derived key testlib.ysi_name_import( "foo.test", wallets[4].addr, "11" * 20, wallets[2].privkey, safety_checks=False ) testlib.ysi_name_import( "bar.test", wallets[2].addr, "22" * 20, wallets[3].privkey, safety_checks=False ) testlib.ysi_name_import( "baz.test", wallets[3].addr, "33" * 20, wallets[4].privkey, safety_checks=False ) testlib.next_block( **kw ) testlib.ysi_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.expect_snv_fail( "foo.test" ) testlib.expect_snv_fail( "bar.test" ) testlib.expect_snv_fail( "baz.test" )
def scenario(wallets, **kw): global debug resp = testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_name_import("foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_namespace_ready("test", wallets[1].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # ping-ping a bit... 3 --> 4 --> 5 --> 4 --> 5 --> 4 resp = testlib.ysi_name_transfer("foo.test", wallets[4].addr, True, wallets[3].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_transfer("foo.test", wallets[5].addr, True, wallets[4].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_transfer("foo.test", wallets[4].addr, True, wallets[5].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_transfer("foo.test", wallets[5].addr, True, wallets[4].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_transfer("foo.test", wallets[4].addr, True, wallets[5].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # update (4) resp = testlib.ysi_name_update("foo.test", "11" * 20, wallets[4].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) # ping-ping a bit... 4 --> 5 --> 4 --> 5 --> 4 --> 5 resp = testlib.ysi_name_transfer("foo.test", wallets[5].addr, True, wallets[4].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_transfer("foo.test", wallets[4].addr, True, wallets[5].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_transfer("foo.test", wallets[5].addr, True, wallets[4].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_transfer("foo.test", wallets[4].addr, True, wallets[5].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_transfer("foo.test", wallets[5].addr, True, wallets[4].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) # now update (5) resp = testlib.ysi_name_update("foo.test", "22" * 20, wallets[5].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # update transfer resp = testlib.ysi_name_transfer("foo.test", wallets[4].addr, True, wallets[5].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_update("foo.test", "33" * 20, wallets[4].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # update --> transfer --> transfer --> update resp = testlib.ysi_name_update("foo.test", "44" * 20, wallets[4].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_transfer("foo.test", wallets[5].addr, True, wallets[4].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_transfer("foo.test", wallets[4].addr, True, wallets[5].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_update("foo.test", "55" * 20, wallets[4].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # update --> transfer --> update --> transfer resp = testlib.ysi_name_update("foo.test", "66" * 20, wallets[4].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_transfer("foo.test", wallets[5].addr, True, wallets[4].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_update("foo.test", "11" * 20, wallets[5].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # transfer resp = testlib.ysi_name_transfer("foo.test", wallets[4].addr, True, wallets[5].privkey, safety_checks=False) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw)
def scenario(wallets, **kw): testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey, version_bits=2) testlib.next_block(**kw) resp = testlib.ysi_name_import("foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) testlib.ysi_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) namespace_rec = testlib.ysi_cli_get_namespace_blockchain_record("test") if 'error' in namespace_rec: print namespace_rec return False namespace_balance = testlib.get_balance(namespace_rec['address']) burn_balance = testlib.get_balance( ysi_client.constants.BLOCKSTACK_BURN_ADDRESS) # should send to namespace burn address res = testlib.ysi_name_renew('foo.test', wallets[3].privkey) if 'error' in res: print res return False testlib.next_block(**kw) # should send to namespace burn address res = testlib.ysi_name_renew('foo.test', wallets[3].privkey) if 'error' in res: print res return False testlib.next_block(**kw) new_namespace_balance = testlib.get_balance(namespace_rec['address']) name_rec = testlib.get_name_blockchain_record('foo.test') name_cost = name_rec['op_fee'] if new_namespace_balance - namespace_balance != 2 * name_cost: print 'address {} did not get credited'.format( namespace_rec['address']) print '{} != {} + {}'.format(new_namespace_balance, namespace_balance, name_cost) return False # should be rejected if not burned res = testlib.ysi_name_renew('foo.test', wallets[3].privkey, burn_addr=namespace_rec['address']) if 'error' not in res: print res return False res = testlib.ysi_name_renew('foo.test', wallets[3].privkey, burn_addr=namespace_rec['address'], safety_checks=False, tx_fee=10000 * 5) if 'error' in res: print res return False testlib.next_block(**kw) # should have been rejected name_rec_2 = testlib.get_name_blockchain_record('foo.test') if name_rec_2['last_renewed'] != name_rec['last_renewed']: print 'accidentally renewed' return False # renew, but correctly (with proper burn address) res = testlib.ysi_name_renew('foo.test', wallets[3].privkey) if 'error' in res: print res return False testlib.next_block(**kw) name_rec_2 = testlib.get_name_blockchain_record('foo.test') if name_rec_2['last_renewed'] <= name_rec['last_renewed']: print 'did not renew' return False # must have burned new_burn_balance = testlib.get_balance( ysi_client.constants.BLOCKSTACK_BURN_ADDRESS) if new_burn_balance - name_cost != burn_balance: print 'did not burn fee' print '{} != {} + {}'.format(new_burn_balance, burn_balance, name_cost) return False
def scenario(wallets, **kw): global first_name_block # make a test namespace resp = testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # end of 689 resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 2, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # 690 resp = testlib.ysi_name_import("foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # 691 first_name_block = testlib.get_current_block(**kw) resp = testlib.ysi_namespace_ready("test", wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # end of 692 (epoch 3 should be active) whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print 'failed to whois foo.test' print json.dumps(whois, indent=4) return False # epoch 3 should be active... if whois['expire_block'] != testlib.get_current_block(**kw) + 4: print 'wrong expire block (should be 4 away)' print whois return False resp = testlib.ysi_name_renew('foo.test', wallets[3].privkey, zonefile_hash='22' * 20, recipient_addr=wallets[2].addr) if 'error' in resp: print resp return False testlib.next_block(**kw) # end of 693 (new epoch) whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print whois return False if whois['expire_block'] != testlib.get_current_block(**kw) + 4: print 'expire block: {}'.format(whois['expire_block']) print 'current block + 4: {}'.format( testlib.get_current_block(**kw) + 4) return False if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 9: print 'renewal deadline: {}'.format(whois['renewal_deadline']) print 'current block + 9: {}'.format( testlib.get_current_block(**kw) + 9) return False
def scenario( wallets, **kw ): global import_block_1, import_block_2 # make a test namespace resp = testlib.ysi_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 5, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.ysi_name_import( "foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) # for funsies, pass the namespace lifetime for i in xrange(0, 10): testlib.next_block( **kw ) # 269--next epoch import_block_1 = testlib.get_current_block( **kw ) testlib.next_block( **kw ) resp = testlib.ysi_name_import( "foo.test", wallets[4].addr, "22" * 20, wallets[1].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) import_block_2 = testlib.get_current_block( **kw ) testlib.next_block( **kw ) resp = testlib.ysi_namespace_ready( "test", wallets[1].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) # name should definitely not be expired res = testlib.ysi_cli_get_name_blockchain_record( "foo.test" ) if 'error' in res: print "name is expired unexpectedly" print json.dumps(res, indent=4, sort_keys=True) return False # wait for expiration (with multipler)... for i in xrange(0, 5 * ysi.config.get_epoch_namespace_lifetime_multiplier( testlib.get_current_block(**kw), "test" ) ): testlib.next_block( **kw ) # name should definitely be expired res = testlib.ysi_cli_get_name_blockchain_record( "foo.test" ) if 'error' not in res: print json.dumps(res, indent=4, sort_keys=True) return False # re-register (should work) testlib.ysi_name_preorder( "foo.test", wallets[7].privkey, wallets[8].addr ) testlib.next_block( **kw ) testlib.ysi_name_register( "foo.test", wallets[7].privkey, wallets[8].addr ) testlib.next_block( **kw )
def scenario(wallets, **kw): global first_name_block # make a test namespace resp = testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # end of 689 resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 2, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # 690 resp = testlib.ysi_name_import("foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # 691 first_name_block = testlib.get_current_block(**kw) resp = testlib.ysi_namespace_ready("test", wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # end of 692 whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print 'failed to whois foo.test' print json.dumps(whois, indent=4) return False # this should be the second-to-last block if whois['expire_block'] != testlib.get_current_block(**kw) + 2: print 'wrong expire block (expect 2 more)' print whois return False testlib.next_block(**kw) # end of 693; begin epoch 2 # begin epoch 2 testlib.next_block(**kw) # 694 whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print 'failed to whois foo.test' print json.dumps(whois, indent=4) return False # this should be the last block if whois['expire_block'] != testlib.get_current_block(**kw) + 2: print 'wrong expire block (expect 2 more)' print whois return False if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 2: print 'wrong renewal block (expect 2 more)' print whois return False print whois testlib.next_block(**kw) # 695 (epoch 3 begins) testlib.next_block(**kw) # end of 696 whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print whois return False # this should be the expire block if whois['expire_block'] != testlib.get_current_block(**kw): print 'wrong expire block (now at {})'.format( testlib.get_current_block(**kw)) print whois return False # should now be a grace period if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 5: print 'wrong renewal block (now at {})'.format( testlib.get_current_block(**kw)) print whois return False # safety checks should NOT allow the preorder to go through resp = testlib.ysi_name_preorder('foo.test', wallets[3].privkey, wallets[4].addr) if 'error' not in resp: print resp return False # begin epoch 3 (grace period) testlib.next_block(**kw) # end of 697 # safety checks should NOT allow the preorder to go through resp = testlib.ysi_name_preorder('foo.test', wallets[3].privkey, wallets[4].addr) if 'error' not in resp: print resp return False testlib.next_block(**kw) # 698 # safety checks should NOT allow the preorder to go through resp = testlib.ysi_name_preorder('foo.test', wallets[3].privkey, wallets[4].addr) if 'error' not in resp: print resp return False testlib.next_block(**kw) # 699 # safety checks should NOT allow the preorder to go through resp = testlib.ysi_name_preorder('foo.test', wallets[3].privkey, wallets[4].addr) if 'error' not in resp: print resp return False testlib.next_block(**kw) # 700 # safety checks should NOT allow the preorder to go through resp = testlib.ysi_name_preorder('foo.test', wallets[3].privkey, wallets[4].addr) if 'error' not in resp: print resp return False testlib.next_block(**kw) # end of 701 # safety checks SHOULD allow the preorder to go through (will be incorporated into block 702) resp = testlib.ysi_name_preorder('foo.test', wallets[3].privkey, wallets[4].addr) if 'error' in resp: print resp return False testlib.next_block(**kw) # 702 resp = testlib.ysi_name_register("foo.test", wallets[3].privkey, wallets[4].addr, zonefile_hash='33' * 20) if 'error' in resp: print resp return False testlib.next_block(**kw) # 703
def scenario(wallets, **kw): global import_block global failed_blocks # make a test namespace resp = testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 2, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_name_import("foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) import_block = testlib.get_current_block(**kw) resp = testlib.ysi_namespace_ready("test", wallets[1].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # wait for expiration (with multipler)... for i in xrange(0, 2 * NAMESPACE_LIFETIME_MULTIPLIER + 1): testlib.next_block(**kw) # verify that operations fail resp = testlib.ysi_name_update("foo.test", "11" * 20, wallets[3].privkey, safety_checks=False) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) fail_blocks.append(testlib.get_current_block(**kw)) testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw)) # should fail resp = testlib.ysi_name_transfer("foo.test", wallets[4].addr, True, wallets[3].privkey, safety_checks=False) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) fail_blocks.append(testlib.get_current_block(**kw)) testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw)) # should fail resp = testlib.ysi_name_renew("foo.test", wallets[3].privkey, safety_checks=False, tx_fee=10000 * 5) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) fail_blocks.append(testlib.get_current_block(**kw)) testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw)) # should fail resp = testlib.ysi_name_revoke("foo.test", wallets[3].privkey, safety_checks=False) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) fail_blocks.append(testlib.get_current_block(**kw)) testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw))
def scenario( wallets, **kw ): global first_name_block # make a test namespace resp = testlib.ysi_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) return False testlib.next_block( **kw ) # end of 689 resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 2, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) return False testlib.next_block( **kw ) # 690 resp = testlib.ysi_name_import( "foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) return False testlib.next_block( **kw ) # 691 first_name_block = testlib.get_current_block( **kw ) resp = testlib.ysi_namespace_ready( "test", wallets[1].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) return False testlib.next_block( **kw ) # end of 692 # should go through resp = testlib.ysi_name_preorder('foo.test', wallets[1].privkey, wallets[2].addr, safety_checks=False, tx_fee=500*5) if 'error' in resp: print resp return False whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print 'failed to whois foo.test' print json.dumps(whois, indent=4) return False # this should be the second-to-last block if whois['expire_block'] != testlib.get_current_block(**kw) + 2: print 'wrong expire block (expect 2 more)' print whois return False testlib.next_block(**kw) # end of 693; begin epoch 2 # begin epoch 2 # should go through, but be rejected resp = testlib.ysi_name_register("foo.test", wallets[1].privkey, wallets[2].addr, safety_checks=False, tx_fee=500*5) if 'error' in resp: print resp return False whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print 'failed to whois foo.test' print json.dumps(whois, indent=4) return False if whois['owner_address'] != wallets[3].addr: print 'accidentally registered' print json.dumps(whois) return False testlib.next_block(**kw) # 694 testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) # should go through, but be rejected resp = testlib.ysi_name_register("foo.test", wallets[1].privkey, wallets[2].addr, safety_checks=False, tx_fee=500*5) if 'error' in resp: print resp return False whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print 'failed to whois foo.test' print json.dumps(whois, indent=4) return False if whois['owner_address'] != wallets[3].addr: print 'accidentally registered' print json.dumps(whois) return False # this should be the last block if whois['expire_block'] != testlib.get_current_block(**kw) + 2: print 'wrong expire block (expect 2 more)' print whois return False if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 2: print 'wrong renewal block (expect 2 more)' print whois return False print whois testlib.next_block(**kw) # 695 (epoch 3 begins) testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print 'failed to whois foo.test' print json.dumps(whois, indent=4) return False if whois['owner_address'] != wallets[3].addr: print 'accidentally registered' print json.dumps(whois) return False # should go through, but be rejected resp = testlib.ysi_name_register("foo.test", wallets[1].privkey, wallets[2].addr, safety_checks=False, tx_fee=500*5) if 'error' in resp: print resp return False testlib.next_block(**kw) # end of 696 testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print whois return False # this should be the expire block if whois['expire_block'] != testlib.get_current_block(**kw): print 'wrong expire block (now at {})'.format(testlib.get_current_block(**kw)) print whois return False # should now be a grace period if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 5: print 'wrong renewal block (now at {})'.format(testlib.get_current_block(**kw)) print whois return False if whois['owner_address'] != wallets[3].addr: print 'accidentally registered' print json.dumps(whois) return False last_transaction_height = whois['last_transaction_height'] # should go through, but be rejected resp = testlib.ysi_name_register("foo.test", wallets[1].privkey, wallets[2].addr, safety_checks=False, tx_fee=500*5) if 'error' in resp: print resp return False # begin epoch 3 (grace period) testlib.next_block(**kw) # end of 697 testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print whois if whois['owner_address'] != wallets[3].addr: print 'accidentally registered' print json.dumps(whois) return False resp = testlib.ysi_name_register("foo.test", wallets[1].privkey, wallets[2].addr) if 'error' not in resp: print resp return False # should go through, but be rejected resp = testlib.ysi_name_register("foo.test", wallets[1].privkey, wallets[2].addr, safety_checks=False, tx_fee=500*5) if 'error' in resp: print resp return False testlib.next_block(**kw) # 698 testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) # should NOT have gone through whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print whois return False if whois['owner_address'] != wallets[3].addr: print 'accidentally registered' print json.dumps(whois) return False if whois['last_transaction_height'] != last_transaction_height: print 'accidentally registered' return False resp = testlib.ysi_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20) if 'error' not in resp: print resp return False # should go through, but be rejected resp = testlib.ysi_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20, safety_checks=False, tx_fee=500*5) if 'error' in resp: print resp return False testlib.next_block(**kw) # 699 testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print whois return False if whois['owner_address'] != wallets[3].addr: print 'accidentally registered' print json.dumps(whois) return False if whois['last_transaction_height'] != last_transaction_height: print 'accidentally registered' return False resp = testlib.ysi_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20) if 'error' not in resp: print resp return False # should go through, but be rejected resp = testlib.ysi_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20, safety_checks=False, tx_fee=500*5) if 'error' in resp: print resp return False # should go through, and be acccepted resp = testlib.ysi_name_preorder('foo.test', wallets[3].privkey, wallets[0].addr, safety_checks=False, tx_fee=500*5) if 'error' in resp: print resp return False testlib.next_block(**kw) # 700 testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print whois return False if whois['owner_address'] != wallets[3].addr: print 'accidentally registered' print json.dumps(whois) return False if whois['last_transaction_height'] != last_transaction_height: print 'accidentally registered' return False # should fail resp = testlib.ysi_name_register("foo.test", wallets[3].privkey, wallets[0].addr, zonefile_hash='44' * 20) if 'error' not in resp: print resp return False # should go through, but be rejected resp = testlib.ysi_name_register("foo.test", wallets[3].privkey, wallets[0].addr, zonefile_hash='44' * 20, safety_checks=False, tx_fee=500*5) if 'error' in resp: print resp return False testlib.next_block(**kw) # end of 701 (end of grace period) testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) whois = testlib.ysi_cli_whois('foo.test') if 'error' not in whois: print whois return False # should go through, and be rejected (expired preorder) resp = testlib.ysi_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20) if 'error' in resp: print resp return False testlib.next_block(**kw) # 702 (name can be registered again) testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) whois = testlib.ysi_cli_whois('foo.test') if 'error' not in whois: print whois return False # should go through, and be accepted resp = testlib.ysi_name_register("foo.test", wallets[3].privkey, wallets[0].addr, zonefile_hash='33' * 20) if 'error' in resp: print resp return False testlib.next_block(**kw) # 703 whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print whois return False if whois['owner_address'] != wallets[0].addr: print 'accidentally registered foo.test to {}'.format(whois['owner_address']) return False
def scenario(wallets, **kw): # make a test namespace resp = testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # import 3 names in the same block: foo.test, bar.test, baz.test names = ['foo.test', 'bar.test', 'baz.test'] name_preorder_wallets = [wallets[2], wallets[3], wallets[4]] name_register_wallets = [wallets[5], wallets[6], wallets[7]] name_transfer_wallets = [wallets[6], wallets[7], wallets[5]] # derive importer keys and do imports # NOTE: breaks consensus trace from 0.14.0 private_keychain = keychain.PrivateKeychain.from_private_key( wallets[1].privkey) private_keys = [ wallets[1].privkey ] # NOTE: always start with the reveal key, then use children for i in xrange(0, len(names) - 1): import_key = private_keychain.child(i).private_key() print "fund {} (child {})".format(import_key, i) res = testlib.send_funds( wallets[1].privkey, 100000000, virtualchain.BitcoinPrivateKey(import_key).public_key().address()) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) return False testlib.next_block(**kw) private_keys.append(import_key) for i in xrange(0, len(names)): name = names[i] register_wallet = name_register_wallets[i] import_key = private_keys[i] resp = testlib.ysi_name_import(name, register_wallet.addr, str(9 - i) * 40, import_key, safety_checks=False) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # namespace ready... resp = testlib.ysi_namespace_ready("test", wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # update 3 names in the same block for i in xrange(0, len(names)): name = names[i] register_wallet = name_register_wallets[i] resp = testlib.ysi_name_update(name, str(i + 2) * 40, register_wallet.privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # update 3 names in the same block, again for i in xrange(0, len(names)): name = names[i] register_wallet = name_register_wallets[i] resp = testlib.ysi_name_update(name, str(i + 1) * 40, register_wallet.privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # transfer 3 names in the same block for i in xrange(0, len(names)): name = names[i] register_wallet = name_register_wallets[i] transfer_wallet = name_transfer_wallets[i] resp = testlib.ysi_name_transfer(name, transfer_wallet.addr, True, register_wallet.privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # exchange after transfer... tmp = name_register_wallets name_register_wallets = name_transfer_wallets name_transfer_wallets = tmp # revoke 3 names in the same block for i in xrange(0, len(names)): name = names[i] register_wallet = name_register_wallets[i] resp = testlib.ysi_name_revoke(name, register_wallet.privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False # iterate the blocks a few times for i in xrange(0, 5): testlib.next_block(**kw)
def scenario(wallets, **kw): global first_name_block # make a test namespace resp = testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # 689 resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 2, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # 690 resp = testlib.ysi_name_import("foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # 691 first_name_block = testlib.get_current_block(**kw) resp = testlib.ysi_namespace_ready("test", wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # 692 testlib.next_block(**kw) # end of 693 whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print 'failed to whois foo.test' print json.dumps(whois, indent=4) return False # this should be the penultimate block if whois['expire_block'] != testlib.get_current_block(**kw) + 1: print 'wrong expire block (got {}, expected {})'.format( whois['expire_block'], testlib.get_current_block(**kw)) print whois return False resp = testlib.ysi_name_renew('foo.test', wallets[3].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # end of 694 (epoch 2 is now active) testlib.next_block(**kw) # 695 whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print whois return False if whois['expire_block'] != testlib.get_current_block(**kw) + 3: print 'wrong expire block: {} != {} + 3'.format( whois['expire_block'], testlib.get_current_block(**kw)) return False testlib.next_block(**kw) # end of 696 (epoch 3 is now active) whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print whois return False if whois['expire_block'] != testlib.get_current_block(**kw) + 2: print 'wrong expire block: {} != {} + 2'.format( whois['expire_block'], testlib.get_current_block(**kw)) return False testlib.next_block(**kw) # 697 whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print whois return False if whois['expire_block'] != testlib.get_current_block(**kw) + 1: print 'wrong expire block: {} != {} + 1'.format( whois['expire_block'], testlib.get_current_block(**kw)) return False testlib.next_block(**kw) # 698 if whois['expire_block'] != testlib.get_current_block(**kw): print 'wrong expire block: {} != {}'.format( whois['expire_block'], testlib.get_current_block(**kw)) return False testlib.next_block(**kw) # end of 699 (expired now) testlib.next_block(**kw) # 700 testlib.next_block(**kw) # 701 testlib.next_block(**kw) # 702 resp = testlib.ysi_name_renew('foo.test', wallets[3].privkey, zonefile_hash='22' * 20, recipient_addr=wallets[2].addr) if 'error' in resp: print resp return False testlib.next_block(**kw) # 703 whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print whois return False if whois['expire_block'] != testlib.get_current_block(**kw) + 4: print 'expire block: {}'.format(whois['expire_block']) print 'current block + 4: {}'.format( testlib.get_current_block(**kw) + 4) return False if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 9: print 'renewal deadline: {}'.format(whois['renewal_deadline']) print 'current block + 9: {}'.format( testlib.get_current_block(**kw) + 9) return False
def scenario(wallets, **kw): global first_name_block # make a test namespace resp = testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # end of 689 # 4-block lifetime in practice resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 2, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # 690 resp = testlib.ysi_name_import("foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # 691 first_name_block = testlib.get_current_block(**kw) resp = testlib.ysi_namespace_ready("test", wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # end of 692. epoch 2 activates now whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print 'failed to whois foo.test' print json.dumps(whois, indent=4) return False # this should be the second-to-last block if whois['expire_block'] != testlib.get_current_block(**kw) + 2: print 'wrong expire block (now: {})'.format( testlib.get_current_block(**kw)) print whois return False print whois testlib.next_block(**kw) # end of 693 whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print 'failed to whois foo.test' print json.dumps(whois, indent=4) return False # we should have 3 more block to go now. if whois['expire_block'] != testlib.get_current_block(**kw) + 3: print 'wrong expire block (should be 3 blocks away from {})'.format( testlib.get_current_block(**kw)) print whois return False print whois resp = testlib.ysi_name_transfer('foo.test', wallets[4].addr, True, wallets[3].privkey) if 'error' in resp: print resp return False testlib.next_block(**kw) # end of 694, begin epoch 3 whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print 'failed to whois foo.test' print json.dumps(whois, indent=4) return False # we should have 2 more blocks to go now. if whois['expire_block'] != testlib.get_current_block(**kw) + 2: print 'wrong expire block' print whois return False if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 2: print 'wrong renewal deadline' print whois return False print whois testlib.next_block(**kw) # end of 695 whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print 'failed to whois foo.test' print json.dumps(whois, indent=4) return False # we should have 1 more blocks to go now. if whois['expire_block'] != testlib.get_current_block(**kw) + 1: print 'wrong expire block' print whois return False if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 6: print 'wrong renewal deadline' print whois return False print whois testlib.next_block(**kw) # end of 696. Name should be expired # update should be impossible, since we're now in the renewal period resp = testlib.ysi_name_update('foo.test', '66' * 20, wallets[4].privkey) if 'error' not in resp: print resp return False # renew should work resp = testlib.ysi_name_renew('foo.test', wallets[4].privkey, zonefile_hash='22' * 20, recipient_addr=wallets[2].addr) if 'error' in resp: print resp return False testlib.next_block(**kw) # end of 697 whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print whois return False print whois if whois['expire_block'] != testlib.get_current_block(**kw) + 4: print 'expire block: {}'.format(whois['expire_block']) print 'current block + 4: {}'.format( testlib.get_current_block(**kw) + 4) return False if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 9: print 'renewal deadline: {}'.format(whois['renewal_deadline']) print 'current block + 9: {}'.format( testlib.get_current_block(**kw) + 9) return False
def scenario(wallets, **kw): print '\nactivating segwit\n' virtualchain.set_features("segwit", True) print '\nsegwit state: {}\n'.format(virtualchain.get_features('segwit')) testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[5].privkey) testlib.ysi_namespace_preorder("mult", wallets[2].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[5].privkey) testlib.ysi_namespace_reveal( "mult", wallets[2].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey, version_bits=2) testlib.next_block(**kw) private_keychain = keychain.PrivateKeychain.from_private_key( wallets[2].privkey) private_keys = [ wallets[2].privkey ] # NOTE: always start with the reveal key, then use children for i in xrange(0, 4): import_key = private_keychain.child(i).private_key() print "fund {} (child {})".format(import_key, i) res = testlib.send_funds( wallets[1].privkey, 100000000, virtualchain.BitcoinPrivateKey(import_key).public_key().address()) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) return False testlib.next_block(**kw) private_keys.append(import_key) # should succeed resp = testlib.ysi_name_import("foo.mult", wallets[2].addr, '00' * 20, private_keys[0]) if 'error' in resp: print json.dumps(resp, indent=4, sort_keys=True) return False testlib.next_block(**kw) # should succeed resp = testlib.ysi_name_import("bar.mult", wallets[3].addr, "11" * 20, private_keys[1]) if 'error' in resp: print json.dumps(resp, indent=4, sort_keys=True) return False # should succeed resp = testlib.ysi_name_import("baz.mult", wallets[4].addr, "22" * 20, private_keys[2]) if 'error' in resp: print json.dumps(resp, indent=4, sort_keys=True) return False # should succeed resp = testlib.ysi_name_import("goo.mult", wallets[5].addr, "33" * 20, private_keys[3]) if 'error' in resp: print json.dumps(resp, indent=4, sort_keys=True) return False testlib.next_block(**kw) testlib.ysi_namespace_ready("test", wallets[1].privkey) testlib.ysi_namespace_ready("mult", wallets[2].privkey) testlib.next_block(**kw) namespace_balance = testlib.get_balance(wallets[0].addr) # get prices hello_cost = testlib.ysi_get_name_cost('hello.mult') world_cost = testlib.ysi_get_name_cost('world.mult') foo_cost = testlib.ysi_get_name_cost('foo.mult') # register/renew res = testlib.ysi_name_preorder("hello.mult", wallets[1].privkey, wallets[2].addr) if 'error' in res: print res return False res = testlib.ysi_name_preorder('world.mult', wallets[6].privkey, wallets[7].addr, wallet=wallets[7]) if 'error' in res: print res return False res = testlib.ysi_name_renew('foo.mult', wallets[2].privkey) if 'error' in res: print res return False testlib.next_block(**kw) new_namespace_balance = testlib.get_balance(wallets[0].addr) if new_namespace_balance != namespace_balance + hello_cost + world_cost + foo_cost: print 'wrong balance' print new_namespace_balance print namespace_balance print hello_cost print foo_cost return False res = testlib.ysi_name_register("hello.mult", wallets[1].privkey, wallets[2].addr) if 'error' in res: print res return False res = testlib.ysi_name_register('world.mult', wallets[6].privkey, wallets[7].addr, wallet=wallets[7], zonefile_hash='44' * 20) if 'error' in res: print res return False testlib.next_block(**kw)
def scenario(wallets, **kw): # make a test namespace resp = testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # derive importer keys and do imports # NOTE: breaks consensus trace from 0.14.0 private_keychain = keychain.PrivateKeychain.from_private_key( wallets[1].privkey) private_keys = [ wallets[1].privkey ] # NOTE: always start with the reveal key, then use children for i in xrange(0, 3): import_key = private_keychain.child(i).private_key() print "fund {} (child {})".format(import_key, i) res = testlib.send_funds( wallets[1].privkey, 100000000, virtualchain.BitcoinPrivateKey(import_key).public_key().address()) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) return False testlib.next_block(**kw) private_keys.append(import_key) resp = testlib.ysi_name_import("foo.test", wallets[3].addr, "11" * 20, private_keys[0]) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # import twice resp = testlib.ysi_name_import("bar.test", wallets[4].addr, "22" * 20, private_keys[0]) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.ysi_name_import("bar.test", wallets[4].addr, "33" * 20, private_keys[1]) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # import thrice in the same block resp = testlib.ysi_name_import("baz.test", wallets[5].addr, "44" * 20, private_keys[0]) if 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_import("baz.test", wallets[5].addr, "55" * 20, private_keys[1]) if 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_import("baz.test", wallets[5].addr, "66" * 20, private_keys[2]) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # import all three in the same block resp = testlib.ysi_name_import("foo.test", wallets[5].addr, "66" * 20, private_keys[0]) if 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_import("bar.test", wallets[3].addr, "77" * 20, private_keys[1]) if 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_import("baz.test", wallets[4].addr, "88" * 20, private_keys[2]) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # import thrice in the same block, again resp = testlib.ysi_name_import("baz.test", wallets[5].addr, "44" * 20, private_keys[0]) if 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_import("baz.test", wallets[5].addr, "55" * 20, private_keys[1]) if 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_import("baz.test", wallets[5].addr, "66" * 20, private_keys[2]) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # import all three in the same block, again resp = testlib.ysi_name_import("foo.test", wallets[5].addr, "66" * 20, private_keys[0]) if 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_import("bar.test", wallets[3].addr, "77" * 20, private_keys[1]) if 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.ysi_name_import("baz.test", wallets[4].addr, "88" * 20, private_keys[2]) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) testlib.ysi_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw)
def scenario( wallets, **kw ): testlib.ysi_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 3, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey, version_bits=2) testlib.next_block( **kw ) resp = testlib.ysi_name_import( "foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) return False testlib.next_block( **kw ) testlib.ysi_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) namespace_rec = testlib.ysi_cli_get_namespace_blockchain_record("test") if 'error' in namespace_rec: print namespace_rec return False namespace_balance = testlib.get_balance(namespace_rec['address']) burn_balance = testlib.get_balance(ysi_client.constants.BLOCKSTACK_BURN_ADDRESS) testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.next_block( **kw ) # expired res = testlib.ysi_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) if 'error' in res: print res return False testlib.next_block( **kw ) res = testlib.ysi_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) if 'error' in res: print res return False testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.next_block( **kw ) # expired res = testlib.ysi_name_preorder( "foo.test", wallets[3].privkey, wallets[4].addr ) if 'error' in res: print res return False testlib.next_block( **kw ) res = testlib.ysi_name_register( "foo.test", wallets[3].privkey, wallets[4].addr ) if 'error' in res: print res return False testlib.next_block( **kw ) testlib.next_block( **kw ) res = testlib.ysi_name_renew("foo.test", wallets[4].privkey) if 'error' in res: print res return False testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.next_block( **kw ) # expired res = testlib.ysi_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) if 'error' in res: print res return False testlib.next_block( **kw ) res = testlib.ysi_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) if 'error' in res: print res return False testlib.next_block( **kw ) new_namespace_balance = testlib.get_balance(namespace_rec['address']) name_rec = testlib.get_name_blockchain_record('foo.test') name_cost = name_rec['op_fee'] testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.next_block( **kw ) # expired if new_namespace_balance - namespace_balance != 4*name_cost: print 'address {} did not get credited'.format(namespace_rec['address']) print '{} != {} + 4*{}'.format(new_namespace_balance, namespace_balance, name_cost) return False # preorder should send to the null burn address now. res = testlib.ysi_name_preorder( "foo2.test", wallets[4].privkey, wallets[0].addr ) if 'error' in res: print res return False # try forcing it to the namespace burn address, to verify that it fails res = testlib.ysi_name_preorder( "foo_fail.test", wallets[4].privkey, wallets[0].addr, burn_addr=namespace_rec['address'] ) if 'error' not in res: print res return False res = testlib.ysi_name_preorder( "foo_fail.test", wallets[4].privkey, wallets[0].addr, burn_addr=namespace_rec['address'], safety_checks=False, tx_fee=10000*5 ) if 'error' in res: print res return False testlib.next_block( **kw ) testlib.expect_snv_fail_at('foo_fail.test', testlib.get_current_block(**kw)) # should be accepted res = testlib.ysi_name_register( "foo2.test", wallets[4].privkey, wallets[0].addr ) if 'error' in res: print res return False # should be rejected res = testlib.ysi_name_register( "foo_fail.test", wallets[4].privkey, wallets[0].addr ) if 'error' in res: print res return False testlib.next_block( **kw ) testlib.expect_snv_fail_at('foo_fail.test', testlib.get_current_block(**kw)) # should have been rejected due to wrong burn address whois = testlib.ysi_cli_whois('foo_fail.test') if 'error' not in whois: print whois return False new_burn_balance = testlib.get_balance(ysi_client.constants.BLOCKSTACK_BURN_ADDRESS) new_namespace_balance = testlib.get_balance(namespace_rec['address']) name_rec_2 = testlib.get_name_blockchain_record('foo2.test') 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: print 'address {} got credited after fee capture period'.format(namespace_rec['address']) print '{} != {} + 4*{}'.format(new_namespace_balance, namespace_balance, name_cost) return False # burn address should have received the fee for the second name if new_burn_balance - name_cost_2 != burn_balance: print 'null burn address did not get credited' print '{} != {} + {}'.format(new_burn_balance, burn_balance, name_cost_2) return False
def scenario(wallets, **kw): global first_name_block test_proxy = testlib.make_proxy() # make a test namespace resp = testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # end of 689 resp = testlib.ysi_namespace_reveal( "test", wallets[1].addr, 2, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # 690 # make a zonefile and a profile driver_urls = ysi_client.storage.make_mutable_data_urls( 'foo.test', use_only=['dht', 'disk']) zonefile = ysi_client.zonefile.make_empty_zonefile('foo.test', wallets[4].pubkey_hex, urls=driver_urls) zonefile_txt = ysi_zones.make_zone_file(zonefile, origin='foo.test', ttl=4200) # make a new keyfile as well user_profile = ysi_client.user.make_empty_user_profile() ''' res = ysi_client.key_file.make_initial_key_file(user_profile, wallets[3].privkey) if 'error' in res: print res return res keyfile_txt = res['key_file'] ''' zonefile_hash = ysi_client.get_zonefile_data_hash(zonefile_txt) resp = testlib.ysi_name_import("foo.test", wallets[3].addr, zonefile_hash, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # 691 # broadcast zonefile res = testlib.ysi_cli_sync_zonefile('foo.test', zonefile_string=zonefile_txt) if 'error' in res: print res return False ''' # upload keyfile res = ysi_client.key_file.key_file_put('foo.test', keyfile_txt) if 'error' in res: print res return False ''' rc = ysi_client.profile.put_profile('foo.test', user_profile, blockchain_id='foo.test', user_data_privkey=wallets[4].privkey, user_zonefile=zonefile, proxy=test_proxy) if not rc: print 'failed to put profile' return False # try lookup res = testlib.ysi_cli_lookup('foo.test') if 'error' in res: print res return False first_name_block = testlib.get_current_block(**kw) resp = testlib.ysi_namespace_ready("test", wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False # try lookup res = testlib.ysi_cli_lookup('foo.test') if 'error' in res: print res return False testlib.next_block(**kw) # end of 692 whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print 'failed to whois foo.test' print json.dumps(whois, indent=4) return False # this should be the second-to-last block if whois['expire_block'] != testlib.get_current_block(**kw) + 2: print 'wrong expire block (expect 2 more)' print whois return False # try lookup res = testlib.ysi_cli_lookup('foo.test') if 'error' in res: print res return False testlib.next_block(**kw) # end of 693; begin epoch 2 # begin epoch 2 # try lookup res = testlib.ysi_cli_lookup('foo.test') if 'error' in res: print res return False testlib.next_block(**kw) # 694 # try lookup res = testlib.ysi_cli_lookup('foo.test') if 'error' in res: print res return False whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print 'failed to whois foo.test' print json.dumps(whois, indent=4) return False # this should be the last block if whois['expire_block'] != testlib.get_current_block(**kw) + 2: print 'wrong expire block (expect 2 more)' print whois return False if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 2: print 'wrong renewal block (expect 2 more)' print whois return False print whois testlib.next_block(**kw) # 695 (epoch 3 begins) # try lookup res = testlib.ysi_cli_lookup('foo.test') if 'error' in res: print res return False testlib.next_block(**kw) # end of 696 # try lookup (should fail) res = testlib.ysi_cli_lookup('foo.test') if 'error' not in res: print res return False if 'expired' not in res['error']: print res return False whois = testlib.ysi_cli_whois('foo.test') if 'error' in whois: print whois return False # this should be the expire block if whois['expire_block'] != testlib.get_current_block(**kw): print 'wrong expire block (now at {})'.format( testlib.get_current_block(**kw)) print whois return False # should now be a grace period if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 5: print 'wrong renewal block (now at {})'.format( testlib.get_current_block(**kw)) print whois return False last_transaction_height = whois['last_transaction_height'] # begin epoch 3 (grace period) testlib.next_block(**kw) # end of 697 # try lookup (should fail) res = testlib.ysi_cli_lookup('foo.test') if 'error' not in res: print res return False if 'expired' not in res['error']: print res return False testlib.next_block(**kw) # 698 # try lookup (should fail) res = testlib.ysi_cli_lookup('foo.test') if 'error' not in res: print res return False if 'expired' not in res['error']: print res return False testlib.next_block(**kw) # 699 # try lookup (should fail) res = testlib.ysi_cli_lookup('foo.test') if 'error' not in res: print res return False if 'expired' not in res['error']: print res return False testlib.next_block(**kw) # 700 # try lookup (should fail) res = testlib.ysi_cli_lookup('foo.test') if 'error' not in res: print res return False if 'expired' not in res['error']: print res return False # make a zonefile and a profile driver_urls = ysi_client.storage.make_mutable_data_urls( 'foo.test', use_only=['dht', 'disk']) new_zonefile = ysi_client.zonefile.make_empty_zonefile( 'foo.test', wallets[4].pubkey_hex, urls=driver_urls) new_zonefile_txt = ysi_zones.make_zone_file(new_zonefile, origin='foo.test', ttl=4200) # make a new keyfile as well new_user_profile = ysi_client.user.make_empty_user_profile() new_user_profile['new_user'] = True ''' res = ysi_client.key_file.make_initial_key_file(new_user_profile, wallets[0].privkey) if 'error' in res: print res return res new_keyfile_txt = res['key_file'] ''' new_zonefile_hash = ysi_client.get_zonefile_data_hash(new_zonefile_txt) rc = ysi_client.profile.put_profile('foo.test', new_user_profile, blockchain_id='foo.test', user_data_privkey=wallets[4].privkey, user_zonefile=new_zonefile, proxy=test_proxy) if not rc: print 'failed to put profile' return False # renew/xfer/update resp = testlib.ysi_name_renew('foo.test', wallets[3].privkey, zonefile_hash=new_zonefile_hash, recipient_addr=wallets[0].addr) if 'error' in resp: print resp return False testlib.next_block(**kw) # end of 701 (end of grace period) # try lookup (should succeed again) res = testlib.ysi_cli_lookup('foo.test') if 'error' in res: print res return False if res['zonefile'] != new_zonefile_txt: print 'wrong zonefile' print new_zonefile_txt print res return False testlib.next_block(**kw) # 702 (name can be registered again)