def scenario( wallets, **kw ): global put_result, 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 ) # 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] nonstandard_hash = blockstack.lib.storage.get_zonefile_data_hash(zf_data[i]) resp = testlib.blockstack_name_update("foo.test", nonstandard_hash, wallets[3].privkey) 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.next_block(**kw) testlib.blockstack_put_zonefile(nonstandard_zonefile) # getting zonefile should still work... resp = testlib.blockstack_cli_get_name_zonefile( "foo.test") if 'error' in resp: print "failed to get zonefile %s" % zi print json.dumps(resp, indent=4, sort_keys=True) return False if resp != nonstandard_zonefile: print "failed to load nonstandard zonefile json" print "expected:\n%s\n\ngot:\n%s" % (nonstandard_zonefile.encode('hex'), resp.encode('hex')) return False
def check(state_engine): # not revealed, but ready addrs = [wallets[5].addr, wallets[0].addr] for i, nsid in enumerate(['test', 'mult']): ns = state_engine.get_namespace_reveal(nsid) if ns is not None: return False ns = state_engine.get_namespace(nsid) if ns is None: return False if ns['namespace_id'] != nsid: return False if ns['address'] != addrs[i]: print 'wrong address' return False # names all imported name_info = { 'foo.mult': { 'address': wallets[2].addr, 'zonefile_hash': '00' * 20, }, 'bar.mult': { 'address': wallets[3].addr, 'zonefile_hash': '11' * 20, }, 'baz.mult': { 'address': wallets[4].addr, 'zonefile_hash': '22' * 20, }, 'goo.mult': { 'address': wallets[5].addr, 'zonefile_hash': '33' * 20, }, 'hello.mult': { 'address': wallets[2].addr, 'zonefile': None, 'zonefile_hash': None, }, 'world.mult': { 'address': wallets[7].addr, 'zonefile_hash': '44' * 20, } } for name in name_info.keys(): name_rec = state_engine.get_name(name) if name_rec is None or 'error' in name_rec: print 'missing name {}'.format(name) return False expected_zonefile = name_info[name].get('zonefile', None) expected_zonefile_hash = name_info[name].get('zonefile_hash', None) zonefile = testlib.blockstack_cli_get_name_zonefile(name) if (zonefile is None or 'error' in zonefile) and expected_zonefile is not None: print 'missing zonefile for {}'.format(name) return False if expected_zonefile is not None and zonefile != expected_zonefile: print 'different zonefiles:' print zonefile print name_info[name]['zonefile'] return False if name_rec['address'] != name_info[name]['address']: print 'wrong address for {}'.format(name) return False if expected_zonefile_hash is not None and expected_zonefile_hash != name_rec[ 'value_hash']: print 'wrong value hash for {}'.format(name) return False return True
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 = virtualchain.lib.hashing.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(10) # getting zonefile should still work... resp = testlib.blockstack_cli_get_name_zonefile("foo.test", json=True, raw=False) if 'error' in resp: print "failed to get zonefile %s" % zi print 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: if data_func_name != 'lookup': print "%s succeeded when it should not have:\n%s" % ( data_func_name, json.dumps(resp, indent=4, sort_keys=True)) return False elif 'error' not in resp['profile']: 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, interactive=False) 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(10) # 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(10) # 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 preorder_info, register_info, update_info, balance_before, balance_after, names_owned_before, names_owned_after, whois, blockchain_record, deposit_info, price_info global blockchain_history, zonefile_info, all_names_info, namespace_names_info, wallet_info, lookup_info, update_history, zonefile_history, names_info testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey ) balance_before = testlib.blockstack_cli_balance() deposit_info = testlib.blockstack_cli_deposit() price_info = testlib.blockstack_cli_price( "foo.test", password="******" ) wallet_info = testlib.blockstack_cli_wallet( "0123456789abcdef" ) resp = testlib.blockstack_cli_register( "foo.test", "0123456789abcdef" ) if 'error' in resp: print >> sys.stderr, json.dumps(resp, indent=4, sort_keys=True) return False # wait for the preorder to get confirmed for i in xrange(0, 5): testlib.next_block( **kw ) # queued? preorder_info = testlib.blockstack_cli_info() names_owned_before = testlib.blockstack_cli_get_names_owned_by_address( wallets[3].addr ) for i in xrange(0, 7): testlib.next_block( **kw ) # wait for the poller to pick it up print >> sys.stderr, "Waiting 10 seconds for the backend to submit the register" time.sleep(10) # wait for the register to get confirmed for i in xrange(0, 5): testlib.next_block( **kw ) # registered? register_info = testlib.blockstack_cli_info() names_info = testlib.blockstack_cli_names() for i in xrange(0, 7): testlib.next_block( **kw ) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge registration" time.sleep(10) # wait for update to get confirmed for i in xrange(0, 5): testlib.next_block( **kw ) update_info = testlib.blockstack_cli_info() names_owned_after = testlib.blockstack_cli_get_names_owned_by_address( wallets[3].addr ) whois = testlib.blockstack_cli_whois( "foo.test" ) for i in xrange(0, 7): testlib.next_block( **kw ) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge update" time.sleep(10) # put some immutable data put_immutable_info = testlib.blockstack_cli_put_immutable( "foo.test", "hello_world", '{"hello": "world"}' ) if 'error' in put_immutable_info: print "put_immutable failed" print json.dumps(put_immutable_info, indent=4, sort_keys=True) return False # wait for update to be confirmed for i in xrange(0, 12): testlib.next_block( **kw ) print >> sys.stderr, "Waiting 10 seconds for backend to acknowledge put-immutable update" time.sleep(10) balance_after = testlib.blockstack_cli_balance() blockchain_history = testlib.blockstack_cli_get_name_blockchain_history( "foo.test" ) zonefile_info = testlib.blockstack_cli_get_name_zonefile( "foo.test", json=False ) all_names_info = testlib.blockstack_cli_get_all_names(0) namespace_names_info = testlib.blockstack_cli_get_names_in_namespace("test", 0) lookup_info = testlib.blockstack_cli_lookup( "foo.test" ) update_history = testlib.blockstack_cli_list_update_history( "foo.test" ) zonefile_history = testlib.blockstack_cli_list_zonefile_history( "foo.test" ) blockchain_record = testlib.blockstack_cli_get_name_blockchain_record( "foo.test" )
def scenario(wallets, **kw): global preorder_info, register_info, update_info, balance_before, balance_after, names_owned_before, names_owned_after, whois, blockchain_record, deposit_info, price_info global blockchain_history, zonefile_info, all_names_info, namespace_names_info, wallet_info, lookup_info, update_history, zonefile_history, names_info testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey) balance_before = testlib.blockstack_cli_balance() deposit_info = testlib.blockstack_cli_deposit() price_info = testlib.blockstack_cli_price("foo.test", password="******") wallet_info = testlib.blockstack_cli_wallet("0123456789abcdef") resp = testlib.blockstack_cli_register("foo.test", "0123456789abcdef") if 'error' in resp: print >> sys.stderr, json.dumps(resp, indent=4, sort_keys=True) return False # wait for the preorder to get confirmed for i in xrange(0, 5): testlib.next_block(**kw) # queued? preorder_info = testlib.blockstack_cli_info() names_owned_before = testlib.blockstack_cli_get_names_owned_by_address( wallets[3].addr) for i in xrange(0, 7): testlib.next_block(**kw) # wait for the poller to pick it up print >> sys.stderr, "Waiting 10 seconds for the backend to submit the register" time.sleep(10) # wait for the register to get confirmed for i in xrange(0, 5): testlib.next_block(**kw) # registered? register_info = testlib.blockstack_cli_info() names_info = testlib.blockstack_cli_names() for i in xrange(0, 7): testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge registration" time.sleep(10) # wait for update to get confirmed for i in xrange(0, 5): testlib.next_block(**kw) update_info = testlib.blockstack_cli_info() names_owned_after = testlib.blockstack_cli_get_names_owned_by_address( wallets[3].addr) whois = testlib.blockstack_cli_whois("foo.test") for i in xrange(0, 7): testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge update" time.sleep(10) # put some immutable data put_immutable_info = testlib.blockstack_cli_put_immutable( "foo.test", "hello_world", '{"hello": "world"}') if 'error' in put_immutable_info: print "put_immutable failed" print json.dumps(put_immutable_info, indent=4, sort_keys=True) return False # wait for update to be confirmed for i in xrange(0, 12): testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for backend to acknowledge put-immutable update" time.sleep(10) balance_after = testlib.blockstack_cli_balance() blockchain_history = testlib.blockstack_cli_get_name_blockchain_history( "foo.test") zonefile_info = testlib.blockstack_cli_get_name_zonefile("foo.test", json=False) all_names_info = testlib.blockstack_cli_get_all_names(0) namespace_names_info = testlib.blockstack_cli_get_names_in_namespace( "test", 0) lookup_info = testlib.blockstack_cli_lookup("foo.test") update_history = testlib.blockstack_cli_list_update_history("foo.test") zonefile_history = testlib.blockstack_cli_list_zonefile_history("foo.test") blockchain_record = testlib.blockstack_cli_get_name_blockchain_record( "foo.test")
def scenario( wallets, **kw ): global zonefile_hash, final_balance, new_expire_block testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey ) resp = testlib.blockstack_cli_register( "foo.test", "0123456789abcdef" ) if 'error' in resp: print >> sys.stderr, json.dumps(resp, indent=4, sort_keys=True) return False # wait for the preorder to get confirmed for i in xrange(0, 12): testlib.next_block( **kw ) # wait for the poller to pick it up print >> sys.stderr, "Waiting 10 seconds for the backend to submit the register" time.sleep(10) # wait for the register to get confirmed for i in xrange(0, 12): # warn the serialization checker that this changes behavior from 0.13 print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge registration" time.sleep(10) # what's the name's renewal block? proxy = testlib.make_proxy() res = blockstack_client.get_name_blockchain_record( "foo.test", proxy=proxy ) if 'error' in res: print >> sys.stderr, json.dumps(res, indent=4, sort_keys=True) return False old_expire_block = res['expire_block'] new_zonefile = blockstack_client.zonefile.make_empty_zonefile('foo.test', None) new_zonefile_txt = blockstack_zones.make_zone_file(new_zonefile) print 'renew with:' print new_zonefile_txt # renew it resp = testlib.blockstack_cli_renew( "foo.test", "0123456789abcdef", new_zonefile_txt=new_zonefile_txt ) if 'error' in resp: print >> sys.stderr, "Renewal request failed:\n%s" % json.dumps(resp, indent=4, sort_keys=True) return False # wait for it to go through for i in xrange(0, 6): # warn the serialization checker that this changes behavior from 0.13 print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) # verify that it's in the queue queue_state = testlib.blockstack_cli_info() if 'error' in queue_state: print json.dumps(queue_state) return False if not queue_state.has_key('queues'): print 'no queues' print json.dumps(queue_state) return False if not queue_state['queues'].has_key('renew'): print 'no renew queue' print json.dumps(queue_state) return False if len(queue_state['queues']['renew']) != 1: print 'wrong renew state' print json.dumps(queue_state) return False if queue_state['queues']['renew'][0]['name'] != 'foo.test': print 'wrong name' print json.dumps(queue_state) return False # wait for it to go through for i in xrange(0, 6): # warn the serialization checker that this changes behavior from 0.13 print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) proxy = testlib.make_proxy() res = blockstack_client.get_name_blockchain_record( "foo.test", proxy=proxy ) if 'error' in res: print >> sys.stderr, json.dumps(res, indent=4, sort_keys=True) return False zonefile_hash = res['value_hash'] zf = testlib.blockstack_cli_get_name_zonefile("foo.test") if 'error' in zf: print zf return False print zf if zf != new_zonefile_txt: print 'zonefile mismatch' print 'expected:' print new_zonefile_txt print 'got:' print zf return False new_expire_block = res['expire_block'] if old_expire_block >= new_expire_block + 12: # didn't go through print >> sys.stderr, "Renewal didn't go through: %s --> %s" % (old_expire_block, new_expire_block) return False if res['op'] != blockstack_client.config.NAME_REGISTRATION + ":": print >> sys.stderr, "Renewal didn't go through (last op is %s)" % res['op'] error = True return False final_balance = testlib.getbalance( wallets[2].addr )
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 )