def check(state_engine): global wallet_keys, wallet_keys_2, datasets, zonefile_hash, zonefile_hash_2, datastore_name # not revealed, but ready ns = state_engine.get_namespace_reveal("test") if ns is not None: print "namespace not ready" return False ns = state_engine.get_namespace("test") if ns is None: print "no namespace" return False if ns['namespace_id'] != 'test': print "wrong namespace" return False # not preordered names = ['foo.test', 'bar.test'] wallet_keys_list = [wallet_keys, wallet_keys_2] zonefile_hashes = [zonefile_hash[:], zonefile_hash_2[:]] for i in xrange(0, len(names)): name = names[i] wallet_payer = 3 * (i + 1) - 1 wallet_owner = 3 * (i + 1) wallet_data_pubkey = 3 * (i + 1) + 1 wallet_keys = wallet_keys_list[i] zonefile_hash = zonefile_hashes[i] preorder = state_engine.get_name_preorder( name, pybitcoin.make_pay_to_address_script(wallets[wallet_payer].addr), wallets[wallet_owner].addr) if preorder is not None: print "still have preorder" return False # registered name_rec = state_engine.get_name(name) if name_rec is None: print "name does not exist" return False # owned if name_rec['address'] != wallets[wallet_owner].addr or name_rec[ 'sender'] != pybitcoin.make_pay_to_address_script( wallets[wallet_owner].addr): print "name has wrong owner" return False # zonefile is NOT legacy user_zonefile = blockstack_client.load_name_zonefile( name, zonefile_hash) if 'error' in user_zonefile: print json.dumps(user_zonefile, indent=4, sort_keys=True) return False if blockstack_profiles.is_profile_in_legacy_format(user_zonefile): print "legacy still" print json.dumps(user_zonefile, indent=4, sort_keys=True) return False # still have all the right info user_profile = blockstack_client.get_profile( name, user_zonefile=user_zonefile) if user_profile is None: print "Unable to load user profile for %s (%s)" % ( name, wallets[wallet_data_pubkey].pubkey_hex) return False if 'error' in user_profile: print json.dumps(user_profile, indent=4, sort_keys=True) return False # can fetch latest by name immutable_data = get_data("blockstack://hello_world_immutable.foo.test/") if 'error' in immutable_data: print json.dumps(immutable_data, indent=4, sort_keys=True) return False if json.loads(immutable_data['data']) != {'hello': 'world'}: print "immutable fetch-latest mismatch:\n%s (%s)\n%s" % ( immutable_data['data'], type(immutable_data['data']), { 'hello': 'world' }) return False if immutable_data['hash'] != immutable_hash: print "immutable fetch-latest hash mismatch: %s != %s" % ( immutable_data['hash'], immutable_hash) return False # can fetch by name and hash immutable_data = get_data( "blockstack://hello_world_immutable.foo.test/#%s" % immutable_hash) if 'error' in immutable_data: print json.dumps(immutable_data, indent=4, sort_keys=True) return False if json.loads(immutable_data['data']) != {'hello': 'world'}: print "immutable fetch-by-hash mismatch:\n%s (%s)\n%s" % ( immutable_data['data'], type(immutable_data['data']), { 'hello': 'world' }) return False if immutable_data['hash'] != immutable_hash: print "immutable fetch-by-hash mismatch: %s != %s" % ( immutable_data['hash'], immutable_hash) return False # hash must match (if we put the wrong hash, it must fail) try: immutable_data = get_data( "blockstack://hello_world_immutable.foo.test/#%s" % ("0" * len(immutable_hash))) print "no error" print json.dumps(immutable_data, indent=4, sort_keys=True) return False except urllib2.URLError: pass # can list names and hashes immutable_data_list = get_data("blockstack://foo.test/#immutable") if 'error' in immutable_data_list: print json.dumps(immutable_data, indent=4, sort_keys=True) return False if len(immutable_data_list['data']) != 2: print "multiple immutable data" print json.dumps(immutable_data_list, indent=4, sort_keys=True) return False # order preserved if immutable_data_list['data'][0][ 'data_id'] != 'hello_world_immutable' or immutable_data_list[ 'data'][0]['hash'] != immutable_hash: print "wrong data ID and/or hash" print json.dumps(immutable_data_list, indent=4, sort_keys=True) return False device_id = blockstack_client.config.get_local_device_id() data_id = blockstack_client.storage.make_fq_data_id( device_id, 'hello_world_mutable') # can fetch latest mutable by name mutable_data = get_data("blockstack://bar.test/{}".format(data_id)) if 'error' in mutable_data: print json.dumps(mutable_data, indent=4, sort_keys=True) return False if json.loads(mutable_data['data']) != {'hello': 'world'}: print json.dumps(mutable_data, indent=4, sort_keys=True) return False if mutable_data['version'] != 1: print "wrong version: %s" % mutable_data['data']['version'] return False # can fetch by version mutable_data = get_data("blockstack://bar.test/{}#1".format(data_id)) if 'error' in mutable_data: print json.dumps(mutable_data, indent=4, sort_keys=True) return False if json.loads(mutable_data['data']) != {'hello': 'world'}: print json.dumps(mutable_data, indent=4, sort_keys=True) return False # will fail to fetch if we give the wrong version try: mutable_data = get_data("blockstack://bar.test/{}#2".format(data_id)) print "mutable fetch by wrong version worked" print json.dumps(mutable_data, indent=4, sort_keys=True) return False except urllib2.URLError: pass # can fetch mutable data put by URL data_id = blockstack_client.storage.make_fq_data_id(device_id, 'foo_data2') mutable_data = get_data("blockstack://foo.test/{}".format(data_id)) if 'error' in mutable_data or 'data' not in mutable_data or 'version' not in mutable_data: print json.dumps(mutable_data, indent=4, sort_keys=True) return False if json.loads(mutable_data['data']) != {'hello2': 'world2'}: print "Invalid mutable data fetched from blockstack://foo.test/{}".format( data_id) print json.dumps(mutable_data, indent=4, sort_keys=True) return False # can fetch immutable data put by URL immutable_data = get_data("blockstack://foo_immutable.foo.test") if 'error' in immutable_data or 'hash' not in immutable_data: print json.dumps(immutable_data, indent=4, sort_keys=True) return False if json.loads(immutable_data['data']) != {'hello3': 'world3'}: print "Invalid immutable data fetched from blockstack://foo_immutable.foo.test" print json.dumps(immutable_data, indent=4, sort_keys=True) return False # can fetch files and directories mutable_data = get_data( "blockstack://{}@foo-app.com/hello_datastore".format(datastore_name)) if 'error' in mutable_data or 'file' not in mutable_data or mutable_data[ 'file']['idata'] != 'hello datastore': print 'Failed to get blockstack://{}@foo-app.com/hello_datastore'.format( datastore_name) print json.dumps(mutable_data, indent=4, sort_keys=True) return False mutable_data = get_data( "blockstack://{}@foo-app.com/hello_dir/".format(datastore_name)) if 'error' in mutable_data or 'dir' not in mutable_data or 'hello_dir_datastore' not in mutable_data[ 'dir']['idata'].keys(): print 'Failed to get blockstack://{}@foo-app.com/hello_dir/'.format( datastore_name) print json.dumps(mutable_data, indent=4, sort_keys=True) return False mutable_data = get_data( "blockstack://{}@foo-app.com/hello_dir/hello_dir_datastore".format( datastore_name)) if 'error' in mutable_data or 'file' not in mutable_data or mutable_data[ 'file']['idata'] != 'hello dir datastore': print 'Failed to get blockstack://{}@foo-app.com/hello_dir/hello_dir_datastore'.format( datastore_name) print json.dumps(mutable_data, indent=4, sort_keys=True) return False return True
def check( state_engine ): global wallet_keys, wallet_keys_2, datasets, zonefile_hash, zonefile_hash_2, datastore_name # not revealed, but ready ns = state_engine.get_namespace_reveal( "test" ) if ns is not None: print "namespace not ready" return False ns = state_engine.get_namespace( "test" ) if ns is None: print "no namespace" return False if ns['namespace_id'] != 'test': print "wrong namespace" return False # not preordered names = ['foo.test', 'bar.test'] wallet_keys_list = [wallet_keys, wallet_keys_2] zonefile_hashes = [zonefile_hash[:], zonefile_hash_2[:]] for i in xrange(0, len(names)): name = names[i] wallet_payer = 3 * (i+1) - 1 wallet_owner = 3 * (i+1) wallet_keys = wallet_keys_list[i] zonefile_hash = zonefile_hashes[i] preorder = state_engine.get_name_preorder( name, pybitcoin.make_pay_to_address_script(wallets[wallet_payer].addr), wallets[wallet_owner].addr ) if preorder is not None: print "still have preorder" return False # registered name_rec = state_engine.get_name( name ) if name_rec is None: print "name does not exist" return False # owned if name_rec['address'] != wallets[wallet_owner].addr or name_rec['sender'] != pybitcoin.make_pay_to_address_script(wallets[wallet_owner].addr): print "name has wrong owner" return False # zonefile is NOT legacy user_zonefile = blockstack_client.load_name_zonefile( name, zonefile_hash ) if 'error' in user_zonefile: print json.dumps(user_zonefile, indent=4, sort_keys=True) return False if blockstack_profiles.is_profile_in_legacy_format( user_zonefile ): print "legacy still" print json.dumps(user_zonefile, indent=4, sort_keys=True) return False # still have all the right info user_profile = blockstack_client.get_profile(name, user_zonefile=user_zonefile) if user_profile is None: print "Unable to load user profile for %s" % name return False if 'error' in user_profile: print json.dumps(user_profile, indent=4, sort_keys=True) return False # can fetch latest by name immutable_data = get_data( "blockstack://hello_world_immutable.foo.test/" ) if 'error' in immutable_data: print json.dumps(immutable_data, indent=4, sort_keys=True) return False if json.loads(immutable_data['data']) != {'hello': 'world'}: print "immutable fetch-latest mismatch:\n%s (%s)\n%s" % (immutable_data['data'], type(immutable_data['data']), {'hello': 'world'}) return False if immutable_data['hash'] != immutable_hash: print "immutable fetch-latest hash mismatch: %s != %s" % (immutable_data['hash'], immutable_hash) return False # can fetch by name and hash immutable_data = get_data( "blockstack://hello_world_immutable.foo.test/#%s" % immutable_hash ) if 'error' in immutable_data: print json.dumps(immutable_data, indent=4, sort_keys=True) return False if json.loads(immutable_data['data']) != {'hello': 'world'}: print "immutable fetch-by-hash mismatch:\n%s (%s)\n%s" % (immutable_data['data'], type(immutable_data['data']), {'hello': 'world'}) return False if immutable_data['hash'] != immutable_hash: print "immutable fetch-by-hash mismatch: %s != %s" % (immutable_data['hash'], immutable_hash) return False # hash must match (if we put the wrong hash, it must fail) try: immutable_data = get_data( "blockstack://hello_world_immutable.foo.test/#%s" % ("0" * len(immutable_hash))) print "no error" print json.dumps(immutable_data, indent=4, sort_keys=True) return False except urllib2.URLError: pass # can list names and hashes immutable_data_list = get_data( "blockstack://foo.test/#immutable" ) if 'error' in immutable_data_list: print json.dumps(immutable_data, indent=4, sort_keys=True ) return False if len(immutable_data_list['data']) != 2: print "multiple immutable data" print json.dumps(immutable_data_list, indent=4, sort_keys=True ) return False # order preserved if immutable_data_list['data'][0]['data_id'] != 'hello_world_immutable' or immutable_data_list['data'][0]['hash'] != immutable_hash: print "wrong data ID and/or hash" print json.dumps(immutable_data_list, indent=4, sort_keys=True ) return False device_id = blockstack_client.config.get_local_device_id() data_id = blockstack_client.storage.make_fq_data_id( device_id, 'hello_world_mutable' ) # can fetch latest mutable by name mutable_data = get_data( "blockstack://bar.test/{}".format(data_id)) if 'error' in mutable_data: print json.dumps(mutable_data, indent=4, sort_keys=True) return False if json.loads(mutable_data['data']) != {'hello': 'world'}: print json.dumps(mutable_data, indent=4, sort_keys=True) return False if mutable_data['version'] != 1: print "wrong version: %s" % mutable_data['data']['version'] return False # can fetch by version mutable_data = get_data( "blockstack://bar.test/{}#1".format(data_id)) if 'error' in mutable_data: print json.dumps(mutable_data, indent=4, sort_keys=True) return False if json.loads(mutable_data['data']) != {'hello': 'world'}: print json.dumps(mutable_data, indent=4, sort_keys=True) return False # will fail to fetch if we give the wrong version try: mutable_data = get_data("blockstack://bar.test/{}#2".format(data_id)) print "mutable fetch by wrong version worked" print json.dumps(mutable_data, indent=4, sort_keys=True) return False except urllib2.URLError: pass # can fetch mutable data put by URL data_id = blockstack_client.storage.make_fq_data_id(device_id, 'foo_data2') mutable_data = get_data( "blockstack://foo.test/{}".format(data_id) ) if 'error' in mutable_data or 'data' not in mutable_data or 'version' not in mutable_data: print json.dumps(mutable_data, indent=4, sort_keys=True) return False if json.loads(mutable_data['data']) != {'hello2': 'world2'}: print "Invalid mutable data fetched from blockstack://foo.test/{}".format(data_id) print json.dumps(mutable_data, indent=4, sort_keys=True) return False # can fetch immutable data put by URL immutable_data = get_data( "blockstack://foo_immutable.foo.test" ) if 'error' in immutable_data or 'hash' not in immutable_data: print json.dumps(immutable_data, indent=4, sort_keys=True) return False if json.loads(immutable_data['data']) != {'hello3': 'world3'}: print "Invalid immutable data fetched from blockstack://foo_immutable.foo.test" print json.dumps(immutable_data, indent=4, sort_keys=True) return False # can fetch files and directories mutable_data = get_data( "blockstack://{}@foo-app.com/hello_datastore".format(datastore_name) ) if 'error' in mutable_data or 'file' not in mutable_data or mutable_data['file']['idata'] != 'hello datastore': print 'Failed to get blockstack://{}@foo-app.com/hello_datastore'.format(datastore_name) print json.dumps(mutable_data, indent=4, sort_keys=True) return False mutable_data = get_data( "blockstack://{}@foo-app.com/hello_dir/".format(datastore_name) ) if 'error' in mutable_data or 'dir' not in mutable_data or 'hello_dir_datastore' not in mutable_data['dir']['idata'].keys(): print 'Failed to get blockstack://{}@foo-app.com/hello_dir/'.format(datastore_name) print json.dumps(mutable_data, indent=4, sort_keys=True) return False mutable_data = get_data( "blockstack://{}@foo-app.com/hello_dir/hello_dir_datastore".format(datastore_name) ) if 'error' in mutable_data or 'file' not in mutable_data or mutable_data['file']['idata'] != 'hello dir datastore': print 'Failed to get blockstack://{}@foo-app.com/hello_dir/hello_dir_datastore'.format(datastore_name) print json.dumps(mutable_data, indent=4, sort_keys=True) return False return True