def check(state_engine): global wallet_keys, error, index_file_data, resource_data config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG") assert config_path if error: print "Key operation failed." return False # not revealed, but ready ns = state_engine.get_namespace_reveal("test") if ns is not None: print "namespace not ready" return False ns = state_engine.get_namespace("test") if ns is None: print "no namespace" return False if ns['namespace_id'] != 'test': print "wrong namespace" return False names = ['foo.test', 'bar.test'] wallet_keys_list = [wallet_keys] test_proxy = testlib.TestAPIProxy() owners = [3, 4] for i in xrange(0, len(names)): name = names[i] wallet_payer = 5 wallet_owner = owners[i] wallet_data_pubkey = 4 # not preordered preorder = state_engine.get_name_preorder( name, virtualchain.make_payment_script(wallets[wallet_payer].addr), wallets[wallet_owner].addr) if preorder is not None: print "still have preorder" return False # registered name_rec = state_engine.get_name(name) if name_rec is None: print "name does not exist" return False # owned if name_rec['address'] != wallets[wallet_owner].addr or name_rec[ 'sender'] != virtualchain.make_payment_script( wallets[wallet_owner].addr): print "name {} has wrong owner".format(name) return False return True
def scenario( wallets, **kw ): global put_result, wallet_keys, datasets, zonefile_hash, dataset_change testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) wallet_keys = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey ) # migrate profile res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return else: zonefile_hash = res['zonefile_hash'] testlib.next_block( **kw ) put_result = blockstack_client.put_mutable( "foo.test", "hello_world_1", datasets[0], proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) testlib.next_block( **kw ) put_result = blockstack_client.put_mutable( "foo.test", "hello_world_2", datasets[1], proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) put_result = blockstack_client.put_mutable( "foo.test", "hello_world_3", datasets[2], proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) # increment version too datasets[0]['buf'] = [] for i in xrange(0, 5): datasets[0]["dataset_change"] = dataset_change datasets[0]['buf'].append(i) put_result = blockstack_client.put_mutable( "foo.test", "hello_world_1", datasets[0], proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) testlib.next_block( **kw )
def check(state_engine): global wallet_keys, error if error: print "Key operation failed." return False # not revealed, but ready ns = state_engine.get_namespace_reveal("test") if ns is not None: print "namespace not ready" return False ns = state_engine.get_namespace("test") if ns is None: print "no namespace" return False if ns['namespace_id'] != 'test': print "wrong namespace" return False names = ['foo.test'] wallet_keys_list = [wallet_keys] test_proxy = testlib.TestAPIProxy() for i in xrange(0, len(names)): name = names[i] wallet_payer = 3 * (i + 1) - 1 wallet_owner = 3 * (i + 1) wallet_data_pubkey = 3 * (i + 1) + 1 wallet_keys = wallet_keys_list[i] # not preordered preorder = state_engine.get_name_preorder( name, pybitcoin.make_pay_to_address_script(wallets[wallet_payer].addr), wallets[wallet_owner].addr) if preorder is not None: print "still have preorder" return False # registered name_rec = state_engine.get_name(name) if name_rec is None: print "name does not exist" return False # owned if name_rec['address'] != wallets[wallet_owner].addr or name_rec[ 'sender'] != pybitcoin.make_pay_to_address_script( wallets[wallet_owner].addr): print "name has wrong owner" return False # try to authenticate return True
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data empty_key = ECPrivateKey().to_hex() wallet_keys = testlib.ysi_client_initialize_wallet( "0123456789abcdef", wallets[1].privkey, wallets[2].privkey, wallets[0].privkey) test_proxy = testlib.TestAPIProxy() ysi_client.set_default_proxy( test_proxy ) testlib.ysi_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.ysi_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.ysi_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) config_dir = os.path.dirname(config_path) conf = ysi_client.get_config(config_path) assert conf api_pass = conf['api_password'] # let's do a withdraw of all res = testlib.ysi_REST_call('POST', '/v1/wallet/balance', None, api_pass=api_pass, data= { 'address' : virtualchain.get_privkey_address(empty_key), }) if 'error' in res['response']: res['test'] = 'Failed to perform withdraw' print json.dumps(res) error = True return False for i in xrange (0, 1): testlib.next_block( **kw ) print 'Waiting for the withdraw to go through' res = testlib.ysi_REST_call('GET', '/v1/wallet/balance/0', None, api_pass=api_pass) if 'error' in res['response']: res['test'] = 'Failed to get wallet balance' print json.dumps(res) error = True return False res = testlib.ysi_REST_call('GET', '/v1/wallet/balance/0', None, api_pass=api_pass) if 'error' in res['response']: res['test'] = 'Failed to get wallet balance' print json.dumps(res) error = True return False
def check(state_engine): global last_consensus, snv_block_id # not revealed, but ready ns = state_engine.get_namespace_reveal("test") if ns is not None: return False ns = state_engine.get_namespace("test") if ns is None: return False if ns['namespace_id'] != 'test': return False # not preordered for i in xrange(0, len(wallets)): preorder = state_engine.get_name_preorder( "foo.test", pybitcoin.make_pay_to_address_script(wallets[i].addr), wallets[(i + 1) % 5].addr) if preorder is not None: print "preordered" return False # registered name_rec = state_engine.get_name("foo.test") if name_rec is None: print "no name" return False # updated, and data preserved if name_rec['value_hash'] != "22" * 20: print "wrong value hash" return False # transferred if name_rec['address'] != wallets[4].addr or name_rec[ 'sender'] != pybitcoin.make_pay_to_address_script(wallets[4].addr): print "wrong owner" return False # snv lookup works test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) spv_headers_path = test_proxy.spv_headers_path snv_rec = blockstack_client.snv_lookup("foo.test", snv_block_id, last_consensus, proxy=test_proxy) if 'error' in snv_rec: print json.dumps(snv_rec, indent=4) return False print snv_rec return True
def check( state_engine ): global wallet_keys, datasets, zonefile_hash # not revealed, but ready ns = state_engine.get_namespace_reveal( "test" ) if ns is not None: print "namespace not ready" return False ns = state_engine.get_namespace( "test" ) if ns is None: print "no namespace" return False if ns['namespace_id'] != 'test': print "wrong namespace" return False # not preordered preorder = state_engine.get_name_preorder( "foo.test", pybitcoin.make_pay_to_address_script(wallets[2].addr), wallets[3].addr ) if preorder is not None: print "still have preorder" return False # registered name_rec = state_engine.get_name( "foo.test" ) if name_rec is None: print "name does not exist" return False # owned if name_rec['address'] != wallets[3].addr or name_rec['sender'] != pybitcoin.make_pay_to_address_script(wallets[3].addr): print "name has wrong owner" return False # have right hash if name_rec['value_hash'] != zonefile_hash: print "Invalid zonefile hash" return False # have no data test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) for i in xrange(0, len(datasets)): print "get hello_world_%s" % (i+1) dat = testlib.blockstack_cli_get_mutable( "foo.test", "hello_world_%s" % (i+1) ) if dat is not None and 'error' not in dat: print "still have '%s'\n%s" % ("hello_world_%s" % (i+1), json.dumps(dat,indent=4,sort_keys=True)) return False if 'error' in dat and dat['error'] != 'Failed to fetch mutable data': print json.dumps(dat, indent=4, sort_keys=True) return False return True
def check(state_engine): global wallet_keys, error, index_file_data, resource_data config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG") assert config_path if error: print "Key operation failed." return False # not revealed, but ready ns = state_engine.get_namespace_reveal("test") if ns is not None: print "namespace not ready" return False ns = state_engine.get_namespace("test") if ns is None: print "no namespace" return False if ns['namespace_id'] != 'test': print "wrong namespace" return False names = ['bar.test', 'tricky1.test', 'tricky2.test', 'tricky3.test'] owners = [new_addr] * 4 payers = [wallets[1].addr] * 4 test_proxy = testlib.TestAPIProxy() for i in xrange(0, len(names)): name = names[i] # not preordered preorder = state_engine.get_name_preorder( name, pybitcoin.make_pay_to_address_script(payers[i]), owners[i]) if preorder is not None: print "still have preorder" return False # registered name_rec = state_engine.get_name(name) if name_rec is None: print "name does not exist" return False # owned if name_rec['address'] != owners[i]: print "name {} has wrong owner".format(name) return False print name_rec return True
def check(state_engine): global wallet_keys, datasets, zonefile_hash # not revealed, but ready ns = state_engine.get_namespace_reveal("test") if ns is not None: print "namespace not ready" return False ns = state_engine.get_namespace("test") if ns is None: print "no namespace" return False if ns['namespace_id'] != 'test': print "wrong namespace" return False # not preordered preorder = state_engine.get_name_preorder( "foo.test", pybitcoin.make_pay_to_address_script(wallets[2].addr), wallets[3].addr) if preorder is not None: print "still have preorder" return False # registered name_rec = state_engine.get_name("foo.test") if name_rec is None: print "name does not exist" return False # owned if name_rec['address'] != wallets[3].addr or name_rec[ 'sender'] != pybitcoin.make_pay_to_address_script(wallets[3].addr): print "name has wrong owner" return False # have right hash if name_rec['value_hash'] != zonefile_hash: print "Invalid zonefile hash" return False # have right data test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) res = testlib.blockstack_cli_lookup("foo.test") if 'error' in res: print 'error looking up profile: {}'.format(res) return False assert 'profile' in res assert 'zonefile' in res return True
def check(state_engine): global snv_block_id, last_consensus # not revealed, but ready ns = state_engine.get_namespace_reveal("test") if ns is not None: return False ns = state_engine.get_namespace("test") if ns is None: return False if ns['namespace_id'] != 'test': return False # not preordered preorder = state_engine.get_name_preorder( "foo.test", virtualchain.make_payment_script(wallets[2].addr), wallets[3].addr) if preorder is not None: print "preorder exists" return False # registered name_rec = state_engine.get_name("foo.test") if name_rec is None: print "no such name" return False # owned by if name_rec['address'] != wallets[3].addr or name_rec[ 'sender'] != virtualchain.make_payment_script(wallets[3].addr): print "wrong owner" return False # revoked if not name_rec['revoked']: return False # snv lookup works test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) snv_rec = blockstack_client.snv_lookup("foo.test", snv_block_id, last_consensus, proxy=test_proxy) if 'error' in snv_rec: print json.dumps(snv_rec, indent=4) return False print snv_rec return True
def check(state_engine): global snv_block_id, last_block_id, last_consensus # not revealed, but ready ns = state_engine.get_namespace_reveal("test") if ns is not None: return False ns = state_engine.get_namespace("test") if ns is None: return False if ns['namespace_id'] != 'test': return False # not preordered preorder = state_engine.get_name_preorder( "foo.test", pybitcoin.make_pay_to_address_script(wallets[2].addr), wallets[3].addr) if preorder is not None: return False # registered name_rec = state_engine.get_name("foo.test") if name_rec is None: return False # owned by if name_rec['address'] != wallets[3].addr or name_rec[ 'sender'] != pybitcoin.make_pay_to_address_script(wallets[3].addr): return False # renewed (11 blocks later) if name_rec['last_renewed'] - 11 != name_rec['first_registered']: print name_rec['last_renewed'] print name_rec['first_registered'] return False # snv lookup works test_proxy = testlib.TestAPIProxy() snv_client.client.set_default_proxy(test_proxy) # snv_rec = snv_client.snv( "foo.test", lastblock, lastconsensus, snv_block_id, snv_consensus, proxy=test_proxy ) snv_rec = snv_client.client.snv_lookup("foo.test", snv_block_id, last_consensus, proxy=test_proxy) if 'error' in snv_rec: print json.dumps(snv_rec, indent=4) return False print snv_rec return True
def check(state_engine): global snv_block_id, snv_consensus # not revealed, but ready ns = state_engine.get_namespace_reveal("test") if ns is not None: print "'test' not revealed" return False ns = state_engine.get_namespace("test") if ns is None: print "'test' not found" return False if ns['namespace_id'] != 'test': print "'test' not returned" return False # not preordered preorder = state_engine.get_name_preorder( "foo.test", pybitcoin.make_pay_to_address_script(wallets[2].addr), wallets[3].addr) if preorder is not None: print "'foo.test' still preordered" return False # registered name_rec = state_engine.get_name("foo.test") if name_rec is None: print "'foo.test' not registered" return False # transferred if name_rec['address'] != wallets[4].addr or name_rec[ 'sender'] != pybitcoin.make_pay_to_address_script(wallets[4].addr): print "'foo.test' invalid owner" return False # snv lookup works test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) snv_rec = blockstack_client.snv_lookup("foo.test", snv_block_id, snv_consensus, proxy=test_proxy) if 'error' in snv_rec: print json.dumps(snv_rec, indent=4) return False print snv_rec return True
def check(state_engine): global wallet_keys, data_history_1, data_history_2, data_history_3 # not revealed, but ready ns = state_engine.get_namespace_reveal("test") if ns is not None: print "namespace not ready" return False ns = state_engine.get_namespace("test") if ns is None: print "no namespace" return False if ns['namespace_id'] != 'test': print "wrong namespace" return False # not preordered preorder = state_engine.get_name_preorder( "foo.test", pybitcoin.make_pay_to_address_script(wallets[2].addr), wallets[3].addr) if preorder is not None: print "still have preorder" return False # registered name_rec = state_engine.get_name("foo.test") if name_rec is None: print "name does not exist" return False # owned if name_rec['address'] != wallets[3].addr or name_rec[ 'sender'] != pybitcoin.make_pay_to_address_script(wallets[3].addr): print "name has wrong owner" return False # have right data history test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) hist = [data_history_1, data_history_2, data_history_3] for i in xrange(0, len(hist)): test_hist = blockstack_client.list_immutable_data_history( "foo.test", "hello_world_%s" % (i + 1)) if test_hist != hist[i]: print "hello_world_%s expected: %s" % (i + 1, ",".join(hist[i])) print "hello_world_%s got: %s" % (i + 1, ",".join(test_hist)) return False return True
def check(state_engine): global update_hashes # not revealed, but ready ns = state_engine.get_namespace_reveal("test") if ns is not None: print "namespace not ready" return False ns = state_engine.get_namespace("test") if ns is None: print "no namespace" return False if ns['namespace_id'] != 'test': print "wrong namespace" return False name = "foo.test" preorder = state_engine.get_name_preorder( name, pybitcoin.make_pay_to_address_script(wallets[2].addr), wallets[3].addr) if preorder is not None: print "still have preorder" return False # registered name_rec = state_engine.get_name(name) if name_rec is None: print "name does not exist" return False # owned if name_rec['address'] != wallets[4].addr or name_rec[ 'sender'] != pybitcoin.make_pay_to_address_script(wallets[4].addr): print "name has wrong owner" return False test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) update_history = blockstack_client.list_update_history(name) if update_history != update_hashes: print "update history: %s" % ",".join(update_history) print "update hashes: %s" % ",".join(update_hashes) return False return True
def check(state_engine): # not revealed, but ready ns = state_engine.get_namespace_reveal("test") if ns is not None: return False ns = state_engine.get_namespace("test") if ns is None: return False if ns['namespace_id'] != 'test': return False # not preordered preorder = state_engine.get_name_preorder( "foo.test", pybitcoin.make_pay_to_address_script(wallets[2].addr), wallets[3].addr) if preorder is not None: return False # registered name_rec = state_engine.get_name("foo.test") if name_rec is None: return False # owned if name_rec['address'] != wallets[3].addr or name_rec[ 'sender'] != pybitcoin.make_pay_to_address_script(wallets[3].addr): return False # updated if name_rec['value_hash'] != '11' * 20: return False # snv lookup works test_proxy = testlib.TestAPIProxy() snv_rec = snv_client.lookup_snv("foo.test", snv_block_id, snv_consensus, proxy=test_proxy) if 'error' in snv_rec: print json.dumps(snv_rec, indent=4) return False print snv_rec return True
def check(state_engine): global snv_block_id, last_consensus # not revealed, but ready ns = state_engine.get_namespace_reveal("test") if ns is not None: return False ns = state_engine.get_namespace("test") if ns is None: return False if ns['namespace_id'] != 'test': return False # not preordered preorder = state_engine.get_name_preorder( "foo.test", pybitcoin.make_pay_to_address_script(wallets[2].addr), wallets[3].addr) if preorder is not None: return False # not registered name_rec = state_engine.get_name("foo.test") if name_rec is not None: print "Not expired:" print json.dumps(name_rec, indent=4) return False # snv lookup works test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) snv_rec = blockstack_client.snv_lookup("foo.test", snv_block_id, last_consensus, proxy=test_proxy) if 'error' in snv_rec: print json.dumps(snv_rec, indent=4) print "Expected (%s, %s) from (%s, %s)" % (snv_block_id, snv_consensus, lastblock, lastconsensus) return False print snv_rec return True
def check(state_engine): global wallet_keys, error, index_file_data, resource_data config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG") assert config_path if error: print "Key operation failed." return False # not revealed, but ready ns = state_engine.get_namespace_reveal("test") if ns is not None: print "namespace not ready" return False ns = state_engine.get_namespace("test") if ns is None: print "no namespace" return False if ns['namespace_id'] != 'test': print "wrong namespace" return False names = ['bar.test'] wallet_keys_list = [wallet_keys, wallet_keys] test_proxy = testlib.TestAPIProxy() for i in xrange(0, len(names)): name = names[i] # registered name_rec = state_engine.get_name(name) if name_rec is None: print "name does not exist" return False # owned if name_rec['address'] != owner_addr: print "name {} has wrong owner".format(name) return False return True
def scenario( wallets, **kw ): testlib.next_block(**kw) rpcclient = testlib.TestAPIProxy() res = rpcclient.getinfo() assert 'stale' not in res and 'error' not in res res = rpcclient.ping() assert 'stale' not in res and 'error' not in res res = rpcclient.get_all_names(0,10) assert 'stale' not in res and 'error' not in res # force the rpc server to think we're stale blockstack.blockstackd.rpc_chain_sync(testlib.get_server_state(), testlib.get_current_block(**kw), time.time() - blockstack.lib.config.RPC_MAX_INDEXING_DELAY - 1) res = rpcclient.getinfo() if 'stale' not in res or not res['stale']: print 'no stale; {}'.format(res) return False res = rpcclient.ping() if res['status'] != 'stale': print 'no stale: {}'.format(res) return False res = rpcclient.get_all_names(0,10) if 'stale' not in res or not res['stale']: print 'no stale: {}'.format(res) return False # reset testlib.next_block(**kw) res = rpcclient.getinfo() assert 'stale' not in res and 'error' not in res res = rpcclient.ping() assert 'stale' not in res and 'error' not in res res = rpcclient.get_all_names(0,10) assert 'stale' not in res and 'error' not in res
def check( state_engine ): global wallet_keys, error, index_file_data, resource_data config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG") assert config_path names = ['bar.test'] owners = [ new_addr ] payers = [ wallets[1].addr ] test_proxy = testlib.TestAPIProxy() for i in xrange(0, len(names)): name = names[i] wallet_payer = 5 wallet_owner = 3 + i for name, wallet_payer, wallet_owner in zip(names, payers, owners): # not preordered preorder = state_engine.get_name_preorder( name, virtualchain.make_payment_script(wallet_payer), wallet_owner) if preorder is not None: print "still have preorder" return False # registered name_rec = state_engine.get_name( name ) if name_rec is None: print "name does not exist" return False # owned if name_rec['address'] != owners[i]: print "name {} has wrong owner".format(name) return False return True
def scenario(wallets, **kw): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.ysi_client_initialize_wallet("0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey) test_proxy = testlib.TestAPIProxy() ysi_client.set_default_proxy(test_proxy) testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.ysi_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.ysi_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) conf = ysi_client.get_config(config_path) assert conf api_pass = conf['api_password'] # register the name bar.test. autogenerate the rest postage = { 'name': 'bar.test', 'owner_key': owner_key, 'payment_key': payment_key } res = testlib.ysi_REST_call('POST', '/v1/names', None, api_pass=api_pass, data=postage) if 'error' in res: res['test'] = 'Failed to register user' print json.dumps(res) error = True return False print res tx_hash = res['response']['transaction_hash'] # wait for preorder to get confirmed... for i in xrange(0, 6): testlib.next_block(**kw) res = testlib.verify_in_queue(None, 'bar.test', 'preorder', tx_hash) if not res: return False # wait for the preorder to get confirmed for i in xrange(0, 4): testlib.next_block(**kw) # wait for register to go through print 'Wait for register to be submitted' time.sleep(10) # wait for the register to get confirmed for i in xrange(0, 6): testlib.next_block(**kw) res = testlib.verify_in_queue(None, 'bar.test', 'register', None) if not res: return False for i in xrange(0, 4): testlib.next_block(**kw) print 'Wait for update to be submitted' time.sleep(10) # wait for update to get confirmed for i in xrange(0, 6): testlib.next_block(**kw) res = testlib.verify_in_queue(None, 'bar.test', 'update', None) if not res: return False for i in xrange(0, 4): testlib.next_block(**kw) print 'Wait for update to be confirmed' time.sleep(10) res = testlib.ysi_REST_call("GET", "/v1/names/bar.test", None, api_pass=api_pass) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name bar.test' print json.dumps(res) return False zonefile_hash = res['response']['zonefile_hash'] old_expire_block = res['response']['expire_block'] # renew it res = testlib.ysi_REST_call('POST', '/v1/names', None, api_pass=api_pass, data=postage) if 'error' in res or res['http_status'] != 202: res['test'] = 'Failed to renew name' print json.dumps(res) return False # verify in renew queue for i in xrange(0, 6): testlib.next_block(**kw) res = testlib.verify_in_queue(None, 'bar.test', 'renew', None) if not res: return False for i in xrange(0, 4): testlib.next_block(**kw) # new expire block res = testlib.ysi_REST_call("GET", "/v1/names/bar.test", None, api_pass=api_pass) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name bar.test' print json.dumps(res) return False new_expire_block = res['response']['expire_block'] # do we have the history for the name? res = testlib.ysi_REST_call("GET", "/v1/names/bar.test/history", None, api_pass=api_pass) if 'error' in res or res['http_status'] != 200: res['test'] = "Failed to get name history for bar.test" print json.dumps(res) return False # valid history? hist = res['response'] if len(hist.keys()) != 4: res['test'] = 'Failed to get update history' res['history'] = hist print json.dumps(res, indent=4, sort_keys=True) return False # get the zonefile res = testlib.ysi_REST_call( "GET", "/v1/names/bar.test/zonefile/{}".format(zonefile_hash), None, api_pass=api_pass) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name zonefile' print json.dumps(res) return False # verify pushed back if old_expire_block + 12 >= new_expire_block: # didn't go through print >> sys.stderr, "Renewal didn't work: %s --> %s" % ( old_expire_block, new_expire_block) return False
def check(state_engine): global error # not revealed, but ready ns = state_engine.get_namespace_reveal("test") if ns is not None: print "namespace not ready" return False ns = state_engine.get_namespace("test") if ns is None: print "no namespace" return False if ns['namespace_id'] != 'test': print "wrong namespace" return False # not preordered preorder = state_engine.get_name_preorder( "foo.test", pybitcoin.make_pay_to_address_script(wallets[2].addr), wallets[3].addr) if preorder is not None: print "still have preorder" return False # registered name_rec = state_engine.get_name("foo.test") if name_rec is None: print "name does not exist" return False # owned if name_rec['address'] != wallets[3].addr or name_rec[ 'sender'] != pybitcoin.make_pay_to_address_script(wallets[3].addr): print "name has wrong owner" return False # have right data test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) # should always work for i in xrange(1, len(datasets)): immutable_data = blockstack_client.get_immutable_by_name( "foo.test", "hello_world_%s_immutable" % (i + 1), proxy=test_proxy) if immutable_data is None: print "No data received for immutable dataset %s" % i return False if 'error' in immutable_data: print "No data received for immutable dataset %s: %s" % ( i, immutable_data['error']) return False if not immutable_data.has_key('data'): print "Missing data\n%s" % json.dumps( immutable_data, indent=4, sort_keys=True) return False data_json = immutable_data['data'] if data_json != datasets[i]: print "did not get dataset %s\ngot %s\nexpected %s" % ( i, data_json, datasets[i]) return False mutable_data = blockstack_client.get_mutable("foo.test", "hello_world_%s_mutable" % (i + 1), proxy=test_proxy) if mutable_data is None: print "No data received for mutable dataset %s" % (i + 1) return False if 'error' in mutable_data: print "No data received for mutable dataset %s: %s" % ( i + 1, mutable_data['error']) return False data_json = mutable_data['data'] if data_json != datasets[i]: print "did not get dataset %s\ngot %s\nexpected %s" % ( i + 1, data_json, datasets[i]) return False # should fail immutable_data = blockstack_client.get_immutable_by_name( "foo.test", "hello_world_1_immutable", proxy=test_proxy) if immutable_data is not None and 'error' not in immutable_data: print "Got deleted immutable dataset" return False mutable_data = blockstack_client.get_mutable("foo.tesT", "hello_world_1_mutable", proxy=test_proxy) if mutable_data is not None and 'error' not in mutable_data: print "Got deleted mutable dataset" return False return True
def scenario(wallets, **kw): global datasets testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) wallet_keys = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey) # migrate profile (but no data key) res = testlib.migrate_profile("foo.test", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return testlib.next_block(**kw) # put immutable (with owner key) log.debug("put immutable 1 with owner key") put_result = blockstack_client.put_immutable( "foo.test", "hello_world_1_immutable", datasets[0], data_url="http://www.example.unroutable", 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 testlib.next_block(**kw) # put immutable (with owner key) log.debug("put immutable 2 with owner key") put_result = blockstack_client.put_immutable( "foo.test", "hello_world_2_immutable", datasets[1], data_url="http://www.example.unroutable", 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 testlib.next_block(**kw) # put mutable (with owner key) log.debug("put mutable 1 with owner key") put_result = blockstack_client.put_mutable("foo.test", "hello_world_1_mutable", datasets[0], 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 # put mutable (with owner key) log.debug("put mutable 2 with owner key") put_result = blockstack_client.put_mutable("foo.test", "hello_world_2_mutable", datasets[1], 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 testlib.next_block(**kw) # add data signing key res = blockstack_client.set_data_pubkey("foo.test", wallets[4].pubkey_hex, wallet_keys=wallet_keys, proxy=test_proxy) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return wallet_keys['data_privkey'] = wallets[4].privkey wallet_keys['data_pubkey'] = wallets[4].pubkey_hex testlib.next_block(**kw) # put immutable (with new key) log.debug("put immutable with new key") put_result = blockstack_client.put_immutable( "foo.test", "hello_world_3_immutable", datasets[2], data_url="http://www.example.unroutable", 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 testlib.next_block(**kw) # put mutable (with new key) log.debug("put mutable with new key") put_result = blockstack_client.put_mutable("foo.test", "hello_world_3_mutable", datasets[2], 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 testlib.next_block(**kw) # delete immutable (new key) log.debug("delete immutable with new key") result = blockstack_client.delete_immutable( "foo.test", None, data_id="hello_world_1_immutable", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in result: print json.dumps(result, indent=4, sort_keys=True) error = True return testlib.next_block(**kw) # delete mutable (new key) log.debug("delete mutable with new key") result = blockstack_client.delete_mutable("foo.test", "hello_world_1_mutable", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in result: print json.dumps(result, indent=4, sort_keys=True) error = True return testlib.next_block(**kw)
def scenario(wallets, **kw): global wallet_keys, wallet_keys_2, key_names, error testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) wallet_keys = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey) # migrate profiles res = testlib.migrate_profile("foo.test", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return testlib.next_block(**kw) # make an account res = blockstack_client.put_account("foo.test", "serviceFoo", "serviceFooID", "foo://bar.com", proxy=test_proxy, wallet_keys=wallet_keys, foofield="foo!") if 'error' in res: res['test'] = 'Failed to create foo.test account' print json.dumps(res, indent=4, sort_keys=True) error = True return res = blockstack_client.put_account("foo.test", "deletedService", "deletedServiceID", "foo://deleted", proxy=test_proxy, wallet_keys=wallet_keys, barfield="bar!") if 'error' in res: res['test'] = 'Failed to create foo.test deletedService account' print json.dumps(res, indent=4, sort_keys=True) error = True return # delete an account res = blockstack_client.delete_account("foo.test", "deletedService", "deletedServiceID", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to delete foo.test deletedService' print json.dumps(res, indent=4, sort_keys=True) error = True return testlib.next_block(**kw)
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, key_names, error, gpghome testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.blockstack_name_preorder( "bar.test", wallets[5].privkey, wallets[6].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.blockstack_name_register( "bar.test", wallets[5].privkey, wallets[6].addr ) testlib.next_block( **kw ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) wallet_keys = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey, data_privkey=wallets[4].privkey ) wallet_keys_2 = blockstack_client.make_wallet_keys( owner_privkey=wallets[6].privkey, data_privkey=wallets[7].privkey ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return res = testlib.migrate_profile( "bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2 ) if 'error' in res: res['test'] = 'Failed to initialize bar.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return testlib.next_block( **kw ) # add account keys res = blockstack_gpg.gpg_profile_create_key( "foo.test", "foo_test_account_key", immutable=False, proxy=test_proxy, wallet_keys=wallet_keys, config_dir=testlib.get_working_dir(**kw), gpghome=testlib.gpg_key_dir(**kw), use_key_server=False ) if 'error' in res: res['test'] = 'Failed to create foo.test account key' print json.dumps(res, indent=4, sort_keys=True) error = True return else: key_names['foo.test'].append( res ) res = blockstack_gpg.gpg_profile_create_key( "bar.test", "bar_test_account_key", immutable=False, proxy=test_proxy, wallet_keys=wallet_keys_2, config_dir=testlib.get_working_dir(**kw), gpghome=testlib.gpg_key_dir(**kw), use_key_server=False ) if 'error' in res: res['test'] = 'Failed to create bar.test account key' print json.dumps(res, indent=4, sort_keys=True) error = True return else: key_names['bar.test'].append( res ) testlib.next_block( **kw ) # add immutable app keys res = blockstack_gpg.gpg_app_create_key( "foo.test", "secure_messaging", "foo_test_immutable_secmsg_key", immutable=True, proxy=test_proxy, wallet_keys=wallet_keys, config_dir=testlib.get_working_dir(**kw) ) if 'error' in res: res['test'] = 'Failed to create foo.test immutable app key' print json.dumps(res, indent=4, sort_keys=True) error = True return else: key_names['foo.test'].append( res ) testlib.next_block( **kw ) res = blockstack_gpg.gpg_app_create_key( "bar.test", "secure_messaging", "bar_test_immutable_secmsg_key", immutable=True, proxy=test_proxy, wallet_keys=wallet_keys_2, config_dir=testlib.get_working_dir(**kw) ) if 'error' in res: res['test'] = 'Failed to create bar.test immutable app key' print json.dumps(res, indent=4, sort_keys=True ) error = True return else: key_names['bar.test'].append( res ) testlib.next_block( **kw ) # add mutable app keys res = blockstack_gpg.gpg_app_create_key( "foo.test", "less-secure_messaging", "foo_test_mutable_secmsg_key", proxy=test_proxy, wallet_keys=wallet_keys, config_dir=testlib.get_working_dir(**kw) ) if 'error' in res: res['test'] = 'Failed to create foo.test mutable app key' print json.dumps(res, indent=4, sort_keys=True) error = True return else: key_names['foo.test'].append( res ) testlib.next_block( **kw ) res = blockstack_gpg.gpg_app_create_key( "bar.test", "less-secure_messaging", "bar_test_mutable_secmsg_key", proxy=test_proxy, wallet_keys=wallet_keys_2, config_dir=testlib.get_working_dir(**kw) ) if 'error' in res: res['test'] = 'Failed to create bar.test mutable app key' print json.dumps(res, indent=4, sort_keys=True ) error = True return else: key_names['bar.test'].append( res ) testlib.next_block( **kw ) # add profile keys that we'll delete res = blockstack_gpg.gpg_profile_create_key( "foo.test", "foo_test_deleted_account_key", immutable=True, proxy=test_proxy, wallet_keys=wallet_keys, config_dir=testlib.get_working_dir(**kw), gpghome=testlib.gpg_key_dir(**kw), use_key_server=False) foo_profile_delete_key_id = None if 'error' in res: res['test'] = 'Failed to create deletable foo.test account key' print json.dumps(res, indent=4, sort_keys=True) error = True return else: key_names['foo.test'].append( res ) foo_profile_delete_key_id = res['key_id'] testlib.next_block( **kw ) res = blockstack_gpg.gpg_profile_create_key( "bar.test", "bar_test_deleted_account_key", immutable=True, proxy=test_proxy, wallet_keys=wallet_keys_2, config_dir=testlib.get_working_dir(**kw), gpghome=testlib.gpg_key_dir(**kw), use_key_server=False) bar_profile_delete_key_id = None if 'error' in res: res['test'] = 'Failed to create deletable bar.test account key' print json.dumps(res, indent=4, sort_keys=True) error = True return else: key_names['bar.test'].append( res ) bar_profile_delete_key_id = res['key_id'] testlib.next_block( **kw ) # add immutable app keys, which we can delete res = blockstack_gpg.gpg_app_create_key( "foo.test", "immutable_delete", "foo_test_deleted_immutable_secmsg_key", immutable=True, proxy=test_proxy, wallet_keys=wallet_keys, config_dir=testlib.get_working_dir(**kw) ) foo_immutable_delete_key_id = None if 'error' in res: res['test'] = 'Failed to create deletable foo.test immutable app key' print json.dumps(res, indent=4, sort_keys=True) error = True return else: key_names['foo.test'].append( res ) foo_immutable_delete_key_id = res['key_id'] testlib.next_block( **kw ) res = blockstack_gpg.gpg_app_create_key( "bar.test", "immutable_delete", "bar_test_deleted_immutable_secmsg_key", immutable=True, proxy=test_proxy, wallet_keys=wallet_keys_2, config_dir=testlib.get_working_dir(**kw) ) bar_immutable_delete_key_id = None if 'error' in res: res['test'] = 'Failed to create deletable bar.test immutable app key' print json.dumps(res, indent=4, sort_keys=True ) error = True return else: key_names['bar.test'].append( res ) bar_immutable_delete_key_id = res['key_id'] testlib.next_block( **kw ) # add mutable app keys which we can delete res = blockstack_gpg.gpg_app_create_key( "foo.test", "mutable_delete", "foo_test_deleted_mutable_secmsg_key", proxy=test_proxy, wallet_keys=wallet_keys, config_dir=testlib.get_working_dir(**kw) ) foo_mutable_delete_key_id = None if 'error' in res: res['test'] = 'Failed to create deletable mutable foo.test app key' print json.dumps(res, indent=4, sort_keys=True) error = True return else: key_names['foo.test'].append( res ) foo_mutable_delete_key_id = res['key_id'] testlib.next_block( **kw ) res = blockstack_gpg.gpg_app_create_key( "bar.test", "mutable_delete", "bar_test_deleted_mutable_secmsg_key", proxy=test_proxy, wallet_keys=wallet_keys_2, config_dir=testlib.get_working_dir(**kw) ) bar_mutable_delete_key_id = None if 'error' in res: res['test'] = 'Failed to create deletable mutable bar.test app key' print json.dumps(res, indent=4, sort_keys=True ) error = True return else: key_names['bar.test'].append( res ) bar_mutable_delete_key_id = res['key_id'] testlib.next_block( **kw ) # delete profile keys res = blockstack_gpg.gpg_profile_delete_key( "foo.test", foo_profile_delete_key_id, proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to create deletable account foo.test profile key' print json.dumps(res, indent=4, sort_keys=True ) error = True return testlib.next_block( **kw ) res = blockstack_gpg.gpg_profile_delete_key( "bar.test", bar_profile_delete_key_id, proxy=test_proxy, wallet_keys=wallet_keys_2 ) if 'error' in res: res['test'] = 'Failed to create deletable account bar.test profile key' print json.dumps(res, indent=4, sort_keys=True ) error = True return # delete immutable app keys res = blockstack_gpg.gpg_app_delete_key( "foo.test", "immutable_delete", "foo_test_deleted_immutable_secmsg_key", immutable=True, proxy=test_proxy, wallet_keys=wallet_keys, config_dir=testlib.get_working_dir(**kw)) if 'error' in res: res['test'] = 'Failed to create deletable foo.test immutable app key' print json.dumps(res, indent=4, sort_keys=True ) error = True return testlib.next_block( **kw ) res = blockstack_gpg.gpg_app_delete_key( "bar.test", "immutable_delete", "bar_test_deleted_immutable_secmsg_key", immutable=True, proxy=test_proxy, wallet_keys=wallet_keys_2, config_dir=testlib.get_working_dir(**kw)) if 'error' in res: res['test'] = 'Failed to create deletable bar.test immutable app key' print json.dumps(res, indent=4, sort_keys=True ) error = True return testlib.next_block( **kw ) # delete mutable app keys res = blockstack_gpg.gpg_app_delete_key( "foo.test", "mutable_delete", "foo_test_deleted_mutable_secmsg_key", proxy=test_proxy, wallet_keys=wallet_keys, config_dir=testlib.get_working_dir(**kw)) if 'error' in res: res['test'] = 'Failed to create deletable foo.test mutable app key' print json.dumps(res, indent=4, sort_keys=True ) error = True return testlib.next_block( **kw ) res = blockstack_gpg.gpg_app_delete_key( "bar.test", "mutable_delete", "bar_test_deleted_mutable_secmsg_key", proxy=test_proxy, wallet_keys=wallet_keys_2, config_dir=testlib.get_working_dir(**kw)) if 'error' in res: res['test'] = 'Failed to create deletable bar.test mutable app key' print json.dumps(res, indent=4, sort_keys=True ) error = True return testlib.next_block( **kw ) gpghome = testlib.gpg_key_dir(**kw)
def scenario(wallets, **kw): global wallet_keys, error, index_file_data, resource_data test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) wallet_keys = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey, data_privkey=wallets[4].privkey, payment_privkey=wallets[5].privkey) testlib.blockstack_client_set_wallet("0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey']) testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) # migrate profiles res = testlib.migrate_profile("foo.test", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # sign in and make a token datastore_pk = keylib.ECPrivateKey(wallets[-1].privkey).to_hex() res = testlib.blockstack_cli_app_signin( "foo.test", datastore_pk, 'foo-app.com', ['store_read', 'store_write', 'store_admin']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return # export to environment blockstack_client.set_secret("BLOCKSTACK_API_SESSION", res['token']) ses = res['token'] datastore_id_res = testlib.blockstack_cli_datastore_get_id(datastore_pk) datastore_id = datastore_id_res['datastore_id'] # use random data for file file_data = None with open('/dev/urandom', 'r') as f: file_data = f.read(16384) # make datastore with two storage drivers res = testlib.blockstack_cli_create_datastore('foo.test', datastore_pk, ['disk', 'test'], ses) if 'error' in res: print "failed to create datastore: {}".format(res['error']) return False # make directories for dpath in ['/dir1', '/dir2', '/dir1/dir3', '/dir1/dir3/dir4']: print 'mkdir {}'.format(dpath) res = testlib.blockstack_cli_datastore_mkdir('foo.test', datastore_pk, dpath, ses) if 'error' in res: print 'failed to mkdir {}: {}'.format(dpath, res['error']) return False # stat directories for dpath in ['/dir1', '/dir2', '/dir1/dir3', '/dir1/dir3/dir4']: print 'stat {}'.format(dpath) res = testlib.blockstack_cli_datastore_stat('foo.test', datastore_id, dpath, ses) if 'error' in res: print 'failed to stat {}: {}'.format(dpath, res['error']) return False if res['type'] != blockstack_client.schemas.MUTABLE_DATUM_DIR_TYPE: print 'not a directory: {}, {}'.format(dpath, res) return False # list directories for dpath, expected in [('/', ['dir1', 'dir2']), ('/dir1', ['dir3']), ('/dir1/dir3', ['dir4']), ('/dir1/dir3/dir4', [])]: print 'listdir {}'.format(dpath) res = testlib.blockstack_cli_datastore_listdir('foo.test', datastore_id, dpath, ses) if 'error' in res: print 'failed to listdir {}: {}'.format(dpath, res['error']) return False if len(res['children'].keys()) != len(expected): print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format( expected, res) return False for child in expected: if not res['children'].has_key(child): print 'invalid directory: missing {} in {}'.format(child, res) return False # put files for dpath in [ '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5' ]: print 'putfile {}'.format(dpath) data = '{} hello {}'.format(file_data, dpath) res = testlib.blockstack_cli_datastore_putfile('foo.test', datastore_pk, dpath, data, ses) if 'error' in res: print 'failed to putfile {}: {}'.format(dpath, res['error']) return False # stat files for dpath in [ '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5' ]: print 'stat {}'.format(dpath) res = testlib.blockstack_cli_datastore_stat('foo.test', datastore_id, dpath, ses) if 'error' in res: print 'failed to stat {}: {}'.format(dpath, res['error']) return False if res['type'] != blockstack_client.schemas.MUTABLE_DATUM_FILE_TYPE: print 'not a file: {}, {}'.format(dpath, res) return False # list directories again for dpath, expected in [('/', ['dir1', 'dir2', 'file1', 'file2']), ('/dir1', ['dir3', 'file3']), ('/dir1/dir3', ['dir4', 'file4']), ('/dir1/dir3/dir4', ['file5'])]: print 'listdir {}'.format(dpath) res = testlib.blockstack_cli_datastore_listdir('foo.test', datastore_id, dpath, ses) if 'error' in res: print 'failed to listdir {}: {}'.format(dpath, res['error']) return False if len(res['children'].keys()) != len(expected): print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format( expected, res) return False for child in expected: if not res['children'].has_key(child): print 'invalid directory: missing {} in {}'.format(child, res) return False # get files for dpath in [ '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5' ]: print 'getfile {}'.format(dpath) res = testlib.blockstack_cli_datastore_getfile('foo.test', datastore_id, dpath, ses) if 'error' in res: print 'failed to getfile {}: {}'.format(dpath, res['error']) return False if res != '{} hello {}'.format(file_data, dpath): print 'failed to read {}'.format(dpath) return False # put files again! for dpath in [ '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5' ]: print 'putfile {}'.format(dpath) data = '{} hello 2 {}'.format(file_data, dpath) res = testlib.blockstack_cli_datastore_putfile('foo.test', datastore_pk, dpath, data, ses) if 'error' in res: print 'failed to putfile {}: {}'.format(dpath, res['error']) return False # get files again! for dpath in [ '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5' ]: print 'getfile {}'.format(dpath) res = testlib.blockstack_cli_datastore_getfile('foo.test', datastore_id, dpath, ses) if 'error' in res: print 'failed to getfile {}: {}'.format(dpath, res['error']) return False if res != '{} hello 2 {}'.format(file_data, dpath): print 'failed to read {}'.format(dpath) return False # remove files for dpath in [ '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5' ]: print 'deletefile {}'.format(dpath) res = testlib.blockstack_cli_datastore_deletefile( 'foo.test', datastore_pk, dpath, ses) if 'error' in res: print 'failed to deletefile {}: {}'.format(dpath, res['error']) return False # stat files (should all fail) for dpath in [ '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5' ]: print 'stat {} (expect failure)'.format(dpath) res = testlib.blockstack_cli_datastore_stat('foo.test', datastore_id, dpath, ses) if 'error' not in res or 'errno' not in res: print 'accidentally succeeded to stat {}: {}'.format(dpath, res) return False if res['errno'] != errno.ENOENT: print 'wrong errno: {}'.format(res) return False # get files (should all fail) for dpath in [ '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5' ]: print 'getfile {} (expect failure)'.format(dpath) res = testlib.blockstack_cli_datastore_getfile('foo.test', datastore_id, dpath, ses) if 'error' not in res or 'errno' not in res: print 'accidentally succeeded to get {}: {}'.format(dpath, res) return False if res['errno'] != errno.ENOENT: print 'wrong errno: {}'.format(res) return False # list directories, 3rd time for dpath, expected in [('/', ['dir1', 'dir2']), ('/dir1', ['dir3']), ('/dir1/dir3', ['dir4']), ('/dir1/dir3/dir4', [])]: print 'listdir {}'.format(dpath) res = testlib.blockstack_cli_datastore_listdir('foo.test', datastore_id, dpath, ses) if 'error' in res: print 'failed to listdir {}: {}'.format(dpath, res['error']) return False if len(res['children'].keys()) != len(expected): print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format( expected, res) return False for child in expected: if not res['children'].has_key(child): print 'invalid directory: missing {} in {}'.format(child, res) return False # remove directories for dpath in ['/dir1/dir3/dir4', '/dir1/dir3', '/dir2', '/dir1']: print 'rmdir {}'.format(dpath) res = testlib.blockstack_cli_datastore_rmdir('foo.test', datastore_pk, dpath, ses) if 'error' in res: print 'failed to rmdir {}: {}'.format(dpath, res['error']) return False # stat directories (should all fail) for dpath in ['/dir1/dir3/dir4', '/dir1/dir3', '/dir2', '/dir1']: print 'stat {} (expect failure)'.format(dpath) res = testlib.blockstack_cli_datastore_stat('foo.test', datastore_id, dpath, ses) if 'error' not in res or 'errno' not in res: print 'accidentally succeeded to stat {}: {}'.format(dpath, res) return False if res['errno'] != errno.ENOENT: print 'wrong errno: {}'.format(res) return False # list directories (should all fail) for dpath, expected in [('/dir1', ['dir3']), ('/dir1/dir3', ['dir4']), ('/dir1/dir3/dir4', [])]: print 'listdir {} (expect failure)'.format(dpath) res = testlib.blockstack_cli_datastore_listdir('foo.test', datastore_id, dpath, ses) if 'error' not in res or 'errno' not in res: print 'accidentally succeeded to list {}: {}'.format(dpath, res) return False if res['errno'] != errno.ENOENT: print 'wrong errno: {}'.format(res) return False # root should be empty print 'listdir {}'.format('/') res = testlib.blockstack_cli_datastore_listdir('foo.test', datastore_id, '/', ses) if 'error' in res: print 'failed to listdir /: {}'.format(res['error']) return False if len(res['children'].keys()) > 0: print 'root still has children: {}'.format(res['children'].keys()) return False # delete datastore print 'delete datastore' res = testlib.blockstack_cli_delete_datastore('foo.test', datastore_pk, ses) if 'error' in res: print 'failed to delete foo-app.com datastore' print json.dumps(res) return False # no more data in disk driver names = os.listdir("/tmp/blockstack-disk/mutable") if names != ['foo.test']: print 'improper cleanup' return False # no more data in test-disk driver names = os.listdir("/tmp/blockstack-integration-test-storage/mutable") if names != ['foo.test']: print 'improper cleanup' return False testlib.next_block(**kw)
def check(state_engine): global wallet_keys, error if error: print "Key operation failed." return False # not revealed, but ready ns = state_engine.get_namespace_reveal("test") if ns is not None: print "namespace not ready" return False ns = state_engine.get_namespace("test") if ns is None: print "no namespace" return False if ns['namespace_id'] != 'test': print "wrong namespace" return False # not preordered names = ['foo.test'] wallet_keys_list = [wallet_keys] test_proxy = testlib.TestAPIProxy() for i in xrange(0, len(names)): name = names[i] wallet_payer = 3 * (i + 1) - 1 wallet_owner = 3 * (i + 1) wallet_data_pubkey = 3 * (i + 1) # same as owner key wallet_keys = wallet_keys_list[i] preorder = state_engine.get_name_preorder( name, pybitcoin.make_pay_to_address_script(wallets[wallet_payer].addr), wallets[wallet_owner].addr) if preorder is not None: print "still have preorder" return False # registered name_rec = state_engine.get_name(name) if name_rec is None: print "name does not exist" return False # owned if name_rec['address'] != wallets[wallet_owner].addr or name_rec[ 'sender'] != pybitcoin.make_pay_to_address_script( wallets[wallet_owner].addr): print "name has wrong owner" return False # only serviceFoo exists accounts = blockstack_client.list_accounts("foo.test", proxy=test_proxy, wallet_keys=wallet_keys) if len(accounts) != 1: print "wrong number of accounts" print json.dumps(accounts, indent=4, sort_keys=True) return False account = accounts['accounts'][0] on_file_accounts = blockstack_client.get_account( "foo.test", "serviceFoo", "serviceFooID", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in on_file_accounts: print json.dumps(on_file_account, sort_keys=True, indent=4) return False on_file_account = on_file_accounts['account'][0] if account != on_file_account: print "wrong service\nexpected:\n%s\n\ngot:\n%s\n" % \ (json.dumps(account, indent=4, sort_keys=True), json.dumps(on_file_account, indent=4, sort_keys=True)) return False if account['identifier'] != 'serviceFooID': print "wrong identifier: %s" % account return False if account['contentUrl'] != 'foo://bar.com': print "wrong URL: %s" % account return False if account['service'] != 'serviceFoo': print "wrong service: %s" % account return False return True
def scenario(wallets, **kw): global datasets, immutable_data_hashes, put_result, last_hash wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, None) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) wallet_keys = wallet testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) # migrate profile res = testlib.migrate_profile("foo.test", proxy=test_proxy, wallet_keys=wallet_keys) 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) put_result = testlib.blockstack_cli_put_immutable( "foo.test", "hello_world_1", json.dumps(datasets[0], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) testlib.expect_atlas_zonefile(put_result['zonefile_hash']) immutable_data_hashes.append(put_result['immutable_data_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block(**kw) print "waiting for confirmation" time.sleep(10) put_result = testlib.blockstack_cli_put_immutable( "foo.test", "hello_world_2", json.dumps(datasets[1], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) testlib.expect_atlas_zonefile(put_result['zonefile_hash']) immutable_data_hashes.append(put_result['immutable_data_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() for i in xrange(0, 12): testlib.next_block(**kw) print "waiting for confirmation" time.sleep(10) put_result = testlib.blockstack_cli_put_immutable( "foo.test", "hello_world_3", json.dumps(datasets[2], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) testlib.expect_atlas_zonefile(put_result['zonefile_hash']) immutable_data_hashes.append(put_result['immutable_data_hash']) last_hash = put_result['zonefile_hash'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() for i in xrange(0, 12): testlib.next_block(**kw) print "waiting for confirmation" time.sleep(10) # should succeed (name collision) datasets[0][u'newdata'] = u"asdf" put_result = testlib.blockstack_cli_put_immutable( "foo.test", "hello_world_1", json.dumps(datasets[0], sort_keys=True), password='******') if 'error' not in put_result: immutable_data_hashes[0] = put_result['immutable_data_hash'] else: print json.dumps(put_result, indent=4, sort_keys=True) testlib.expect_atlas_zonefile(put_result['zonefile_hash']) last_hash = put_result['zonefile_hash'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() for i in xrange(0, 12): testlib.next_block(**kw) print "waiting for confirmation" time.sleep(10)
def check( state_engine ): global last_consensus, snv_block_id # not revealed, but ready ns = state_engine.get_namespace_reveal( "test" ) if ns is not None: return False ns = state_engine.get_namespace( "test" ) if ns is None: return False if ns['namespace_id'] != 'test': return False names = ['foo.test', 'bar.test', 'baz.test'] name_preorder_wallets = [wallets[2], wallets[3], wallets[4]] name_register_wallets = [wallets[5], wallets[6], wallets[7]] name_transfer_wallets = [wallets[6], wallets[7], wallets[5]] test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) for i in xrange(0, len(names)): name = names[i] name_preorder_wallet = name_preorder_wallets[i] name_register_wallet = name_register_wallets[i] name_transfer_wallet = name_transfer_wallets[i] # not preordered preorder = state_engine.get_name_preorder( name, pybitcoin.make_pay_to_address_script(name_preorder_wallet.addr), name_register_wallet.addr ) if preorder is not None: return False # registered name_rec = state_engine.get_name( name ) if name_rec is None: return False # data is gone if name_rec['value_hash'] is not None: return False # owned by the right transfer wallet if name_rec['address'] != name_transfer_wallet.addr or name_rec['sender'] != pybitcoin.make_pay_to_address_script(name_transfer_wallet.addr): return False # renewed if name_rec['last_renewed'] == name_rec['first_registered']: return False # revoked if not name_rec['revoked']: return False # snv lookup works snv_rec = blockstack_client.snv_lookup( name, snv_block_id, last_consensus, proxy=test_proxy ) if 'error' in snv_rec: print json.dumps(snv_rec, indent=4 ) return False return True
def scenario( wallets, **kw ): global datasets wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, None ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # migrate profile (but no data key) res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) return False # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) # put immutable (with owner key) log.debug("put immutable 1 with owner key") testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], None ) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False put_result = testlib.blockstack_cli_put_immutable("foo.test", "hello_world_1_immutable", json.dumps(datasets[0], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.expect_atlas_zonefile(put_result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block( **kw ) print "waiting for confirmation" time.sleep(10) # put immutable (with owner key) log.debug("put immutable 2 with owner key") testlib.blockstack_cli_put_immutable("foo.test", "hello_world_2_immutable", json.dumps(datasets[1], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.expect_atlas_zonefile(put_result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block( **kw ) print "waiting for confirmation" time.sleep(10) # put mutable (with owner key) log.debug("put mutable 1 with owner key") put_result = testlib.blockstack_cli_put_mutable("foo.test", "hello_world_1_mutable", json.dumps(datasets[0], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False # put mutable (with owner key) log.debug("put mutable 2 with owner key") put_result = testlib.blockstack_cli_put_mutable("foo.test", "hello_world_2_mutable", json.dumps(datasets[1], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.next_block( **kw ) # add data signing key res = blockstack_client.set_data_pubkey("foo.test", wallets[4].pubkey_hex, wallet_keys=wallet_keys, proxy=test_proxy ) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) return False testlib.expect_atlas_zonefile(res['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block( **kw ) print "waiting for confirmation" time.sleep(10) # put immutable (with new key) log.debug("put immutable with new key") # restart daemon wallet_keys = testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey'] ) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # put immutable put_result = testlib.blockstack_cli_put_immutable("foo.test", "hello_world_3_immutable", json.dumps(datasets[2], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.expect_atlas_zonefile(put_result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block( **kw ) print "waiting for confirmation" time.sleep(10) # put mutable (with new key) log.debug("put mutable with new key") put_result = testlib.blockstack_cli_put_mutable("foo.test", "hello_world_3_mutable", json.dumps(datasets[2], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.next_block( **kw ) # delete immutable (new key) log.debug("delete immutable with new key") result = testlib.blockstack_cli_delete_immutable("foo.test", "hello_world_1_immutable", password='******') if 'error' in result: print json.dumps(result, indent=4, sort_keys=True) return False testlib.expect_atlas_zonefile(result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block( **kw ) print "waiting for confirmation" time.sleep(10) # delete mutable (new key) log.debug("delete mutable with new key") result = testlib.blockstack_cli_delete_mutable("foo.test", "hello_world_1_mutable", password='******') if 'error' in result: print json.dumps(result, indent=4, sort_keys=True) return False testlib.next_block( **kw )
def scenario( wallets, **kw ): global put_result, wallet_keys, legacy_profile, zonefile_hash, zonefile_hash_2 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 wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) for i in xrange(0, 3): testlib.next_block(**kw) # try to preorder another namespace; it should fail res = testlib.blockstack_namespace_preorder("test2", wallets[1].addr, wallets[0].privkey) if 'error' not in res: print 'accidentally succeeded to preorder test2' return False # try to reveal; it should fail res = testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) if 'error' not in res: print 'accidentally succeeded to reveal test' return False testlib.expect_snv_fail_at("test2", testlib.get_current_block(**kw) + 1) testlib.expect_snv_fail_at("test", testlib.get_current_block(**kw) + 1) for i in xrange(0, 3): testlib.next_block(**kw) # should succeed res = testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) if 'error' in res: print res return False for i in xrange(0, 3): testlib.next_block(**kw) # should fail, since we have an unusable address res = testlib.blockstack_namespace_ready("test", wallets[1].privkey) if 'error' not in res: print res return False testlib.expect_snv_fail_at("test", testlib.get_current_block(**kw) + 1) for i in xrange(0, 3): testlib.next_block(**kw) # should work now res = testlib.blockstack_namespace_ready("test", wallets[1].privkey) if 'error' in res: print res return False testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) for i in xrange(0, 3): testlib.next_block(**kw) # should fail to re-preorder, since address isn't ready res = testlib.blockstack_name_preorder("foo2.test", wallets[2].privkey, wallets[3].addr) if 'error' not in res: print 'accidentally succeeded to preorder foo2.test' return False testlib.expect_snv_fail_at("foo2.test", testlib.get_current_block(**kw) + 1) # should fail for the same reason: the payment address is not ready res = testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) if 'error' not in res: print 'accidentally succeeded to register foo.test' return False testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw) + 1) for i in xrange(0, 3): testlib.next_block(**kw) # should succeed now that it's confirmed res = testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) if 'error' in res: print res return False for i in xrange(0, 3): testlib.next_block(**kw) # should fail; address not ready res = testlib.migrate_profile("foo.test", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' not in res: print 'accidentally succeeded to migrate profile' return False testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw) + 1) for i in xrange(0, 3): testlib.next_block(**kw) # migrate profiles (should succeed now) 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() config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) # make a session datastore_pk = keylib.ECPrivateKey(wallets[-1].privkey).to_hex() res = testlib.blockstack_cli_app_signin( "foo.test", datastore_pk, 'register.app', [ 'names', 'register', 'prices', 'zonefiles', 'blockchain', 'node_read', 'wallet_read' ]) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] # make zonefile for recipient driver_urls = blockstack_client.storage.make_mutable_data_urls( 'bar.test', use_only=['dht', 'disk']) zonefile = blockstack_client.zonefile.make_empty_zonefile( 'bar.test', wallets[4].pubkey_hex, urls=driver_urls) zonefile_txt = blockstack_zones.make_zone_file(zonefile, origin='bar.test', ttl=3600) # register the name bar.test (no zero-conf, should fail) res = testlib.blockstack_REST_call('POST', '/v1/names', ses, data={ 'name': 'bar.test', 'zonefile': zonefile_txt, 'owner_address': wallets[4].addr }) if res['http_status'] == 200: print 'accidentally succeeded to register bar.test' print res return False # let's test /v1/wallet/balance res = testlib.blockstack_REST_call('GET', '/v1/wallet/balance', ses) if res['http_status'] != 200: print '/v1/wallet/balance returned ERR' print json.dumps(res) return False if res['response']['balance']['satoshis'] > 0: print '/v1/wallet/balance accidentally incorporated 0-conf txns in balance register bar.test' print json.dumps(res['response']) return False # let's test /v1/wallet/balance with minconfs=0 res = testlib.blockstack_REST_call('GET', '/v1/wallet/balance/0', ses) if res['http_status'] != 200: print '/v1/wallet/balance/0 returned ERR' print json.dumps(res) return False if res['response']['balance']['satoshis'] < 1e6: print "/v1/wallet/balance/0 didn't incorporate 0-conf txns" print json.dumps(res['response']) return False # register the name bar.test (1-conf, should fail) res = testlib.blockstack_REST_call('POST', '/v1/names', ses, data={ 'name': 'bar.test', 'zonefile': zonefile_txt, 'owner_address': wallets[4].addr, 'min_confs': 1 }) if res['http_status'] == 200: print 'accidentally succeeded to register bar.test' print res return False # register the name bar.test (zero-conf, should succeed) res = testlib.blockstack_REST_call('POST', '/v1/names', ses, data={ 'name': 'bar.test', 'zonefile': zonefile_txt, 'owner_address': wallets[4].addr, 'min_confs': 0 }) if 'error' in res: res['test'] = 'Failed to register user' print json.dumps(res) error = True return False print res tx_hash = res['response']['transaction_hash'] # wait for preorder to get confirmed... for i in xrange(0, 6): testlib.next_block(**kw) res = testlib.verify_in_queue(ses, 'bar.test', 'preorder', tx_hash) if not res: return False # wait for the preorder to get confirmed for i in xrange(0, 6): testlib.next_block(**kw) # wait for register to go through print 'Wait for register to be submitted' time.sleep(10) # wait for the register to get confirmed for i in xrange(0, 6): testlib.next_block(**kw) res = testlib.verify_in_queue(ses, 'bar.test', 'register', None) if not res: return False for i in xrange(0, 6): testlib.next_block(**kw) print 'Wait for update to be submitted' time.sleep(10) # wait for update to get confirmed for i in xrange(0, 6): testlib.next_block(**kw) res = testlib.verify_in_queue(ses, 'bar.test', 'update', None) if not res: return False for i in xrange(0, 6): testlib.next_block(**kw) print 'Wait for transfer to be submitted' time.sleep(10) # wait for transfer to get confirmed for i in xrange(0, 6): testlib.next_block(**kw) res = testlib.verify_in_queue(ses, 'bar.test', 'transfer', None) if not res: return False for i in xrange(0, 6): testlib.next_block(**kw) print 'Wait for transfer to be confirmed' time.sleep(10) res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test", ses) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name bar.test' print json.dumps(res) return False zonefile_hash = res['response']['zonefile_hash'] # should still be registered if res['response']['status'] != 'registered': print "register not complete" print json.dumps(res) return False # do we have the history for the name? res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test/history", ses) if 'error' in res or res['http_status'] != 200: res['test'] = "Failed to get name history for foo.test" print json.dumps(res) return False # valid history? hist = res['response'] if len(hist.keys()) != 4: res['test'] = 'Failed to get update history' res['history'] = hist print json.dumps(res, indent=4, sort_keys=True) return False # get the zonefile res = testlib.blockstack_REST_call( "GET", "/v1/names/bar.test/zonefile/{}".format(zonefile_hash), ses) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name zonefile' print json.dumps(res) return False # same zonefile we put? if res['response']['zonefile'] != zonefile_txt: res['test'] = 'mismatched zonefile, expected\n{}\n'.format( zonefile_txt) print json.dumps(res) return False