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 ): 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, 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 register_block, revoke_block # 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, 6, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.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 ) # wait for a bit... for i in xrange(0, 6): 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 ) # revoke it resp = testlib.blockstack_name_revoke( "foo.test", wallets[3].privkey ) if 'error' in resp: print json.dumps(resp, indent=4 ) testlib.next_block( **kw ) revoke_block = testlib.get_current_block( **kw ) # wait for it to expire for i in xrange(0, 6 * NAMESPACE_LIFETIME_MULTIPLIER): testlib.next_block( **kw ) # re-register testlib.blockstack_name_preorder( "foo.test", wallets[7].privkey, wallets[8].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[7].privkey, wallets[8].addr ) testlib.next_block( **kw ) register_block = testlib.get_current_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 ) # 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 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 ) 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 ): 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 ): 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 ): 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 ): 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 ): 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 ): global import_block_1, import_block_2 # 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, 10, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.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_1 = testlib.get_current_block( **kw ) testlib.next_block( **kw ) resp = testlib.blockstack_name_import( "foo.test", wallets[4].addr, "22" * 20, wallets[1].privkey ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) import_block_2 = testlib.get_current_block( **kw ) testlib.next_block( **kw ) resp = testlib.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, 10 * NAMESPACE_LIFETIME_MULTIPLIER): testlib.next_block( **kw ) # re-register testlib.blockstack_name_preorder( "foo.test", wallets[7].privkey, wallets[8].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[7].privkey, wallets[8].addr ) 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 ): 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 ): 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 ): 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 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 ) preorder_consensus = testlib.get_consensus_at( testlib.get_current_block() ) 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) 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) testlib.next_block( **kw ) # should cause the whole thing to fail, since we didn't preorder this separately resp = testlib.blockstack_name_register( "goo.test", wallets[2].privkey, wallets[5].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 ): 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 ): 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 ) # only wallets[3] should get it testlib.blockstack_name_register( "foo.test", wallets[4].privkey, wallets[3].addr, safety_checks=False ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr, safety_checks=False ) 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 ) 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 ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) testlib.next_block( **kw ) resp = testlib.blockstack_name_renew( "foo.test", wallets[3].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) testlib.next_block( **kw ) resp = testlib.blockstack_name_transfer( "foo.test", wallets[4].addr, True, wallets[3].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.blockstack_name_update( "foo.test", "11" * 20, wallets[4].privkey ) if debug or '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 ) # 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 ) for i in xrange(0, 15): 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 ) 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 ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.blockstack_name_update( "foo.test", "11" * 20, wallets[3].privkey ) if debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.blockstack_name_revoke( "foo.test", wallets[3].privkey ) if debug or '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 debug or 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_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, 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 ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # pre-0.0.14 uses lifetime field literally; this should no longer work. for i in xrange(0, 5 * NAMESPACE_LIFETIME_MULTIPLIER ): testlib.next_block( **kw ) 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 ) preorder_consensus = testlib.get_consensus_at( testlib.get_current_block() ) # these should all fail, since they're paired with the wrong addresses resp = testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[5].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) sys.exit(1) resp = testlib.blockstack_name_register( "bar.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[4].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) sys.exit(1) 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 ) # try to exceed quota (currently 25) for i in xrange(0, 25): resp = testlib.blockstack_name_preorder( "foo%s.test" % i, wallets[2].privkey, wallets[3].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) for i in xrange(0, 25): resp = testlib.blockstack_name_register( "foo%s.test" % i, wallets[2].privkey, wallets[3].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) resp = testlib.blockstack_name_preorder( "bar.test", wallets[2].privkey, wallets[3].addr ) if 'error' in resp: print json.dumps( resp, indent=4 ) testlib.next_block( **kw ) # should fail resp = testlib.blockstack_name_register( "bar.test", wallets[2].privkey, wallets[3].addr ) if '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, 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 ) # preorder, register, update, expire (multiple times) for i in xrange(2, 5): 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 ) 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 ) testlib.next_block( **kw ) update_blocks.append( testlib.get_current_block( **kw )) update_hashes.append( ("%02x" % i) * 20 ) 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 ) testlib.next_block( **kw ) transfer_blocks.append( testlib.get_current_block( **kw ) ) transfer_recipients.append( wallets[i].addr ) if i == 4: break for j in xrange(0, 2 * NAMESPACE_LIFETIME_MULTIPLIER - 1): 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 = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, None) # 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) # make an account res = testlib.blockstack_cli_put_account("foo.test", "serviceFoo", "serviceFooID", "foo://bar.com", None, extra_data='foofield=foo!', wallet_keys=wallet_keys) 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 = testlib.blockstack_cli_put_account("foo.test", "deletedService", "deletedServiceID", "foo://deleted", None, extra_data='barfield=bar!', wallet_keys=wallet_keys) 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 = testlib.blockstack_cli_delete_account("foo.test", "deletedService", "deletedServiceID", None, 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 wallet_keys, error, index_file_data, resource_data 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']) 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) datastore_id_res = testlib.blockstack_cli_datastore_get_id("foo-app.com") datastore_id = 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 # make directories for dpath in ['/dir1', '/dir2', '/dir1/dir3', '/dir1/dir3/dir4']: print 'mkdir {}'.format(dpath) res = testlib.blockstack_cli_datastore_mkdir("foo-app.com", dpath) if 'error' in res: print 'failed to mkdir {}: {}'.format(dpath, res['error']) return False # stat directories for dpath in ['/dir1', '/dir2', '/dir1/dir3', '/dir1/dir3/dir4']: print 'stat {}'.format(dpath) res = testlib.blockstack_cli_datastore_stat(datastore_id, dpath) if 'error' in res: print 'failed to stat {}: {}'.format(dpath, res['error']) return False if res['inode'][ '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_cli_datastore_listdir(datastore_id, dpath) if 'error' in res: print 'failed to listdir {}: {}'.format(dpath, res['error']) return False res = res['dir'] if len(res['idata'].keys()) != len(expected): print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format( expected, res['idata']) return False for child in expected: if not res['idata'].has_key(child): print 'invalid directory: missing {} in {}'.format( child, res['idata']) 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_cli_datastore_putfile('foo-app.com', dpath, data) if 'error' in res: print 'failed to putfile {}: {}'.format(dpath, res['error']) 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_cli_datastore_stat(datastore_id, dpath) if 'error' in res: print 'failed to stat {}: {}'.format(dpath, res['error']) return False if res['inode'][ '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_cli_datastore_listdir(datastore_id, dpath) if 'error' in res: print 'failed to listdir {}: {}'.format(dpath, res['error']) return False res = res['dir'] if len(res['idata'].keys()) != len(expected): print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format( expected, res['idata']) return False for child in expected: if not res['idata'].has_key(child): print 'invalid directory: missing {} in {}'.format( child, res['idata']) 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_cli_datastore_getfile(datastore_id, dpath) if 'error' in res: print 'failed to getfile {}: {}'.format(dpath, res['error']) return False res = res['file'] if res['idata'] != 'hello {}'.format(os.path.basename(dpath)): print 'failed to read {}: got "{}"'.format(dpath, res['idata']) return False # remove files for dpath in [ '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5' ]: print 'deletefile {}'.format(dpath) res = testlib.blockstack_cli_datastore_deletefile("foo-app.com", dpath) if 'error' in res: print 'failed to deletefile {}: {}'.format(dpath, res['error']) return False # stat files (should all fail) for dpath in [ '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5' ]: print 'stat {} (expect failure)'.format(dpath) res = testlib.blockstack_cli_datastore_stat(datastore_id, dpath) if 'error' not in res or 'errno' not in res: print 'accidentally succeeded to stat {}: {}'.format(dpath, res) return False if res['errno'] != errno.ENOENT: print 'wrong errno: {}'.format(res) return False # get files (should all fail) for dpath in [ '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5' ]: print 'getfile {} (expect failure)'.format(dpath) res = testlib.blockstack_cli_datastore_getfile(datastore_id, dpath) if 'error' not in res or 'errno' not in res: print 'accidentally succeeded to get {}: {}'.format(dpath, res) return False if res['errno'] != errno.ENOENT: print 'wrong errno: {}'.format(res) return False # list directories, 3rd time for dpath, expected in [('/', ['dir1', 'dir2']), ('/dir1', ['dir3']), ('/dir1/dir3', ['dir4']), ('/dir1/dir3/dir4', [])]: print 'listdir {}'.format(dpath) res = testlib.blockstack_cli_datastore_listdir(datastore_id, dpath) if 'error' in res: print 'failed to listdir {}: {}'.format(dpath, res['error']) return False res = res['dir'] if len(res['idata'].keys()) != len(expected): print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format( expected, res['idata']) return False for child in expected: if not res['idata'].has_key(child): print 'invalid directory: missing {} in {}'.format( child, res['idata']) return False # remove directories for dpath in ['/dir1/dir3/dir4', '/dir1/dir3', '/dir2', '/dir1']: print 'rmdir {}'.format(dpath) res = testlib.blockstack_cli_datastore_rmdir("foo-app.com", dpath) if 'error' in res: print 'failed to rmdir {}: {}'.format(dpath, res['error']) return False # stat directories (should all fail) for dpath in ['/dir1/dir3/dir4', '/dir1/dir3', '/dir2', '/dir1']: print 'stat {} (expect failure)'.format(dpath) res = testlib.blockstack_cli_datastore_stat(datastore_id, dpath) if 'error' not in res or 'errno' not in res: print 'accidentally succeeded to stat {}: {}'.format(dpath, res) return False if res['errno'] != errno.ENOENT: print 'wrong errno: {}'.format(res) return False # list directories (should all fail) for dpath, expected in [('/dir1', ['dir3']), ('/dir1/dir3', ['dir4']), ('/dir1/dir3/dir4', [])]: print 'listdir {} (expect failure)'.format(dpath) res = testlib.blockstack_cli_datastore_listdir(datastore_id, dpath) if 'error' not in res or 'errno' not in res: print 'accidentally succeeded to list {}: {}'.format(dpath, res) return False if res['errno'] != errno.ENOENT: print 'wrong errno: {}'.format(res) return False # root should be empty print 'listdir {}'.format('/') res = testlib.blockstack_cli_datastore_listdir(datastore_id, '/') if 'error' in res: print 'failed to listdir /: {}'.format(res['error']) return False res = res['dir'] if len(res['idata'].keys()) > 0: print 'root still has children: {}'.format(res['idata'].keys()) return False # delete datastore print 'delete datastore' res = testlib.blockstack_cli_delete_datastore('foo-app.com') if 'error' in res: print 'failed to delete foo-app.com datastore' print json.dumps(res) return False # no more data in disk driver names = os.listdir("/tmp/blockstack-disk/mutable") if names != ['foo.test']: print 'improper cleanup' return False testlib.next_block(**kw)
def scenario(wallets, **kw): global datasets, put_result, legacy_profile, data_history_1, data_history_2, data_history_3 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) # empty data testlib.blockstack_name_update("foo.test", "00" * 20, wallets[3].privkey) data_history_1.append("missing zonefile") data_history_2.append("missing zonefile") data_history_3.append("missing zonefile") 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 = testlib.blockstack_name_update("foo.test", legacy_hash, wallets[3].privkey) data_history_1.append("non-standard zonefile") data_history_2.append("non-standard zonefile") data_history_3.append("non-standard zonefile") testlib.next_block(**kw) rc = blockstack_client.storage.put_immutable_data( legacy_txt, result['transaction_hash'], data_hash=legacy_hash) assert rc is not None # put immutable data 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) # 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 # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) data_history_1.append("data not defined") data_history_2.append("data not defined") data_history_3.append("data not defined") 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 put_result = blockstack_client.put_immutable("foo.test", "hello_world_1", json.dumps(datasets[0], sort_keys=True), proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) testlib.expect_atlas_zonefile(put_result['zonefile_hash']) data_history_1.append(put_result['immutable_data_hash']) data_history_2.append("data not defined") data_history_3.append("data not defined") # 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) put_result = blockstack_client.put_immutable("foo.test", "hello_world_2", json.dumps(datasets[1], sort_keys=True), proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) testlib.expect_atlas_zonefile(put_result['zonefile_hash']) data_history_1.append(data_history_1[-1]) data_history_2.append(put_result['immutable_data_hash']) data_history_3.append("data not defined") # 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) put_result = blockstack_client.put_immutable("foo.test", "hello_world_3", json.dumps(datasets[2], sort_keys=True), proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) testlib.expect_atlas_zonefile(put_result['zonefile_hash']) data_history_1.append(data_history_1[-1]) data_history_2.append(data_history_2[-1]) data_history_3.append(put_result['immutable_data_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) # wait for confirmation for i in xrange(0, 12): testlib.next_block(**kw) print "waiting for confirmation" time.sleep(10) # overwrite datasets[0]['newdata'] = "asdf" put_result = blockstack_client.put_immutable("foo.test", "hello_world_3", json.dumps(datasets[0], sort_keys=True), proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) testlib.expect_atlas_zonefile(put_result['zonefile_hash']) data_history_1.append(data_history_1[-1]) data_history_2.append(data_history_2[-1]) data_history_3.append(put_result['immutable_data_hash']) del datasets[0]['newdata'] # 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)
def scenario(wallets, **kw): global pk, pk2, pk3 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) # pay for a name in a v1 namespace with Stacks addr = virtualchain.address_reencode(virtualchain.get_privkey_address(pk)) addr2 = virtualchain.address_reencode( virtualchain.get_privkey_address(pk2)) addr3 = virtualchain.address_reencode( virtualchain.get_privkey_address(pk3)) # calculate the cost of doing so namespace = testlib.get_state_engine().get_namespace('test') stacks_price = blockstack.lib.scripts.price_name_stacks( 'foo', namespace, testlib.get_current_block(**kw)) btc_price = blockstack.lib.scripts.price_name( 'foo', namespace, testlib.get_current_block(**kw)) # try to preorder/register using not enough Bitcoin and not enough Bitcoin (should fail) print '' print 'price of {} in Stacks is {}'.format('foo.test', stacks_price) print 'price of {} in BTC is {}'.format('foo.test', btc_price) print '' testlib.send_funds(wallets[0].privkey, btc_price * 2, addr) # try to preorder/register using not enough bitcoin (preorder should succeed; register should fail) testlib.blockstack_name_preorder("foo.test", pk, wallets[3].addr, price={ 'units': 'BTC', 'amount': btc_price - 1 }, safety_checks=False) testlib.next_block(**kw) testlib.expect_snv_fail_at('foo.test', testlib.get_current_block(**kw)) testlib.blockstack_name_register("foo.test", pk, wallets[3].addr, safety_checks=False) testlib.next_block(**kw) testlib.expect_snv_fail_at('foo.test', testlib.get_current_block(**kw)) # pass tokens testlib.send_funds(wallets[0].privkey, btc_price * 2, addr2) testlib.blockstack_send_tokens(addr2, "STACKS", stacks_price, wallets[0].privkey) testlib.next_block(**kw) # try to preorder/register using not enough Stacks (preorder should succeed; register should fail) testlib.blockstack_name_preorder("foo.test", pk2, wallets[4].addr, price={ 'units': 'STACKS', 'amount': stacks_price - 1 }, safety_checks=False) testlib.next_block(**kw) testlib.expect_snv_fail_at('foo.test', testlib.get_current_block(**kw)) testlib.blockstack_name_register("foo.test", pk2, wallets[4].addr, safety_checks=False) testlib.next_block(**kw) testlib.expect_snv_fail_at('foo.test', testlib.get_current_block(**kw)) # pass tokens testlib.send_funds(wallets[0].privkey, btc_price * 2, addr3) testlib.blockstack_send_tokens(addr3, "STACKS", stacks_price, wallets[0].privkey) testlib.next_block(**kw) # try to preorder/register using the right amount of stacks, but not paying in BTC (should succeed) testlib.blockstack_name_preorder("foo.test", pk3, wallets[1].addr, price={ 'units': 'STACKS', 'amount': stacks_price }) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", pk3, wallets[1].addr) testlib.next_block(**kw)
def scenario(wallets, **kw): global import_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) resp = 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) if 'error' in resp: print json.dumps(resp, indent=4) return False 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) return False testlib.next_block(**kw) import_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) resp = testlib.blockstack_name_transfer("foo.test", wallets[4].addr, True, wallets[3].privkey) if 'error' in resp: print resp 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 resp 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 update_ch = name_rec['consensus_hash'] resp = testlib.blockstack_name_transfer("foo.test", wallets[3].addr, True, wallets[4].privkey) if 'error' in resp: print resp 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'] != update_ch: print 'wrong consensus hash: expected {}'.format(update_ch) print json.dumps(name_rec, indent=4, sort_keys=True) return False # wait for expiration (with multipler)... for i in xrange(0, 10 * NAMESPACE_LIFETIME_MULTIPLIER): testlib.next_block(**kw) # re-register testlib.blockstack_name_preorder("foo.test", wallets[7].privkey, wallets[8].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[7].privkey, wallets[8].addr) testlib.next_block(**kw) # consensus hash must be None db = testlib.get_state_engine() name_rec = db.get_name('foo.test') if name_rec['consensus_hash'] is not None: print 'wrong consensus hash: expected {}'.format(None) print json.dumps(name_rec, indent=4, sort_keys=True) return False resp = testlib.blockstack_name_transfer("foo.test", wallets[0].addr, True, wallets[8].privkey) if 'error' in resp: print resp 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_transfer("foo.test", wallets[8].addr, True, wallets[0].privkey) if 'error' in resp: print resp 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", "33" * 20, wallets[8].privkey) if 'error' in resp: print resp 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 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, 3, 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[2].privkey, wallets[3].addr ) testlib.blockstack_name_preorder( "baz.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.blockstack_name_register( "bar.test", wallets[2].privkey, wallets[3].addr ) testlib.blockstack_name_register( "baz.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # dids for each of these names foo_did = 'did:stack:v0:{}-0'.format(wallets[3].addr) bar_did = 'did:stack:v0:{}-1'.format(wallets[3].addr) baz_did = 'did:stack:v0:{}-2'.format(wallets[3].addr) for did in [foo_did, bar_did, baz_did]: res = blockstack.lib.client.get_DID_record(did, hostport='http://localhost:{}'.format(blockstack.lib.client.RPC_SERVER_PORT)) if 'error' in res: print res return False if res['address'] != wallets[3].addr: print 'wrong address; expected {}'.format(wallets[3].addr) print json.dumps(res, indent=4, sort_keys=True) return False # revoke foo.test testlib.blockstack_name_revoke( "foo.test", wallets[3].privkey ) testlib.next_block( **kw ) # wait for them all to expire... for i in xrange(0, 3): testlib.next_block( **kw ) # re-preorder/reregister to different addresses testlib.blockstack_name_preorder( "foo.test", wallets[4].privkey, wallets[0].addr ) testlib.blockstack_name_preorder( "bar.test", wallets[4].privkey, wallets[1].addr ) testlib.blockstack_name_preorder( "baz.test", wallets[4].privkey, wallets[2].addr ) testlib.next_block( **kw ) # re-register testlib.blockstack_name_register( "foo.test", wallets[4].privkey, wallets[0].addr ) testlib.blockstack_name_register( "bar.test", wallets[4].privkey, wallets[1].addr ) testlib.blockstack_name_register( "baz.test", wallets[4].privkey, wallets[2].addr ) testlib.next_block( **kw ) # foo's DID should no longer resolve, since foo was revoked res = blockstack.lib.client.get_DID_record(foo_did, hostport='http://localhost:{}'.format(blockstack.lib.client.RPC_SERVER_PORT)) if 'error' not in res: print 'accidentally resolved {}'.format(foo_did) print res return False # non-revoked DIDs should resolve to the old addresses, just before the reregister for did, addr in zip([bar_did, baz_did], [wallets[3].addr, wallets[3].addr]): res = blockstack.lib.client.get_DID_record(did, hostport='http://localhost:{}'.format(blockstack.lib.client.RPC_SERVER_PORT)) if 'error' in res: print res return False if res['address'] != addr: print 'wrong address post-reregister; expected {}'.format(addr) print json.dumps(res, indent=4, sort_keys=True) return False # dids for the new names foo2_did = 'did:stack:v0:{}-0'.format(wallets[0].addr) bar2_did = 'did:stack:v0:{}-0'.format(wallets[1].addr) baz2_did = 'did:stack:v0:{}-0'.format(wallets[2].addr) # new DIDs should all resolve to new addresses for did, addr in zip([foo2_did, bar2_did, baz2_did], [wallets[0].addr, wallets[1].addr, wallets[2].addr]): res = blockstack.lib.client.get_DID_record(did, hostport='http://localhost:{}'.format(blockstack.lib.client.RPC_SERVER_PORT)) if 'error' in res: print res return False if res['address'] != addr: print 'wrong address post-reregister: expected {}'.format(addr) print json.dumps(res, indent=4, sort_keys=True) return False # transfer all names back to wallets[3] testlib.blockstack_name_transfer( "foo.test", wallets[3].addr, True, wallets[0].privkey ) testlib.blockstack_name_transfer( "bar.test", wallets[3].addr, True, wallets[1].privkey ) testlib.blockstack_name_transfer( "baz.test", wallets[3].addr, True, wallets[2].privkey ) testlib.next_block( **kw ) # all DIDs except for the original DID for foo.test should now resolve to wallets[3].addr for did in [bar_did, baz_did, foo2_did, bar2_did, baz2_did]: res = blockstack.lib.client.get_DID_record(did, hostport='http://localhost:{}'.format(blockstack.lib.client.RPC_SERVER_PORT)) if 'error' in res: print res return False if res['address'] != wallets[3].addr: print 'wrong address post-transfer: expected {}'.format(wallets[3].addr) print json.dumps(res, indent=4, sort_keys=True) return False # foo's original DID should not resolve res = blockstack.lib.client.get_DID_record(foo_did, hostport='http://localhost:{}'.format(blockstack.lib.client.RPC_SERVER_PORT)) if 'error' not in res: print 'accidentally resolved {}'.format(foo_did) print res return False
def scenario(wallets, **kw): global debug, consensus, small_unspents res = check_utxo_consumption( "test", wallets[0], wallets[1], wallets[2], ['namespace_preorder', 'namespace_reveal', 'namespace_ready'], wallets[1].addr, **kw) if 'error' in res: return False expected_utxo_count = res['expected_utxo_count'] # do the preorder resp = testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) if debug or 'error' in resp: print simplejson.dumps(resp, indent=4) testlib.next_block(**kw) # verify that all the small UTXOs are NOT consumed bitcoind = testlib.connect_bitcoind() bitcoind.ping() txdata = bitcoind.getrawtransaction(resp['transaction_hash'], 1) if len(txdata['vin']) != 1: print simplejson.dumps(txdata, indent=4) print "wrong number of inputs: {} != 1".format(len(txdata['vin'])) return False if spent_small_transaction(resp['transaction_hash']): return False # finish ordering the namespace 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 simplejson.dumps(resp, indent=4) if spent_small_transaction(resp['transaction_hash']): return False testlib.next_block(**kw) resp = testlib.blockstack_namespace_ready("test", wallets[1].privkey) if debug or 'error' in resp: print simplejson.dumps(resp, indent=4) if spent_small_transaction(resp['transaction_hash']): return False testlib.next_block(**kw) res = check_utxo_consumption( "foo.test", wallets[2], wallets[3], wallets[4], ['preorder', 'register', 'update', 'transfer'], wallets[4].addr, **kw) if 'error' in res: return False expected_utxo_count = res['expected_utxo_count'] resp = testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) if debug or 'error' in resp: print simplejson.dumps(resp, indent=4) if spent_small_transaction(resp['transaction_hash']): return False testlib.next_block(**kw) # verify that all the small UTXOs are NOT consumed bitcoind = testlib.connect_bitcoind() bitcoind.ping() txdata = bitcoind.getrawtransaction(resp['transaction_hash'], 1) if len(txdata['vin']) != 1: print simplejson.dumps(txdata, indent=4) print "wrong number of inputs: {} != {}".format( len(txdata['vin']), expected_utxo_count) return False # proceed to register resp = testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) if debug or 'error' in resp: print simplejson.dumps(resp, indent=4) if spent_small_transaction(resp['transaction_hash']): return False testlib.next_block(**kw) # verify that all the UTXOs are consumed bitcoind = testlib.connect_bitcoind() bitcoind.ping() txdata = bitcoind.getrawtransaction(resp['transaction_hash'], 1) if len(txdata['vin']) != 1: print simplejson.dumps(txdata, indent=4) print "wrong number of inputs: {} != {}".format( len(txdata['vin']), expected_utxo_count) return False # make a few small UTXOs for the preorder payment addr for i in xrange(0, 3): res = testlib.send_funds(wallets[1].privkey, 10000, testlib.get_default_payment_wallet().addr) if 'error' in res: print simplejson.dumps(res, indent=4, sort_keys=True) return False testlib.next_block(**kw) small_unspents.append(res['transaction_hash']) utxos = testlib.get_utxos(testlib.get_default_payment_wallet().addr) assert len(utxos) > 3 resp = testlib.blockstack_name_update("foo.test", "11" * 20, wallets[3].privkey) if debug or 'error' in resp: print simplejson.dumps(resp, indent=4) if spent_small_transaction(resp['transaction_hash']): return False consensus = testlib.get_consensus_at(testlib.get_current_block(**kw), **kw) testlib.next_block(**kw) # inspect the transaction: only 3 UTXOs should have been consumed (2 owner UTXOs and 1 payment UTXO) txdata = testlib.connect_bitcoind().getrawtransaction( resp['transaction_hash'], 1) if len(txdata['vin']) != 3: print simplejson.dumps(txdata, indent=4) print "too many inputs" return False # make a few more small UTXOs for the preorder payment addr for i in xrange(0, 3): res = testlib.send_funds(wallets[1].privkey, 10000, testlib.get_default_payment_wallet().addr) if 'error' in res: print simplejson.dumps(res, indent=4, sort_keys=True) return False testlib.next_block(**kw) small_unspents.append(res['transaction_hash']) utxos = testlib.get_utxos(testlib.get_default_payment_wallet().addr) assert len(utxos) > 3 resp = testlib.blockstack_name_transfer("foo.test", wallets[4].addr, True, wallets[3].privkey) if debug or 'error' in resp: print simplejson.dumps(resp, indent=4) # inspect the transaction: only 2 UTXOs should have been consumed (1 owner UTXO and 1 payment UTXO) txdata = testlib.connect_bitcoind().getrawtransaction( resp['transaction_hash'], 1) if len(txdata['vin']) != 2: print simplejson.dumps(txdata, indent=4) print "too many inputs" return False if spent_small_transaction(resp['transaction_hash']): return False testlib.next_block(**kw) # make a few more small UTXOs for the preorder payment addr for i in xrange(0, 3): res = testlib.send_funds(wallets[1].privkey, 10000, testlib.get_default_payment_wallet().addr) if 'error' in res: print simplejson.dumps(res, indent=4, sort_keys=True) return False testlib.next_block(**kw) small_unspents.append(res['transaction_hash']) utxos = testlib.get_utxos(testlib.get_default_payment_wallet().addr) assert len(utxos) > 3 resp = testlib.blockstack_name_renew("foo.test", wallets[4].privkey) if debug or 'error' in resp: print simplejson.dumps(resp, indent=4) # inspect the transaction: only 3 UTXOs should have been consumed (2 owner UTXO and 1 payment UTXO) # NOTE: produces two UTXOs: an "owner" utxo and the change for the owner address txdata = testlib.connect_bitcoind().getrawtransaction( resp['transaction_hash'], 1) if len(txdata['vin']) != 3: print simplejson.dumps(txdata, indent=4) print "too many inputs" return False if spent_small_transaction(resp['transaction_hash']): return False testlib.next_block(**kw) # make a few more small UTXOs for the preorder payment addr for i in xrange(0, 3): res = testlib.send_funds(wallets[1].privkey, 10000, testlib.get_default_payment_wallet().addr) if 'error' in res: print simplejson.dumps(res, indent=4, sort_keys=True) return False testlib.next_block(**kw) small_unspents.append(res['transaction_hash']) utxos = testlib.get_utxos(testlib.get_default_payment_wallet().addr) assert len(utxos) > 3 resp = testlib.blockstack_name_revoke("foo.test", wallets[4].privkey) if debug or 'error' in resp: print simplejson.dumps(resp, indent=4) # inspect the transaction: only 3 UTXOs should have been consumed (2 owner UTXO and 1 payment UTXO) txdata = testlib.connect_bitcoind().getrawtransaction( resp['transaction_hash'], 1) if len(txdata['vin']) != 3: print simplejson.dumps(txdata, indent=4) print "too many inputs" return False if spent_small_transaction(resp['transaction_hash']): return False 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, 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, zonefile_hash='11' * 20) testlib.blockstack_name_register("foo2.test", wallets[2].privkey, wallets[3].addr, zonefile_hash='22' * 20) testlib.blockstack_name_register("foo3.test", wallets[2].privkey, wallets[3].addr, zonefile_hash='33' * 20) testlib.next_block(**kw) def name_rec_equal(r1, r2): keys = set(r1.keys() + r2.keys()) for k in keys: if k in r1 and k in r2: if r1[k] != r2[k]: return False return True # dids for each of these names dids = [ 'did:stack:v0:{}-0'.format(wallets[3].addr), 'did:stack:v0:{}-1'.format(wallets[3].addr), 'did:stack:v0:{}-2'.format(wallets[3].addr) ] # 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 # DIDs for i in xrange(0, 3): name = 'foo{}.test'.format(i + 1) res = blockstack.lib.client.get_name_DID( name, hostport='http://localhost:{}'.format( blockstack.lib.config.RPC_SERVER_PORT)) if 'error' in res: print res return False if res != dids[i]: print 'DID mismatch: expected {}, got {}'.format(dids[i], res) return False res = blockstack.lib.client.get_name_record( name, hostport='http://localhost:{}'.format( blockstack.lib.client.RPC_SERVER_PORT)) if 'error' in res: print res return False name_rec = res res = blockstack.lib.client.get_DID_record( dids[i], hostport='http://localhost:{}'.format( blockstack.lib.client.RPC_SERVER_PORT)) if 'error' in res: print res return False did_rec = res if not name_rec_equal(name_rec, did_rec): print 'record mismatch' print json.dumps(name_rec, sort_keys=True) print json.dumps(did_rec, sort_keys=True) return False # do stuff with these names testlib.blockstack_name_update("foo1.test", "1b" * 20, wallets[3].privkey) testlib.blockstack_name_update("foo2.test", "2b" * 20, wallets[3].privkey) testlib.blockstack_name_update("foo3.test", "3b" * 20, wallets[3].privkey) testlib.next_block(**kw) testlib.blockstack_name_revoke("foo1.test", wallets[3].privkey) testlib.blockstack_name_transfer("foo2.test", wallets[4].addr, True, wallets[3].privkey) testlib.blockstack_name_transfer("foo3.test", wallets[4].addr, True, wallets[3].privkey) testlib.next_block(**kw) name_recs = { 'foo1.test': blockstack.lib.client.get_name_record( 'foo1.test', hostport='http://localhost:{}'.format( blockstack.lib.client.RPC_SERVER_PORT)), 'foo2.test': blockstack.lib.client.get_name_record( 'foo2.test', hostport='http://localhost:{}'.format( blockstack.lib.client.RPC_SERVER_PORT)), 'foo3.test': blockstack.lib.client.get_name_record( 'foo3.test', hostport='http://localhost:{}'.format( blockstack.lib.client.RPC_SERVER_PORT)), } # expire. Reregister under the same owner testlib.next_block(**kw) testlib.next_block(**kw) testlib.next_block(**kw) 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, zonefile_hash='1a' * 20) testlib.blockstack_name_register("foo2.test", wallets[2].privkey, wallets[3].addr, zonefile_hash='2a' * 20) testlib.blockstack_name_register("foo3.test", wallets[2].privkey, wallets[3].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[3].addr: print res return False # dids for each of these names new_dids = [ 'did:stack:v0:{}-3'.format(wallets[3].addr), 'did:stack:v0:{}-4'.format(wallets[3].addr), 'did:stack:v0:{}-5'.format(wallets[3].addr) ] # new DIDs for i in xrange(0, 3): name = 'foo{}.test'.format(i + 1) res = blockstack.lib.client.get_name_DID( name, hostport='http://localhost:{}'.format( blockstack.lib.config.RPC_SERVER_PORT)) if 'error' in res: print res return False if res != new_dids[i]: print 'DID mismatch: expected {}, got {}'.format(new_dids[i], res) return False res = blockstack.lib.client.get_name_record( name, hostport='http://localhost:{}'.format( blockstack.lib.client.RPC_SERVER_PORT)) if 'error' in res: print res return False name_rec = res res = blockstack.lib.client.get_DID_record( new_dids[i], hostport='http://localhost:{}'.format( blockstack.lib.client.RPC_SERVER_PORT)) if 'error' in res: print res return False did_rec = res if not name_rec_equal(name_rec, did_rec): print 'record mismatch' print json.dumps(name_rec, sort_keys=True) print json.dumps(did_rec, sort_keys=True) return False # old DIDs for i in xrange(0, 3): name = 'foo{}.test'.format(i + 1) res = blockstack.lib.client.get_DID_record( dids[i], hostport='http://localhost:{}'.format( blockstack.lib.client.RPC_SERVER_PORT)) did_rec = res old_rec = name_recs[name] if old_rec['revoked'] and 'error' not in did_rec: print 'revoked did is sitll valid: {}'.format(dids[i]) print did_rec return False elif not name_rec_equal(did_rec, old_rec): print 'old record mismatch' print json.dumps(did_rec, sort_keys=True) print json.dumps(old_rec, sort_keys=True) return False
def scenario(wallets, **kw): global datasets wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].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.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) # migrate profile (but no data key) 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) 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) # put immutable (with owner key) log.debug("put immutable 1 with owner key") testlib.blockstack_client_set_wallet("0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], None) put_result = testlib.blockstack_cli_put_immutable( "foo.test", "hello_world_1_immutable", json.dumps(datasets[0], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False 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) # put immutable (with owner key) log.debug("put immutable 2 with owner key") testlib.blockstack_cli_put_immutable("foo.test", "hello_world_2_immutable", json.dumps(datasets[1], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False 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) # put mutable (with owner key) log.debug("put mutable 1 with owner key") put_result = testlib.blockstack_cli_put_mutable( "foo.test", "hello_world_1_mutable", json.dumps(datasets[0], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False # put mutable (with owner key) log.debug("put mutable 2 with owner key") put_result = testlib.blockstack_cli_put_mutable( "foo.test", "hello_world_2_mutable", json.dumps(datasets[1], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.next_block(**kw) # add data signing key res = blockstack_client.set_data_pubkey("foo.test", wallets[4].pubkey_hex, wallet_keys=wallet_keys, proxy=test_proxy) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) return False testlib.expect_atlas_zonefile(res['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) # put immutable (with new key) log.debug("put immutable with new key") # restart daemon wallet_keys = 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_3_immutable", json.dumps(datasets[2], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False 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) # put mutable (with new key) log.debug("put mutable with new key") put_result = testlib.blockstack_cli_put_mutable( "foo.test", "hello_world_3_mutable", json.dumps(datasets[2], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.next_block(**kw) # delete immutable (new key) log.debug("delete immutable with new key") result = testlib.blockstack_cli_delete_immutable( "foo.test", "hello_world_1_immutable", password='******') if 'error' in result: print json.dumps(result, indent=4, sort_keys=True) return False testlib.expect_atlas_zonefile(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) # delete mutable (new key) log.debug("delete mutable with new key") result = testlib.blockstack_cli_delete_mutable("foo.test", "hello_world_1_mutable", password='******') if 'error' in result: print json.dumps(result, indent=4, sort_keys=True) return False testlib.next_block(**kw)
def scenario( wallets, **kw ): global put_result, wallet_keys, legacy_profile, zonefile_hash, zonefile_hash_2, error wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[8].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 ) # 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_cli_update("foo.test", legacy_txt, '0123456789abcdef') if 'error' in result_1: print json.dumps(result_1, indent=4, sort_keys=True) return False # wait for it to go through... for i in xrange(0, 12): testlib.next_block(**kw) print "wait 10 seconds for update to go through" time.sleep(10) 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 testlib.next_block( **kw ) # migrate profiles to standard zonefiles 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) return False testlib.next_block( **kw ) # give foo.test a nonstandard zonefile (as something that serializes to JSON) nonstandard_zonefile_json = {'nonstandard': 'true', 'error': 'nonstandard'} nonstandard_zonefile_txt = json.dumps(nonstandard_zonefile_json, sort_keys=True) nonstandard_zonefile_raw = binascii.unhexlify( "".join(["%02x" % i for i in xrange(0, 256)])) zf_data = [nonstandard_zonefile_txt, nonstandard_zonefile_raw] for zi in xrange(0, len(zf_data)): nonstandard_zonefile = zf_data[zi] resp = testlib.blockstack_cli_update( "foo.test", nonstandard_zonefile, "0123456789abcdef", nonstandard=True ) if 'error' in resp: print "failed to put nonstandard zonefile '%s'" % nonstandard_zonefile print json.dumps(resp, indent=4, sort_keys=True) return False testlib.expect_atlas_zonefile(resp['zonefile_hash']) # wait for it to take effect for i in xrange(0, 12): testlib.next_block( **kw ) time.sleep(3) # getting zonefile should still work... resp = testlib.blockstack_cli_get_name_zonefile( "foo.test", json=True ) if 'error' in resp: print "failed to get zonefile %s" % zi print json.dumps(resp, indent=4, sort_keys=True) return False if 'warning' not in resp: print "no non-standard warning:\n%s" % json.dumps(resp, indent=4, sort_keys=True) return False if resp['zonefile'] != nonstandard_zonefile: print "failed to load nonstandard zonefile json" print "expected:\n%s\n\ngot:\n%s" % (nonstandard_zonefile, resp['zonefile']) return False # the following should all fail dataplane_funcs = [ ("lookup", lambda: testlib.blockstack_cli_lookup( "foo.test" )), ("put_immutable", lambda: testlib.blockstack_cli_put_immutable( "foo.test", "fail", '{"Fail": "Yes"}', password='******' )), ("get_immutable", lambda: testlib.blockstack_cli_get_immutable( "foo.test", "fail" )), ("put_mutable", lambda: testlib.blockstack_cli_put_mutable( "foo.test", "fail", '{"fail": "yes"}', password='******' )), ("get_mutable", lambda: testlib.blockstack_cli_get_mutable( "foo.test", "fail" )), ("delete_immutable", lambda: testlib.blockstack_cli_delete_immutable( "foo.test", "00" * 32, password='******' )), ("delete_mutable", lambda: testlib.blockstack_cli_delete_mutable( "foo.test", "fail", password='******' )) ] for data_func_name, data_func in dataplane_funcs: resp = data_func() if 'error' not in resp: print "%s succeeded when it should not have:\n%s" % (data_func_name, json.dumps(resp, indent=4, sort_keys=True)) return False # this should succeed zf_hist = testlib.blockstack_cli_list_zonefile_history( "foo.test" ) if len(zf_hist) != 2*(zi+1)+1: print "missing zonefile history: %s (expected %s items, got %s)" % (zf_hist, zi+3, len(zf_hist)) return False update_hist = testlib.blockstack_cli_list_update_history( "foo.test" ) if len(update_hist) != 2*(zi+1)+1: print 'missing zonefile history: %s (expected %s items, got %s)' % (zf_hist, zi+3, len(zf_hist)) return False name_hist = testlib.blockstack_cli_get_name_blockchain_history("foo.test") if zf_hist[-1] != nonstandard_zonefile: print "invalid zonefile: expected\n%s\ngot\n%s\n" % (nonstandard_zonefile, zf_hist[-1]) return False # this should work, but with "non-standard zonefiles" hist = testlib.blockstack_cli_list_immutable_data_history("foo.test", "fail") if len(hist) != 2*(zi+1)+1: print "missing immutable data history: %s (expected %s items, got %s)" % (hist, zi+3, len(hist)) return False if hist[-1] != 'non-standard zonefile': print "not a non-standard zonefile: %s" % hist[-1] return False # verify that we can migrate it back resp = testlib.blockstack_cli_migrate( "foo.test", "0123456789abcdef", force=True ) if 'error' in resp: print "failed to migrate" print json.dumps(resp, indent=4, sort_keys=True) return False zonefile_hash = resp['zonefile_hash'] # wait for it to take effect for i in xrange(0, 12): testlib.next_block( **kw ) time.sleep(3) # see that put_immutable works put_result = testlib.blockstack_cli_put_immutable("foo.test", "hello_world_immutable", json.dumps({'hello': 'world'}), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) return False 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(3) # see that put_mutable works put_result = testlib.blockstack_cli_put_mutable("foo.test", "hello_world_mutable", json.dumps({'hello': 'world'}), 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 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) 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) conf = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] config_dir = os.path.dirname(config_path) # make sure we can do REST calls res = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/pending', None, api_pass=api_pass) if 'error' in res: res['test'] = 'Failed to get queues' print json.dumps(res) return False # make sure we can do REST calls with different app names and user names res = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/pending', None, api_pass=api_pass) if 'error' in res: res['test'] = 'Failed to get queues' print json.dumps(res) return False # register the name bar.test res = testlib.blockstack_REST_call('POST', '/v1/names', None, api_pass=api_pass, data={'name': 'bar.test'}) if 'error' in res: res['test'] = 'Failed to register user' print json.dumps(res) error = True return False # wait for update to get confirmed for i in xrange(0, 48): if i % 12 == 0: print "waiting for RPC daemon to catch up" time.sleep(10) testlib.next_block(**kw) res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test", None, api_pass=api_pass) if 'error' in res: res['test'] = 'Failed to query name' print json.dumps(res) error = True return False if res['http_status'] != 200: res['test'] = 'HTTP status {}, response = {}'.format( res['http_status'], res['response']) print json.dumps(res) error = True return False # should now be registered if res['response']['status'] != 'registered': print "register not complete" print json.dumps(res) return False
def scenario(wallets, **kw): subsidy_wallet = wallets[5] print json.dumps(testlib.getrawtransaction( "28f78fbae22d2273341af231a2ac049d74958e1e6ce6ae622cd48d8f0fef591e", 1), indent=4) 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) # subsidized transactions... resp = testlib.blockstack_name_preorder("foo.test", None, wallets[3].addr, subsidy_key=subsidy_wallet.privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) # (already subsidized...) send_subsidized(None, resp, **kw) testlib.next_block(**kw) resp = testlib.blockstack_name_register("foo.test", None, wallets[3].addr, subsidy_key=subsidy_wallet.privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) # (already subsidized...) send_subsidized(None, resp, **kw) testlib.next_block(**kw) resp = testlib.blockstack_name_update( "foo.test", "11" * 20, None, user_public_key=wallets[3].pubkey_hex, subsidy_key=subsidy_wallet.privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) send_subsidized(wallets[3].privkey, resp, **kw) testlib.next_block(**kw) resp = testlib.blockstack_name_transfer( "foo.test", wallets[4].addr, True, None, user_public_key=wallets[3].pubkey_hex, subsidy_key=subsidy_wallet.privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) send_subsidized(wallets[3].privkey, resp, **kw) testlib.next_block(**kw) resp = testlib.blockstack_name_revoke( "foo.test", None, user_public_key=wallets[4].pubkey_hex, subsidy_key=subsidy_wallet.privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) send_subsidized(wallets[4].privkey, resp, **kw) # advance a bit for i in xrange(0, 5): 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) zf_template = "$ORIGIN {}\n$TTL 3600\n{}" zf_default_url = '_https._tcp URI 10 1 "https://gaia.blockstack.org/hub/{}/profile.json'.format( wallets[4].addr) all_zonefiles = [] # do lots and lots of subdomains for i in range(0, 20): subdomain_zonefiles = [] for j in range(0, 100): subdomain_name = 'bar{}.foo.test'.format(i * 100 + j) zf = subdomains.make_subdomain_txt( subdomain_name, 'foo.test', wallets[4].addr, 0, zf_template.format(subdomain_name, zf_default_url), wallets[4].privkey) subdomain_zonefiles.append(zf) zf = zf_template.format('foo.test', '\n'.join(subdomain_zonefiles)) assert len(zf) <= 40960, 'zonefile is too long ({})'.format(len(zf)) all_zonefiles.append(zf) testlib.blockstack_name_update('foo.test', storage.get_zonefile_data_hash(zf), wallets[3].privkey) testlib.next_block(**kw) # broadcast them all for zf in all_zonefiles: assert testlib.blockstack_put_zonefile(zf) # index them all t1 = time.time() testlib.next_block(**kw) t2 = time.time() # reindex assert testlib.check_subdomain_db(**kw)
def scenario( wallets, **kw ): global synchronized, value_hash 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 ) 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 ) # 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 ) # 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 ) # propagate res = testlib.blockstack_cli_sync_zonefile('foo_{}.test'.format(i), zonefile_string=empty_zonefile_str) if 'error' in res: print json.dumps(res) return False # start up an Atlas test network with 9 nodes: the main one doing the test, and 8 subordinate ones that treat it as a seed peer. # the network will ensure each node can reach each other node. atlas_nodes = [17000, 17001, 17002, 17003, 17004, 17005, 17006, 17007] atlas_topology = {} for node_port in atlas_nodes: atlas_topology[node_port] = [16264] network_des = atlas_network.atlas_network_build( atlas_nodes, atlas_topology, {}, os.path.join( testlib.working_dir(**kw), "atlas_network" )) atlas_network.atlas_network_start( network_des ) print "Waiting 60 seconds for the altas peers to catch up" time.sleep(60.0) # wait at most 30 seconds for atlas network to converge synchronized = False for i in xrange(0, 30): 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 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): 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, data_privkey=wallets[4].privkey, payment_privkey=wallets[8].privkey) wallet_keys_2 = blockstack_client.make_wallet_keys( owner_privkey=wallets[6].privkey, data_privkey=wallets[7].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 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) 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'], wallet_keys['data_privkey']) 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) # set new wallet keys testlib.blockstack_client_set_wallet("0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], wallet_keys_2['data_privkey']) 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) # add mutable app keys testlib.blockstack_client_set_wallet("0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey']) 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'], wallet_keys_2['data_privkey']) 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'], wallet_keys['data_privkey']) 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.blockstack_client_set_wallet("0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], wallet_keys_2['data_privkey']) 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) # 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) 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'] # add immutable app keys, which we can delete testlib.blockstack_client_set_wallet("0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey']) 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.blockstack_client_set_wallet("0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], wallet_keys_2['data_privkey']) 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) # add mutable app keys which we can delete testlib.blockstack_client_set_wallet("0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey']) 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'], wallet_keys_2['data_privkey']) 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'], wallet_keys['data_privkey']) 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'], wallet_keys_2['data_privkey']) 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'], wallet_keys['data_privkey']) 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.blockstack_client_set_wallet("0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], wallet_keys_2['data_privkey']) 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) # delete mutable app keys testlib.blockstack_client_set_wallet("0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey']) 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'], wallet_keys_2['data_privkey']) 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): 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) # renew resp = testlib.blockstack_name_renew("foo.test", wallets[3].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # whois res = testlib.blockstack_cli_whois('foo.test') if 'error' in res: print res return False if res.has_key('zonefile_hash') and res['zonefile_hash']: print res return False if res['owner_address'] != wallets[3].addr: print res return False # transfer resp = testlib.blockstack_name_transfer('foo.test', wallets[4].addr, True, wallets[3].privkey) if 'error' in resp: print resp return False testlib.next_block(**kw) # whois res = testlib.blockstack_cli_whois('foo.test') if 'error' in res: print res return False if res.has_key('zonefile_hash') and res['zonefile_hash']: print res return False if res['owner_address'] != wallets[4].addr: print res return False # renew/update resp = testlib.blockstack_name_renew("foo.test", wallets[4].privkey, zonefile_hash='11' * 20, recipient_addr=wallets[4].addr, use_cli=False) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # whois res = testlib.blockstack_cli_whois('foo.test') if 'error' in res: print res return False if not res.has_key('zonefile_hash') or res['zonefile_hash'] != '11' * 20: print res return False if res['owner_address'] != wallets[4].addr: print res return False # transfer resp = testlib.blockstack_name_transfer('foo.test', wallets[1].addr, True, wallets[4].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # whois res = testlib.blockstack_cli_whois('foo.test') if 'error' in res: print res return False if not res.has_key('zonefile_hash') or res['zonefile_hash'] != '11' * 20: print res return False if res['owner_address'] != wallets[1].addr: print res return False # renew/update/transfer resp = testlib.blockstack_name_renew("foo.test", wallets[1].privkey, zonefile_hash='22' * 20, recipient_addr=wallets[0].addr) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # whois res = testlib.blockstack_cli_whois('foo.test') if 'error' in res: print res return False if not res.has_key('zonefile_hash') or res['zonefile_hash'] != '22' * 20: print res return False if res['owner_address'] != wallets[0].addr: print res return False # transfer resp = testlib.blockstack_name_transfer('foo.test', wallets[2].addr, True, wallets[0].privkey) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # whois res = testlib.blockstack_cli_whois('foo.test') if 'error' in res: print res return False if not res.has_key('zonefile_hash') or res['zonefile_hash'] != '22' * 20: print res return False if res['owner_address'] != wallets[2].addr: print res return False # renew/transfer resp = testlib.blockstack_name_renew("foo.test", wallets[2].privkey, recipient_addr=wallets[1].addr) if 'error' in resp: print json.dumps(resp, indent=4) return False testlib.next_block(**kw) # whois res = testlib.blockstack_cli_whois('foo.test') if 'error' in res: print res return False if not res.has_key('zonefile_hash') or res['zonefile_hash'] != '22' * 20: print res return False if res['owner_address'] != wallets[1].addr: print res return False
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) return False else: zonefile_hash = res['zonefile_hash'] print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" testlib.next_block(**kw) # should fail with no public key res = testlib.blockstack_cli_get_public_key("foo.test") if 'error' not in res: print 'accidentally succeeded to get public key for zone file without one' print res return False # verify this also fails for the RESTful API res = testlib.blockstack_REST_call('GET', '/v1/names/foo.test/public_key', None) if res['http_status'] == 200: print 'accidentally succeeded to get public key for zone file without one' print res return False if res['http_status'] != 404: print 'wrong status code: expected 404' print res return False wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey) wallet_keys = wallet # migrate profile; add data key 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) return False else: zonefile_hash = res['zonefile_hash'] print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" testlib.next_block(**kw) # should have a public key now res = testlib.blockstack_cli_get_public_key("foo.test") if 'error' in res: print 'no public key from zone file for foo.test' print res return False if res['public_key'] != keylib.key_formatting.decompress( keylib.ECPrivateKey(wallets[4].privkey).public_key().to_hex()): print 'wrong public key' print res return False # verify this also succeeds for the RESTful API res = testlib.blockstack_REST_call('GET', '/v1/names/foo.test/public_key', None) if res['http_status'] != 200: print 'failed to get public key from RESTful API' print res return False if res['response']['public_key'] != keylib.key_formatting.decompress( keylib.ECPrivateKey(wallets[4].privkey).public_key().to_hex()): print 'wrong public key' print res 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)
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, 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) 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)) # wait for it to expire... for i in xrange(0, 8 * NAMESPACE_LIFETIME_MULTIPLIER): testlib.next_block(**kw) # verify that operations continue to fail (BUG IN 0.13: THIS SUCCEEDS WHEN IT SHOULD 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)) # re-preorder... resp = testlib.blockstack_name_preorder("foo.test", wallets[4].privkey, wallets[0].addr) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) # re-register resp = testlib.blockstack_name_register("foo.test", wallets[4].privkey, wallets[0].addr) 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): global datasets, zonefile_hashes, put_result, last_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) 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 = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, None) # 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 # 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 "put hello_world_1" 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 put_result = blockstack_client.put_immutable("foo.test", "hello_world_1", json.dumps(datasets[0], sort_keys=True), proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.expect_atlas_zonefile(put_result['zonefile_hash']) zonefile_hashes.append(put_result['immutable_data_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) print "put hello_world_2" put_result = blockstack_client.put_immutable("foo.test", "hello_world_2", json.dumps(datasets[1], sort_keys=True), proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.expect_atlas_zonefile(put_result['zonefile_hash']) zonefile_hashes.append(put_result['immutable_data_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) print "put hello_world_3" put_result = blockstack_client.put_immutable("foo.test", "hello_world_3", json.dumps(datasets[2], sort_keys=True), proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.expect_atlas_zonefile(put_result['zonefile_hash']) zonefile_hashes.append(put_result['immutable_data_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() for i in xrange(0, 12): testlib.next_block(**kw) print "waiting for confirmation" time.sleep(10) # should succeed (name collision) datasets[0]['newdata'] = "asdf" put_result = blockstack_client.put_immutable("foo.test", "hello_world_1", json.dumps(datasets[0], sort_keys=True), proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False zonefile_hashes[0] = put_result['immutable_data_hash'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.expect_atlas_zonefile(put_result['zonefile_hash']) del datasets[0]['newdata'] for i in xrange(0, 12): testlib.next_block(**kw) print "waiting for confirmation" time.sleep(10) # delete everything for i in xrange(0, len(datasets)): print "delete %s" % zonefile_hashes[i] put_result = blockstack_client.delete_immutable( "foo.test", zonefile_hashes[i], wallet_keys=wallet_keys) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) print "delete_immutable collision failed" return False 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() for i in xrange(0, 12): testlib.next_block(**kw) print "waiting for confirmation" time.sleep(10) last_hash = put_result['zonefile_hash']
def scenario(wallets, **kw): global wallet_keys, error, foo_output, bar_output, baz_output, config_paths 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.blockstack_name_preorder("baz.test", wallets[8].privkey, wallets[9].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.blockstack_name_register("baz.test", wallets[8].privkey, wallets[9].addr) testlib.next_block(**kw) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) wallet_keys['foo.test'] = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey, data_privkey=wallets[4].privkey, payment_privkey=wallets[11].privkey) wallet_keys['bar.test'] = blockstack_client.make_wallet_keys( owner_privkey=wallets[6].privkey, data_privkey=wallets[7].privkey, payment_privkey=wallets[12].privkey) wallet_keys['baz.test'] = blockstack_client.make_wallet_keys( owner_privkey=wallets[9].privkey, data_privkey=wallets[10].privkey, payment_privkey=wallets[13].privkey) # migrate profiles for name in ['foo.test', 'bar.test', 'baz.test']: res = testlib.migrate_profile(name, proxy=test_proxy, wallet_keys=wallet_keys[name]) if 'error' in res: res['test'] = 'Failed to initialize %s profile' % name 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) # set up config file config_path = os.environ['BLOCKSTACK_FILE_CONFIG'] with open(config_path, "w") as f: f.write(TEST_CONFIG_FILE) config_paths = {} # set up config file and directory for each principal for name in ['foo.test', 'bar.test', 'baz.test']: config_dir = os.path.dirname(config_path) + "." + name os.makedirs(config_dir) name_config_path = os.path.join(config_dir, os.path.basename(config_path)) config_paths[name] = name_config_path with open(config_paths[name], "w") as f: f.write(TEST_CONFIG_FILE) foo_output = os.path.join(os.path.dirname(config_path), 'foo.test-out.txt') foo_fail_output = os.path.join(os.path.dirname(config_path), 'foo.test-out-fail.txt') bar_output = os.path.join(os.path.dirname(config_path), 'bar.test-out.txt') bar_fail_output = os.path.join(os.path.dirname(config_path), 'bar.test-out-fail.txt') baz_output = os.path.join(os.path.dirname(config_path), 'baz.test-out.txt') baz_fail_output = os.path.join(os.path.dirname(config_path), 'baz.test-out-fail.txt') # initialize file app res = blockstack_file.file_key_regenerate( "foo.test", "localhost", config_path=config_paths['foo.test'], wallet_keys=wallet_keys['foo.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return res = blockstack_file.file_key_regenerate( "bar.test", "localhost", config_path=config_paths['bar.test'], wallet_keys=wallet_keys['bar.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return res = blockstack_file.file_key_regenerate( "bar.test", "mobile-phone", config_path=config_paths['bar.test'], wallet_keys=wallet_keys['bar.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return res = blockstack_file.file_key_regenerate( "baz.test", "laptop", config_path=config_paths['baz.test'], wallet_keys=wallet_keys['baz.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return # send a file from foo.test to bar.test and baz.test res = blockstack_file.file_put('foo.test', 'localhost', ['bar.test', 'baz.test'], 'config-file-from-foo.test', config_path, config_path=config_paths['foo.test'], wallet_keys=wallet_keys['foo.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return # send a file from bar.test's mobile phone to foo.test (but not baz.test) res = blockstack_file.file_put('bar.test', 'mobile-phone', ['foo.test'], 'config-file-from-bar.test', config_path, config_path=config_paths['bar.test'], wallet_keys=wallet_keys['bar.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return # send a file from baz.test's laptop to baz.test's laptop (and no one else) res = blockstack_file.file_put('baz.test', 'laptop', [], 'config-file-from-baz.test', config_path, config_path=config_paths['baz.test'], wallet_keys=wallet_keys['baz.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return # have foo.test receive bar.test's file log.debug("foo.test receives bar.test's file") res = blockstack_file.file_get('foo.test', 'localhost', 'bar.test', 'config-file-from-bar.test', foo_output, config_path=config_paths['foo.test'], wallet_keys=wallet_keys['foo.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return # have bar.test receive bar.test's file to localhost log.debug("bar.test receives bar.tests's file") res = blockstack_file.file_get('bar.test', 'localhost', 'bar.test', 'config-file-from-bar.test', bar_output, config_path=config_paths['bar.test'], wallet_keys=wallet_keys['bar.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return # have baz.test receive foo.test's file log.debug("baz.test recieves foo.test's file") res = blockstack_file.file_get('baz.test', 'laptop', 'foo.test', 'config-file-from-foo.test', baz_output, config_path=config_paths['baz.test'], wallet_keys=wallet_keys['baz.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return # have bar.test receive foo.test's file to its mobile-phone key log.debug("bar.test receives foo.test's file") res = blockstack_file.file_get('bar.test', 'mobile-phone', 'foo.test', 'config-file-from-foo.test', bar_output, config_path=config_paths['bar.test'], wallet_keys=wallet_keys['bar.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return # have baz.test try to receive bar.test's file (should fail) log.debug("baz.test receives bar.test's file (should fail)") res = blockstack_file.file_get('baz.test', 'laptop', 'bar.test', 'config-file-from-bar.test', baz_fail_output, config_path=config_paths['baz.test'], wallet_keys=wallet_keys['baz.test']) print json.dumps(res, indent=4, sort_keys=True) if 'error' not in res or res['error'] != 'Failed to decrypt data': print 'baz decrypting hidden file: succeeded when we should not have, or failed incorrectly: %s' % res error = True return # have foo.test and bar.test try to receive baz.test's file (should fail) for (name, failpath) in [('foo.test', foo_fail_output), ('bar.test', bar_fail_output)]: log.debug("%s receives baz.test's file (should fail)" % name) res = blockstack_file.file_get(name, 'localhost', 'baz.test', 'config-file-from-baz.test', failpath, config_path=config_paths[name], wallet_keys=wallet_keys[name]) print json.dumps(res, indent=4, sort_keys=True) if 'error' not in res or res['error'] != 'Failed to decrypt data': print '%s decrypting hidden file: succeeded when we should not have, or fialed incorrectly: %s' % ( name, res) error = True return # regenerate everyone's keys res = blockstack_file.file_key_regenerate( "foo.test", "localhost", config_path=config_paths['foo.test'], wallet_keys=wallet_keys['foo.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return res = blockstack_file.file_key_regenerate( "bar.test", "localhost", config_path=config_paths['bar.test'], wallet_keys=wallet_keys['bar.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return res = blockstack_file.file_key_regenerate( "bar.test", "mobile-phone", config_path=config_paths['bar.test'], wallet_keys=wallet_keys['bar.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return res = blockstack_file.file_key_regenerate( "baz.test", "laptop", config_path=config_paths['baz.test'], wallet_keys=wallet_keys['baz.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return # have foo.test receive bar.test's file, despite regeneration log.debug("foo.test receives bar.test's file, despite regeneration") res = blockstack_file.file_get('foo.test', 'localhost', 'bar.test', 'config-file-from-bar.test', foo_output, config_path=config_paths['foo.test'], wallet_keys=wallet_keys['foo.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return if 'warning' not in res or res['warning'] != 'Used stale key': print json.dumps(res, indent=4, sort_keys=True) print "did not use stale key" error = True return # have bar.test receive bar.test's file to localhost log.debug("bar.test receives bar.tests's file, despite regeneration") res = blockstack_file.file_get('bar.test', 'localhost', 'bar.test', 'config-file-from-bar.test', bar_output, config_path=config_paths['bar.test'], wallet_keys=wallet_keys['bar.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return if 'warning' not in res or res['warning'] != 'Used stale key': print json.dumps(res, indent=4, sort_keys=True) print "did not use stale key" error = True return # have baz.test receive foo.test's file log.debug("baz.test recieves foo.test's file, despite regeneration") res = blockstack_file.file_get('baz.test', 'laptop', 'foo.test', 'config-file-from-foo.test', baz_output, config_path=config_paths['baz.test'], wallet_keys=wallet_keys['baz.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return if 'warning' not in res or res['warning'] != 'Used stale key': print json.dumps(res, indent=4, sort_keys=True) print "did not use stale key" error = True return # have bar.test receive foo.test's file to its mobile-phone key log.debug("bar.test receives foo.test's file, despite regeneration") res = blockstack_file.file_get('bar.test', 'mobile-phone', 'foo.test', 'config-file-from-foo.test', bar_output, config_path=config_paths['bar.test'], wallet_keys=wallet_keys['bar.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return if 'warning' not in res or res['warning'] != 'Used stale key': print json.dumps(res, indent=4, sort_keys=True) print "did not use stale key" error = True return # delete the file from foo log.debug("delete foo.test's file") res = blockstack_file.file_delete('foo.test', 'config-file-from-foo.test', config_path=config_paths['foo.test'], wallet_keys=wallet_keys['foo.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return # delete the file from bar log.debug("delete bar.test's file") res = blockstack_file.file_delete('bar.test', 'config-file-from-bar.test', config_path=config_paths['bar.test'], wallet_keys=wallet_keys['bar.test']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return # verify that no one can read foo's file for (name, host, failpath) in [('foo.test', 'localhost', foo_fail_output), ('bar.test', 'mobile-phone', bar_fail_output), ('baz.test', 'laptop', baz_fail_output)]: log.debug("%s receives foo.test's deleted file (should fail)" % name) res = blockstack_file.file_get(name, host, 'foo.test', 'config-file-from-foo.test', failpath, config_path=config_paths[name], wallet_keys=wallet_keys[name]) print json.dumps(res, indent=4, sort_keys=True) if 'error' not in res or res['error'] != 'Failed to get encrypted file': print 'reading deleted file: succeeded when we should not have, or failed incorrectly: %s' % res error = True return
def scenario(wallets, **kw): global datasets, zonefile_hashes, put_result, last_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) 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 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 testlib.next_block(**kw) put_result = blockstack_client.put_immutable("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) zonefile_hashes.append(put_result['immutable_data_hash']) testlib.next_block(**kw) put_result = blockstack_client.put_immutable("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) zonefile_hashes.append(put_result['immutable_data_hash']) testlib.next_block(**kw) put_result = blockstack_client.put_immutable("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) zonefile_hashes.append(put_result['immutable_data_hash']) testlib.next_block(**kw) # should fail (name collision) datasets[0]['newdata'] = "asdf" put_result = blockstack_client.put_immutable("foo.test", "hello_world_1", datasets[0], proxy=test_proxy, wallet_keys=wallet_keys) if 'error' not in put_result: zonefile_hashes[0] = put_result['immutable_data_hash'] del datasets[0]['newdata'] testlib.next_block(**kw) # delete everything for i in xrange(0, len(datasets)): print "delete %s" % zonefile_hashes[i] put_result = blockstack_client.delete_immutable( "foo.test", zonefile_hashes[i], wallet_keys=wallet_keys) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) testlib.next_block(**kw) last_hash = put_result['zonefile_hash']
def scenario(wallets, **kw): global synchronized, value_hash, atlasdb_path, zonefile_dir, working_dir, atlas_dir atlasdb_path = kw['blockstack_opts']['atlasdb_path'] zonefile_dir = kw['blockstack_opts']['zonefiles'] working_dir = testlib.working_dir(**kw) 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) 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) # 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) # make 10 empty zonefiles and propagate them for i in xrange(0, 10): empty_zonefile_str = testlib.make_empty_zonefile( "foo_{}.test".format(i), wallets[3].addr) value_hash = blockstack.lib.storage.get_zonefile_data_hash( empty_zonefile_str) res = testlib.blockstack_name_update("foo_{}.test".format(i), value_hash, wallets[3].privkey) if 'error' in res: print json.dumps(res) return False value_hashes.append(value_hash) testlib.next_block(**kw) res = testlib.blockstack_put_zonefile(empty_zonefile_str) if not res: return False # 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. atlas_dir = os.path.join(working_dir, "atlas_network") network_des = atlas_network.atlas_network_build(testlib.working_dir(**kw), [17000], {17000: [16264]}, {}, atlas_dir) atlas_network.atlas_network_start(network_des) # wait at most 60 seconds for atlas network to converge synchronized = False for i in xrange(0, 60): 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 time.sleep(15.0) atlas_network.atlas_network_stop(network_des) return synchronized
def scenario(wallets, **kw): # disable subdomains at first subdomaindb_path = None blockstack_opts = blockstack.lib.config.get_blockstack_opts() assert 'subdomaindb_path' in blockstack_opts subdomaindb_path = blockstack_opts['subdomaindb_path'] del blockstack_opts['subdomaindb_path'] blockstack.lib.config.set_blockstack_opts(blockstack_opts) 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.blockstack_name_preorder("foo4.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_preorder("foo5.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_preorder("foo6.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_preorder("foo7.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)), } # register initial subdomains 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.blockstack_name_register("foo4.test", wallets[2].privkey, wallets[3].addr, zonefile_hash='11' * 20) testlib.blockstack_name_register("foo5.test", wallets[2].privkey, wallets[3].addr, zonefile_hash='11' * 20) testlib.blockstack_name_register("foo6.test", wallets[2].privkey, wallets[3].addr, zonefile_hash='11' * 20) testlib.blockstack_name_register("foo7.test", wallets[2].privkey, wallets[3].addr, zonefile_hash='11' * 20) testlib.next_block(**kw) assert testlib.blockstack_put_zonefile(zonefiles['foo1.test']) assert testlib.blockstack_put_zonefile(zonefiles['foo2.test']) assert testlib.blockstack_put_zonefile(zonefiles['foo3.test']) # send updates, but only on foo1.test. 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) name = 'foo{}.test'.format(i + 4) zonefiles = { 'foo1.test': zf_template.format( name, subdomains.make_subdomain_txt( 'bar.foo1.test', name, wallets[4].addr, i + 1, zf_template.format('bar.foo1.test', zf_default_url), wallets[4].privkey)), 'foo2.test': zf_template.format( name, subdomains.make_subdomain_txt( 'bar.foo2.test', name, wallets[4].addr, i + 1, zf_template.format('bar.foo2.test', zf_default_url), wallets[4].privkey)), 'foo3.test': zf_template.format( name, subdomains.make_subdomain_txt( 'bar.foo3.test', name, wallets[4].addr, i + 1, zf_template.format('bar.foo3.test', zf_default_url), wallets[4].privkey)), } testlib.blockstack_name_update( name, storage.get_zonefile_data_hash(zonefiles['foo1.test']), wallets[3].privkey) testlib.blockstack_name_update( name, storage.get_zonefile_data_hash(zonefiles['foo2.test']), wallets[3].privkey) testlib.blockstack_name_update( name, storage.get_zonefile_data_hash(zonefiles['foo3.test']), wallets[3].privkey) testlib.next_block(**kw) assert testlib.blockstack_put_zonefile(zonefiles['foo1.test']) assert testlib.blockstack_put_zonefile(zonefiles['foo2.test']) assert testlib.blockstack_put_zonefile(zonefiles['foo3.test']) # subdomains should not exist---we haven't indexed them yet 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' not in res: print 'got a subdomain' print res return False # wait until they exist testlib.next_block(**kw) testlib.next_block(**kw) testlib.next_block(**kw) blockstack_opts['subdomaindb_path'] = subdomaindb_path blockstack.lib.config.set_blockstack_opts(blockstack_opts) 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 # domain should be foo6.test if res['domain'] != 'foo6.test': print 'wrong domain' 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(firstblock=256, **kw)
def scenario(wallets, **kw): global debug, expected_consensus 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) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.blockstack_name_preorder("foo2.test", wallets[2].privkey, wallets[3].addr) 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) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.blockstack_name_register("foo2.test", wallets[2].privkey, wallets[3].addr) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.blockstack_name_update("foo2.test", "11" * 20, wallets[3].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.blockstack_name_update("foo.test", "11" * 20, wallets[3].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) # this is the hash that must be present in the name after the TRANSFER expected_consensus = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw) testlib.next_block(**kw) testlib.next_block(**kw) testlib.next_block(**kw) resp = testlib.blockstack_name_transfer("foo.test", wallets[4].addr, True, wallets[3].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) resp = testlib.blockstack_name_transfer("foo2.test", wallets[4].addr, True, wallets[3].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw)
def scenario(wallets, **kw): 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) wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey) # should be zero names, zero cumulative names num_names = blockstack_client.proxy.get_num_names() num_names_cum = blockstack_client.proxy.get_num_names(include_expired=True) if num_names != 0: print 'wrong number of names: {}'.format(num_names) return False if num_names_cum != 0: print 'wrong number of cumulative names: {}'.format(num_names_cum) return False 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) # should be 1 name, 1 cumulative name res = test_name_count(1, 1) if not res: return res # expire for i in xrange(0, 5 * NAMESPACE_LIFETIME_MULTIPLIER): testlib.next_block(**kw) testlib.next_block(**kw) # should be 1 name, 1 cumulative name res = test_name_count(0, 1) if not res: return res testlib.blockstack_name_preorder("foo2.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo2.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) # should be 1 name, 2 cumulative names res = test_name_count(1, 2) if not res: return res 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) # should be 2 names, 2 cumulative names res = test_name_count(2, 2) if not res: return res
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, wallet=register_wallet) 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, wallet=register_wallet) 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 pk, pk2 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) # pay for a name in a v1 namespace with Stacks addr = virtualchain.address_reencode(virtualchain.get_privkey_address(pk)) addr2 = virtualchain.address_reencode( virtualchain.get_privkey_address(pk2)) # calculate the cost of doing so namespace = testlib.get_state_engine().get_namespace('test') stacks_price = blockstack.lib.scripts.price_name_stacks( 'foo', namespace, testlib.get_current_block(**kw)) btc_price = blockstack.lib.scripts.price_name( 'foo', namespace, testlib.get_current_block(**kw)) print '' print 'price of {} in Stacks is {}'.format('foo.test', stacks_price) print 'price of {} in BTC is {}'.format('foo.test', btc_price) print '' testlib.blockstack_send_tokens(addr, "STACKS", stacks_price + 1, wallets[0].privkey) testlib.blockstack_send_tokens(addr2, "STACKS", stacks_price + 1, wallets[0].privkey) testlib.send_funds(wallets[0].privkey, 2 * btc_price, addr) testlib.send_funds(wallets[0].privkey, 2 * btc_price, addr2) testlib.next_block(**kw) # preorder/register using Stacks testlib.blockstack_name_preorder("foo.test", pk, addr2, price={ 'units': 'STACKS', 'amount': stacks_price + 1 }) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", pk, addr2) testlib.next_block(**kw) # renew using more stacks than we have (should fail) testlib.blockstack_name_renew('foo.test', pk2, price={ 'units': 'STACKS', 'amount': stacks_price + 2 }, expect_fail=True, safety_checks=False) testlib.next_block(**kw) testlib.expect_snv_fail_at('foo.test', testlib.get_current_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) wallet_keys_2 = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[9].privkey, wallets[7].privkey, wallets[8].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[6].privkey, wallets[7].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_register("bar.test", wallets[6].privkey, wallets[7].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 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) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False data_pk = wallets[-1].privkey data_pub = wallets[-1].pubkey_hex config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) # make an index file index_file_path = "/tmp/name_preorder_register_update_app_auth.foo.test.index.html" with open(index_file_path, "w") as f: f.write(index_file_data) testlib.blockstack_client_set_wallet("0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # register an application under foo.test res = testlib.blockstack_cli_app_publish("foo.test", "ping.app", "node_read", index_file_path, password="******") if 'error' in res: res['test'] = 'Failed to register foo.test/bar app' print json.dumps(res, indent=4, sort_keys=True) error = True return # activate bar.test testlib.blockstack_client_set_wallet("0123456789abcdef", wallets[9].privkey, wallets[7].privkey, wallets[8].privkey) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # sign in pk = 'ce100586279d3b127b7dcc137fcc2f18b272bb2b43bdaea3584d0ea17087ec0201' pubk = keylib.ECPrivateKey(pk).public_key().to_hex() res = testlib.blockstack_cli_app_signin("foo.test", pk, "ping.app", ["node_read"]) if 'error' in res: res['test'] = 'Failed to signin: {}'.format(res['error']) print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] res = testlib.blockstack_REST_call("GET", "/v1/ping", ses) if res['http_status'] != 200: print "failed to GET /api/v1/ping" print json.dumps(res, indent=4, sort_keys=True) error = True return False if res['response']['status'] != 'alive': print "failed to GET /api/v1/ping" print json.dumps(res, indent=4, sort_keys=True) error = True return False # access index.html res = testlib.blockstack_REST_call( "GET", "/v1/resources/foo.test/ping.app?name=index.html&pubkey={}".format( wallets[4].pubkey_hex), ses) if 'error' in res or res['http_status'] != 200: print 'failed to GET /v1/resources?name=/index.html' print json.dumps(res) error = True return False if res['raw'] != index_file_data: print 'expected {}\ngot {}\n'.format(index_file_data, res['raw']) print json.dumps(res) error = True return False 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 = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].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'] # 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], sort_keys=True), password="******") if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.next_block(**kw) put_result = testlib.blockstack_cli_put_mutable( "foo.test", "hello_world_2", json.dumps(datasets[1], sort_keys=True), password="******") if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False put_result = testlib.blockstack_cli_put_mutable( "foo.test", "hello_world_3", json.dumps(datasets[2], sort_keys=True), password="******") if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False # 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], sort_keys=True), password="******") if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False # now delete everything for i in xrange(0, len(datasets)): delete_result = testlib.blockstack_cli_delete_mutable( "foo.test", "hello_world_%s" % (i + 1), password="******") if 'error' in delete_result: print json.dumps(delete_result, indent=4, sort_keys=True) return False testlib.next_block(**kw)