def get_hash(profile): if type(profile) is not dict: try: # if string with valid JSON, convert profile = json.loads(profile) except: # if not valid JSON return hex_hash160(profile) return hex_hash160(json.dumps(profile, sort_keys=True))
def get_blockchain_compat_hash( data_txt ): """ Generate a hash suitable for embedding into the blockchain (e.g. for user zonefiles and announcements). """ return pybitcoin.hex_hash160( data_txt )
def write_dht_profile(profile): resp = None dht_client = get_dht_client() if is_profile_in_legacy_format(profile): key = get_hash(profile) value = json.dumps(profile, sort_keys=True) else: key = hex_hash160(profile) value = profile if len(value) > MAX_DHT_WRITE: log.debug("DHT value too large: %s, %s" % (key, len(value))) return resp log.debug("DHT write (%s, %s)" % (key, value)) try: resp = dht_client.set(key, value) log.debug(pprint(resp)) except Exception as e: log.debug(e) return resp
def hash_names( name_list, script_pubkey, register_addrs ): """ Calculate the canonical hash of a set of names and their register addresses. """ # sanity checks... if len(name_list) != len(register_addrs): raise Exception("Name list and register addresses are not the same size") if len(name_list) != len(set(name_list)): raise Exception("Name list has duplicate names") for name in name_list: # check this here, just to catch bugs if not is_b40( name ): raise Exception("Name '%s' is not b40-encoded" % name) # names are sorted, but the addresses are put in the same order as the names name_addrs = zip( name_list, register_addrs ) name_addrs.sort() name_addrs_str = ",".join( [ "%s:%s" % (n, a) for (n, a) in name_addrs ] ) h = hex_hash160( name_addrs_str + script_pubkey ) return h
def get_blockchain_compat_hash(data_txt): """ Generate a hash suitable for embedding into the blockchain (e.g. for user zonefiles and announcements). """ return pybitcoin.hex_hash160(data_txt)
def get_hash(profile): if type(profile) is not dict: try: # print "WARNING: converting to json" profile = json.loads(profile) except: log.debug("WARNING: not valid json") return hex_hash160(json.dumps(profile, sort_keys=True))
def _get_hash(self, value): if type(value) is not dict: try: #self.log.info("WARNING: converting to json") value = json.loads(value) except: self.log.info("WARNING: not valid json") return hex_hash160(json.dumps(value, sort_keys=True))
def hash_name(name, script_pubkey, register_addr=None): """ Generate the hash over a name and hex-string script pubkey """ bin_name = b40_to_bin(name) name_and_pubkey = bin_name + unhexlify(script_pubkey) if register_addr is not None: name_and_pubkey += str(register_addr) return pybitcoin.hex_hash160(name_and_pubkey)
def put_announcement( announcement_text, txid ): """ Go put an announcement into back-end storage. Use the blockstack client library, so we can get at the storage drivers for the storage systems this host is configured to use. Return the data's hash """ session = get_blockstack_client_session() # has the side-effect of initializing all storage drivers, if they're not already data_hash = blockstack_client.storage.put_immutable_data( announcement_text, txid ) if data_hash is None: log.error("Failed to put announcement '%s'" % (pybitcoin.hex_hash160(announcement_text))) return None return data_hash
def create_test_namespace(): reply = namecoind.name_filter('u/', 200) counter = 0 namespace = [] for entry in reply: username = entry['name'].lstrip('u/') if len(username) > 30: continue counter += 1 if counter >= 100: break new_entry = {} new_entry['username'] = username profile = namecoind.get_full_profile('u/' + username) print username print profile new_entry['hash'] = hex_hash160(json.dumps(profile)) print new_entry['hash'] namespace.append(new_entry) fout = open('output_file.txt', 'w') fout.write(json.dumps(namespace)) print counter print namespace
log.debug("GET %s status code %s" % (url, req.status_code)) return None try: res = json.loads(req.content) except Exception, e: log.exception(e) log.debug("Failed to parse request to %s" % url) return None if 'zone_file' not in res.keys(): log.debug("No zonefile in request to %s" % url) return None zone_file_str = str(res['zone_file']) if pybitcoin.hex_hash160( zone_file_str ) != zonefile_hash: log.debug("Hash mismatch: expected %s, got %s" % (pybitcoin.hex_hash160(zone_file_str), zonefile_hash)) return None return zone_file_str def get_profile( fqu ): """ Try to get a profile, from S3 """ url = "%s/%s" % (STORAGE_URL, fqu) req = requests.get(url) if req.status_code != 200: log.debug("GET %s status code %s" % (url, req.status_code)) return None
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( legacy_txt, result_1['transaction_hash'], data_hash=legacy_hash) 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 put_data(data_id, data_txt, zonefile=False, fqu=None): """ Put data or a zonefile to the server. """ import blockstack_client if os.environ.get("BLOCKSTACK_RPC_PID", None) == str(os.getpid()): # don't talk to ourselves log.debug("Do not put_data to ourselves") return False url = "http://%s:%s/RPC2" % (SERVER_NAME, SERVER_PORT) ses = xmlrpclib.ServerProxy(url, allow_none=True) if zonefile: # must be a zonefile try: zf = blockstack_zones.parse_zone_file(data_txt) except: log.error("Failed to parse zone file for %s" % data_id) return False log.debug("Replicate zonefile for %s" % data_id) res_json = ses.put_zonefiles([base64.b64encode(data_txt)]) try: res = json.loads(res_json) except: log.error("Invalid non-JSON response") return False if 'error' in res: log.error("Failed to put %s: %s" % (data_id, data_txt)) return False elif len(res['saved']) != 1 or res['saved'][0] != 1: log.error("Server %s:%s failed to save %s" % (SERVER_NAME, SERVER_PORT, data_id)) return False else: return True elif data_id == fqu: log.debug("Replicate profile for %s" % data_id) # get current profile cur_profile_txt = get_data(data_id, zonefile=False) if cur_profile_txt is None: log.warning("Could not get profile for %s" % data_id) cur_profile_txt = "" # get the data private key (or owner private key if not given) wallet_info = blockstack_client.get_wallet() data_privkey = wallet_info.get('data_privkey', None) if data_privkey is None: data_privkey = wallet_info.get('owner_privkey', None) # sign this request cur_profile_hash = pybitcoin.hex_hash160(cur_profile_txt) sigb64 = blockstack_client.storage.sign_raw_data( "%s%s" % (cur_profile_hash, data_txt), data_privkey) # include signature res = ses.put_profile(data_id, data_txt, cur_profile_hash, sigb64) if 'error' in res: log.error("Failed to put %s: %s" % (data_id, res)) return False else: return True else: # neither profile nor zonefile if os.environ.get("BLOCKSTACK_TEST", None) is not None: # for testing raise Exception("Failed to replicate profile or zonefile") else: return False
def scenario( wallets, **kw ): global put_result, wallet_keys, wallet_keys_2, legacy_profile, zonefile_hash, zonefile_hash_2 wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[8].privkey, wallets[3].privkey, None ) wallet_keys_2 = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[9].privkey, wallets[6].privkey, None ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.blockstack_name_preorder( "bar.test", wallets[5].privkey, wallets[6].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.blockstack_name_register( "bar.test", wallets[5].privkey, wallets[6].addr ) testlib.next_block( **kw ) # set up legacy profile hash legacy_txt = json.dumps(legacy_profile,sort_keys=True) legacy_hash = pybitcoin.hex_hash160( legacy_txt ) result_1 = testlib.blockstack_name_update( "foo.test", legacy_hash, wallets[3].privkey ) result_2 = testlib.blockstack_name_update( "bar.test", legacy_hash, wallets[6].privkey ) testlib.next_block( **kw ) rc = blockstack_client.storage.put_immutable_data( legacy_txt, result_1['transaction_hash'], data_hash=legacy_hash ) assert rc is not None rc = blockstack_client.storage.put_immutable_data( legacy_txt, result_2['transaction_hash'], data_hash=legacy_hash ) assert rc is not None testlib.next_block( **kw ) # migrate profiles, but no zone file keys res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys, zonefile_has_data_key=False ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return zonefile_hash = res['zonefile_hash'] res = testlib.migrate_profile( "bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2, zonefile_has_data_key=False ) if 'error' in res: res['test'] = 'Failed to initialize bar.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return zonefile_hash_2 = res['zonefile_hash'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey'] ) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # see that put_immutable works put_result = testlib.blockstack_cli_put_immutable( 'foo.test', 'hello_world_immutable', json.dumps({'hello': 'world_immutable'}, sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) testlib.expect_atlas_zonefile(put_result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block( **kw ) print "waiting for confirmation" time.sleep(10) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], wallet_keys_2['data_privkey'] ) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # put_mutable should fail on its own, since we have no privat ekey put_result = testlib.blockstack_cli_put_mutable( "bar.test", "hello_world_mutable", json.dumps({'hello': 'world'}, sort_keys=True), password='******') if 'error' not in put_result: print json.dumps(put_result, indent=4, sort_keys=True) print "accidentally succeeded to put_mutable with no public key in zone file" return False # see that put_mutable works, if we give a private key put_result = testlib.blockstack_cli_put_mutable( "bar.test", "hello_world_mutable", json.dumps({'hello': 'world'}, sort_keys=True), password='******', private_key=wallet_keys_2['data_privkey']) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) 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( None, result['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt) 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']) 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) 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", datasets[1], 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", datasets[2], 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", 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.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 put_result, wallet_keys, legacy_profile, zonefile_hash, zonefile_hash_2 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 ) wallet_keys_2 = blockstack_client.make_wallet_keys( owner_privkey=wallets[6].privkey, data_privkey=wallets[7].privkey ) # set up legacy profile hash legacy_txt = json.dumps(legacy_profile,sort_keys=True) legacy_hash = pybitcoin.hex_hash160( legacy_txt ) result_1 = testlib.blockstack_name_update( "foo.test", legacy_hash, wallets[3].privkey ) result_2 = testlib.blockstack_name_update( "bar.test", legacy_hash, wallets[6].privkey ) testlib.next_block( **kw ) rc = blockstack_client.storage.put_immutable_data( None, result_1['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt ) assert rc is not None rc = blockstack_client.storage.put_immutable_data( None, result_2['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt ) assert rc is not None testlib.next_block( **kw ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return zonefile_hash = res['zonefile_hash'] res = testlib.migrate_profile( "bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2 ) if 'error' in res: res['test'] = 'Failed to initialize bar.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return zonefile_hash_2 = res['zonefile_hash'] testlib.next_block( **kw ) # see that put_immutable works put_result = blockstack_client.put_immutable( "foo.test", "hello_world_immutable", {"hello": "world"}, 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 ) # see that put_mutable works put_result = blockstack_client.put_mutable( "bar.test", "hello_world_mutable", {"hello": "world"}, proxy=test_proxy, wallet_keys=wallet_keys_2 ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) testlib.next_block( **kw )
log.debug("GET %s status code %s" % (url, req.status_code)) return None try: res = json.loads(req.content) except Exception, e: log.exception(e) log.debug("Failed to parse request to %s" % url) return None if 'zone_file' not in res.keys(): log.debug("No zonefile in request to %s" % url) return None zone_file_str = str(res['zone_file']) if pybitcoin.hex_hash160(zone_file_str) != zonefile_hash: log.debug("Hash mismatch: expected %s, got %s" % (pybitcoin.hex_hash160(zone_file_str), zonefile_hash)) return None return zone_file_str def get_profile(fqu): """ Try to get a profile, from S3 """ url = "%s/%s" % (STORAGE_URL, fqu) req = requests.get(url) if req.status_code != 200: log.debug("GET %s status code %s" % (url, req.status_code))
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("missing zonefile") data_history_2.append("missing zonefile") data_history_3.append("missing zonefile") testlib.next_block(**kw) rc = blockstack_client.storage.put_immutable_data( None, result['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt) 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) # 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) data_history_1.append("data not defined") data_history_2.append("data not defined") data_history_3.append("data not defined") 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) data_history_1.append(put_result['immutable_data_hash']) data_history_2.append("data not defined") data_history_3.append("data not defined") 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) data_history_1.append(data_history_1[-1]) data_history_2.append(put_result['immutable_data_hash']) data_history_3.append("data not defined") 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) 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']) testlib.next_block(**kw) # overwrite datasets[0]['newdata'] = "asdf" put_result = blockstack_client.put_immutable("foo.test", "hello_world_3", datasets[0], proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) 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'] testlib.next_block(**kw)
log.debug("GET %s status code %s" % (url, req.status_code)) return None try: res = json.loads(req.content) except Exception, e: log.exception(e) log.debug("Failed to parse request to %s" % url) return None if 'zone_file' not in res.keys(): log.debug("No zonefile in request to %s" % url) return None zone_file_str = str(res['zone_file']) if pybitcoin.hex_hash160(zone_file_str) != zonefile_hash: log.debug("Hash mismatch: expected %s, got %s" % (zonefile_hash, pybitcoin.hex_hash160(zone_file_str))) return None return zone_file_str def get_profile(fqu): """ Try to get a profile, from S3 """ url = "%s/%s" % (STORAGE_URL, fqu) req = requests.get(url) if req.status_code != 200: log.debug("GET %s status code %s" % (url, req.status_code))
def scenario( wallets, **kw ): global put_result, wallet_keys, legacy_profile, zonefile_hash, zonefile_hash_2 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 ) wallet_keys_2 = blockstack_client.make_wallet_keys( owner_privkey=wallets[6].privkey ) # set up legacy profile hash legacy_txt = json.dumps(legacy_profile,sort_keys=True) legacy_hash = pybitcoin.hex_hash160( legacy_txt ) result_1 = testlib.blockstack_name_update( "foo.test", legacy_hash, wallets[3].privkey ) result_2 = testlib.blockstack_name_update( "bar.test", legacy_hash, wallets[6].privkey ) testlib.next_block( **kw ) rc = blockstack_client.storage.put_immutable_data( None, result_1['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt ) assert rc is not None rc = blockstack_client.storage.put_immutable_data( None, result_2['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt ) assert rc is not None testlib.next_block( **kw ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return zonefile_hash = res['zonefile_hash'] res = testlib.migrate_profile( "bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2 ) if 'error' in res: res['test'] = 'Failed to initialize bar.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return zonefile_hash_2 = res['zonefile_hash'] testlib.next_block( **kw ) # see that put_immutable works put_result = blockstack_client.put_immutable( "foo.test", "hello_world_immutable", {"hello": "world"}, 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 ) # see that put_mutable works put_result = blockstack_client.put_mutable( "bar.test", "hello_world_mutable", {"hello": "world"}, proxy=test_proxy, wallet_keys=wallet_keys_2 ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) testlib.next_block( **kw )
def get_zonefile_data_hash(data_txt): """ Generate a hash over a user's zonefile. Return the hex string. """ return pybitcoin.hex_hash160(data_txt)
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("missing zonefile") data_history_2.append("missing zonefile") data_history_3.append("missing zonefile") testlib.next_block( **kw ) rc = blockstack_client.storage.put_immutable_data( None, result['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt ) 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 ) # 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 ) data_history_1.append("data not defined") data_history_2.append("data not defined") data_history_3.append("data not defined") 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) data_history_1.append(put_result['immutable_data_hash']) data_history_2.append("data not defined") data_history_3.append("data not defined") 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) data_history_1.append(data_history_1[-1]) data_history_2.append(put_result['immutable_data_hash']) data_history_3.append("data not defined") 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) 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']) testlib.next_block( **kw ) # overwrite datasets[0]['newdata'] = "asdf" put_result = blockstack_client.put_immutable( "foo.test", "hello_world_3", datasets[0], proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) 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'] testlib.next_block( **kw )
def get_zonefile_data_hash( data_txt ): """ Generate a hash over a user's zonefile. Return the hex string. """ return pybitcoin.hex_hash160( data_txt )
def scenario( wallets, **kw ): global put_result, wallet_keys, legacy_profile, zonefile_hash, zonefile_hash_2, 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, payment_privkey=wallets[8].privkey ) # set up legacy profile hash legacy_txt = json.dumps(legacy_profile,sort_keys=True) legacy_hash = pybitcoin.hex_hash160( legacy_txt ) result_1 = testlib.blockstack_name_update( "foo.test", legacy_hash, wallets[3].privkey ) testlib.next_block( **kw ) rc = blockstack_client.storage.put_immutable_data( None, result_1['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt ) assert rc is not None 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) error = True return 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)])) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey'] ) 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) error = True return testlib.expect_atlas_zonefile(resp['value_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_advanced_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) error = True return if 'warning' not in resp: print "no non-standard warning:\n%s" % json.dumps(resp, indent=4, sort_keys=True) error = True return if resp['zonefile'] != nonstandard_zonefile: print "failed to load nonstandard zonefile json" print "expected:\n%s\n\ngot:\n%s" % (nonstandard_zonefile, resp['zonefile']) error = True return # the following should all fail dataplane_funcs = [ ("lookup", lambda: testlib.blockstack_cli_lookup( "foo.test" )), ("put_immutable", lambda: testlib.blockstack_cli_advanced_put_immutable( "foo.test", "fail", '{"Fail": "Yes"}' )), ("get_immutable", lambda: testlib.blockstack_cli_advanced_get_immutable( "foo.test", "fail" )), ("put_mutable", lambda: testlib.blockstack_cli_advanced_put_mutable( "foo.test", "fail", '{"fail": "yes"}' )), ("get_mutable", lambda: testlib.blockstack_cli_advanced_get_mutable( "foo.test", "fail" )), ("delete_immutable", lambda: testlib.blockstack_cli_advanced_delete_immutable( "foo.test", "00" * 32 )), ("delete_mutable", lambda: testlib.blockstack_cli_advanced_delete_mutable( "foo.test", "fail" )) ] 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)) error = True return # this should succeed zf_hist = testlib.blockstack_cli_advanced_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)) error = True return if zf_hist[-1] != nonstandard_zonefile: print "invalid zonefile: expected\n%s\ngot\n%s\n" % (nonstandard_zonefile, zf_hist[-1]) error = True return # this should work, but with "non-standard zonefiles" hist = testlib.blockstack_cli_advanced_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)) error = True return if hist[-1] != 'non-standard zonefile': print "not a non-standard zonefile: %s" % hist[-1] error = True return # 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) error = True return 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 = blockstack_client.put_immutable( "foo.test", "hello_world_immutable", {"hello": "world"}, 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']) # 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 = blockstack_client.put_mutable( "foo.test", "hello_world_mutable", {"hello": "world"}, proxy=test_proxy, wallet_keys=wallet_keys_2 ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) testlib.next_block( **kw )
def scenario(wallets, **kw): global put_result, wallet_keys, legacy_profile, zonefile_hash, zonefile_hash_2, immutable_hash, datastore_name wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[8].privkey, wallets[3].privkey, wallets[4].privkey) wallet_keys_2 = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[9].privkey, wallets[6].privkey, wallets[7].privkey) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_preorder("bar.test", wallets[5].privkey, wallets[6].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_register("bar.test", wallets[5].privkey, wallets[6].addr) testlib.next_block(**kw) # set up legacy profile hash legacy_txt = json.dumps(legacy_profile, sort_keys=True) legacy_hash = pybitcoin.hex_hash160(legacy_txt) result_1 = testlib.blockstack_name_update("foo.test", legacy_hash, wallets[3].privkey) result_2 = testlib.blockstack_name_update("bar.test", legacy_hash, wallets[6].privkey) testlib.next_block(**kw) rc = blockstack_client.storage.put_immutable_data( None, result_1['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt) assert rc is not None rc = blockstack_client.storage.put_immutable_data( None, result_2['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt) assert rc is not None testlib.next_block(**kw) # migrate res = testlib.migrate_profile("foo.test", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return else: zonefile_hash = res['zonefile_hash'] # migrate res = testlib.migrate_profile("bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return else: zonefile_hash_2 = res['zonefile_hash'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) # start up RPC for 'foo.test' testlib.blockstack_client_set_wallet("0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey']) # put immutable put_result = testlib.blockstack_cli_put_immutable( "foo.test", "hello_world_immutable", json.dumps({'hello': 'world'}), password='******') log.debug("put immutable for foo.test") if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) error = True return immutable_hash = put_result['immutable_data_hash'] testlib.expect_atlas_zonefile(put_result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block(**kw) print "waiting for confirmation" time.sleep(10) # start up RPC for 'bar.test' testlib.blockstack_client_set_wallet("0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], wallet_keys_2['data_privkey']) log.debug("put mutable for bar.test") put_result = testlib.blockstack_cli_put_mutable( 'bar.test', 'hello_world_mutable', json.dumps({'hello': 'world'}), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.next_block(**kw) # put mutable data again testlib.blockstack_client_set_wallet("0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey']) res = testlib.blockstack_cli_put_mutable('foo.test', 'foo_data2', json.dumps({'hello2': 'world2'}), password='******') if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) return False # put immutable data with the URL # start up RPC for 'foo.test' log.debug("put immutable for foo.test (2)") res = testlib.blockstack_cli_put_immutable('foo.test', 'foo_immutable', json.dumps({'hello3': 'world3'}), password='******') if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) return False # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) datastore_pk = keylib.ECPrivateKey(wallets[-1].privkey).to_hex() datastore_id_res = testlib.blockstack_cli_datastore_get_id(datastore_pk) datastore_name = datastore_id_res['datastore_id'] # make datastore res = testlib.blockstack_cli_create_datastore(datastore_pk) if 'error' in res: print "failed to create datastore: {}".format(res['error']) return False # put a file into the datastore data = 'hello datastore' log.debug("putfile") res = testlib.blockstack_cli_datastore_putfile(datastore_pk, '/hello_datastore', data) if 'error' in res: print 'failed to putfile /hello_datastore: {}'.format(res['error']) return False # make a directory log.debug("mkdir") res = testlib.blockstack_cli_datastore_mkdir(datastore_pk, '/hello_dir') if 'error' in res: print 'failed to mkdir /hello_dir: {}'.format(res['error']) return False # put a file into the directory data = 'hello dir datastore' log.debug("putfile in dir") res = testlib.blockstack_cli_datastore_putfile( datastore_pk, '/hello_dir/hello_dir_datastore', data) if 'error' in res: print 'failed to putfile /hello_dir/hello_dir_datastore: {}'.format( res['error']) return False testlib.next_block(**kw)
def scenario( wallets, **kw ): global 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( None, result['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt ) 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'] ) 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) 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", datasets[1], 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", datasets[2], 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", 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.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 put_result, wallet_keys, legacy_profile, zonefile_hash, zonefile_hash_2 wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[8].privkey, wallets[3].privkey, wallets[4].privkey ) wallet_keys_2 = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[9].privkey, wallets[6].privkey, wallets[7].privkey ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.blockstack_name_preorder( "bar.test", wallets[5].privkey, wallets[6].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.blockstack_name_register( "bar.test", wallets[5].privkey, wallets[6].addr ) testlib.next_block( **kw ) # set up legacy profile hash legacy_txt = json.dumps(legacy_profile,sort_keys=True) legacy_hash = pybitcoin.hex_hash160( legacy_txt ) result_1 = testlib.blockstack_name_update( "foo.test", legacy_hash, wallets[3].privkey ) result_2 = testlib.blockstack_name_update( "bar.test", legacy_hash, wallets[6].privkey ) testlib.next_block( **kw ) rc = blockstack_client.storage.put_immutable_data( legacy_txt, result_1['transaction_hash'], data_hash=legacy_hash ) assert rc is not None rc = blockstack_client.storage.put_immutable_data( legacy_txt, result_2['transaction_hash'], data_hash=legacy_hash ) assert rc is not None testlib.next_block( **kw ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return zonefile_hash = res['zonefile_hash'] res = testlib.migrate_profile( "bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2 ) if 'error' in res: res['test'] = 'Failed to initialize bar.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return zonefile_hash_2 = res['zonefile_hash'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey'] ) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # see that put_immutable works put_result = testlib.blockstack_cli_put_immutable( 'foo.test', 'hello_world_immutable', json.dumps({'hello': 'world_immutable'}, sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) testlib.expect_atlas_zonefile(put_result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block( **kw ) print "waiting for confirmation" time.sleep(10) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], wallet_keys_2['data_privkey'] ) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # see that put_mutable works put_result = testlib.blockstack_cli_put_mutable( "bar.test", "hello_world_mutable", json.dumps({'hello': 'world'}, sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) testlib.next_block( **kw )
def scenario( wallets, **kw ): global put_result, wallet_keys, legacy_profile, zonefile_hash, zonefile_hash_2, immutable_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.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 ) # set up legacy profile hash legacy_txt = json.dumps(legacy_profile,sort_keys=True) legacy_hash = pybitcoin.hex_hash160( legacy_txt ) result_1 = testlib.blockstack_name_update( "foo.test", legacy_hash, wallets[3].privkey ) result_2 = testlib.blockstack_name_update( "bar.test", legacy_hash, wallets[6].privkey ) testlib.next_block( **kw ) rc = blockstack_client.storage.put_immutable_data( None, result_1['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt ) assert rc is not None rc = blockstack_client.storage.put_immutable_data( None, result_2['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt ) assert rc is not None testlib.next_block( **kw ) # migrate res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return else: zonefile_hash = res['zonefile_hash'] # migrate res = testlib.migrate_profile( "bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2 ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return else: zonefile_hash_2 = res['zonefile_hash'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) # start up RPC for 'foo.test' testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey'] ) # put immutable put_result = blockstack_client.put_immutable( "foo.test", "hello_world_immutable", {"hello": "world"}, proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) error = True return immutable_hash = put_result['immutable_data_hash'] testlib.expect_atlas_zonefile(put_result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block( **kw ) print "waiting for confirmation" time.sleep(10) # start up RPC for 'bar.test' testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], wallet_keys_2['data_privkey'] ) put_result = blockstack_client.put_mutable( "bar.test", "hello_world_mutable", {"hello": "world"}, proxy=test_proxy, wallet_keys=wallet_keys_2 ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) error = True return testlib.next_block( **kw ) # put mutable data with the URL res = blockstack_client.data_put( "blockstack://foo.test/foo_data2", {"hello2": "world2"}, proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return # put immutable data with the URL # start up RPC for 'foo.test' testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey'] ) res = blockstack_client.data_put( "blockstack://foo_immutable.foo.test", {'hello3': 'world3'}, proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: 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 ) # app data data_pk = wallets[-1].privkey data_pub = wallets[-1].pubkey_hex res = blockstack_client.create_app_account("foo.test", "serviceFoo", "serviceFooID", "foo://foo.com", ["disk"], data_pub, proxy=test_proxy, 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 # put some data into the account res = blockstack_client.put_app_data( "foo.test", "serviceFoo", "serviceFooID", "foo_app_data", "foo_app_payload", data_pk, proxy=test_proxy ) if 'error' in res: res['test'] = 'Failed to put app data' print json.dumps(res, indent=4, sort_keys=True) error = True return # put some app data, using the blockstack URL res = blockstack_client.data_put( "blockstack://[email protected]/foo_app_data2#3", "foo_app_payload2", data_privkey=data_pk, proxy=test_proxy ) if 'error' in res: res['test'] = 'Failed to put app data' print json.dumps(res, indent=4, sort_keys=True) error = True return testlib.next_block( **kw )
def scenario( wallets, **kw ): global put_result, wallet_keys, legacy_profile, zonefile_hash, zonefile_hash_2 testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.blockstack_name_preorder( "bar.test", wallets[5].privkey, wallets[6].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.blockstack_name_register( "bar.test", wallets[5].privkey, wallets[6].addr ) testlib.next_block( **kw ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) wallet_keys = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey, payment_privkey=wallets[8].privkey ) wallet_keys_2 = blockstack_client.make_wallet_keys( owner_privkey=wallets[6].privkey, payment_privkey=wallets[9].privkey ) # set up legacy profile hash legacy_txt = json.dumps(legacy_profile,sort_keys=True) legacy_hash = pybitcoin.hex_hash160( legacy_txt ) result_1 = testlib.blockstack_name_update( "foo.test", legacy_hash, wallets[3].privkey ) result_2 = testlib.blockstack_name_update( "bar.test", legacy_hash, wallets[6].privkey ) testlib.next_block( **kw ) rc = blockstack_client.storage.put_immutable_data( None, result_1['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt ) assert rc is not None rc = blockstack_client.storage.put_immutable_data( None, result_2['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt ) assert rc is not None testlib.next_block( **kw ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return zonefile_hash = res['zonefile_hash'] res = testlib.migrate_profile( "bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2 ) if 'error' in res: res['test'] = 'Failed to initialize bar.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return zonefile_hash_2 = res['zonefile_hash'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey'] ) # see that put_immutable works put_result = blockstack_client.put_immutable( "foo.test", "hello_world_immutable", {"hello": "world"}, 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']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block( **kw ) print "waiting for confirmation" time.sleep(10) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], wallet_keys_2['data_privkey'] ) # see that put_mutable works put_result = blockstack_client.put_mutable( "bar.test", "hello_world_mutable", {"hello": "world"}, proxy=test_proxy, wallet_keys=wallet_keys_2 ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) testlib.next_block( **kw )
def scenario( wallets, **kw ): global put_result, wallet_keys, legacy_profile, zonefile_hash, zonefile_hash_2, immutable_hash, datastore_name wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[8].privkey, wallets[3].privkey, None ) wallet_keys_2 = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[9].privkey, wallets[6].privkey, None ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.blockstack_name_preorder( "bar.test", wallets[5].privkey, wallets[6].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.blockstack_name_register( "bar.test", wallets[5].privkey, wallets[6].addr ) testlib.next_block( **kw ) # set up legacy profile hash legacy_txt = json.dumps(legacy_profile,sort_keys=True) legacy_hash = pybitcoin.hex_hash160( legacy_txt ) result_1 = testlib.blockstack_name_update( "foo.test", legacy_hash, wallets[3].privkey ) result_2 = testlib.blockstack_name_update( "bar.test", legacy_hash, wallets[6].privkey ) testlib.next_block( **kw ) rc = blockstack_client.storage.put_immutable_data( None, result_1['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt ) assert rc is not None rc = blockstack_client.storage.put_immutable_data( None, result_2['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt ) assert rc is not None testlib.next_block( **kw ) # migrate res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys, zonefile_has_data_key=False ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return else: zonefile_hash = res['zonefile_hash'] # migrate res = testlib.migrate_profile( "bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2, zonefile_has_data_key=False ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return else: zonefile_hash_2 = res['zonefile_hash'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) # start up RPC for 'foo.test' testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], None ) # put immutable put_result = testlib.blockstack_cli_put_immutable( "foo.test", "hello_world_immutable", json.dumps({'hello': 'world'}), password='******') log.debug("put immutable for foo.test") if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) error = True return immutable_hash = put_result['immutable_data_hash'] testlib.expect_atlas_zonefile(put_result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block( **kw ) print "waiting for confirmation" time.sleep(10) # start up RPC for 'bar.test' testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], None ) log.debug("put mutable for bar.test") put_result = testlib.blockstack_cli_put_mutable( 'bar.test', 'hello_world_mutable', json.dumps({'hello': 'world'}), password='******' ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) return False testlib.next_block( **kw ) # put mutable data again testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], None ) res = testlib.blockstack_cli_put_mutable( 'foo.test', 'foo_data2', json.dumps({'hello2': 'world2'}), password='******') if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) return False # put immutable data with the URL # start up RPC for 'foo.test' log.debug("put immutable for foo.test (2)") res = testlib.blockstack_cli_put_immutable('foo.test', 'foo_immutable', json.dumps({'hello3': 'world3'}), password='******') if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) return False # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) datastore_id_res = testlib.blockstack_cli_datastore_get_id( "foo-app.com" ) datastore_name = datastore_id_res['datastore_id'] # make datastore res = testlib.blockstack_cli_create_datastore( "foo-app.com" ) if 'error' in res: print "failed to create datastore: {}".format(res['error']) return False # put a file into the datastore data = 'hello datastore' log.debug("putfile") res = testlib.blockstack_cli_datastore_putfile( "foo-app.com", '/hello_datastore', data ) if 'error' in res: print 'failed to putfile /hello_datastore: {}'.format(res['error']) return False # make a directory log.debug("mkdir") res = testlib.blockstack_cli_datastore_mkdir( "foo-app.com", '/hello_dir' ) if 'error' in res: print 'failed to mkdir /hello_dir: {}'.format(res['error']) return False # put a file into the directory data = 'hello dir datastore' log.debug("putfile in dir") res = testlib.blockstack_cli_datastore_putfile( 'foo-app.com', '/hello_dir/hello_dir_datastore', data ) if 'error' in res: print 'failed to putfile /hello_dir/hello_dir_datastore: {}'.format(res['error']) return False testlib.next_block( **kw )