def scenario( wallets, **kw ): global put_result, wallet_keys, datasets, zonefile_hash, dataset_change testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) wallet_keys = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey ) # migrate profile res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return else: zonefile_hash = res['zonefile_hash'] testlib.next_block( **kw ) put_result = blockstack_client.put_mutable( "foo.test", "hello_world_1", datasets[0], proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) testlib.next_block( **kw ) put_result = blockstack_client.put_mutable( "foo.test", "hello_world_2", datasets[1], proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) put_result = blockstack_client.put_mutable( "foo.test", "hello_world_3", datasets[2], proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) # increment version too datasets[0]['buf'] = [] for i in xrange(0, 5): datasets[0]["dataset_change"] = dataset_change datasets[0]['buf'].append(i) put_result = blockstack_client.put_mutable( "foo.test", "hello_world_1", datasets[0], proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) testlib.next_block( **kw )
def scenario( wallets, **kw ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_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.blockstack_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.blockstack_name_import( "foo.test", wallets[4].addr, "44" * 20, wallets[1].privkey ) resp = testlib.blockstack_name_import( "foo.test", wallets[4].addr, "55" * 20, wallets[1].privkey ) resp = testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw )
def scenario( wallets, **kw ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_update( "foo.test", "11" * 20, wallets[3].privkey ) testlib.next_block( **kw ) consensus_hash = testlib.get_consensus_at( testlib.get_current_block( **kw ), **kw ) # lots of blocks later... for i in xrange(0, 50): testlib.next_block( **kw ) # update with stale consensus hash (should fail) print "\n\nsend update with consensus hash %s\n\n" % consensus_hash testlib.blockstack_name_update( "foo.test", "22" * 20, wallets[3].privkey, consensus_hash=consensus_hash ) testlib.next_block( **kw )
def scenario( wallets, **kw ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_update( "foo.test", "11" * 20, wallets[3].privkey ) testlib.next_block( **kw ) # should fail--can't give a name to yourself testlib.blockstack_name_transfer( "foo.test", wallets[4].addr, True, wallets[4].privkey ) testlib.next_block( **kw ) # should fail--can't steal a name testlib.blockstack_name_transfer( "foo.test", wallets[4].addr, True, wallets[0].privkey ) testlib.next_block( **kw )
def scenario( wallets, **kw ): global working_dir testlib.blockstack_namespace_preorder( "id", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "id", 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.blockstack_namespace_ready( "id", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "judecn.id", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "judecn.id", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) resp = testlib.blockstack_announce( "hello world!", wallets[3].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.blockstack_announce( "This should not appear", wallets[4].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) # save... working_dir = testlib.get_working_dir( **kw )
def scenario( wallets, **kw ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) resp = testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) if 'error' in resp: print json.dumps( resp ) testlib.next_block( **kw ) # wait for it to expire (takes a day) for i in xrange(0, 145): testlib.next_block( **kw ) # re-preorder it resp = testlib.blockstack_name_preorder( "foo.test", wallets[3].privkey, wallets[4].addr ) if 'error' in resp: print json.dumps( resp ) testlib.next_block( **kw ) # register it resp = testlib.blockstack_name_register( "foo.test", wallets[3].privkey, wallets[4].addr ) if 'error' in resp: print json.dumps( resp ) testlib.next_block( **kw )
def scenario( wallets, **kw ): global last_first_block, first_preorder testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) # NOTE: names expire in 5 * NAMESPACE_LIFETIME_MULTIPLER blocks testlib.blockstack_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 ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) first_preorder = testlib.get_current_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) for i in xrange(0, 5 * blockstack_server.config.get_epoch_namespace_lifetime_multiplier( testlib.get_current_block(**kw), "test" )): testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) last_first_block = testlib.get_current_block( **kw )
def scenario( wallets, **kw ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # update and transfer back and forth a few times for i in xrange(0, 5): result = testlib.blockstack_name_update( "foo.test", str(i) * 40, wallets[3 + (i%2)].privkey ) update_hashes.append( str(i) * 40 ) testlib.next_block( **kw ) result = testlib.blockstack_name_transfer( "foo.test", wallets[3 + ((i+1)%2)].addr, True, wallets[3 + (i%2)].privkey ) testlib.next_block( **kw )
def scenario( wallets, **kw ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # wait for a bit... for i in xrange(0, 10): testlib.next_block( **kw ) resp = testlib.blockstack_name_renew( "foo.test", wallets[3].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) global snv_consensus, snv_block_id snv_block_id = testlib.get_current_block() snv_consensus = testlib.get_consensus_at( snv_block_id ) testlib.next_block( **kw )
def scenario( wallets, **kw ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 1, 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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) # preorder, register, expire (multiple times) for i in xrange(2, 5): resp = testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) if i == 4: break testlib.next_block( **kw ) testlib.next_block( **kw )
def scenario( wallets, **kw ): global snv_block_id, last_consensus testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) # NOTE: names expire in 13 blocks testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 13, 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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) snv_block_id = testlib.get_current_block() for i in xrange(0, 15): testlib.next_block( **kw ) last_consensus = testlib.get_consensus_at( testlib.get_current_block() )
def scenario( wallets, **kw ): global snv_block_id, last_consensus testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) snv_block_id = testlib.get_current_block() resp = testlib.blockstack_name_revoke( "foo.test", wallets[3].privkey ) testlib.next_block( **kw ) last_consensus = testlib.get_consensus_at( testlib.get_current_block() )
def scenario( wallets, **kw ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_name_import( "foo.test", wallets[4].addr, "11" * 20, wallets[2].privkey ) testlib.blockstack_name_import( "bar.test", wallets[2].addr, "22" * 20, wallets[3].privkey ) testlib.blockstack_name_import( "baz.test", wallets[3].addr, "33" * 20, wallets[4].privkey ) testlib.next_block( **kw ) # will be accepted testlib.blockstack_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.blockstack_name_import( "foo.test", wallets[4].addr, "11" * 20, wallets[2].privkey ) testlib.blockstack_name_import( "bar.test", wallets[2].addr, "22" * 20, wallets[3].privkey ) testlib.blockstack_name_import( "baz.test", wallets[3].addr, "33" * 20, wallets[4].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw )
def scenario( wallets, **kw ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_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.blockstack_name_import( "foo.test", addr_reencode("1ARVjrtKnUVWt2GNrpuFLnNCL2WGUhKdkW"), "33" * 20, wallets[3].privkey ) # derived child 2 if 'error' in resp: print json.dumps(resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.blockstack_name_import( "foo.test", addr_reencode("1PYu4vKB3g2QLDFdurxqYSJ9aJSed7tne1"), "22" * 20, wallets[2].privkey ) # derived child 1 if 'error' in resp: print json.dumps(resp, indent=4 ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw )
def scenario( wallets, **kw ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # wait for a bit... for i in xrange(0, 10): testlib.next_block( **kw ) # has to be the same key that registered... resp = testlib.blockstack_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): testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_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.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw)
def scenario( wallets, **kw ): global txids global consensuses testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.next_block( **kw ) # do a sequence of updates, every other block for i in xrange( 0, 20 ): if (i % 2) != 0: update_hash = ("%02x" % (i)) * 20 resp = testlib.blockstack_name_update( "foo.test", update_hash, wallets[3].privkey ) txids[ update_hash ] = resp['transaction_hash'] consensuses[ update_hash ] = testlib.get_consensus_at( testlib.get_current_block( **kw ), **kw ) testlib.next_block( **kw ) testlib.next_block( **kw )
def scenario( wallets, **kw ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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 ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) consensus_hash = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw) testlib.next_block( **kw ) testlib.next_block( **kw ) # preorder, register, update, expire (multiple times) for i in xrange(2, 11): resp = testlib.blockstack_name_preorder( "foo.test", wallets[i].privkey, wallets[(i+1)%11].addr, consensus_hash=consensus_hash ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) consensus_hash = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw) testlib.next_block( **kw ) testlib.next_block( **kw ) resp = testlib.blockstack_name_register( "foo.test", wallets[i].privkey, wallets[(i+1)%11].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) consensus_hash = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw) testlib.next_block( **kw ) testlib.next_block( **kw ) resp = testlib.blockstack_name_transfer( "foo.test", wallets[i].addr, True, wallets[(i+1)%11].privkey, consensus_hash=consensus_hash ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) consensus_hash = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw) testlib.next_block( **kw ) testlib.next_block( **kw ) resp = testlib.blockstack_name_update( "foo.test", ("%02x" % i) * 20, wallets[i].privkey, consensus_hash=consensus_hash ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) consensus_hash = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw) testlib.next_block( **kw ) testlib.next_block( **kw ) if i == 10: break testlib.next_block( **kw ) consensus_hash = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw) testlib.next_block( **kw ) testlib.next_block( **kw )
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, key_names, error testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) wallet_keys = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey, data_privkey=wallets[4].privkey ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return testlib.next_block( **kw ) # make an account res = blockstack_client.put_account("foo.test", "serviceFoo", "serviceFooID", "foo://bar.com", proxy=test_proxy, wallet_keys=wallet_keys, foofield="foo!" ) if 'error' in res: res['test'] = 'Failed to create foo.test account' print json.dumps(res, indent=4, sort_keys=True) error = True return res = blockstack_client.put_account("foo.test", "deletedService", "deletedServiceID", "foo://deleted", proxy=test_proxy, wallet_keys=wallet_keys, barfield="bar!") if 'error' in res: res['test'] = 'Failed to create foo.test deletedService account' print json.dumps(res, indent=4, sort_keys=True) error = True return # delete an account res = blockstack_client.delete_account("foo.test", "deletedService", "deletedServiceID", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to delete foo.test deletedService' print json.dumps(res, indent=4, sort_keys=True) error = True return testlib.next_block( **kw )
def scenario( wallets, **kw ): global fail_blocks testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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 ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # wait for it to expire... for i in xrange(0, 2 * NAMESPACE_LIFETIME_MULTIPLIER + 1): testlib.next_block( **kw ) # verify that operations fail resp = testlib.blockstack_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.blockstack_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.blockstack_name_renew( "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)) # should fail resp = testlib.blockstack_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 ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 4, 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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) # preorder, register, update, expire (twice; should fail the second time) for i in xrange(2, 4): resp = testlib.blockstack_name_preorder( "foo.test", wallets[i].privkey, wallets[(i+1)%11].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.blockstack_name_register( "foo.test", wallets[i].privkey, wallets[(i+1)%11].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) if i == 3: testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) testlib.next_block( **kw ) resp = testlib.blockstack_name_update( "foo.test", ("%02x" % i) * 20, wallets[(i+1)%11].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) if i == 3: testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) testlib.next_block( **kw ) resp = testlib.blockstack_name_transfer( "foo.test", wallets[i].addr, True, wallets[(i+1)%11].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) if i == 3: testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) testlib.next_block( **kw ) resp = testlib.blockstack_name_renew( "foo.test", wallets[i].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) if i == 3: testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) if i == 3: break testlib.next_block( **kw )
def scenario( wallets, **kw ): global zonefile_hash testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, None ) resp = testlib.blockstack_rpc_register( "foo.test", "0123456789abcdef" ) if 'error' in resp: print >> sys.stderr, json.dumps(resp, indent=4, sort_keys=True) return False # wait for the preorder to get confirmed for i in xrange(0, 12): testlib.next_block( **kw ) # wait for the poller to pick it up print >> sys.stderr, "Waiting 10 seconds for the backend to submit the register" time.sleep(10) # wait for the register to get confirmed for i in xrange(0, 12): testlib.next_block( **kw ) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge registration" time.sleep(10) # wait for update to get confirmed for i in xrange(0, 12): testlib.next_block( **kw ) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge update" time.sleep(10) # transfer to a new address resp = testlib.blockstack_rpc_transfer( "foo.test", wallets[4].addr, "0123456789abcdef" ) if 'error' in resp: print >> sys.stderr, "transfer error: %s" % resp['error'] return False # wait for it to go through for i in xrange(0, 12): testlib.next_block( **kw ) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge the transfer" time.sleep(10) testlib.next_block(**kw)
def scenario( wallets, **kw ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) # can't steal test resp = testlib.blockstack_namespace_reveal( "test", wallets[3].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[4].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) # can't re-create test resp = testlib.blockstack_namespace_preorder( "test", wallets[3].addr, wallets[4].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.blockstack_namespace_reveal( "test", wallets[3].addr, 52595, 251, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[4].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.blockstack_namespace_ready( "test", wallets[4].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) # can't re-reveal test resp = testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 252, 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 ) testlib.next_block( **kw ) # can't re-ready test resp = testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) # warn the serialization checker that this changes behavior from 0.13 print "BLOCKSTACK_SERIALIZATION_CHANGE_BEHAVIOR" sys.stdout.flush()
def scenario( wallets, **kw ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey ) resp = testlib.blockstack_cli_register( "foo.test", "0123456789abcdef" ) if 'error' in resp: print >> sys.stderr, json.dumps(resp, indent=4, sort_keys=True) return False # wait for the preorder to get confirmed for i in xrange(0, 12): testlib.next_block( **kw ) # wait for the poller to pick it up print >> sys.stderr, "Waiting 10 seconds for the backend to submit the register" time.sleep(10) # wait for the register to get confirmed for i in xrange(0, 12): testlib.next_block( **kw ) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge registration" time.sleep(10) # wait for update to get confirmed for i in xrange(0, 12): testlib.next_block( **kw ) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge update" time.sleep(10) # let's make sure the zonefile propagates... res = testlib.blockstack_REST_call("GET", "/v1/names/foo.test", None) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name bar.test' print json.dumps(res) return False response_json = json.loads(res['raw']) # assert that we're getting a mainnet address if response_json['address'] != "1K4SCfqffVHTnHvqsW2whH1Jn57dDjDdQA": print "Address returned to REST call isn't converted to mainnet!" print "Returned: {}, Expected: {}".format(response_json['address'], "1K4SCfqffVHTnHvqsW2whH1Jn57dDjDdQA") return False
def scenario( wallets, **kw ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) resp = testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) if 'error' in resp: print json.dumps(resp) testlib.next_block( **kw ) # no name operations should work on this name, except register resp = testlib.blockstack_name_update( "foo.test", "11" * 20, wallets[3].privkey, safety_checks=False ) if 'error' in resp: print json.dumps(resp) testlib.next_block( **kw ) testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) resp = testlib.blockstack_name_renew( "foo.test", wallets[3].privkey, safety_checks=False ) if 'error' in resp: print json.dumps(resp) testlib.next_block( **kw ) testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) resp = testlib.blockstack_name_transfer( "foo.test", wallets[4].addr, True, wallets[3].privkey, safety_checks=False ) if 'error' in resp: print json.dumps(resp) testlib.next_block( **kw ) testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) # try both addresses (should both fail) resp = testlib.blockstack_name_revoke( "foo.test", wallets[4].privkey, safety_checks=False) if 'error' in resp: print json.dumps(resp) testlib.next_block( **kw ) testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) resp = testlib.blockstack_name_revoke( "foo.test", wallets[3].privkey, safety_checks=False ) if 'error' in resp: print json.dumps(resp) testlib.next_block( **kw ) testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))
def scenario( wallets, **kw ): global snv_block_id_foo, snv_serial_number_bar, snv_serial_number_baz, last_consensus, snv_txid_bar, snv_txid_baz testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) snv_block_id_foo = testlib.get_current_block() testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.next_block( **kw ) bar_preorder = testlib.blockstack_name_preorder( "bar.test", wallets[4].privkey, wallets[5].addr ) testlib.next_block( **kw ) snv_serial_number_bar = "%s-%s" % (testlib.get_current_block(), 0 ) snv_txid_bar = bar_preorder['transaction_hash'] testlib.blockstack_name_register( "bar.test", wallets[4].privkey, wallets[5].addr ) testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.next_block( **kw ) testlib.next_block( **kw ) baz_preorder = testlib.blockstack_name_preorder( "baz.test", wallets[6].privkey, wallets[7].addr ) testlib.next_block( **kw ) snv_serial_number_baz = "%s-%s" % (testlib.get_current_block(), 0 ) snv_txid_baz = baz_preorder['transaction_hash'] testlib.blockstack_name_register( "baz.test", wallets[6].privkey, wallets[7].addr ) testlib.next_block( **kw ) last_consensus = testlib.get_consensus_at( testlib.get_current_block() )
def scenario( wallets, **kw ): global reveal_block global preorder_block testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) preorder_block = testlib.get_current_block( **kw ) + 1 testlib.next_block( **kw ) testlib.blockstack_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 ) reveal_block = testlib.get_current_block( **kw ) + 1 testlib.next_block( **kw )
def scenario( wallets, **kw ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) # can't steal test resp = testlib.blockstack_namespace_reveal( "test", wallets[3].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[4].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) # can't re-create test resp = testlib.blockstack_namespace_preorder( "test", wallets[3].addr, wallets[4].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.blockstack_namespace_reveal( "test", wallets[3].addr, 52595, 251, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[4].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.blockstack_namespace_ready( "test", wallets[4].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) # can't re-reveal test resp = testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 252, 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 ) testlib.next_block( **kw ) # can't re-ready test resp = testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw )
def scenario( wallets, **kw ): global final_consensus testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) resp = testlib.blockstack_name_preorder_multi( ["foo.test", "bar.test", "baz.test"], wallets[2].privkey, [wallets[3].addr, wallets[4].addr, wallets[5].addr] ) if 'error' in resp: print json.dumps( resp, indent=4 ) sys.exit(1) testlib.next_block( **kw ) resp = testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) sys.exit(1) testlib.next_block( **kw ) resp = testlib.blockstack_name_preorder( "goo.test", wallets[2].privkey, wallets[3].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) sys.exit(1) testlib.next_block( **kw ) resp = testlib.blockstack_name_register( "bar.test", wallets[2].privkey, wallets[4].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) sys.exit(1) resp = testlib.blockstack_name_register( "goo.test", wallets[2].privkey, wallets[3].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) sys.exit(1) resp = testlib.blockstack_name_register( "baz.test", wallets[2].privkey, wallets[5].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) sys.exit(1) testlib.next_block( **kw )
def scenario( wallets, **kw ): global reveal_block, namespace_block_number resp = testlib.blockstack_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.blockstack_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.blockstack_name_import( "foo.test", wallets[2].addr, "11" * 20, wallets[1].privkey ) testlib.blockstack_name_import( "bar.test", wallets[3].addr, "22" * 20, wallets[1].privkey ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block( **kw ) # try to re-preorder it resp = testlib.blockstack_namespace_preorder( "test", wallets[3].addr, wallets[2].privkey ) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block( **kw ) # try to re-reveal it testlib.blockstack_namespace_reveal( "test", wallets[3].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[2].privkey ) testlib.next_block( **kw ) reveal_block = testlib.get_current_block(**kw) + 1 # import some names testlib.blockstack_name_import( "foo.test", wallets[2].addr, "11" * 20, wallets[1].privkey ) testlib.blockstack_name_import( "bar.test", wallets[3].addr, "22" * 20, wallets[1].privkey ) testlib.blockstack_name_import( "baz.test", wallets[4].addr, "33" * 20, wallets[1].privkey ) testlib.next_block( **kw ) namespace_block_number = testlib.get_current_block(**kw)
def scenario(wallets, **kw): testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_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) testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.blockstack_name_revoke("foo.test", wallets[3].privkey) testlib.next_block(**kw) # can't do anything with the name for another 10 blocks resp = testlib.blockstack_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) # should fail resp = testlib.blockstack_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) # should fail resp = testlib.blockstack_name_renew("foo.test", wallets[3].privkey, safety_checks=False) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # wait for it to expire... for i in xrange(0, 8): testlib.next_block(**kw) # verify that operations continue to fail resp = testlib.blockstack_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) # should fail resp = testlib.blockstack_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) # should fail resp = testlib.blockstack_name_renew("foo.test", wallets[3].privkey, safety_checks=False) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw)
def scenario(wallets, **kw): global put_result, wallet_keys, legacy_profile, zonefile_hash, zonefile_hash_2, immutable_hash, datastore_name wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[8].privkey, wallets[3].privkey, wallets[4].privkey) wallet_keys_2 = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[9].privkey, wallets[6].privkey, wallets[7].privkey) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_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.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_preorder("bar.test", wallets[5].privkey, wallets[6].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_register("bar.test", wallets[5].privkey, wallets[6].addr) testlib.next_block(**kw) # set up legacy profile hash legacy_txt = json.dumps(legacy_profile, sort_keys=True) legacy_hash = pybitcoin.hex_hash160(legacy_txt) result_1 = testlib.blockstack_name_update("foo.test", legacy_hash, wallets[3].privkey) result_2 = testlib.blockstack_name_update("bar.test", legacy_hash, wallets[6].privkey) testlib.next_block(**kw) rc = blockstack_client.storage.put_immutable_data( None, result_1['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt) assert rc is not None rc = blockstack_client.storage.put_immutable_data( None, result_2['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt) assert rc is not None testlib.next_block(**kw) # migrate res = testlib.migrate_profile("foo.test", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return else: zonefile_hash = res['zonefile_hash'] # migrate res = testlib.migrate_profile("bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return else: zonefile_hash_2 = res['zonefile_hash'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) # start up RPC for 'foo.test' testlib.blockstack_client_set_wallet("0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey']) # put immutable put_result = testlib.blockstack_cli_put_immutable( "foo.test", "hello_world_immutable", json.dumps({'hello': 'world'}), password='******') log.debug("put immutable for foo.test") if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) error = True return immutable_hash = put_result['immutable_data_hash'] testlib.expect_atlas_zonefile(put_result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block(**kw) print "waiting for confirmation" time.sleep(10) # start up RPC for 'bar.test' testlib.blockstack_client_set_wallet("0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], wallet_keys_2['data_privkey']) log.debug("put mutable for bar.test") put_result = testlib.blockstack_cli_put_mutable( 'bar.test', 'hello_world_mutable', json.dumps({'hello': 'world'}), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.next_block(**kw) # put mutable data again testlib.blockstack_client_set_wallet("0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey']) res = testlib.blockstack_cli_put_mutable('foo.test', 'foo_data2', json.dumps({'hello2': 'world2'}), password='******') if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) return False # put immutable data with the URL # start up RPC for 'foo.test' log.debug("put immutable for foo.test (2)") res = testlib.blockstack_cli_put_immutable('foo.test', 'foo_immutable', json.dumps({'hello3': 'world3'}), password='******') if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) return False # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) datastore_id_res = testlib.blockstack_cli_datastore_get_id("foo-app.com") datastore_name = datastore_id_res['datastore_id'] # make datastore res = testlib.blockstack_cli_create_datastore("foo-app.com") if 'error' in res: print "failed to create datastore: {}".format(res['error']) return False # put a file into the datastore data = 'hello datastore' log.debug("putfile") res = testlib.blockstack_cli_datastore_putfile("foo-app.com", '/hello_datastore', data) if 'error' in res: print 'failed to putfile /hello_datastore: {}'.format(res['error']) return False # make a directory log.debug("mkdir") res = testlib.blockstack_cli_datastore_mkdir("foo-app.com", '/hello_dir') if 'error' in res: print 'failed to mkdir /hello_dir: {}'.format(res['error']) return False # put a file into the directory data = 'hello dir datastore' log.debug("putfile in dir") res = testlib.blockstack_cli_datastore_putfile( 'foo-app.com', '/hello_dir/hello_dir_datastore', data) if 'error' in res: print 'failed to putfile /hello_dir/hello_dir_datastore: {}'.format( res['error']) return False testlib.next_block(**kw)
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) # make a session datastore_pk = keylib.ECPrivateKey(wallets[-1].privkey).to_hex() res = testlib.blockstack_cli_app_signin("foo.test", datastore_pk, 'register.app', ['names', 'register', 'prices', 'zonefiles', 'blockchain', 'node_read', 'wallet_write']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] # for funsies, get the price of .test res = testlib.blockstack_REST_call('GET', '/v1/prices/namespaces/test', ses) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get price of .test' print json.dumps(res) return False test_price = res['response']['satoshis'] print '\n\n.test costed {} satoshis\n\n'.format(test_price) # get the price for bar.test res = testlib.blockstack_REST_call('GET', '/v1/prices/names/bar.test', ses) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get price of bar.test' print json.dumps(res) return False bar_price = res['response']['total_estimated_cost']['satoshis'] print "\n\nbar.test will cost {} satoshis\n\n".format(bar_price) # let's set the key to skip the transfer. config_dir = os.path.dirname(config_path) conf = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] res = testlib.blockstack_REST_call('PUT', '/v1/wallet/keys/owner', None, api_pass=api_pass, data=new_key) if res['http_status'] != 200 or 'error' in res: print 'failed to set owner key' print res return False # make zonefile for recipient driver_urls = blockstack_client.storage.make_mutable_data_urls('bar.test', use_only=['dht', 'disk']) zonefile = blockstack_client.zonefile.make_empty_zonefile('bar.test', wallets[4].pubkey_hex, urls=driver_urls) zonefile_txt = blockstack_zones.make_zone_file( zonefile, origin='bar.test', ttl=3600 ) # leaving the call format of this one the same to make sure that our registrar correctly # detects that the requested TRANSFER is superfluous # register the name bar.test res = testlib.blockstack_REST_call('POST', '/v1/names', ses, data={'name': 'bar.test', 'zonefile': zonefile_txt, 'owner_address': new_addr }) if 'error' in res: res['test'] = 'Failed to register user' print json.dumps(res) error = True return False print res tx_hash = res['response']['transaction_hash'] # wait for preorder to get confirmed... for i in xrange(0, 6): testlib.next_block( **kw ) res = testlib.verify_in_queue(ses, 'bar.test', 'preorder', tx_hash ) if not res: return False # wait for the preorder to get confirmed for i in xrange(0, 6): testlib.next_block( **kw ) # wait for register to go through print 'Wait for register to be submitted' time.sleep(10) # wait for the register to get confirmed for i in xrange(0, 6): testlib.next_block( **kw ) res = testlib.verify_in_queue(ses, 'bar.test', 'register', None ) if not res: return False for i in xrange(0, 6): testlib.next_block( **kw ) print 'Wait for update to be submitted' time.sleep(10) # wait for update to get confirmed for i in xrange(0, 6): testlib.next_block( **kw ) res = testlib.verify_in_queue(ses, 'bar.test', 'update', None ) if not res: return False for i in xrange(0, 6): testlib.next_block( **kw ) print 'Wait for transfer to be submitted' time.sleep(10) # wait for transfer to get confirmed for i in xrange(0, 6): testlib.next_block( **kw ) res = testlib.verify_in_queue(ses, 'bar.test', 'transfer', None ) if res: print "Wrongly issued a TRANSFER" return False for i in xrange(0, 6): testlib.next_block( **kw ) print 'Wait for transfer to be confirmed' time.sleep(10) res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test", ses) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name bar.test' print json.dumps(res) return False zonefile_hash = res['response']['zonefile_hash'] # should still be registered if res['response']['status'] != 'registered': print "register not complete" print json.dumps(res) return False # do we have the history for the name? res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test/history", ses ) if 'error' in res or res['http_status'] != 200: res['test'] = "Failed to get name history for foo.test" print json.dumps(res) return False # valid history? hist = res['response'] if len(hist.keys()) != 3: res['test'] = 'Failed to get update history' res['history'] = hist print json.dumps(res, indent=4, sort_keys=True) return False # get the zonefile res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test/zonefile/{}".format(zonefile_hash), ses ) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name zonefile' print json.dumps(res) return False # same zonefile we put? if res['response']['zonefile'] != zonefile_txt: res['test'] = 'mismatched zonefile, expected\n{}\n'.format(zonefile_txt) print json.dumps(res) return False ### Now, we'll do it again, but this time, we're going to CHANGE THE KEY in the middle of registrations. ### to test the different paths, I'll start 3 registrations: # 1 has submitted preorder # 1 has submitted register # 1 has submitted update ### And then I'll issue a change-key # make zonefile for recipients zonefiles = [] for i in [1,2,3]: name = "tricky{}.test".format(i) driver_urls = blockstack_client.storage.make_mutable_data_urls(name, use_only=['dht', 'disk']) zonefile = blockstack_client.zonefile.make_empty_zonefile(name, wallets[4].pubkey_hex, urls=driver_urls) zonefiles.append(blockstack_zones.make_zone_file( zonefile, origin=name, ttl=3600 )) # leaving the call format of this one the same to make sure that our registrar correctly # detects that the requested TRANSFER is superfluous res = testlib.blockstack_REST_call( 'POST', '/v1/names', ses, data={'name':'tricky1.test', 'zonefile':zonefiles[0], 'owner_address':new_addr}) if 'error' in res: res['test'] = 'Failed to register tricky1.test' print json.dumps(res) error = True return False tx_hash = res['response']['transaction_hash'] # wait for preorder to get confirmed... for i in xrange(0, 6): testlib.next_block( **kw ) res = testlib.blockstack_REST_call( 'POST', '/v1/names', ses, data={'name':'tricky2.test', 'zonefile':zonefiles[1], 'owner_address':new_addr}) if 'error' in res: res['test'] = 'Failed to register tricky2.test' print json.dumps(res) error = True return False # wait for the preorder to get confirmed for i in xrange(0, 6): testlib.next_block( **kw ) # wait for register to go through print 'Wait for register to be submitted' time.sleep(10) # wait for the register to get confirmed for i in xrange(0, 6): testlib.next_block( **kw ) res = testlib.blockstack_REST_call( 'POST', '/v1/names', ses, data={'name':'tricky3.test', 'zonefile':zonefiles[2], 'owner_address':new_addr}) if 'error' in res: res['test'] = 'Failed to register tricky3.test' print json.dumps(res) error = True return False for i in xrange(0, 6): testlib.next_block( **kw ) print 'Wait for update to be submitted' time.sleep(10) for i in xrange(0, 1): testlib.next_block( **kw ) res = testlib.verify_in_queue(ses, 'tricky1.test', 'update', None) res = testlib.verify_in_queue(ses, 'tricky2.test', 'register', None) res = testlib.verify_in_queue(ses, 'tricky3.test', 'preorder', None) # let's go crazy. res = testlib.blockstack_REST_call('PUT', '/v1/wallet/keys/owner', None, api_pass=api_pass, data=insanity_key) if res['http_status'] != 200 or 'error' in res: print 'failed to set owner key' print res return False # wait for preorder to get confirmed for i in xrange(0, 6): testlib.next_block( **kw ) # wake up registrar, submit register time.sleep(10) for i in xrange(0, 12): testlib.next_block( **kw ) # wake up registrar, submit update time.sleep(10) for i in xrange(0, 12): testlib.next_block( **kw ) # wake up registrar, propogate zonefile time.sleep(10)
def scenario(wallets, **kw): global put_result, wallet_keys, legacy_profile, zonefile_hash, zonefile_hash_2 wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[8].privkey, wallets[3].privkey, None) wallet_keys_2 = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[9].privkey, wallets[6].privkey, None) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_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.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_preorder("bar.test", wallets[5].privkey, wallets[6].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_register("bar.test", wallets[5].privkey, wallets[6].addr) testlib.next_block(**kw) # set up legacy profile hash legacy_txt = json.dumps(legacy_profile, sort_keys=True) legacy_hash = virtualchain.lib.hashing.hex_hash160(legacy_txt) result_1 = testlib.blockstack_name_update("foo.test", legacy_hash, wallets[3].privkey) result_2 = testlib.blockstack_name_update("bar.test", legacy_hash, wallets[6].privkey) testlib.next_block(**kw) rc = blockstack_client.storage.put_immutable_data( legacy_txt, result_1['transaction_hash'], data_hash=legacy_hash) assert rc is not None rc = blockstack_client.storage.put_immutable_data( legacy_txt, result_2['transaction_hash'], data_hash=legacy_hash) assert rc is not None testlib.next_block(**kw) # migrate profiles res = testlib.migrate_profile("foo.test", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return zonefile_hash = res['zonefile_hash'] res = testlib.migrate_profile("bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2) if 'error' in res: res['test'] = 'Failed to initialize bar.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return zonefile_hash_2 = res['zonefile_hash'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) testlib.blockstack_client_set_wallet("0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey']) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # see that put_immutable works put_result = testlib.blockstack_cli_put_immutable( 'foo.test', 'hello_world_immutable', json.dumps({'hello': 'world_immutable'}, sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) testlib.expect_atlas_zonefile(put_result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block(**kw) print "waiting for confirmation" time.sleep(10) testlib.blockstack_client_set_wallet("0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], wallet_keys_2['data_privkey']) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # see that put_mutable works put_result = testlib.blockstack_cli_put_mutable( "bar.test", "hello_world_mutable", json.dumps({'hello': 'world'}, sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) testlib.next_block(**kw)
def scenario(wallets, **kw): global put_result, wallet_keys, datasets, zonefile_hash, dataset_change testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_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.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) wallet_keys = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey) # migrate profile res = testlib.migrate_profile("foo.test", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return else: zonefile_hash = res['zonefile_hash'] testlib.next_block(**kw) put_result = blockstack_client.put_mutable("foo.test", "hello_world_1", datasets[0], proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) testlib.next_block(**kw) put_result = blockstack_client.put_mutable("foo.test", "hello_world_2", datasets[1], proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) put_result = blockstack_client.put_mutable("foo.test", "hello_world_3", datasets[2], proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) # increment version too datasets[0]['buf'] = [] for i in xrange(0, 5): datasets[0]["dataset_change"] = dataset_change datasets[0]['buf'].append(i) put_result = blockstack_client.put_mutable("foo.test", "hello_world_1", datasets[0], proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) # now delete everything for i in xrange(0, len(datasets)): delete_result = blockstack_client.delete_mutable( "foo.test", "hello_world_%s" % (i + 1), wallet_keys=wallet_keys) if 'error' in delete_result: print json.dumps(delete_result, indent=4, sort_keys=True) testlib.next_block(**kw)
def scenario( wallets, **kw ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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 ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) namespace_rec = testlib.blockstack_cli_get_namespace_blockchain_record("test") if 'error' in namespace_rec: print namespace_rec return False namespace_balance = testlib.get_balance(namespace_rec['address']) # should fail safety checks res = testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr, burn_addr=wallets[1].addr, expect_fail=True) if 'error' not in res: print res return False # should succeed to be transmitted and should be accepted res = testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr, burn_addr=wallets[1].addr, safety_checks=False, tx_fee=300 * 5) if 'error' in res: print res return False testlib.next_block( **kw ) res = testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr, safety_checks=False, tx_fee=300*5 ) if 'error 'in res: print res return False testlib.next_block( **kw ) testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)) # should NOT have registered (wrong burn address) name_rec = testlib.get_name_blockchain_record('foo.test') if 'error' not in name_rec: print name_rec return False # try again, with the right burn address but the same register address (should be rejected) res = testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr, burn_addr=wallets[0].addr, safety_checks=False, tx_fee=300 * 5) if 'error' in res: print res return False testlib.next_block( **kw ) nameops = blockstack.lib.client.get_blockstack_transactions_at(testlib.get_current_block(**kw), hostport='http://localhost:16264') if 'error' in nameops: print nameops return False if len(nameops) > 0: print nameops return False # try again, but with the right burn address AND a different register address (should be accepted) res = testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[4].addr, burn_addr=wallets[0].addr, safety_checks=False, tx_fee=300 * 5) if 'error' in res: print res return False testlib.next_block( **kw ) # should succeed res = testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[4].addr ) if 'error 'in res: print res return False testlib.next_block( **kw ) # should have registered name_rec = testlib.get_name_blockchain_record('foo.test') if 'error' in name_rec: print name_rec return False new_namespace_balance = testlib.get_balance(namespace_rec['address']) name_cost = name_rec['op_fee'] if new_namespace_balance - namespace_balance != name_cost * 2: print 'address {} did not get credited'.format(namespace_rec['address']) print '{} != {} + {}'.format(new_namespace_balance, namespace_balance, name_cost * 2) return False
def scenario(wallets, **kw): global first_name_block # make a test namespace resp = testlib.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, expect_fail=True) if 'error' not in resp: print resp return False # should go through, but be rejected resp = testlib.blockstack_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.blockstack_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.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20, expect_fail=True) if 'error' not in resp: print resp return False # should go through, but be rejected resp = testlib.blockstack_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.blockstack_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.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20, expect_fail=True) if 'error' not in resp: print resp return False # should go through, but be rejected resp = testlib.blockstack_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.blockstack_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.blockstack_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.blockstack_name_register("foo.test", wallets[3].privkey, wallets[0].addr, zonefile_hash='44' * 20, expect_fail=True) if 'error' not in resp: print resp return False # should go through, but be rejected resp = testlib.blockstack_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.blockstack_cli_whois('foo.test') if 'error' not in whois: print whois return False # should go through, and be rejected (expired preorder) resp = testlib.blockstack_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.blockstack_cli_whois('foo.test') if 'error' not in whois: print whois return False # should go through, and be accepted resp = testlib.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_name_import("baz.test", wallets[5].addr, "44" * 20, private_keys[0]) if 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.blockstack_name_import("baz.test", wallets[5].addr, "55" * 20, private_keys[1]) if 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.blockstack_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.blockstack_name_import("foo.test", wallets[5].addr, "66" * 20, private_keys[0]) if 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.blockstack_name_import("bar.test", wallets[3].addr, "77" * 20, private_keys[1]) if 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.blockstack_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.blockstack_name_import("baz.test", wallets[5].addr, "44" * 20, private_keys[0]) if 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.blockstack_name_import("baz.test", wallets[5].addr, "55" * 20, private_keys[1]) if 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.blockstack_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.blockstack_name_import("foo.test", wallets[5].addr, "66" * 20, private_keys[0]) if 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.blockstack_name_import("bar.test", wallets[3].addr, "77" * 20, private_keys[1]) if 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.blockstack_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.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw)
def scenario( wallets, **kw ): global TRANSACTION_BROADCASTER_URL global GAIA_READ_URL global GAIA_READ_PORT global GAIA_WRITE_PORT global GAIA_WRITE_URL # get gaia hub info with open(os.path.join(os.environ['BLOCKSTACK_WORKING_DIR'], 'gaia.conf'), 'r') as f: GAIA_CONF = json.loads(f.read().strip()) try: GAIA_READ_PORT = urlparse.urlparse(GAIA_CONF['readURL']).netloc.split(':')[-1] GAIA_READ_PORT = int(GAIA_READ_PORT) except: GAIA_READ_PORT = 80 if os.environ.get('BLOCKSTACK_PUBLIC_TESTNET_GAIA_READ_PORT'): GAIA_READ_PORT = int(os.environ['BLOCKSTACK_PUBLIC_TESTNET_GAIA_READ_PORT']) read_urlinfo = urlparse.urlparse(GAIA_CONF['readURL']) GAIA_READ_URL = 'http://{}:{}'.format(read_urlinfo.netloc.split(':')[0], GAIA_READ_PORT) GAIA_WRITE_PORT = GAIA_CONF['port'] if os.environ.get('BLOCKSTACK_PUBLIC_TESTNET_GAIA_WRITE_PORT'): GAIA_WRITE_PORT = int(os.environ['BLOCKSTACK_PUBLIC_TESTNET_GAIA_WRITE_PORT']) GAIA_WRITE_URL = 'http://{}:{}'.format(GAIA_CONF['servername'], GAIA_WRITE_PORT) # fill in URL tb_conf_path = os.path.join(os.environ['BLOCKSTACK_WORKING_DIR'], 'transaction-broadcaster.conf') with open(tb_conf_path, 'r') as f: tb_conf = json.loads(f.read().strip()) TRANSACTION_BROADCASTER_URL = 'http://{}:{}'.format(TESTNET_PUBLIC_HOST, tb_conf['port']) PORTNUM = int(os.environ.get('TESTNET_PORTNUM', '30001')) start_test_server(PORTNUM) testlib.blockstack_namespace_preorder( "id2", wallets[1].addr, wallets[0].privkey ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.blockstack_namespace_preorder( "sandbox", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) # same price curve as public .id namespace testlib.blockstack_namespace_reveal( "id2", 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=3) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, -1, 250, 4, [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey, version_bits=3) testlib.blockstack_namespace_reveal( "sandbox", wallets[1].addr, -1, 250, 4, [6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey, version_bits=3) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "id2", wallets[1].privkey ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.blockstack_namespace_ready( "sandbox", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_register_user(SUBDOMAIN_DOMAIN, SUBDOMAIN_PAYMENT_KEY, SUBDOMAIN_OWNER_KEY, gaia_host='{}:{}'.format(TESTNET_PUBLIC_HOST, GAIA_READ_PORT), **kw) start_subdomain_registrar() testlib.set_account_audits(False) print 'Testnet initialized' # do 1-minute block times forever while True: time.sleep(60) testlib.next_block(**kw)
def scenario( wallets, **kw ): start_transaction_broadcaster() start_subdomain_registrar() testlib.blockstack_namespace_preorder( "id", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "id", 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.blockstack_namespace_ready( "id", wallets[1].privkey ) testlib.next_block( **kw ) wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey ) resp = testlib.blockstack_cli_register( "foo.id", "0123456789abcdef" ) if 'error' in resp: print >> sys.stderr, json.dumps(resp, indent=4, sort_keys=True) return False # wait for the preorder to get confirmed for i in xrange(0, 12): testlib.next_block( **kw ) # wait for the poller to pick it up print >> sys.stderr, "Waiting 10 seconds for the backend to submit the register" time.sleep(10) # wait for the register to get confirmed for i in xrange(0, 12): testlib.next_block( **kw ) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge registration" time.sleep(10) # wait for update to get confirmed for i in xrange(0, 12): testlib.next_block( **kw ) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge update" time.sleep(10) # now, queue a registration. requests.post('http://localhost:3000/register', json = { 'zonefile' : 'hello world', 'name' : 'bar', 'owner_address': '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa' }) # force a batch out of the subdomain registrar requests.post('http://localhost:3000/issue_batch', headers = {'Authorization': 'bearer tester129'}) for i in xrange(0, 12): testlib.next_block( **kw ) print >> sys.stderr, "Waiting 10 seconds for the backend to pickup first batch" time.sleep(10) # now, queue another registration requests.post('http://localhost:3000/register', json = { 'zonefile' : 'hello world', 'name' : 'zap', 'owner_address': '1Ez69SnzzmePmZX3WpEzMKTrcBF2gpNQ55' }) res = testlib.blockstack_REST_call('GET', '/v1/names/zap.foo.id', None) if 'error' in res: res['test'] = 'Failed to query zap.foo.id' print json.dumps(res) return False if res['http_status'] != 200: res['test'] = 'HTTP status {}, response = {} on name lookup'.format(res['http_status'], res['response']) print json.dumps(res) return False name_info = res['response'] try: if (name_info['zonefile'] != 'hello world' or name_info['address'] != '1Ez69SnzzmePmZX3WpEzMKTrcBF2gpNQ55'): res['test'] = 'Unexpected name info lookup for zap.foo.id' print 'zap.foo.id JSON:' print json.dumps(name_info) return False except: res['test'] = 'Unexpected name info lookup for zap.foo.id' print 'zap.foo.id JSON:' print json.dumps(name_info) return False
def scenario(wallets, **kw): global import_block global failed_blocks # make a test namespace resp = testlib.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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): wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) zonefile_batches = [] testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_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.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo1.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_preorder("foo2.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_preorder("foo3.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) zf_template = "$ORIGIN {}\n$TTL 3600\n{}" zf_default_url = '_https._tcp URI 10 1 "https://raw.githubusercontent.com/nobody/content/profile.md"' zonefiles = { 'foo1.test': zf_template.format( 'foo1.test', subdomains.make_subdomain_txt( 'bar.foo1.test', 'foo1.test', wallets[4].addr, 0, zf_template.format('bar.foo1.test', zf_default_url), wallets[4].privkey)), 'foo2.test': zf_template.format( 'foo2.test', subdomains.make_subdomain_txt( 'bar.foo2.test', 'foo2.test', wallets[4].addr, 0, zf_template.format('bar.foo2.test', zf_default_url), wallets[4].privkey)), 'foo3.test': zf_template.format( 'foo3.test', subdomains.make_subdomain_txt( 'bar.foo3.test', 'foo3.test', wallets[4].addr, 0, zf_template.format('bar.foo3.test', zf_default_url), wallets[4].privkey)), } zonefile_batches.append(zonefiles) testlib.blockstack_name_register( "foo1.test", wallets[2].privkey, wallets[3].addr, zonefile_hash=storage.get_zonefile_data_hash(zonefiles['foo1.test'])) testlib.blockstack_name_register( "foo2.test", wallets[2].privkey, wallets[3].addr, zonefile_hash=storage.get_zonefile_data_hash(zonefiles['foo2.test'])) testlib.blockstack_name_register( "foo3.test", wallets[2].privkey, wallets[3].addr, zonefile_hash=storage.get_zonefile_data_hash(zonefiles['foo3.test'])) testlib.next_block(**kw) # send updates too for i in range(0, 3): zf_template = "$ORIGIN {}\n$TTL 3600\n{}" zf_default_url = '_https._tcp URI 10 1 "https://test.com/?index={}"'.format( i + 1) zonefiles = { 'foo1.test': zf_template.format( 'foo1.test', subdomains.make_subdomain_txt( 'bar.foo1.test', 'foo1.test', wallets[4].addr, i + 1, zf_template.format('bar.foo1.test', zf_default_url), wallets[4].privkey)), 'foo2.test': zf_template.format( 'foo2.test', subdomains.make_subdomain_txt( 'bar.foo2.test', 'foo2.test', wallets[4].addr, i + 1, zf_template.format('bar.foo2.test', zf_default_url), wallets[4].privkey)), 'foo3.test': zf_template.format( 'foo3.test', subdomains.make_subdomain_txt( 'bar.foo3.test', 'foo3.test', wallets[4].addr, i + 1, zf_template.format('bar.foo3.test', zf_default_url), wallets[4].privkey)), } zonefile_batches.append(zonefiles) testlib.blockstack_name_update( 'foo1.test', storage.get_zonefile_data_hash(zonefiles['foo1.test']), wallets[3].privkey) testlib.blockstack_name_update( 'foo2.test', storage.get_zonefile_data_hash(zonefiles['foo2.test']), wallets[3].privkey) testlib.blockstack_name_update( 'foo3.test', storage.get_zonefile_data_hash(zonefiles['foo3.test']), wallets[3].privkey) testlib.next_block(**kw) # send all zonefiles at once for zfbatch in zonefile_batches: for name in zfbatch: assert testlib.blockstack_put_zonefile(zfbatch[name]) # kick off subdomain indexing testlib.next_block(**kw) # query each subdomain proxy = testlib.make_proxy() for i in xrange(1, 4): fqn = 'bar.foo{}.test'.format(i) res = client.get_name_record(fqn, proxy=proxy) if 'error' in res: print res return False expected_zonefile = zf_template.format(fqn, zf_default_url) if base64.b64decode(res['zonefile']) != expected_zonefile: print 'zonefile mismatch' print 'expected\n{}'.format(expected_zonefile) print 'got\n{}'.format(base64.b64decode(res['zonefile'])) return False # should be in atlas as well zf = testlib.blockstack_get_zonefile(res['value_hash'], parse=False) if not zf: print 'no zone file {} in atlas'.format(res['value_hash']) return False if zf != expected_zonefile: print 'zonefile mismatch in atlas' print 'expected\n{}'.format(expected_zonefile) print 'got\n{}'.format(base64.b64decode(res['zonefile'])) return False # reindex assert testlib.check_subdomain_db(**kw)
def scenario(wallets, **kw): testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_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) testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo1.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_preorder("foo2.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_preorder("foo3.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo1.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_register("foo2.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_register("foo3.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.blockstack_name_update('foo1.test', '11' * 20, wallets[3].privkey) testlib.blockstack_name_update('foo2.test', '22' * 20, wallets[3].privkey) testlib.blockstack_name_update('foo3.test', '33' * 20, wallets[3].privkey) testlib.next_block(**kw) # whois for i in xrange(1, 4): name = 'foo{}.test'.format(i) res = testlib.blockstack_cli_whois(name) if 'error' in res: print res return False if not res.has_key('zonefile_hash') or res[ 'zonefile_hash'] != '{}{}'.format(i, i) * 20: print res return False if res['owner_address'] != wallets[3].addr: print res return False # expire testlib.next_block(**kw) testlib.next_block(**kw) testlib.next_block(**kw) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo1.test", wallets[3].privkey, wallets[2].addr) testlib.blockstack_name_preorder("foo2.test", wallets[3].privkey, wallets[2].addr) testlib.blockstack_name_preorder("foo3.test", wallets[3].privkey, wallets[2].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo1.test", wallets[3].privkey, wallets[2].addr, zonefile_hash='1a' * 20) testlib.blockstack_name_register("foo2.test", wallets[3].privkey, wallets[2].addr, zonefile_hash='2a' * 20) testlib.blockstack_name_register("foo3.test", wallets[3].privkey, wallets[2].addr, zonefile_hash='3a' * 20) testlib.next_block(**kw) # whois for i in xrange(1, 4): name = 'foo{}.test'.format(i) res = testlib.blockstack_cli_whois(name) if 'error' in res: print res return False if not res.has_key('zonefile_hash' ) or res['zonefile_hash'] != '{}a'.format(i) * 20: print res return False if res['owner_address'] != wallets[2].addr: print res return False
def scenario(wallets, **kw): global snv_block_id_foo, snv_txid_bar, snv_txid_baz, last_consensus # make a test namespace resp = testlib.blockstack_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.blockstack_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.blockstack_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_foo = testlib.get_current_block() resp = testlib.blockstack_name_import("bar.test", wallets[5].addr, "33" * 20, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.blockstack_name_import("baz.test", wallets[6].addr, "33" * 20, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.blockstack_namespace_ready("test", wallets[1].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.blockstack_name_transfer("bar.test", wallets[4].addr, True, wallets[5].privkey) if 'error' in resp: print json.dumps(resp, indent=4) snv_txid_bar = resp['transaction_hash'] testlib.next_block(**kw) resp = testlib.blockstack_name_update("baz.test", "22" * 20, wallets[6].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(**kw))
def scenario(wallets, **kw): global synchronized import blockstack_integration_tests.atlas_network as atlas_network testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_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.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) # set up RPC daemon test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) wallet_keys = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey, data_privkey=wallets[4].privkey, payment_privkey=wallets[5].privkey) testlib.blockstack_client_set_wallet("0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey']) # register 10 names for i in xrange(0, 10): res = testlib.blockstack_name_preorder("foo_{}.test".format(i), wallets[2].privkey, wallets[3].addr) if 'error' in res: print json.dumps(res) return False testlib.next_block(**kw) for i in xrange(0, 10): res = testlib.blockstack_name_register("foo_{}.test".format(i), wallets[2].privkey, wallets[3].addr) if 'error' in res: print json.dumps(res) return False testlib.next_block(**kw) # start up a simple Atlas test network with two nodes: the main one doing the test, and a subordinate one that treats it as a seed peer. network_des = atlas_network.atlas_network_build( testlib.working_dir(**kw), [17000], {17000: [16264]}, {}, os.path.join(testlib.working_dir(**kw), "atlas_network")) atlas_network.atlas_network_start(network_des) time.sleep(5.0) # make 10 empty zonefiles and propagate them for i in xrange(0, 10): data_pubkey = virtualchain.BitcoinPrivateKey( wallet_keys['data_privkey']).public_key().to_hex() empty_zonefile = blockstack_client.zonefile.make_empty_zonefile( "foo_{}.test".format(i), data_pubkey, urls=["file:///tmp/foo_{}.test".format(i)]) empty_zonefile_str = blockstack_zones.make_zone_file(empty_zonefile) value_hash = blockstack_client.hash_zonefile(empty_zonefile) res = testlib.blockstack_name_update("foo_{}.test".format(i), value_hash, wallets[3].privkey) if 'error' in res: print json.dumps(res) return False testlib.next_block(**kw) res = testlib.blockstack_put_zonefile(empty_zonefile_str) if not res: return False # wait at most 10 seconds for atlas network to converge synchronized = False for i in xrange(0, 10): atlas_network.atlas_print_network_state(network_des) if atlas_network.atlas_network_is_synchronized( network_des, testlib.last_block(**kw) - 1, 1): print "Synchronized!" synchronized = True break else: time.sleep(1.0) # shut down atlas_network.atlas_network_stop(network_des) return synchronized
def scenario(wallets, **kw): global zonefile_hash testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_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.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey) resp = testlib.blockstack_cli_register("foo.test", "0123456789abcdef") if 'error' in resp: print >> sys.stderr, json.dumps(resp, indent=4, sort_keys=True) return False # wait for the preorder to get confirmed for i in xrange(0, 12): testlib.next_block(**kw) # wait for the poller to pick it up print >> sys.stderr, "Waiting 10 seconds for the backend to submit the register" time.sleep(10) # wait for the register to get confirmed for i in xrange(0, 12): # warn the serialization checker that this changes behavior from 0.13 print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge registration" time.sleep(10) # wait for update to get confirmed for i in xrange(0, 12): # warn the serialization checker that this changes behavior from 0.13 print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge update" time.sleep(10) # transfer to a new address resp = testlib.blockstack_cli_transfer("foo.test", wallets[4].addr, "0123456789abcdef") if 'error' in resp: print >> sys.stderr, "transfer error: %s" % resp['error'] return False # wait for it to go through for i in xrange(0, 12): # warn the serialization checker that this changes behavior from 0.13 print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge the transfer" time.sleep(10) testlib.next_block(**kw)
def scenario(wallets, **kw): global put_result, wallet_keys, datasets, zonefile_hash, dataset_change wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) wallet_keys = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey, data_privkey=wallets[4].privkey) testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_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.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) resp = testlib.blockstack_cli_register("foo.test", "0123456789abcdef") if 'error' in resp: print >> sys.stderr, json.dumps(resp, indent=4, sort_keys=True) return False # wait for the preorder to get confirmed for i in xrange(0, 12): testlib.next_block(**kw) # wait for the poller to pick it up print >> sys.stderr, "Waiting for the backend to submit the register" time.sleep(10) # wait for the register to get confirmed for i in xrange(0, 12): testlib.next_block(**kw) print >> sys.stderr, "Waiting for the backend to acknowledge registration" time.sleep(10) # wait for initial update to get confirmed for i in xrange(0, 12): # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) print >> sys.stderr, "Waiting for the backend to acknowledge update" time.sleep(10) # wait for zonefile/profile replication for i in xrange(0, 12): testlib.next_block(**kw) print >> sys.stderr, "Waiting for the backend to replicate zonefile and profile" time.sleep(10) # make a few accounts res = testlib.blockstack_cli_put_account("foo.test", "serviceFoo", "serviceFooID", "foo://bar.com", "0123456789abcdef", extra_data='foofield=foo!', wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to create foo.test serviceFoo account' print json.dumps(res, indent=4, sort_keys=True) error = True return time.sleep(2) res = testlib.blockstack_cli_put_account("foo.test", "serviceBar", "serviceBarID", "bar://baz.com", "0123456789abcdef", extra_data='barfield=bar!', wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to create foo.test serviceBar account' print json.dumps(res, indent=4, sort_keys=True) error = True return time.sleep(2) # put some data put_result = testlib.blockstack_cli_put_mutable( "foo.test", "hello_world_1", json.dumps(datasets[0]), password="******") if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.next_block(**kw) time.sleep(2) put_result = testlib.blockstack_cli_put_mutable( "foo.test", "hello_world_2", json.dumps(datasets[1]), password="******", \ storage_drivers=['blockstack_server'], storage_drivers_exclusive=True) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False time.sleep(2) put_result = testlib.blockstack_cli_put_mutable( "foo.test", "hello_world_3", json.dumps(datasets[2]), password="******", \ storage_drivers=['blockstack_server'], storage_drivers_exclusive=True) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False time.sleep(2) # increment data version too datasets[0]['buf'] = [] for i in xrange(0, 5): datasets[0]["dataset_change"] = dataset_change datasets[0]['buf'].append(i) put_result = testlib.blockstack_cli_put_mutable( "foo.test", "hello_world_1", json.dumps(datasets[0]), password="******", \ storage_drivers=['blockstack_server'], storage_drivers_exclusive=True) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False time.sleep(2) testlib.next_block(**kw)
def scenario(wallets, **kw): global debug resp = testlib.blockstack_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.blockstack_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.blockstack_namespace_ready("test", wallets[1].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr, wallet=wallets[3]) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr, wallet=wallets[3]) 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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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.blockstack_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): global update_blocks, transfer_blocks, update_hashes, transfer_recipients testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_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) testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) consensus_hash = testlib.get_consensus_at(testlib.get_current_block(**kw), **kw) testlib.next_block(**kw) testlib.next_block(**kw) # preorder, register, update, expire (multiple times) # account for namespace lifetime multipler (in 0.0.14) for i in xrange(2, 5): resp = testlib.blockstack_name_preorder("foo.test", wallets[i].privkey, wallets[(i + 1) % 11].addr, consensus_hash=consensus_hash) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) consensus_hash = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw) testlib.next_block(**kw) testlib.next_block(**kw) resp = testlib.blockstack_name_register("foo.test", wallets[i].privkey, wallets[(i + 1) % 11].addr) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) consensus_hash = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw) testlib.next_block(**kw) testlib.next_block(**kw) resp = testlib.blockstack_name_update("foo.test", ("%02x" % i) * 20, wallets[(i + 1) % 11].privkey, consensus_hash=consensus_hash) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) update_blocks.append(testlib.get_current_block(**kw)) update_hashes.append(("%02x" % i) * 20) consensus_hash = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw) testlib.next_block(**kw) testlib.next_block(**kw) resp = testlib.blockstack_name_transfer("foo.test", wallets[i].addr, True, wallets[(i + 1) % 11].privkey, consensus_hash=consensus_hash) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) transfer_blocks.append(testlib.get_current_block(**kw)) transfer_recipients.append(wallets[i].addr) consensus_hash = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw) testlib.next_block(**kw) testlib.next_block(**kw) if i == 4: break # eat up the rest of the lifetime for j in xrange(0, 10 * NAMESPACE_LIFETIME_MULTIPLIER - 10): testlib.next_block(**kw) consensus_hash = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw) testlib.next_block(**kw) testlib.next_block(**kw) testlib.next_block(**kw)
def scenario(wallets, **kw): testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) res = testlib.blockstack_namespace_preorder("teststacks", wallets[1].addr, wallets[3].privkey, safety_checks=False, price={ 'units': 'STACKS', 'amount': 64000000 }, tx_only=True) ns_preorder_tx_stacks = res['transaction'] res = testlib.blockstack_namespace_preorder('test2', wallets[1].addr, wallets[2].privkey, tx_only=True) ns_preorder_tx = res['transaction'] testlib.broadcast_transaction(ns_preorder_tx_stacks) testlib.next_block(**kw) # end of 689 # should have only accepted one operation block_stats = virtualchain.lib.indexer.StateEngine.get_block_statistics( testlib.get_current_block(**kw)) if block_stats['num_parsed_ops'] != 1: print 'invalid number of parsed ops: {}'.format( block_stats['num_parsed_ops']) return False # try to register a Stacks transaction (should fail) testlib.blockstack_namespace_reveal( "teststacks", 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[3].privkey) testlib.next_block(**kw) # end of 690, begin Stacks testlib.expect_snv_fail_at('teststacks', testlib.get_current_block(**kw)) # should not be accepted, since no stacks are paid testlib.broadcast_transaction(ns_preorder_tx) # should succeed, even though preordered after the Stacks token activation testlib.blockstack_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) # end of 690 testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) # should fail testlib.blockstack_namespace_reveal( "test2", 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[2].privkey) testlib.next_block(**kw)
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, key_names, error, gpghome testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.blockstack_name_preorder( "bar.test", wallets[5].privkey, wallets[6].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.blockstack_name_register( "bar.test", wallets[5].privkey, wallets[6].addr ) testlib.next_block( **kw ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) wallet_keys = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey, payment_privkey=wallets[8].privkey ) wallet_keys_2 = blockstack_client.make_wallet_keys( owner_privkey=wallets[6].privkey, payment_privkey=wallets[9].privkey ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return res = testlib.migrate_profile( "bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2 ) if 'error' in res: res['test'] = 'Failed to initialize bar.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) # add account keys testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], None ) res = blockstack_gpg.gpg_profile_create_key( "foo.test", "foo_test_account_key", immutable=False, proxy=test_proxy, wallet_keys=wallet_keys, config_dir=testlib.get_working_dir(**kw), gpghome=testlib.gpg_key_dir(**kw), use_key_server=False ) if 'error' in res: res['test'] = 'Failed to create foo.test account key' print json.dumps(res, indent=4, sort_keys=True) error = True return else: key_names['foo.test'].append( res ) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], None ) res = blockstack_gpg.gpg_profile_create_key( "bar.test", "bar_test_account_key", immutable=False, proxy=test_proxy, wallet_keys=wallet_keys_2, config_dir=testlib.get_working_dir(**kw), gpghome=testlib.gpg_key_dir(**kw), use_key_server=False ) if 'error' in res: res['test'] = 'Failed to create bar.test account key' print json.dumps(res, indent=4, sort_keys=True) error = True return else: key_names['bar.test'].append( res ) testlib.next_block( **kw ) # add immutable app keys testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], None ) res = blockstack_gpg.gpg_app_create_key( "foo.test", "secure_messaging", "foo_test_immutable_secmsg_key", immutable=True, proxy=test_proxy, wallet_keys=wallet_keys, config_dir=testlib.get_working_dir(**kw) ) if 'error' in res: res['test'] = 'Failed to create foo.test immutable app key' print json.dumps(res, indent=4, sort_keys=True) error = True return else: key_names['foo.test'].append( res ) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for it to go through for i in xrange(0, 12): testlib.next_block( **kw ) print "wait for confirmation" time.sleep(10) testlib.next_block( **kw ) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], None ) res = blockstack_gpg.gpg_app_create_key( "bar.test", "secure_messaging", "bar_test_immutable_secmsg_key", immutable=True, proxy=test_proxy, wallet_keys=wallet_keys_2, config_dir=testlib.get_working_dir(**kw) ) if 'error' in res: res['test'] = 'Failed to create bar.test immutable app key' print json.dumps(res, indent=4, sort_keys=True ) error = True return else: key_names['bar.test'].append( res ) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for it to go through for i in xrange(0, 12): testlib.next_block( **kw ) print "wait for confirmation" time.sleep(10) testlib.next_block( **kw ) # add mutable app keys testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], None ) res = blockstack_gpg.gpg_app_create_key( "foo.test", "less-secure_messaging", "foo_test_mutable_secmsg_key", proxy=test_proxy, wallet_keys=wallet_keys, config_dir=testlib.get_working_dir(**kw) ) if 'error' in res: res['test'] = 'Failed to create foo.test mutable app key' print json.dumps(res, indent=4, sort_keys=True) error = True return else: key_names['foo.test'].append( res ) testlib.next_block( **kw ) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], None ) res = blockstack_gpg.gpg_app_create_key( "bar.test", "less-secure_messaging", "bar_test_mutable_secmsg_key", proxy=test_proxy, wallet_keys=wallet_keys_2, config_dir=testlib.get_working_dir(**kw) ) if 'error' in res: res['test'] = 'Failed to create bar.test mutable app key' print json.dumps(res, indent=4, sort_keys=True ) error = True return else: key_names['bar.test'].append( res ) testlib.next_block( **kw ) # add profile keys that we'll delete testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], None ) res = blockstack_gpg.gpg_profile_create_key( "foo.test", "foo_test_deleted_account_key", immutable=True, proxy=test_proxy, wallet_keys=wallet_keys, config_dir=testlib.get_working_dir(**kw), gpghome=testlib.gpg_key_dir(**kw), use_key_server=False) foo_profile_delete_key_id = None if 'error' in res: res['test'] = 'Failed to create deletable foo.test account key' print json.dumps(res, indent=4, sort_keys=True) error = True return else: key_names['foo.test'].append( res ) foo_profile_delete_key_id = res['key_id'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for it to go through for i in xrange(0, 12): testlib.next_block( **kw ) print "wait for confirmation" time.sleep(10) testlib.next_block( **kw ) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], None ) res = blockstack_gpg.gpg_profile_create_key( "bar.test", "bar_test_deleted_account_key", immutable=True, proxy=test_proxy, wallet_keys=wallet_keys_2, config_dir=testlib.get_working_dir(**kw), gpghome=testlib.gpg_key_dir(**kw), use_key_server=False) bar_profile_delete_key_id = None if 'error' in res: res['test'] = 'Failed to create deletable bar.test account key' print json.dumps(res, indent=4, sort_keys=True) error = True return else: key_names['bar.test'].append( res ) bar_profile_delete_key_id = res['key_id'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for it to go through for i in xrange(0, 12): testlib.next_block( **kw ) print "wait for confirmation" time.sleep(10) testlib.next_block( **kw ) # add immutable app keys, which we can delete testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], None ) res = blockstack_gpg.gpg_app_create_key( "foo.test", "immutable_delete", "foo_test_deleted_immutable_secmsg_key", immutable=True, proxy=test_proxy, wallet_keys=wallet_keys, config_dir=testlib.get_working_dir(**kw) ) foo_immutable_delete_key_id = None if 'error' in res: res['test'] = 'Failed to create deletable foo.test immutable app key' print json.dumps(res, indent=4, sort_keys=True) error = True return else: key_names['foo.test'].append( res ) foo_immutable_delete_key_id = res['key_id'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for it to go through for i in xrange(0, 12): testlib.next_block( **kw ) print "wait for confirmation" time.sleep(10) testlib.next_block( **kw ) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], None ) res = blockstack_gpg.gpg_app_create_key( "bar.test", "immutable_delete", "bar_test_deleted_immutable_secmsg_key", immutable=True, proxy=test_proxy, wallet_keys=wallet_keys_2, config_dir=testlib.get_working_dir(**kw) ) bar_immutable_delete_key_id = None if 'error' in res: res['test'] = 'Failed to create deletable bar.test immutable app key' print json.dumps(res, indent=4, sort_keys=True ) error = True return else: key_names['bar.test'].append( res ) bar_immutable_delete_key_id = res['key_id'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for it to go through for i in xrange(0, 12): testlib.next_block( **kw ) print "wait for confirmation" time.sleep(10) testlib.next_block( **kw ) # add mutable app keys which we can delete testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], None ) res = blockstack_gpg.gpg_app_create_key( "foo.test", "mutable_delete", "foo_test_deleted_mutable_secmsg_key", proxy=test_proxy, wallet_keys=wallet_keys, config_dir=testlib.get_working_dir(**kw) ) foo_mutable_delete_key_id = None if 'error' in res: res['test'] = 'Failed to create deletable mutable foo.test app key' print json.dumps(res, indent=4, sort_keys=True) error = True return else: key_names['foo.test'].append( res ) foo_mutable_delete_key_id = res['key_id'] testlib.next_block( **kw ) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], None ) res = blockstack_gpg.gpg_app_create_key( "bar.test", "mutable_delete", "bar_test_deleted_mutable_secmsg_key", proxy=test_proxy, wallet_keys=wallet_keys_2, config_dir=testlib.get_working_dir(**kw) ) bar_mutable_delete_key_id = None if 'error' in res: res['test'] = 'Failed to create deletable mutable bar.test app key' print json.dumps(res, indent=4, sort_keys=True ) error = True return else: key_names['bar.test'].append( res ) bar_mutable_delete_key_id = res['key_id'] testlib.next_block( **kw ) # delete profile keys testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], None ) res = blockstack_gpg.gpg_profile_delete_key( "foo.test", foo_profile_delete_key_id, proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to create deletable account foo.test profile key' print json.dumps(res, indent=4, sort_keys=True ) error = True return testlib.next_block( **kw ) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], None ) res = blockstack_gpg.gpg_profile_delete_key( "bar.test", bar_profile_delete_key_id, proxy=test_proxy, wallet_keys=wallet_keys_2 ) if 'error' in res: res['test'] = 'Failed to create deletable account bar.test profile key' print json.dumps(res, indent=4, sort_keys=True ) error = True return # delete immutable app keys testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], None ) res = blockstack_gpg.gpg_app_delete_key( "foo.test", "immutable_delete", "foo_test_deleted_immutable_secmsg_key", immutable=True, proxy=test_proxy, wallet_keys=wallet_keys, config_dir=testlib.get_working_dir(**kw)) if 'error' in res: res['test'] = 'Failed to create deletable foo.test immutable app key' print json.dumps(res, indent=4, sort_keys=True ) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for it to go through for i in xrange(0, 12): testlib.next_block( **kw ) print "wait for confirmation" time.sleep(10) testlib.next_block( **kw ) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], None ) res = blockstack_gpg.gpg_app_delete_key( "bar.test", "immutable_delete", "bar_test_deleted_immutable_secmsg_key", immutable=True, proxy=test_proxy, wallet_keys=wallet_keys_2, config_dir=testlib.get_working_dir(**kw)) if 'error' in res: res['test'] = 'Failed to create deletable bar.test immutable app key' print json.dumps(res, indent=4, sort_keys=True ) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for it to go through for i in xrange(0, 12): testlib.next_block( **kw ) print "wait for confirmation" time.sleep(10) testlib.next_block( **kw ) # delete mutable app keys testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], None ) res = blockstack_gpg.gpg_app_delete_key( "foo.test", "mutable_delete", "foo_test_deleted_mutable_secmsg_key", proxy=test_proxy, wallet_keys=wallet_keys, config_dir=testlib.get_working_dir(**kw)) if 'error' in res: res['test'] = 'Failed to create deletable foo.test mutable app key' print json.dumps(res, indent=4, sort_keys=True ) error = True return testlib.next_block( **kw ) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], None ) res = blockstack_gpg.gpg_app_delete_key( "bar.test", "mutable_delete", "bar_test_deleted_mutable_secmsg_key", proxy=test_proxy, wallet_keys=wallet_keys_2, config_dir=testlib.get_working_dir(**kw)) if 'error' in res: res['test'] = 'Failed to create deletable bar.test mutable app key' print json.dumps(res, indent=4, sort_keys=True ) error = True return testlib.next_block( **kw ) gpghome = testlib.gpg_key_dir(**kw)
def scenario(wallets, **kw): global FOO_ZONEFILE_HASH, HELLO_FOO_ZONEFILE_HASH, CONSENSUS_HASH zf_template = "$ORIGIN {}\n$TTL 3600\n{}" zf_default_url = '_https._tcp URI 10 1 "https://raw.githubusercontent.com/nobody/content/profile.md"' hello_foo_zonefile = zf_template.format('bar.foo.test', zf_default_url) foo_zonefile = zf_template.format( 'foo.test', subdomains.make_subdomain_txt('hello.foo.test', 'foo.test', wallets[3].addr, 0, hello_foo_zonefile, wallets[3].privkey)) HELLO_FOO_ZONEFILE_HASH = blockstack.lib.storage.get_zonefile_data_hash( hello_foo_zonefile) FOO_ZONEFILE_HASH = blockstack.lib.storage.get_zonefile_data_hash( foo_zonefile) testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_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.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr, zonefile_hash=FOO_ZONEFILE_HASH) testlib.next_block(**kw) testlib.blockstack_put_zonefile(foo_zonefile) testlib.next_block(**kw) CONSENSUS_HASH = testlib.get_consensus_at(testlib.get_current_block(**kw)) errors = [] fixtures = get_fixtures() for entry in fixtures: url = 'http://localhost:16268' + entry['route'] res = requests.get(url, allow_redirects=False) res_status = res.status_code res_txt = res.text res_json = None try: res_json = res.json() except: pass if 'status' in entry and entry['status'] != res_status: err = '{}: status {} (expected {})\nbody: {}'.format( url, res_status, entry['status'], res_txt) print >> sys.stderr, err errors.append(err) if 'body' in entry and ( (res_json is not None and entry['body'] != res_json) or (res_json is None and res_txt != entry['body'])): err = '{}: wrong body {} (expected {})'.format( url, res_txt, entry['body']) print >> sys.stderr, err errors.append(err) if len(errors) > 0: print >> sys.stderr, json.dumps(errors, indent=4) return False
def scenario(wallets, **kw): testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) # 689 testlib.blockstack_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) # 690 testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) # 691 testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) # 692 testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) # 693 whois = testlib.blockstack_cli_whois("foo.test") if 'error' in whois: print whois return False ''' # DEPRECATED: CLI does not know about this epoch shift # should fail (safety checks stop it) resp = testlib.blockstack_name_renew( "foo.test", wallets[3].privkey, zonefile_hash='22' * 20, recipient_addr=wallets[0].addr, expect_fail=True) if 'error' not in resp: print resp return False ''' # should succeed in being sent resp = testlib.blockstack_name_renew("foo.test", wallets[3].privkey, zonefile_hash='22' * 20, recipient_addr=wallets[0].addr, safety_checks=False, tx_fee=10000 * 5) if 'error' in resp: print resp return False # should fail to get accepted testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw)) testlib.next_block(**kw) # 694 # should NOT have been renewed whois2 = testlib.blockstack_cli_whois('foo.test') if 'error' in whois: print whois return False if whois2['block_renewed_at'] != whois['block_renewed_at']: print 'accidentally renewed' print whois print whois2 return False # activate epoch 3 testlib.next_block(**kw) # 695 # should succeed resp = testlib.blockstack_name_renew("foo.test", wallets[3].privkey, zonefile_hash='22' * 20, recipient_addr=wallets[0].addr) if 'error' in resp: print resp return False testlib.next_block(**kw) # 696
def scenario(wallets, **kw): global put_result, wallet_keys, datasets, zonefile_hash, dataset_change wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, None) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) wallet_keys = wallet testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_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.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) # migrate profile res = testlib.migrate_profile("foo.test", proxy=test_proxy, wallet_keys=wallet_keys, zonefile_has_data_key=False) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return else: zonefile_hash = res['zonefile_hash'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) put_result = testlib.blockstack_cli_put_mutable( "foo.test", "hello_world_1", json.dumps(datasets[0]), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) testlib.next_block(**kw) put_result = testlib.blockstack_cli_put_mutable( "foo.test", "hello_world_2", json.dumps(datasets[1]), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) put_result = testlib.blockstack_cli_put_mutable( "foo.test", "hello_world_3", json.dumps(datasets[2]), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) # increment version too datasets[0]['buf'] = [] for i in xrange(0, 5): datasets[0]["dataset_change"] = dataset_change datasets[0]['buf'].append(i) put_result = testlib.blockstack_cli_put_mutable( "foo.test", "hello_world_1", json.dumps(datasets[0]), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) testlib.next_block(**kw)
def scenario(wallets, **kw): global zonefile_hash testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_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.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey) resp = testlib.blockstack_rpc_register("foo.test", "0123456789abcdef") if 'error' in resp: print >> sys.stderr, json.dumps(resp, indent=4, sort_keys=True) return False # wait for the preorder to get confirmed for i in xrange(0, 12): testlib.next_block(**kw) # wait for the poller to pick it up print >> sys.stderr, "Waiting 10 seconds for the backend to submit the register" time.sleep(10) # wait for the register to get confirmed for i in xrange(0, 12): testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge registration" time.sleep(10) # wait for initial update to get confirmed for i in xrange(0, 12): testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge update" time.sleep(10) # what's the name's renewal block? proxy = testlib.make_proxy() res = blockstack_client.get_name_blockchain_record("foo.test", proxy=proxy) if 'error' in res: print >> sys.stderr, json.dumps(res, indent=4, sort_keys=True) return False old_expire_block = res['expire_block'] # send an update, changing the zonefile data_pubkey = wallet['data_pubkey'] zonefile = blockstack_client.user.make_empty_user_zonefile( "foo.test", data_pubkey) blockstack_client.user.put_immutable_data_zonefile( zonefile, "testdata", blockstack_client.get_data_hash("testdata"), data_url="file:///testdata") zonefile_json = json.dumps(zonefile) resp = testlib.blockstack_rpc_update("foo.test", zonefile_json, "0123456789abcdef") if 'error' in resp: print >> sys.stderr, "update error: %s" % resp['error'] return False zonefile_hash = resp['zonefile_hash'] # wait for it to go through for i in xrange(0, 12): testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowedge the update" time.sleep(10) # wait for it to go through for i in xrange(0, 12): testlib.next_block(**kw) # revoke it resp = testlib.blockstack_rpc_revoke("foo.test", "0123456789abcdef") if 'error' in resp: print >> sys.stderr, "Revoke request failed:\n%s" % json.dumps( resp, indent=4, sort_keys=True) return False print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge the revoke" time.sleep(10) # wait for it to go through for i in xrange(0, 12): testlib.next_block(**kw)
def scenario( wallets, **kw ): # make a test namespace resp = testlib.blockstack_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.blockstack_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.blockstack_namespace_ready( "test", wallets[1].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) # preorder 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]] for i in xrange(0, len(names)): name = names[i] preorder_wallet = name_preorder_wallets[i] register_wallet = name_register_wallets[i] resp = testlib.blockstack_name_preorder( name, preorder_wallet.privkey, register_wallet.addr ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) # regster 3 names in the same block for i in xrange(0, len(names)): name = names[i] preorder_wallet = name_preorder_wallets[i] register_wallet = name_register_wallets[i] resp = testlib.blockstack_name_register( name, preorder_wallet.privkey, register_wallet.addr ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) 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.blockstack_name_update( name, str(i + 1) * 40, register_wallet.privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) 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.blockstack_name_transfer( name, transfer_wallet.addr, True, register_wallet.privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) # exchange after transfer... tmp = name_register_wallets name_register_wallets = name_transfer_wallets name_transfer_wallets = tmp # renew 3 names in the same block for i in xrange(0, len(names)): name = names[i] register_wallet = name_register_wallets[i] resp = testlib.blockstack_name_renew( name, register_wallet.privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) # 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.blockstack_name_revoke( name, register_wallet.privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) # iterate the blocks a few times for i in xrange(0, 5): testlib.next_block( **kw )
def scenario(wallets, **kw): global zonefile_hash testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_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.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey) resp = testlib.blockstack_cli_register("foo.test", "0123456789abcdef") if 'error' in resp: print >> sys.stderr, json.dumps(resp, indent=4, sort_keys=True) return False # wait for the preorder to get confirmed for i in xrange(0, 12): testlib.next_block(**kw) # wait for the poller to pick it up print >> sys.stderr, "Waiting 10 seconds for the backend to submit the register" time.sleep(10) # wait for the register to get confirmed for i in xrange(0, 12): # warn the serialization checker that this changes behavior from 0.13 print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge registration" time.sleep(10) # wait for initial update to get confirmed for i in xrange(0, 12): # warn the serialization checker that this changes behavior from 0.13 print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge update" time.sleep(10) # store a new zonefile data_pubkey = wallet['data_pubkey'] zonefile = blockstack_client.zonefile.make_empty_zonefile( "foo.test", data_pubkey) assert blockstack_client.user.put_immutable_data_zonefile( zonefile, "testdata", blockstack_client.get_data_hash("testdata")) zonefile_txt = blockstack_zones.make_zone_file(zonefile) zonefile_hash = blockstack_client.storage.get_zonefile_data_hash( zonefile_txt) print >> sys.stderr, "\n\nzonefile hash: %s\nzonefile:\n%s\n\n" % ( zonefile_hash, zonefile_txt) # will store to queue test_proxy = testlib.make_proxy() config_path = test_proxy.config_path conf = blockstack_client.config.get_config(config_path) queuedb_path = conf['queue_path'] # update the zonefile hash, but not the zonefile. resp = testlib.blockstack_cli_set_zonefile_hash("foo.test", zonefile_hash) if 'error' in resp: print >> sys.stderr, "\nFailed to set zonefile hash: %s\n" % resp return False txhash = resp['transaction_hash'] for i in xrange(0, 12): # warn the serialization checker that this changes behavior from 0.13 print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge update" time.sleep(10) # stop endpoint print >> sys.stderr, "\nstopping RPC daemon\n" testlib.stop_api() time.sleep(3) # store to queue res = blockstack_client.backend.queue.queue_append( "update", "foo.test", txhash, payment_address=wallets[2].addr, owner_address=wallets[3].addr, config_path=test_proxy.config_path, zonefile_data=zonefile_txt, zonefile_hash=zonefile_hash, path=queuedb_path) # verify that we can sync the zonefile, using the in-queue zonefile resp = testlib.blockstack_cli_sync_zonefile("foo.test") if 'error' in resp: print >> sys.stderr, "\nfailed to sync zonefile: %s\n" % resp return False blockstack_client.backend.queue.queuedb_remove("update", "foo.test", txhash, path=queuedb_path) print >> sys.stderr, "\nstarting RPC daemon\n" testlib.start_api("0123456789abcdef") # store a new zonefile zonefile = blockstack_client.zonefile.make_empty_zonefile( "foo.test", data_pubkey) blockstack_client.user.put_immutable_data_zonefile( zonefile, "testdata2", blockstack_client.get_data_hash("testdata")) zonefile_txt = blockstack_zones.make_zone_file(zonefile) zonefile_hash = blockstack_client.storage.get_zonefile_data_hash( zonefile_txt) # store locally res = blockstack_client.zonefile.store_name_zonefile( "foo.test", zonefile, None, storage_drivers=['disk']) if 'error' in res: print >> sys.stderr, "\nFailed to store zonefile: %s\n" % res return False # update the zonefile hash, but not the zonefile. resp = testlib.blockstack_cli_set_zonefile_hash("foo.test", zonefile_hash) if 'error' in resp: print >> sys.stderr, "\nFailed to set zonefile hash: %s\n" % resp return False for i in xrange(0, 12): # warn the serialization checker that this changes behavior from 0.13 print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) # verify that we can sync the zonefile, using the on-disk zonefile resp = testlib.blockstack_cli_sync_zonefile("foo.test") if 'error' in resp: print >> sys.stderr, "update error: %s" % resp['error'] return False # wait for it to go through for i in xrange(0, 12): testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowedge the update" time.sleep(10)
def scenario(wallets, **kw): # make a test namespace resp = testlib.blockstack_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.blockstack_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.blockstack_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.blockstack_namespace_ready("test", wallets[1].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # consensus hash should be None db = testlib.get_state_engine() name_rec = db.get_name('foo.test') if name_rec['consensus_hash'] != None: print 'wrong consensus hash: expected None' print json.dumps(name_rec, indent=4, sort_keys=True) return False resp = testlib.blockstack_name_transfer("foo.test", wallets[4].addr, True, wallets[3].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # consensus hash should be the one from the last NAME_TRANSFER db = testlib.get_state_engine() name_rec = db.get_name('foo.test') if name_rec['consensus_hash'] != testlib.get_consensus_at( testlib.get_current_block(**kw) - 1): print 'wrong consensus hash: expected {}'.format( testlib.get_consensus_at(testlib.get_current_block(**kw) - 1)) print json.dumps(name_rec, indent=4, sort_keys=True) return False resp = testlib.blockstack_name_update("foo.test", "22" * 20, wallets[4].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # consensus hash should be the one from the last NAME_UPDATE db = testlib.get_state_engine() name_rec = db.get_name('foo.test') if name_rec['consensus_hash'] != testlib.get_consensus_at( testlib.get_current_block(**kw) - 1): print 'wrong consensus hash: expected {}'.format( testlib.get_consensus_at(testlib.get_current_block(**kw) - 1)) print json.dumps(name_rec, indent=4, sort_keys=True) return False
def scenario(wallets, **kw): global zonefile_hash testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_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.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[5].privkey) resp = testlib.blockstack_cli_register("foo.test", "0123456789abcdef") if 'error' in resp: print >> sys.stderr, json.dumps(resp, indent=4, sort_keys=True) return False # wait for the preorder to get confirmed for i in xrange(0, 12): testlib.next_block(**kw) # wait for the poller to pick it up print >> sys.stderr, "Waiting 10 seconds for the backend to submit the register" time.sleep(15) # wait for the register to get confirmed for i in xrange(0, 12): # warn the serialization checker that this changes behavior from 0.13 print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge registration" time.sleep(15) # wait for update to get confirmed for i in xrange(0, 12): # warn the serialization checker that this changes behavior from 0.13 print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge update" time.sleep(15) # send an update, changing the zonefile data_pubkey = wallet['data_pubkey'] zonefile = blockstack_client.zonefile.make_empty_zonefile( "foo.test", data_pubkey) blockstack_client.user.put_immutable_data_zonefile( zonefile, "testdata", blockstack_client.get_data_hash("testdata"), data_url="file:///testdata") zonefile_json = json.dumps(zonefile) resp = testlib.blockstack_cli_update("foo.test", zonefile_json, "0123456789abcdef") if 'error' in resp: print >> sys.stderr, "update error: %s" % resp['error'] return False zonefile_hash = resp['zonefile_hash'] # wait for it to go through for i in xrange(0, 12): # warn the serialization checker that this changes behavior from 0.13 print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowedge the update" time.sleep(15) # transfer to a new address resp = testlib.blockstack_cli_transfer("foo.test", wallets[4].addr, "0123456789abcdef") if 'error' in resp: print >> sys.stderr, "transfer error: %s" % resp['error'] return False # wait for it to go through for i in xrange(0, 12): # warn the serialization checker that this changes behavior from 0.13 print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge the transfer" time.sleep(15) # regenerate the wallet, with the new owner address wallet = testlib.blockstack_client_set_wallet("0123456789abcdef", wallets[5].privkey, wallets[4].privkey, wallets[5].privkey) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # send another update, changing the zonefile again # pay for it using the same payment address zonefile = blockstack_client.zonefile.make_empty_zonefile( "foo.test", new_data_pubkey) blockstack_client.user.put_immutable_data_zonefile( zonefile, "testdata", blockstack_client.get_data_hash("testdata"), data_url="file:///testdata") zonefile_json = json.dumps(zonefile) resp = testlib.blockstack_cli_update("foo.test", zonefile_json, "0123456789abcdef") if 'error' in resp: print >> sys.stderr, "update error: %s" % resp['error'] return False zonefile_hash = resp['zonefile_hash'] # wait for it to go through for i in xrange(0, 12): # warn the serialization checker that this changes behavior from 0.13 print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowedge the update" time.sleep(15)
def scenario(wallets, **kw): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_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.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) testlib.blockstack_client_set_wallet("0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey) # migrate profiles res = testlib.migrate_profile("foo.test", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) # make a session datastore_pk = keylib.ECPrivateKey(wallets[-1].privkey).to_hex() res = testlib.blockstack_cli_app_signin(datastore_pk, 'register.app', [ 'names', 'register', 'prices', 'zonefiles', 'blockchain', 'node_read', 'store_admin', 'store_read', 'store_write' ]) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] # make a datastore res = testlib.blockstack_REST_call('POST', '/v1/stores', ses) if 'error' in res or res['http_status'] != 200: print 'failed to create datastore' print json.dumps(res, indent=4, sort_keys=True) return False # get the data store id res = testlib.blockstack_REST_call('GET', '/v1/stores/register.app', ses) if 'error' in res or res['http_status'] != 200: print 'failed to get store' print json.dumps(res, indent=4, sort_keys=True) return False if 'error' in res['response']: print 'failed to get datastore' print json.dumps(res, indent=4, sort_keys=True) return False datastore_info = res['response'] datastore_name = datastore_info['datastore_id'] # get the data store name res = testlib.blockstack_REST_call('GET', '/v1/stores/register.app', ses) if 'error' in res or res['http_status'] != 200: print 'failed to get datastore' print json.dumps(res, indent=4, sort_keys=True) return False if 'error' in res['response']: print 'failed to get datastore' print json.dumps(res, indent=4, sort_keys=True) return False datastore_info = res['response'] datastore_name = datastore_info['datastore_id'] # make directories for dpath in ['/dir1', '/dir2', '/dir1/dir3', '/dir1/dir3/dir4']: print 'mkdir {}'.format(dpath) res = testlib.blockstack_REST_call( 'POST', '/v1/stores/{}/directories'.format(datastore_name), ses, path=dpath) if 'error' in res or res['http_status'] != 200: print 'failed to mkdir {}: {}'.format(dpath, res['http_status']) return False # stat directories for dpath in ['/dir1', '/dir2', '/dir1/dir3', '/dir1/dir3/dir4']: print 'stat {}'.format(dpath) res = testlib.blockstack_REST_call( 'GET', '/v1/stores/{}/inodes'.format(datastore_name), ses, path=dpath) if 'error' in res or res['http_status'] != 200: print 'failed to stat {}: {}'.format(dpath, res['http_status']) return False inode_info = res['response'] if inode_info[ 'type'] != blockstack_client.schemas.MUTABLE_DATUM_DIR_TYPE: print 'not a directory: {}, {}'.format(dpath, res) return False # list directories for dpath, expected in [('/', ['dir1', 'dir2']), ('/dir1', ['dir3']), ('/dir1/dir3', ['dir4']), ('/dir1/dir3/dir4', [])]: print 'listdir {}'.format(dpath) res = testlib.blockstack_REST_call( 'GET', '/v1/stores/{}/directories'.format(datastore_name), ses, path=dpath) if 'error' in res or res['http_status'] != 200: print 'failed to listdir {}: {}'.format(dpath, res['http_status']) return False dirinfo = res['response'] if len(dirinfo.keys()) != len(expected): print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format( expected, dirinfo) return False for child in expected: if not dirinfo.has_key(child): print 'invalid directory: missing {} in {}'.format( child, dirinfo) print json.dumps(res, indent=4, sort_keys=True) return False # put files for dpath in [ '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5' ]: print 'putfile {}'.format(dpath) data = 'hello {}'.format(os.path.basename(dpath)) res = testlib.blockstack_REST_call( 'POST', '/v1/stores/{}/files'.format(datastore_name), ses, raw_data=data, path=dpath) if 'error' in res or res['http_status'] != 200: print 'failed to putfile {}: {}'.format(dpath, res['http_status']) return False # stat files for dpath in [ '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5' ]: print 'stat {}'.format(dpath) res = testlib.blockstack_REST_call( 'GET', '/v1/stores/{}/inodes'.format(datastore_name), ses, path=dpath) if 'error' in res or res['http_status'] != 200: print 'failed to stat {}: {}'.format(dpath, res['http_status']) return False inode_data = res['response'] if inode_data[ 'type'] != blockstack_client.schemas.MUTABLE_DATUM_FILE_TYPE: print 'not a file: {}, {}'.format(dpath, res) return False # list directories again for dpath, expected in [('/', ['dir1', 'dir2', 'file1', 'file2']), ('/dir1', ['dir3', 'file3']), ('/dir1/dir3', ['dir4', 'file4']), ('/dir1/dir3/dir4', ['file5'])]: print 'listdir {}'.format(dpath) res = testlib.blockstack_REST_call( 'GET', '/v1/stores/{}/directories'.format(datastore_name), ses, path=dpath) if 'error' in res or res['http_status'] != 200: print 'failed to listdir {}: {}'.format(dpath, res['http_status']) return False dirinfo = res['response'] if len(dirinfo.keys()) != len(expected): print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format( expected, dirinfo) return False for child in expected: if not dirinfo.has_key(child): print 'invalid directory: missing {} in {}'.format( child, dirinfo) return False # get files for dpath in [ '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5' ]: print 'getfile {}'.format(dpath) res = testlib.blockstack_REST_call( 'GET', '/v1/stores/{}/files'.format(datastore_name), ses, path=dpath) if 'error' in res or res['http_status'] != 200: print 'failed to getfile {}: {}'.format(dpath, res['http_status']) return False filedata = res['raw'] if filedata != 'hello {}'.format(os.path.basename(dpath)): print 'failed to read {}: got "{}"'.format(dpath, filedata) return False # delete datastore res = testlib.blockstack_REST_call("DELETE", "/v1/stores", ses) if res['http_status'] != 200: print 'failed to delete datastore' print json.dumps(res) return False # nothing should be here res = testlib.blockstack_REST_call( 'GET', '/v1/stores/{}/directories'.format(datastore_name), ses, path='/') if res['http_status'] != 404: print 'got HTTP {} on getting deleted store'.format(res['http_status']) print json.dumps(res) return False