def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data empty_key = ECPrivateKey().to_hex() wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[1].privkey, wallets[2].privkey, wallets[0].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 ) # 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 = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] # let's do a withdraw of all res = testlib.blockstack_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.blockstack_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.blockstack_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_wallet(payment_privkey, owner_privkey, data_privkey): config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) config_dir = os.path.dirname(config_path) conf = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] res = testlib.blockstack_REST_call('GET', '/v1/wallet/keys', None, api_pass=api_pass) if 'error' in res: print 'failed to get wallet' print res return False res = res['response'] if res['payment_privkey'] != payment_privkey: print 'wrong payment privkey' return False if res['owner_privkey'] != owner_privkey: print 'wrong owner privkey' return False if res['data_privkey'] != data_privkey: print 'wrong data privkey' return False return True
def scenario(wallets, **kw): testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_register_user('foo.test', wallets[2].privkey, wallets[3].privkey, **kw) # let's make sure the zonefile propagates... res = testlib.blockstack_REST_call("GET", "/v1/names/foo.test") if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name bar.test' print json.dumps(res) return False response_json = json.loads(res['raw']) # assert that we're getting a mainnet address if response_json['address'] != "1K4SCfqffVHTnHvqsW2whH1Jn57dDjDdQA": print "Address returned to REST call isn't converted to mainnet!" print "Returned: {}, Expected: {}".format( response_json['address'], "1K4SCfqffVHTnHvqsW2whH1Jn57dDjDdQA") return False
def scenario( wallets, **kw ): # save the wallet wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey ) if 'error' in wallet: print 'failed to set wallet: {}'.format(wallet) return False config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) config_dir = os.path.dirname(config_path) conf = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] if not check_wallet(wallets[2].privkey, wallets[3].privkey, wallets[4].privkey): return False res = testlib.blockstack_REST_call('PUT', '/v1/wallet/keys/owner', None, api_pass=api_pass, data=wallets[0].privkey) if 'error' in res: print 'failed to set owner key' print res return False if not check_wallet(wallets[2].privkey, wallets[0].privkey, wallets[4].privkey): return False res = testlib.blockstack_REST_call('PUT', '/v1/wallet/keys/payment', None, api_pass=api_pass, data=wallets[1].privkey) if 'error' in res: print 'failed to set payment key' print res return False if not check_wallet(wallets[1].privkey, wallets[0].privkey, wallets[4].privkey): return False res = testlib.blockstack_REST_call('PUT', '/v1/wallet/keys/data', None, api_pass=api_pass, data=wallets[2].privkey) if 'error' in res: print 'failed to set payment key' print res return False if not check_wallet(wallets[1].privkey, wallets[0].privkey, wallets[2].privkey): return False
def test_name_count(expected_num, expected_cum_num): num_names = blockstack.lib.client.get_num_names( hostport='http://localhost:16264') num_names_cum = blockstack.lib.client.get_num_names( include_expired=True, hostport='http://localhost:16264') if num_names != expected_num: print 'wrong number of names: {}'.format(num_names) return False if num_names_cum != expected_cum_num: print 'wrong number of cumulative names: {}'.format(num_names_cum) return False num_names_res = testlib.blockstack_REST_call( 'GET', '/v1/blockchains/bitcoin/name_count', ) if 'error' in num_names_res or num_names_res['http_status'] != 200: print num_names_res return False num_names = num_names_res['response']['names_count'] num_names_cum_res = testlib.blockstack_REST_call( 'GET', '/v1/blockchains/bitcoin/name_count', all='True') if 'error' in num_names_cum_res or num_names_cum_res['http_status'] != 200: print num_names_cum_res return False num_names_cum = num_names_cum_res['response']['names_count'] if num_names != expected_num: print 'wrong number of names from REST API: {} (expected {})'.format( num_names, expected_num) return False if num_names_cum != expected_cum_num: print 'wrong number of cumulative names from REST API: {} (expected {})'.format( num_names_cum, expected_cum_num) return False return True
def scenario( wallets, **kw ): testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) 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): 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, 12): testlib.next_block( **kw ) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge update" time.sleep(10) # let's make sure the zonefile propagates... res = testlib.blockstack_REST_call("GET", "/v1/names/foo.test", None) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name bar.test' print json.dumps(res) return False response_json = json.loads(res['raw']) # assert that we're getting a mainnet address if response_json['address'] != "1K4SCfqffVHTnHvqsW2whH1Jn57dDjDdQA": print "Address returned to REST call isn't converted to mainnet!" print "Returned: {}, Expected: {}".format(response_json['address'], "1K4SCfqffVHTnHvqsW2whH1Jn57dDjDdQA") return False
def check(state_engine): global error global names, owner_wallets, payment_wallets, recipients config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG") assert config_path config_dir = os.path.dirname(config_path) conf = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] 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 for name, recipient in zip(names, recipients): res = testlib.blockstack_REST_call("GET", "/v1/names/{}".format(name), None, api_pass=api_pass) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name {}'.format(name) print json.dumps(res) return False if 'address' not in res['response']: print res return False cur_owner_address = res['response']['address'] if cur_owner_address != recipient: print "After transfer, unexpected owner. Expected {}, Actual {}".format( recipient, cur_owner_address) return False return True
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) # 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']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] # for funsies, get the price of .test res = testlib.blockstack_REST_call('GET', '/v1/prices/namespaces/test', ses ) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get price of .test' print json.dumps(res) return False test_price = res['response']['satoshis'] print '\n\n.test costed {} satoshis\n\n'.format(test_price) # get the price for bar.test res = testlib.blockstack_REST_call('GET', '/v1/prices/names/bar.test', ses ) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get price of bar.test' print json.dumps(res) return False bar_price = res['response']['total_estimated_cost']['satoshis'] print "\n\nbar.test will cost {} satoshis\n\n".format(bar_price) # register the name bar.test. autogenerate the rest res = testlib.blockstack_REST_call('POST', '/v1/names', ses, data={'name': 'bar.test'} ) 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, 12): testlib.next_block( **kw ) print 'Wait for update 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'] # 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 bar.test" print json.dumps(res) return False # valid history? hist = res['response'] if len(hist.keys()) != 3: 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
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 testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw)+1) # 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( "foo.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( "foo.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
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, wallet_keychain, error, index_file_data, resource_data, sessions test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) wallet_keys_2 = blockstack_client.make_wallet_keys( owner_privkey=wallets[4].privkey, data_privkey=wallets[5].privkey, payment_privkey=wallets[3].privkey ) wallet_keys = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey, data_privkey=wallets[4].privkey, payment_privkey=wallets[5].privkey ) wallet_keychain = { 'foo.test': wallet_keys, 'bar.test': wallet_keys_2, } # install wallet_keys 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.blockstack_name_preorder( "bar.test", wallets[3].privkey, wallets[4].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.blockstack_name_register( "bar.test", wallets[3].privkey, wallets[4].addr ) testlib.next_block( **kw ) setup_storage_dirs(['foo.test', 'bar.test']) # migrate profiles # BUT! make sure we store the profile for foo.test into both foo.test's and bar.test's storage directories! os.environ['TEST_BLOCKSTACK_TEST_DISK_ROOT'] = '/tmp/blockstack-integration-test-storage-foo.test' 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 shutil.copy("/tmp/blockstack-integration-test-storage-foo.test/mutable/foo.test", "/tmp/blockstack-integration-test-storage-bar.test/mutable/foo.test") # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) # store zonefile res = blockstack_client.proxy.put_zonefiles("localhost:16264", [base64.b64encode(res['zonefile_txt'])]) if 'error' in res: print 'failed to store zonefile for foo.test: {}'.format(res) return False # BUT! make sure we store the profile for bar.test into both foo.test's and bar.test's storage directories! os.environ['TEST_BLOCKSTACK_TEST_DISK_ROOT'] = '/tmp/blockstack-integration-test-storage-bar.test' 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) return False shutil.copy("/tmp/blockstack-integration-test-storage-bar.test/mutable/bar.test", "/tmp/blockstack-integration-test-storage-foo.test/mutable/bar.test") # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) # store zonefile res = blockstack_client.proxy.put_zonefiles("localhost:16264", [base64.b64encode(res['zonefile_txt'])]) if 'error' in res: print 'failed to store zonefile for bar.test: {}'.format(res) return False res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API for foo.test: {}'.format(res) return False target_datastore('foo.test') # instantiate foo.test's test driver res = testlib.blockstack_REST_call('POST', '/v1/node/drivers/storage/test?index=1&force=1', None, api_pass='******') if 'error' in res or res['http_status'] != 200: print json.dumps(res, indent=4, sort_keys=True) return False res = testlib.blockstack_cli_put_account("foo.test", "test", 'storage', "test:///index/index.manifest?diskroot=/tmp/blockstack-integration-test-storage-foo.test", None, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to create foo.test account' print json.dumps(res, indent=4, sort_keys=True) return False os.makedirs('/tmp/blockstack-integration-test-storage/mutable') os.makedirs('/tmp/blockstack-integration-test-storage/immutable') shutil.copy("/tmp/blockstack-integration-test-storage-foo.test/mutable/foo.test", "/tmp/blockstack-integration-test-storage-bar.test/mutable/foo.test") shutil.copy("/tmp/blockstack-integration-test-storage-foo.test/mutable/foo.test", "/tmp/blockstack-integration-test-storage/mutable/foo.test") # link test account for bar.test # BUT! make sure we store the profile for bar.test into foo.test's and bar.test's storage directories! target_datastore('bar.test') # instantiate bar.test's test driver res = testlib.blockstack_REST_call('POST', '/v1/node/drivers/storage/test?index=1&force=1', None, api_pass='******') if 'error' in res or res['http_status'] != 200: print json.dumps(res, indent=4, sort_keys=True) return False res = testlib.blockstack_cli_put_account("bar.test", "test", 'storage', "test:///index/index.manifest?diskroot=/tmp/blockstack-integration-test-storage-bar.test", None, wallet_keys=wallet_keys_2 ) if 'error' in res: res['test'] = 'Failed to create bar.test account' print json.dumps(res, indent=4, sort_keys=True) return False shutil.copy("/tmp/blockstack-integration-test-storage-bar.test/mutable/bar.test", "/tmp/blockstack-integration-test-storage-foo.test/mutable/bar.test") shutil.copy("/tmp/blockstack-integration-test-storage-bar.test/mutable/bar.test", "/tmp/blockstack-integration-test-storage/mutable/bar.test") # restore...we'll set up foo.test next res = testlib.blockstack_test_setenv("TEST_BLOCKSTACK_TEST_DISK_ROOT", "/tmp/blockstack-integration-test-storage-foo.test") if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) return False # get datastore keys... foo_datastore_pk = keylib.ECPrivateKey(wallets[-1].privkey).to_hex() datastore_id_res = testlib.blockstack_cli_datastore_get_id( foo_datastore_pk ) foo_datastore_id = datastore_id_res['datastore_id'] bar_datastore_pk = keylib.ECPrivateKey(wallets[-2].privkey).to_hex() datastore_id_res = testlib.blockstack_cli_datastore_get_id( bar_datastore_pk ) bar_datastore_id = datastore_id_res['datastore_id'] # activate foo.test res = activate_account("foo.test", foo_datastore_pk) if not res: print 'failed to start API for bar.test: {}'.format(res) return False # set up foo.test's datastore res = setup_datastore(wallets[-1].privkey, "foo.test", 1) if not res: print 'failed to setup foo.test datastore' return False # activate bar.test res = activate_account("bar.test", bar_datastore_pk) if not res: print 'failed to start API for bar.test: {}'.format(res) return False # make *absolutely certain* that the test driver does not load data from # foo.test's or bar.test's storage directories. We want to verify that we can look up # the index manifest URLs from the profile target_datastore(None) print "\n\nbar.test tries to read foo.test's datastore {}\n\n".format(foo_datastore_id) res = read_datastore(foo_datastore_id, "foo.test", 1) if not res: print 'failed to read foo.test datastore {}'.format(foo_datastore_id) return False # set up bar.test's files res = setup_datastore(wallets[-2].privkey, 'bar.test', 2) if not res: print 'failed to setup bar.test datastore' return False # activate foo.test res = activate_account("foo.test", foo_datastore_pk) if not res: print 'failed to start API for foo.test: {}'.format(res) return False # make *absolutely certain* that the test driver does not load data from # foo.test's or bar.test's storage directories. We want to verify that we can look up # the index manifest URLs from the profile target_datastore(None) # try to read all of bar.test's files print "\n\nfoo.test tries to read bar.test's datastore {}\n\n".format(bar_datastore_id) res = read_datastore(bar_datastore_id, 'bar.test', 2) if not res: print 'failed to read bar.test datastore {}'.format(bar_datastore_id) return False # re-target foo.test's datastore target_datastore('foo.test') # have foo.test write new files print '\n\nupdate foo.test datastore\n\n' res = write_datastore('foo.test', foo_datastore_pk, 3) if not res: print 'failed to update foo.test datastore {}'.format(foo_datastore_id) return False # activate bar.test res = activate_account("bar.test", bar_datastore_pk) if not res: print 'failed to start API for bar.test: {}'.format(res) return False # make *absolutely certain* that the test driver does not load data from # foo.test's or bar.test's storage directories. We want to verify that we can look up # the index manifest URLs from the profile target_datastore(None) # get foo.test's new files res = read_datastore(foo_datastore_id, 'foo.test', 3) if not res: print 'failed to read new files from foo.test' return False # re-target bar.test's datastore target_datastore('bar.test') # have bar write some new files print '\n\nupdate bar.test datastore\n\n' res = write_datastore('bar.test', bar_datastore_pk, 4) if not res: print 'failed ot update bar.test datastore {}'.format(bar_datastore_id) return False # activate foo.test res = activate_account("foo.test", foo_datastore_pk) if not res: print 'failed to start API for foo.test: {}'.format(res) return False # delete foo's files print '\n\ndelete foo.test files\n\n' res = clear_datastore_files('foo.test', foo_datastore_pk) if not res: print 'failed to clear datastore {} for foo.test'.format(foo_datastore_id) return False # activate bar.test res = activate_account("bar.test", bar_datastore_pk) if not res: print 'failed to start API for bar.test: {}'.format(res) return False # make *absolutely certain* that the test driver does not load data from # foo.test's or bar.test's storage directories. We want to verify that we can look up # the index manifest URLs from the profile target_datastore(None) # verify that foo's files are gone res = check_datastore_files_absent(foo_datastore_id, 'foo.test') if not res: print 'failed to verify that foo.test datastore {} is devoid of files'.format(foo_datastore_id) return False # re-target bar.test's datastore target_datastore('bar.test') # clear bar.test's files print '\n\ndelete bar.test files\n\n' res = clear_datastore_files('bar.test', bar_datastore_pk) if not res: print 'failed to clear datastore {} for bar.test'.format(bar_datastore_id) return False # activate foo.test res = activate_account("foo.test", foo_datastore_pk) if not res: print 'failed to start API for foo.test: {}'.format(res) return False # make *absolutely certain* that the test driver does not load data from # foo.test's or bar.test's storage directories. We want to verify that we can look up # the index manifest URLs from the profile target_datastore(None) # verify that bar's files are gone res = check_datastore_files_absent(bar_datastore_id, 'bar.test') if not res: print 'failed to verify that bar.test datastore {} is devoid of files'.format(bar_datastore_id) return False # re-target foo.test's datastore target_datastore("foo.test") # clear foo's directories res = clear_datastore_directories('foo.test', foo_datastore_pk) if not res: print 'failed to clear foo.test datastore {} of directories'.format(foo_datastore_id) return False # activate bar.test res = activate_account("bar.test", bar_datastore_pk) if not res: print 'failed to start API for bar.test: {}'.format(res) return False # make *absolutely certain* that the test driver does not load data from # foo.test's or bar.test's storage directories. We want to verify that we can look up # the index manifest URLs from the profile target_datastore(None) # verify that foo's directories are gone res = check_datastore_directories_absent(foo_datastore_id, "foo.test") if not res: print 'failed to verify that foo.test datastore {} is devoid of directories'.format(foo_datastore_id) return False # re-target bar.test's datastore target_datastore('bar.test') # clear bar's directories res = clear_datastore_directories('bar.test', bar_datastore_pk) if not res: print 'failed to clear bar.test datastore {} of directories'.format(bar_datastore_id) return False # activate foo.test res = activate_account('foo.test', foo_datastore_pk) if not res: print 'failed to start API for foo.test: {}'.format(res) return False # make *absolutely certain* that the test driver does not load data from # foo.test's or bar.test's storage directories. We want to verify that we can look up # the index manifest URLs from the profile target_datastore(None) # verify that bar's directories are gone res = check_datastore_directories_absent(bar_datastore_id, "bar.test") if not res: print 'failed to verify that bar.test datastore {} is devoid of directories'.format(bar_datastore_id) return False # root should be empty in both cases print 'listdir {} (bar.test)'.format('/') res = testlib.blockstack_cli_datastore_listdir( 'bar.test', bar_datastore_id, '/', data_pubkeys=get_data_pubkeys('bar.test')) if 'error' in res: print 'failed to listdir / on bar.test: {}'.format(res['error']) return False if len(res['children'].keys()) > 0: print 'root still has children: {}'.format(res['children'].keys()) return False # activate bar.test res = activate_account('bar.test', bar_datastore_pk) if not res: print 'failed to start API for foo.test: {}'.format(res) return False print 'listdir {} (foo.test)'.format('/') res = testlib.blockstack_cli_datastore_listdir( 'foo.test', foo_datastore_id, '/', data_pubkeys=get_data_pubkeys('foo.test')) if 'error' in res: print 'failed to listdir / on foo.test: {}'.format(res['error']) return False if len(res['children'].keys()) > 0: print 'root still has children: {}'.format(res['children'].keys()) return False testlib.next_block( **kw )
def scenario(wallets, **kw): start_subdomain_registrar() testlib.blockstack_namespace_preorder("id", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "id", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_ready("id", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_register_user("foo.id", wallets[2].privkey, wallets[3].privkey, **kw) # now, queue a registration. requests.post('http://localhost:3000/register', json={ 'zonefile': 'hello world', 'name': 'bar', 'owner_address': '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa' }) # force a batch out of the subdomain registrar requests.post('http://localhost:3000/issue_batch', headers={'Authorization': 'bearer tester129'}) for i in xrange(0, 12): testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to pickup first batch" time.sleep(10) # now, queue another registration requests.post('http://localhost:3000/register', json={ 'zonefile': 'hello world', 'name': 'zap', 'owner_address': '1Ez69SnzzmePmZX3WpEzMKTrcBF2gpNQ55' }) res = testlib.blockstack_REST_call('GET', '/v1/names/zap.foo.id', None) if 'error' in res: res['test'] = 'Failed to query zap.foo.id' print json.dumps(res) return False if res['http_status'] != 200: res['test'] = 'HTTP status {}, response = {} on name lookup'.format( res['http_status'], res['response']) print json.dumps(res) return False name_info = res['response'] try: if (name_info['zonefile'] != 'hello world' or name_info['address'] != '1Ez69SnzzmePmZX3WpEzMKTrcBF2gpNQ55'): res['test'] = 'Unexpected name info lookup for zap.foo.id' print 'zap.foo.id JSON:' print json.dumps(name_info) return False except: res['test'] = 'Unexpected name info lookup for zap.foo.id' print 'zap.foo.id JSON:' print json.dumps(name_info) return False SUBDOMAIN_PROC.kill()
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) # 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) # let's set the key to skip the transfer. config_dir = os.path.dirname(config_path) conf = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] res = testlib.blockstack_REST_call('PUT', '/v1/wallet/keys/owner', None, api_pass=api_pass, data=new_key) if res['http_status'] != 200 or 'error' in res: print 'failed to set owner key' print res return False # 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 ) # leaving the call format of this one the same to make sure that our registrar correctly # detects that the requested TRANSFER is superfluous # register the name bar.test res = testlib.blockstack_REST_call( 'POST', '/v1/names', None, api_pass=api_pass, data={ 'name': 'bar.test', 'zonefile': zonefile_txt, 'owner_address': new_addr }) 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, api_pass = api_pass ) 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, api_pass = api_pass ) 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, api_pass = api_pass ) if not res: print res print "update error in first update" return False for i in xrange(0, 4): 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(None, 'bar.test', 'transfer', None, api_pass = api_pass ) if res: print "Wrongly issued a TRANSFER" return False res = testlib.blockstack_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'] # 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", None, api_pass=api_pass ) 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()) != 3: 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), 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 # 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 # okay, now let's try to do a transfer. # FIRST, I want to change the key to a key that # doesn't own the name and a payment key that has no money res = testlib.blockstack_REST_call('PUT', '/v1/wallet/keys/owner', None, api_pass=api_pass, data=insanity_key) if res['http_status'] != 200 or 'error' in res: print 'failed to set owner key' print res return False res = testlib.blockstack_REST_call('PUT', '/v1/wallet/keys/payment', None, api_pass=api_pass, data=insanity_key) if res['http_status'] != 200 or 'error' in res: print 'failed to set owner key' print res return False payment_key = wallets[1].privkey # let's do this with the bad key res = testlib.blockstack_REST_call( 'PUT', '/v1/names/bar.test/owner', None, api_pass=api_pass, data={ 'owner': destination_owner, 'payment_key' : payment_key }) if 'error' in res or res['http_status'] != 202: res['test'] = '(Correctly) failed to transfer user' print json.dumps(res) # let's do this with the good one! res = testlib.blockstack_REST_call( 'PUT', '/v1/names/bar.test/owner', None, api_pass=api_pass, data={ 'owner': destination_owner, 'owner_key' : new_key, 'payment_key' : payment_key }) if 'error' in res or res['http_status'] != 202: res['test'] = '(Wrongly) failed to transfer user' print json.dumps(res) error = True return False else: print "Submitted transfer!" print res print 'Wait for transfer to be submitted' time.sleep(10) # wait to get confirmed for i in xrange(0, 6): testlib.next_block( **kw ) res = testlib.verify_in_queue(None, 'bar.test', 'transfer', None, api_pass = api_pass ) if not res: print "transfer error" print res return False for i in xrange(0, 4): testlib.next_block( **kw ) # wait for zonefile to propagate time.sleep(10) res = testlib.blockstack_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 cur_owner_address = res['response']['address'] if cur_owner_address != destination_owner: print "After transfer, unexpected owner. Expected {}, Actual {}".format( destination_owner, cur_owner_address) return False
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data, wallet_balance wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[0].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, wallet=wallets[3]) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr, wallet=wallets[3] ) testlib.next_block( **kw ) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[0].privkey ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) config_dir = os.path.dirname(config_path) conf = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] # make sure we can do REST calls res = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/pending', None, api_pass=api_pass ) if 'error' in res: res['test'] = 'Failed to get queues' print json.dumps(res) return False # make sure we can do REST calls with different app names and user names res = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/pending', None, api_pass=api_pass ) if 'error' in res: res['test'] = 'Failed to get queues' print json.dumps(res) return False # what's the balance? res = testlib.blockstack_REST_call('GET', '/v1/wallet/balance', None, api_pass=api_pass ) if res['http_status'] != 200: res['test'] = 'failed to query wallet' print json.dumps(res) return False wallet_balance = res['response']['balance']['satoshis'] balance_before = testlib.get_balance(wallets[3].addr) # can we move the funds? res = testlib.blockstack_REST_call('POST', '/v1/wallet/balance', None, api_pass=api_pass, data={'address': wallets[3].addr} ) if res['http_status'] != 200: res['test'] = 'failed to transfer funds' print json.dumps(res) return False if not res['response'].has_key('transaction_hash'): res['test'] = 'missing tx hash' print json.dumps(res) return False # confirm it for i in xrange(0, 10): testlib.next_block(**kw) new_balance = testlib.get_balance(wallets[5].addr) balance_after = testlib.get_balance(wallets[3].addr) if new_balance != 0: print 'new balance of {} is {}'.format(wallets[5].addr, new_balance) return False if abs(balance_before + wallet_balance - balance_after) > 10000: print "{} + {} !~= {}".format(balance_before, wallet_balance, balance_after) return False
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) # 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']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] # for funsies, get the price of .test res = testlib.blockstack_REST_call('GET', '/v1/prices/namespaces/test', ses ) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get price of .test' print json.dumps(res) return False test_price = res['response']['satoshis'] print '\n\n.test costed {} satoshis\n\n'.format(test_price) # get the price for bar.test res = testlib.blockstack_REST_call('GET', '/v1/prices/names/bar.test', ses ) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get price of bar.test' print json.dumps(res) return False bar_price = res['response']['total_estimated_cost']['satoshis'] print "\n\nbar.test will cost {} satoshis\n\n".format(bar_price) # register the name bar.test. autogenerate the rest res = testlib.blockstack_REST_call('POST', '/v1/names', ses, data={'name': 'bar.test'} ) 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 update 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'] old_expire_block = res['response']['expire_block'] # renew it res = testlib.blockstack_REST_call("POST", "/v1/names", ses, data={'name': 'bar.test'} ) if 'error' in res or res['http_status'] != 202: res['test'] = 'Failed to transfer 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(ses, 'bar.test', 'renew', None ) if not res: return False for i in xrange(0, 6): testlib.next_block( **kw ) # new expire block 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 new_expire_block = res['response']['expire_block'] # 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 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.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 # 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 scenario(wallets, **kw): testlib.blockstack_namespace_preorder("id", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "id", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_ready("id", wallets[1].privkey) testlib.next_block(**kw) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) config_dir = os.path.dirname(config_path) conf = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey) resp = testlib.blockstack_cli_register("foo.id", "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): 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, 12): testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge update" time.sleep(10) test_data = [{ 'hash': '34fdcde8b75440c5cb82480a14b4f3d731a67dc4', 'string': '$ORIGIN aaron.id\n$TTL 3600\n_http._tcp URI 10 1 "https://gaia.blockstack.org/hub/34bNQUVgyhSrA8XpM4HkerHUUdNmLpiyj7/0/profile.json"', 'decoded': None, 'b64': False }, { 'hash': 'd4fbae5d1f66f1ae0431e35bcd5a98782adc29ba', 'decoded': '$ORIGIN baron.id\n$TTL 3600\n_http._tcp URI 10 1 "https://gaia.blockstack.org/hub/34bNQUVgyhSrA8XpM4HkerHUUdNmLpiyj7/0/profile.json"', 'string': 'JE9SSUdJTiBiYXJvbi5pZAokVFRMIDM2MDAKX2h0dHAuX3RjcCBVUkkgMTAgMSAiaHR0cHM6Ly9nYWlhLmJsb2Nrc3RhY2sub3JnL2h1Yi8zNGJOUVVWZ3loU3JBOFhwTTRIa2VySFVVZE5tTHBpeWo3LzAvcHJvZmlsZS5qc29uIg==', 'b64': True }] for datum in test_data: post_data = {} if datum['b64']: key = 'zonefile_b64' else: key = 'zonefile' post_data[key] = datum['string'] zfhash = datum['hash'] res = testlib.blockstack_REST_call("PUT", "/v1/names/foo.id/zonefile", None, api_pass=api_pass, data={'zonefile_hash': zfhash}) if 'error' in res or res['http_status'] != 202: res['test'] = 'failed to update zonefile hash' print json.dumps(res) return False print >> sys.stderr, "Waiting 10 seconds for the backend to submit the register" time.sleep(10) # wait for update to get confirmed for i in xrange(0, 10): testlib.next_block(**kw) print 'Wait for second update to be confirmed' time.sleep(10) res = testlib.blockstack_REST_call("GET", "/v1/names/foo.id", None, api_pass=api_pass) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name foo.id' print json.dumps(res) return False # update set? if res['response']['zonefile_hash'] != zfhash: res['test'] = 'failed to set zonefile hash' print json.dumps(res) return False res = testlib.blockstack_REST_call("POST", "/v1/zonefile/", None, api_pass=api_pass, data=post_data) if 'error' in res or res['http_status'] != 200: res['test'] = 'failed to announce zonefile' print json.dumps(res) return False print 'Broadcasted zonefile' time.sleep(10) res = testlib.blockstack_REST_call("GET", "/v1/names/foo.id", None, api_pass=api_pass) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name foo.id' print json.dumps(res) return False if res['response']['zonefile'] != datum['string'] and \ res['response']['zonefile'] != datum['decoded']: res['test'] = 'failed to set zonefile string' print json.dumps(res) return False
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # 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 ) data_pk = wallets[-1].privkey data_pub = wallets[-1].pubkey_hex 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', 'revoke', 'zonefiles', 'blockchain', 'node_read']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] # register the name bar.test res = testlib.blockstack_REST_call('POST', '/v1/names', ses, data={'name': 'bar.test'}) 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, 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(ses, '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(ses, '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.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'] # present? res = testlib.blockstack_REST_call('GET', '/v1/names?page=0', ses ) if 'error' in res or res['http_status'] != 200: res['test'] = 'failed to list names' print json.dumps(res) return False names = res['response'] names.sort() if names != ['bar.test', 'foo.test']: res['test'] = 'invalid names response: got {}'.format(names) print json.dumps(res) return False # revoke it res = testlib.blockstack_REST_call("DELETE", "/v1/names/bar.test", ses ) if 'error' in res or res['http_status'] != 202: res['test'] = 'Failed to transfer name' print json.dumps(res) return False # verify in revoke queue for i in xrange(0, 6): testlib.next_block( **kw ) res = testlib.verify_in_queue(ses, 'bar.test', 'revoke', None ) if not res: return False for i in xrange(0, 4): testlib.next_block( **kw ) # poll res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test", ses ) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to query name' print json.dumps(res) error = True return False # revoked? if res['response']['status'] != 'revoked': res['test'] = 'name not revoked' 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 revoke history' res['history'] = hist print json.dumps(res, indent=4, sort_keys=True) return False # get the historic 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
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 for i in xrange(1, 4): name = 'foo{}.test'.format(i) # not preordered preorder = state_engine.get_name_preorder( name, virtualchain.make_payment_script(wallets[2].addr), wallets[3].addr) if preorder is not None: print 'still have preorder: {}'.format(preorder) return False # registered name_rec = state_engine.get_name(name) if name_rec is None: print 'did not get name {}'.format(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 address for {}: {}'.format(name, name_rec) return False res = testlib.blockstack_REST_call( "GET", "/v1/subdomains?page=0", 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 names = res['response'] found_names = [ x for x in ['bar.foo1.test', 'bar.foo2.test', 'bar.foo3.test'] if x in names ] if len(found_names) != 3: print names return False print names res = testlib.blockstack_REST_call( "GET", "/v1/blockchains/bitcoin/subdomains_count", 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 names_count = res['response']['names_count'] if names_count != 3: print names return False return True
def scenario(wallets, **kw): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) conf = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] # register the name bar.test. autogenerate the rest postage = { 'name': 'bar.test', 'owner_key': owner_key, 'payment_key': payment_key } res = testlib.blockstack_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, 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(None, '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(None, 'bar.test', 'update', None) if not res: return False for i in xrange(0, 6): testlib.next_block(**kw) print 'Wait for update to be confirmed' time.sleep(10) res = testlib.blockstack_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.blockstack_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, 6): testlib.next_block(**kw) # new expire block res = testlib.blockstack_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.blockstack_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.blockstack_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 scenario(wallets, **kw): testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo1.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_preorder("foo2.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_preorder("foo3.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) working_dir = testlib.get_working_dir(**kw) sub_zf_template = '$ORIGIN {}\n$TTL 3600\n_http._tcp URI 10 1 "http://www.foo.com"\n{}' zf_template = '$ORIGIN {}\n$TTL 3600\n_http._tcp URI 10 1 "http://www.foo.com"\n_resolver URI 10 1 "http://resolver.foo"\n{}' zf_default_url = '_file URI 10 1 "file://' + working_dir + '/{}"' zf_default_url_2 = '_file URI 20 1 "file://' + working_dir + '/{}"' subdomain_zonefiles = { 'bar.foo1.test': sub_zf_template.format('bar.foo1.test', zf_default_url.format('bar.foo1.test')), 'bar.foo2.test': sub_zf_template.format('bar.foo2.test', zf_default_url.format('bar.foo2.test')), 'bar.foo3.test': sub_zf_template.format('bar.foo3.test', zf_default_url.format('bar.foo3.test')), } zonefiles = { 'foo1.test': zf_template.format( 'foo1.test', subdomains.make_subdomain_txt('bar.foo1.test', 'foo1.test', wallets[4].addr, 0, subdomain_zonefiles['bar.foo1.test'], wallets[4].privkey)), 'foo2.test': zf_template.format( 'foo2.test', subdomains.make_subdomain_txt('bar.foo2.test', 'foo2.test', wallets[4].addr, 0, subdomain_zonefiles['bar.foo2.test'], wallets[4].privkey)), 'foo3.test': zf_template.format( 'foo3.test', subdomains.make_subdomain_txt('bar.foo3.test', 'foo3.test', wallets[4].addr, 0, subdomain_zonefiles['bar.foo3.test'], wallets[4].privkey)), } testlib.blockstack_name_register( "foo1.test", wallets[2].privkey, wallets[3].addr, zonefile_hash=storage.get_zonefile_data_hash(zonefiles['foo1.test'])) testlib.blockstack_name_register( "foo2.test", wallets[2].privkey, wallets[3].addr, zonefile_hash=storage.get_zonefile_data_hash(zonefiles['foo2.test'])) testlib.blockstack_name_register( "foo3.test", wallets[2].privkey, wallets[3].addr, zonefile_hash=storage.get_zonefile_data_hash(zonefiles['foo3.test'])) testlib.next_block(**kw) # sign and put profiles for subd in ['bar.foo1.test', 'bar.foo2.test', 'bar.foo3.test']: profile_data = { 'type': 'Person', 'name': subd, } profile_jwt = testlib.blockstack_make_profile(profile_data, wallets[4].privkey) path = os.path.join(working_dir, subd) with open(path, 'w') as f: f.write(profile_jwt) # whois for i in xrange(1, 4): name = 'foo{}.test'.format(i) res = testlib.blockstack_cli_whois(name) if 'error' in res: print res return False if not res.has_key('zonefile_hash') or res[ 'zonefile_hash'] != storage.get_zonefile_data_hash( zonefiles[name]): print res return False if res['owner_address'] != wallets[3].addr: print res return False # upload zonefile assert testlib.blockstack_put_zonefile(zonefiles[name]) subdomain_zonefiles_2 = { 'bar.foo1.test': zf_template.format('bar.foo1.test', zf_default_url_2.format('bar.foo1.test')), 'bar.foo2.test': zf_template.format('bar.foo2.test', zf_default_url_2.format('bar.foo2.test')), 'bar.foo3.test': zf_template.format('bar.foo3.test', zf_default_url_2.format('bar.foo3.test')), } zonefiles = { 'foo1.test': zf_template.format( 'foo1.test', subdomains.make_subdomain_txt('bar.foo1.test', 'foo1.test', wallets[4].addr, 1, subdomain_zonefiles['bar.foo1.test'], wallets[4].privkey)), 'foo2.test': zf_template.format( 'foo2.test', subdomains.make_subdomain_txt('bar.foo2.test', 'foo2.test', wallets[4].addr, 1, subdomain_zonefiles['bar.foo2.test'], wallets[4].privkey)), 'foo3.test': zf_template.format( 'foo3.test', subdomains.make_subdomain_txt('bar.foo3.test', 'foo3.test', wallets[4].addr, 1, subdomain_zonefiles['bar.foo3.test'], wallets[4].privkey)), } # update zone files testlib.blockstack_name_update( 'foo1.test', storage.get_zonefile_data_hash(zonefiles['foo1.test']), wallets[3].privkey) testlib.blockstack_name_update( 'foo2.test', storage.get_zonefile_data_hash(zonefiles['foo2.test']), wallets[3].privkey) testlib.blockstack_name_update( 'foo3.test', storage.get_zonefile_data_hash(zonefiles['foo3.test']), wallets[3].privkey) testlib.next_block(**kw) assert testlib.blockstack_put_zonefile(zonefiles['foo1.test']) assert testlib.blockstack_put_zonefile(zonefiles['foo2.test']) assert testlib.blockstack_put_zonefile(zonefiles['foo3.test']) # kick off subdomain indexing testlib.next_block(**kw) # start API daemon print 'starting API daemon' wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[0].privkey, wallets[1].privkey, wallets[2].privkey) # authenticate pk = keylib.ECPrivateKey(wallets[-1].privkey).to_hex() res = testlib.blockstack_cli_app_signin("foo.test", pk, 'register.app', [ 'names', 'register', 'prices', 'zonefiles', 'blockchain', 'node_read', 'user_read' ]) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] # query each subdomain proxy = testlib.make_proxy() # test 301 redirects. res = testlib.blockstack_REST_call('GET', '/v1/names/baz.foo1.test', ses, allow_redirects=False) if 'error' in res: res['test'] = 'Failed to query non-registered name.' print json.dumps(res) return False if res['http_status'] != 301: res['test'] = 'Failed to get a redirect.' print json.dumps(res) return False for i in xrange(1, 4): fqn = 'bar.foo{}.test'.format(i) # test REST whois res = testlib.blockstack_REST_call('GET', '/v1/names/{}'.format(fqn), ses) if 'error' in res: res['test'] = 'Failed to query name' print json.dumps(res) return False if res['http_status'] != 200 and res['http_status'] != 404: res['test'] = 'HTTP status {}, response = {} on name lookup'.format( res['http_status'], res['response']) print json.dumps(res) return False if res['response']['zonefile'] != subdomain_zonefiles[fqn]: print 'wrong zone file' print res print 'expected' print zonefiles['foo{}.test'.format(i)] return False if res['response']['status'] != 'registered_subdomain': print 'wrong status' print res return False # test CLI lookup res = testlib.blockstack_cli_lookup(fqn) if 'error' in res: print res return False print res if res['profile'] != {'type': 'Person', 'name': fqn}: print 'wrong profile' print res['profile'] return False # test REST lookup res = testlib.blockstack_REST_call("GET", "/v1/users/{}".format(fqn), ses) if 'error' in res: res['test'] = 'Failed to query name profile' print json.dumps(res) return False if res['http_status'] != 200 and res['http_status'] != 404: res['test'] = 'HTTP status {}, response = {} on name profile lookup'.format( res['http_status'], res['response']) print json.dumps(res) return False print res if res['response'] != {'type': 'Person', 'name': fqn}: print 'wrong profile on REST call' print res return False # test CLI lookup by address res = testlib.blockstack_cli_get_names_owned_by_address( wallets[4].addr) if 'error' in res: print 'failed to get subdomains owned by {}'.format( wallets[4].addr) print res return False if fqn not in res: print '{} not in list'.format(fqn) print res return False # test REST lookup by address res = testlib.blockstack_REST_call( 'GET', '/v1/addresses/bitcoin/{}'.format(wallets[4].addr), ses) if 'error' in res: res['test'] = 'Failed to query names owned by address' print json.dumps(res) return False if res['http_status'] != 200 and res['http_status'] != 404: res['test'] = 'HTTP status {}, response = {} on address lookup'.format( res['http_status'], res['response']) print json.dumps(res) return False if fqn not in res['response']['names']: print '{} not in REST list'.format(fqn) print res return False # test REST get name history res = testlib.blockstack_REST_call('GET', '/v1/names/{}/history'.format(fqn), ses) if 'error' in res: res['test'] = 'Failed to query subdomain history' print json.dumps(res) return False if res['http_status'] != 200 and res['http_status'] != 404: res['test'] = 'HTTP status {}, response = {} on subdomain history lookup'.format( res['http_status'], res['response']) print json.dumps(res) return False blocks = res['response'] if len(blocks.keys()) != 2: print 'expected two updates' print blocks return False # get each historic zone file for block_height in blocks: for prev_state in blocks[block_height]: value_hash = prev_state['value_hash'] res = testlib.blockstack_REST_call( 'GET', '/v1/names/{}/zonefile/{}'.format(fqn, value_hash), ses) if 'error' in res: print 'failed to query zone file {} for {}'.format( value_hash, fqn) print json.dumps(res) return False # reindex assert testlib.check_subdomain_db(**kw)
def scenario( wallets, **kw ): global put_result, wallet_keys, datasets, zonefile_hash, dataset_change wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, None ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) wallet_keys = wallet testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # migrate profile res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys, zonefile_has_data_key=False ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) return False else: zonefile_hash = res['zonefile_hash'] print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" testlib.next_block( **kw ) # should fail with no public key res = testlib.blockstack_cli_get_public_key("foo.test") if 'error' not in res: print 'accidentally succeeded to get public key for zone file without one' print res return False # verify this also fails for the RESTful API res = testlib.blockstack_REST_call('GET', '/v1/names/foo.test/public_key', None) if res['http_status'] == 200: print 'accidentally succeeded to get public key for zone file without one' print res return False if res['http_status'] != 404: print 'wrong status code: expected 404' print res return False wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) wallet_keys = wallet # migrate profile; add data key res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) return False else: zonefile_hash = res['zonefile_hash'] print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" testlib.next_block( **kw ) # should have a public key now res = testlib.blockstack_cli_get_public_key("foo.test") if 'error' in res: print 'no public key from zone file for foo.test' print res return False if res['public_key'] != keylib.key_formatting.decompress( keylib.ECPrivateKey(wallets[4].privkey).public_key().to_hex() ): print 'wrong public key' print res return False # verify this also succeeds for the RESTful API res = testlib.blockstack_REST_call('GET', '/v1/names/foo.test/public_key', None) if res['http_status'] != 200: print 'failed to get public key from RESTful API' print res return False if res['response']['public_key'] != keylib.key_formatting.decompress(keylib.ECPrivateKey(wallets[4].privkey).public_key().to_hex()): print 'wrong public key' print res return False # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw )
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data, wallet_balance wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) config_dir = os.path.dirname(config_path) conf = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] # make sure we can do REST calls res = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/pending', None, api_pass=api_pass ) if 'error' in res: res['test'] = 'Failed to get queues' print json.dumps(res) return False # make sure we can do REST calls with different app names and user names res = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/pending', None, api_pass=api_pass ) if 'error' in res: res['test'] = 'Failed to get queues' print json.dumps(res) return False # what's the balance? res = testlib.blockstack_REST_call('GET', '/v1/wallet/balance', None, api_pass=api_pass ) if res['http_status'] != 200: res['test'] = 'failed to query wallet' print json.dumps(res) return False wallet_balance = res['response']['balance']['satoshis'] balance_before = testlib.get_balance(wallets[8].addr) # can we move the funds? res = testlib.blockstack_REST_call('POST', '/v1/wallet/balance', None, api_pass=api_pass, data={'address': wallets[8].addr, 'amount': wallet_balance / 2, 'message': "hello world!"}) if res['http_status'] != 200: res['test'] = 'failed to transfer funds' print json.dumps(res) return False if not res['response'].has_key('transaction_hash'): res['test'] = 'missing tx hash' print json.dumps(res) return False print "\n\nTransaction: {}\n\n".format(res['response']['transaction_hash']) # confirm it for i in xrange(0, 12): testlib.next_block(**kw) new_balance = testlib.get_balance(wallets[5].addr) balance_after = testlib.get_balance(wallets[8].addr) print "wallet balance: {}".format(wallet_balance) print "new balance {}: {}".format(wallets[5].addr, new_balance) print "balance after {}: {}".format(wallets[8].addr, balance_after) print "balance before {}: {}".format(wallets[8].addr, balance_before) if new_balance > wallet_balance / 2: print 'new balance of {} is {}'.format(wallets[5].addr, new_balance) return False if abs(balance_after - balance_before) > abs(wallet_balance / 2) + 54500: print "{} - {} != {}".format(balance_after, balance_before, wallet_balance / 2) return False
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) # make a session datastore_pk = keylib.ECPrivateKey(wallets[-1].privkey).to_hex() res = testlib.blockstack_cli_app_signin(datastore_pk, 'register.app', ['names', 'register', 'prices', 'zonefiles', 'blockchain', 'node_read', 'store_admin', 'store_read', 'store_write']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] # make a datastore res = testlib.blockstack_REST_call('POST', '/v1/stores', ses ) if 'error' in res or res['http_status'] != 200: print 'failed to create datastore' print json.dumps(res, indent=4, sort_keys=True) return False # get the data store id res = testlib.blockstack_REST_call('GET', '/v1/stores/register.app', ses) if 'error' in res or res['http_status'] != 200: print 'failed to get store' print json.dumps(res, indent=4, sort_keys=True) return False if 'error' in res['response']: print 'failed to get datastore' print json.dumps(res, indent=4, sort_keys=True) return False datastore_info = res['response'] datastore_name = datastore_info['datastore_id'] # get the data store name res = testlib.blockstack_REST_call('GET', '/v1/stores/register.app', ses) if 'error' in res or res['http_status'] != 200: print 'failed to get datastore' print json.dumps(res, indent=4, sort_keys=True) return False if 'error' in res['response']: print 'failed to get datastore' print json.dumps(res, indent=4, sort_keys=True) return False datastore_info = res['response'] datastore_name = datastore_info['datastore_id'] # make directories for dpath in ['/dir1', '/dir2', '/dir1/dir3', '/dir1/dir3/dir4']: print 'mkdir {}'.format(dpath) res = testlib.blockstack_REST_call('POST', '/v1/stores/{}/directories'.format(datastore_name), ses, path=dpath) if 'error' in res or res['http_status'] != 200: print 'failed to mkdir {}: {}'.format(dpath, res['http_status']) return False # stat directories for dpath in ['/dir1', '/dir2', '/dir1/dir3', '/dir1/dir3/dir4']: print 'stat {}'.format(dpath) res = testlib.blockstack_REST_call('GET', '/v1/stores/{}/inodes'.format(datastore_name), ses, path=dpath) if 'error' in res or res['http_status'] != 200: print 'failed to stat {}: {}'.format(dpath, res['http_status']) return False inode_info = res['response'] if inode_info['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_REST_call('GET', '/v1/stores/{}/directories'.format(datastore_name), ses, path=dpath) if 'error' in res or res['http_status'] != 200: print 'failed to listdir {}: {}'.format(dpath, res['http_status']) return False dirinfo = res['response'] if len(dirinfo.keys()) != len(expected): print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format(expected, dirinfo) return False for child in expected: if not dirinfo.has_key(child): print 'invalid directory: missing {} in {}'.format(child, dirinfo) print json.dumps(res, indent=4, sort_keys=True) return False # put files for dpath in ['/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5']: print 'putfile {}'.format(dpath) data = 'hello {}'.format(os.path.basename(dpath)) res = testlib.blockstack_REST_call('POST', '/v1/stores/{}/files'.format(datastore_name), ses, raw_data=data, path=dpath) if 'error' in res or res['http_status'] != 200: print 'failed to putfile {}: {}'.format(dpath, res['http_status']) 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_REST_call('GET', '/v1/stores/{}/inodes'.format(datastore_name), ses, path=dpath) if 'error' in res or res['http_status'] != 200: print 'failed to stat {}: {}'.format(dpath, res['http_status']) return False inode_data = res['response'] if inode_data['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_REST_call('GET', '/v1/stores/{}/directories'.format(datastore_name), ses, path=dpath) if 'error' in res or res['http_status'] != 200: print 'failed to listdir {}: {}'.format(dpath, res['http_status']) return False dirinfo = res['response'] if len(dirinfo.keys()) != len(expected): print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format(expected, dirinfo) return False for child in expected: if not dirinfo.has_key(child): print 'invalid directory: missing {} in {}'.format(child, dirinfo) 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_REST_call('GET', '/v1/stores/{}/files'.format(datastore_name), ses, path=dpath) if 'error' in res or res['http_status'] != 200: print 'failed to getfile {}: {}'.format(dpath, res['http_status']) return False filedata = res['raw'] if filedata != 'hello {}'.format(os.path.basename(dpath)): print 'failed to read {}: got "{}"'.format(dpath, filedata) return False # delete datastore res = testlib.blockstack_REST_call("DELETE", "/v1/stores", ses) if res['http_status'] != 200: print 'failed to delete datastore' print json.dumps(res) return False # nothing should be here res = testlib.blockstack_REST_call('GET', '/v1/stores/{}/directories'.format(datastore_name), ses, path='/') if res['http_status'] != 404: print 'got HTTP {} on getting deleted store'.format(res['http_status']) print json.dumps(res) return False
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) # 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_write']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] # for funsies, get the price of .test res = testlib.blockstack_REST_call('GET', '/v1/prices/namespaces/test', ses) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get price of .test' print json.dumps(res) return False test_price = res['response']['satoshis'] print '\n\n.test costed {} satoshis\n\n'.format(test_price) # get the price for bar.test res = testlib.blockstack_REST_call('GET', '/v1/prices/names/bar.test', ses) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get price of bar.test' print json.dumps(res) return False bar_price = res['response']['total_estimated_cost']['satoshis'] print "\n\nbar.test will cost {} satoshis\n\n".format(bar_price) # let's set the key to skip the transfer. config_dir = os.path.dirname(config_path) conf = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] res = testlib.blockstack_REST_call('PUT', '/v1/wallet/keys/owner', None, api_pass=api_pass, data=new_key) if res['http_status'] != 200 or 'error' in res: print 'failed to set owner key' print res return False # 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 ) # leaving the call format of this one the same to make sure that our registrar correctly # detects that the requested TRANSFER is superfluous # register the name bar.test res = testlib.blockstack_REST_call('POST', '/v1/names', ses, data={'name': 'bar.test', 'zonefile': zonefile_txt, 'owner_address': new_addr }) 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 res: print "Wrongly issued a TRANSFER" 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()) != 3: 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 ### Now, we'll do it again, but this time, we're going to CHANGE THE KEY in the middle of registrations. ### to test the different paths, I'll start 3 registrations: # 1 has submitted preorder # 1 has submitted register # 1 has submitted update ### And then I'll issue a change-key # make zonefile for recipients zonefiles = [] for i in [1,2,3]: name = "tricky{}.test".format(i) driver_urls = blockstack_client.storage.make_mutable_data_urls(name, use_only=['dht', 'disk']) zonefile = blockstack_client.zonefile.make_empty_zonefile(name, wallets[4].pubkey_hex, urls=driver_urls) zonefiles.append(blockstack_zones.make_zone_file( zonefile, origin=name, ttl=3600 )) # leaving the call format of this one the same to make sure that our registrar correctly # detects that the requested TRANSFER is superfluous res = testlib.blockstack_REST_call( 'POST', '/v1/names', ses, data={'name':'tricky1.test', 'zonefile':zonefiles[0], 'owner_address':new_addr}) if 'error' in res: res['test'] = 'Failed to register tricky1.test' print json.dumps(res) error = True return False tx_hash = res['response']['transaction_hash'] # wait for preorder to get confirmed... for i in xrange(0, 6): testlib.next_block( **kw ) res = testlib.blockstack_REST_call( 'POST', '/v1/names', ses, data={'name':'tricky2.test', 'zonefile':zonefiles[1], 'owner_address':new_addr}) if 'error' in res: res['test'] = 'Failed to register tricky2.test' print json.dumps(res) error = True 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.blockstack_REST_call( 'POST', '/v1/names', ses, data={'name':'tricky3.test', 'zonefile':zonefiles[2], 'owner_address':new_addr}) if 'error' in res: res['test'] = 'Failed to register tricky3.test' print json.dumps(res) error = True return False for i in xrange(0, 6): testlib.next_block( **kw ) print 'Wait for update to be submitted' time.sleep(10) for i in xrange(0, 1): testlib.next_block( **kw ) res = testlib.verify_in_queue(ses, 'tricky1.test', 'update', None) res = testlib.verify_in_queue(ses, 'tricky2.test', 'register', None) res = testlib.verify_in_queue(ses, 'tricky3.test', 'preorder', None) # let's go crazy. res = testlib.blockstack_REST_call('PUT', '/v1/wallet/keys/owner', None, api_pass=api_pass, data=insanity_key) if res['http_status'] != 200 or 'error' in res: print 'failed to set owner key' print res return False # wait for preorder to get confirmed for i in xrange(0, 6): testlib.next_block( **kw ) # wake up registrar, submit register time.sleep(10) for i in xrange(0, 12): testlib.next_block( **kw ) # wake up registrar, submit update time.sleep(10) for i in xrange(0, 12): testlib.next_block( **kw ) # wake up registrar, propogate zonefile time.sleep(10)
def scenario(wallets, **kw): start_transaction_broadcaster() start_subdomain_registrar() testlib.blockstack_namespace_preorder("id", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "id", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_ready("id", wallets[1].privkey) testlib.next_block(**kw) wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey) resp = testlib.blockstack_name_preorder('foo.id', wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) zonefile = blockstack_client.zonefile.make_empty_zonefile('foo.id', None) zfdata = blockstack_zones.make_zone_file(zonefile) zfhash = blockstack.lib.storage.get_zonefile_data_hash(zfdata) resp = testlib.blockstack_name_register('foo.id', wallets[2].privkey, wallets[3].addr, zonefile_hash=zfhash) testlib.next_block(**kw) testlib.blockstack_put_zonefile(zfdata) # now, queue a subdomain registration. requests.post('http://localhost:3000/register', json={ 'zonefile': 'hello world', 'name': 'bar', 'owner_address': '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa' }) # force a batch out of the subdomain registrar requests.post('http://localhost:3000/issue_batch', headers={'Authorization': 'bearer tester129'}) for i in xrange(0, 12): testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to pickup first batch" time.sleep(10) # update the name on-chain testlib.blockstack_name_update('foo.id', '11' * 20, wallets[3].privkey) testlib.blockstack_name_update('foo.id', '22' * 20, wallets[3].privkey) testlib.blockstack_name_update('foo.id', '33' * 20, wallets[3].privkey) testlib.next_block(**kw) # now, queue another registration requests.post('http://localhost:3000/register', json={ 'zonefile': 'hello world', 'name': 'zap', 'owner_address': '1Ez69SnzzmePmZX3WpEzMKTrcBF2gpNQ55' }) res = testlib.blockstack_REST_call('GET', '/v1/names/zap.foo.id', None) if 'error' in res: res['test'] = 'Failed to query zap.foo.id' print json.dumps(res) return False if res['http_status'] != 200: res['test'] = 'HTTP status {}, response = {} on name lookup'.format( res['http_status'], res['response']) print json.dumps(res) return False name_info = res['response'] try: if (name_info['zonefile'] != 'hello world' or name_info['address'] != '1Ez69SnzzmePmZX3WpEzMKTrcBF2gpNQ55'): res['test'] = 'Unexpected name info lookup for zap.foo.id' print 'zap.foo.id JSON:' print json.dumps(name_info) return False except: res['test'] = 'Unexpected name info lookup for zap.foo.id' print 'zap.foo.id JSON:' print json.dumps(name_info) return False # update the name on-chain again, but lots of times for i in range(0, 20): zonefile_pattern = '{:x}{:x}'.format(i / 16, i % 16) testlib.blockstack_name_update('foo.id', zonefile_pattern * 20, wallets[3].privkey) testlib.next_block(**kw) # should fail--we have too many prior zone files res = testlib.blockstack_REST_call('GET', '/v1/names/zap.foo.id', None) if res['http_status'] != 404: res['test'] = 'HTTP status {}, response = {} on name lookup'.format( res['http_status'], res['response']) print json.dumps(res) return False
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) # 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) # 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_write']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] # my own KEYS owner_key = new_key config_dir = os.path.dirname(config_path) conf = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] payment_key = wallets[1].privkey payer = wallets[1].addr # 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 ) postage = {'name': 'bar.test', 'zonefile': zonefile_txt, 'owner_address': new_addr, 'payment_key' : payment_key, 'owner_key' : owner_key} # leaving the call format of this one the same to make sure that our registrar correctly # detects that the requested TRANSFER is superfluous # register the name bar.test res = testlib.blockstack_REST_call('POST', '/v1/names', ses, 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(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 res: print "Wrongly issued a TRANSFER" 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()) != 3: 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 ### Now, we'll do it again, but this time, we're going to CHANGE THE KEY in the middle of registrations. ### to test the different paths, I'll start 3 registrations: # 1 has submitted preorder # 1 has submitted register # 1 has submitted update ### And then I'll issue a change-key # make zonefile for recipients zonefiles = [] postages = [] for i in [1,2,3]: name = "tricky{}.test".format(i) driver_urls = blockstack_client.storage.make_mutable_data_urls(name, use_only=['dht', 'disk']) zonefile = blockstack_client.zonefile.make_empty_zonefile(name, wallets[4].pubkey_hex, urls=driver_urls) zf_txt = blockstack_zones.make_zone_file( zonefile, origin=name, ttl=3600 ) zonefiles.append(zf_txt) postages.append( {'name': name, 'zonefile' : zf_txt, 'owner_address': new_addr, 'payment_key' : payment_key, 'owner_key' : owner_key}) res = testlib.blockstack_REST_call('POST', '/v1/names', ses, data=postages[0]) if 'error' in res: res['test'] = 'Failed to register tricky1.test' print json.dumps(res) error = True return False tx_hash = res['response']['transaction_hash'] # wait for preorder to get confirmed... for i in xrange(0, 6): testlib.next_block( **kw ) res = testlib.blockstack_REST_call('POST', '/v1/names', ses, data=postages[1]) if 'error' in res: res['test'] = 'Failed to register tricky2.test' print json.dumps(res) error = True 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.blockstack_REST_call('POST', '/v1/names', ses, data=postages[2]) if 'error' in res: res['test'] = 'Failed to register tricky3.test' print json.dumps(res) error = True return False for i in xrange(0, 6): testlib.next_block( **kw ) print 'Wait for update to be submitted' time.sleep(10) for i in xrange(0, 1): testlib.next_block( **kw ) res = testlib.verify_in_queue(ses, 'tricky1.test', 'update', None) res = testlib.verify_in_queue(ses, 'tricky2.test', 'register', None) res = testlib.verify_in_queue(ses, 'tricky3.test', 'preorder', None) # let's go crazy. res = testlib.blockstack_REST_call('PUT', '/v1/wallet/keys/owner', None, api_pass=api_pass, data=insanity_key) res = testlib.blockstack_REST_call('PUT', '/v1/wallet/keys/payment', None, api_pass=api_pass, data=insanity_key) if res['http_status'] != 200 or 'error' in res: print 'failed to set owner key' print res return False # wait for preorder to get confirmed for i in xrange(0, 6): testlib.next_block( **kw ) # wake up registrar, submit register time.sleep(10) for i in xrange(0, 12): testlib.next_block( **kw ) # wake up registrar, submit update time.sleep(10) for i in xrange(0, 12): testlib.next_block( **kw ) # wake up registrar, propogate zonefile time.sleep(10)
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[3].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) # migrate profiles, but no data key in the zone file res = testlib.migrate_profile("foo.test", zonefile_has_data_key=False, proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) # 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', 'user_read' ]) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] # register the name bar.test. autogenerate the rest old_user_zonefile = blockstack_client.zonefile.make_empty_zonefile( 'bar.test', None) old_user_zonefile_txt = blockstack_zones.make_zone_file(old_user_zonefile) res = testlib.blockstack_REST_call('POST', '/v1/names', ses, data={ 'name': 'bar.test', 'zonefile': old_user_zonefile_txt, 'make_profile': True }) 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, 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/update 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, 3): testlib.next_block(**kw) # should have nine confirmations now res = testlib.get_queue(ses, 'register') if 'error' in res: print res return False if len(res) != 1: print res return False reg = res[0] confs = blockstack_client.get_tx_confirmations(reg['tx_hash']) if confs != 9: print 'wrong number of confs for {} (expected 9): {}'.format( reg['tx_hash'], confs) return False # stop the API server testlib.stop_api() # advance blockchain testlib.next_block(**kw) testlib.next_block(**kw) confs = blockstack_client.get_tx_confirmations(reg['tx_hash']) if confs != 11: print 'wrong number of confs for {} (expected 11): {}'.format( reg['tx_hash'], confs) return False # make sure the registrar does not process reg/up zonefile replication # (i.e. we want to make sure that the zonefile gets processed even if the blockchain goes too fast) os.environ[ 'BLOCKSTACK_TEST_REGISTRAR_FAULT_INJECTION_SKIP_REGUP_REPLICATION'] = '1' testlib.start_api("0123456789abcdef") print 'Wait to verify that we do not remove the zone file just because the tx is confirmed' time.sleep(10) # verify that this is still in the queue res = testlib.get_queue(ses, 'register') if 'error' in res: print res return False if len(res) != 1: print res return False # clear the fault print 'Clearing regup replication fault' testlib.blockstack_test_setenv( "BLOCKSTACK_TEST_REGISTRAR_FAULT_INJECTION_SKIP_REGUP_REPLICATION", "0") # wait for register to go through print 'Wait for zonefile to replicate' 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 old_expire_block = res['response']['expire_block'] # get the zonefile res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test/zonefile", ses) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name zonefile' print json.dumps(res) return False # zonefile must not have a public key listed zonefile_txt = res['response']['zonefile'] print zonefile_txt parsed_zonefile = blockstack_zones.parse_zone_file(zonefile_txt) if parsed_zonefile.has_key('txt'): print 'have txt records' print parsed_zonefile return False # renew it, but put the *current* owner key as the zonefile's *new* public key new_user_zonefile = blockstack_client.zonefile.make_empty_zonefile( 'bar.test', wallets[3].pubkey_hex) new_user_zonefile_txt = blockstack_zones.make_zone_file(new_user_zonefile) res = testlib.blockstack_REST_call("POST", "/v1/names", ses, data={ 'name': 'bar.test', 'zonefile': new_user_zonefile_txt }) 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(ses, 'bar.test', 'renew', None) if not res: return False for i in xrange(0, 3): testlib.next_block(**kw) # should have nine confirmations now res = testlib.get_queue(ses, 'renew') if 'error' in res: print res return False if len(res) != 1: print res return False reg = res[0] confs = blockstack_client.get_tx_confirmations(reg['tx_hash']) if confs != 9: print 'wrong number of confs for {} (expected 9): {}'.format( reg['tx_hash'], confs) return False # stop the API server testlib.stop_api() # advance blockchain testlib.next_block(**kw) testlib.next_block(**kw) confs = blockstack_client.get_tx_confirmations(reg['tx_hash']) if confs != 11: print 'wrong number of confs for {} (expected 11): {}'.format( reg['tx_hash'], confs) return False # make the registrar skip the first few steps, so the only thing it does is clear out confirmed updates # (i.e. we want to make sure that the renewal's zonefile gets processed even if the blockchain goes too fast) os.environ[ 'BLOCKSTACK_TEST_REGISTRAR_FAULT_INJECTION_SKIP_RENEWAL_REPLICATION'] = '1' testlib.start_api("0123456789abcdef") # wait a while print 'Wait to verify that clearing out confirmed transactions does NOT remove zonefiles' time.sleep(10) # verify that this is still in the queue res = testlib.get_queue(ses, 'renew') if 'error' in res: print res return False if len(res) != 1: print res return False # clear the fault print 'Clearing renewal replication fault' testlib.blockstack_test_setenv( "BLOCKSTACK_TEST_REGISTRAR_FAULT_INJECTION_SKIP_RENEWAL_REPLICATION", "0") # now the renewal zonefile should replicate print 'Wait for renewal zonefile to replicate' time.sleep(10) # new expire block 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 new_expire_block = res['response']['expire_block'] # 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 bar.test" print json.dumps(res) return False # valid history? hist = res['response'] if len(hist.keys()) != 3: 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", ses) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name zonefile' print json.dumps(res) return False # zonefile must have old owner key zonefile_txt = res['response']['zonefile'] parsed_zonefile = blockstack_zones.parse_zone_file(zonefile_txt) if not parsed_zonefile.has_key('txt'): print 'missing txt' print parsed_zonefile return False found = False for txtrec in parsed_zonefile['txt']: if txtrec['name'] == 'pubkey' and txtrec[ 'txt'] == 'pubkey:data:{}'.format(wallets[3].pubkey_hex): found = True if not found: print 'missing public key {}'.format(wallets[3].pubkey_hex) return False # profile lookup must work res = testlib.blockstack_REST_call("GET", "/v1/users/bar.test", ses) if 'error' in res or res['http_status'] != 200: res['text'] = 'failed to get profile for bar.test' print json.dumps(res) return False print '' print json.dumps(res['response'], indent=4, sort_keys=True) print '' # verify pushed back if old_expire_block + 10 > 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 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
def scenario(wallets, **kw): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) # migrate profiles res = testlib.migrate_profile("foo.test", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) # 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' ]) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] # for funsies, get the price of .test res = testlib.blockstack_REST_call('GET', '/v1/prices/namespaces/test', ses) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get price of .test' print json.dumps(res) return False test_price = res['response']['satoshis'] print '\n\n.test costed {} satoshis\n\n'.format(test_price) # get the price for bar.test res = testlib.blockstack_REST_call('GET', '/v1/prices/names/bar.test', ses) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get price of bar.test' print json.dumps(res) return False bar_price = res['response']['total_estimated_cost']['satoshis'] print "\n\nbar.test will cost {} satoshis\n\n".format(bar_price) # 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 res = testlib.blockstack_REST_call('POST', '/v1/names', ses, data={ 'name': 'bar.test', 'zonefile': zonefile_txt, 'owner_address': wallets[4].addr }) 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, 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(ses, '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(ses, 'bar.test', 'update', None) if not res: return False for i in xrange(0, 4): 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, 4): 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
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) config_dir = os.path.dirname(config_path) conf = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] # make sure we can do REST calls res = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/pending', None, api_pass=api_pass ) if 'error' in res: res['test'] = 'Failed to get queues' print json.dumps(res) return False # make sure we can do REST calls with different app names and user names res = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/pending', None, api_pass=api_pass ) if 'error' in res: res['test'] = 'Failed to get queues' print json.dumps(res) return False # can we even get to the wallet? res = testlib.blockstack_REST_call('POST', '/v1/wallet/balance', None, api_pass=api_pass, data={'address': wallets[4].addr, 'amount': 100000} ) if res['http_status'] != 200: res['test'] = 'failed to transfer funds' # make zonefile for recipient driver_urls = blockstack_client.storage.make_mutable_data_urls('foo.test', use_only=['dht', 'disk']) zonefile = blockstack_client.zonefile.make_empty_zonefile('foo.test', wallets[4].pubkey_hex, urls=driver_urls) zonefile_txt = blockstack_zones.make_zone_file( zonefile, origin='foo.test', ttl=3600 ) # register the name bar.test, with min 3 confirmations on its UTXOs data = { 'name': 'bar.test', 'zonefile': zonefile_txt, 'owner_address': wallets[4].addr, 'min_confs': 3 } # should fail res = testlib.blockstack_REST_call('POST', '/v1/names', None, api_pass=api_pass, data=data) if res['http_status'] == 200: res['test'] = 'succeeded in sending bar.test' print json.dumps(res) error = True return False # wait for confirmations for i in xrange(0, 3): testlib.next_block( **kw ) # should succeed res = testlib.blockstack_REST_call('POST', '/v1/names', None, api_pass=api_pass, data=data) if 'error' in res or 'error' in res['response']: res['test'] = 'failed to send bar.test' print json.dumps(res) error = True return False # wait for update to get confirmed for i in xrange(0, 48): if i % 12 == 0: print "waiting for RPC daemon to catch up" time.sleep(10) testlib.next_block( **kw ) res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test", None, api_pass=api_pass) if 'error' in res: res['test'] = 'Failed to query name' print json.dumps(res) error = True return False if res['http_status'] != 200: res['test'] = 'HTTP status {}, response = {}'.format(res['http_status'], res['response']) print json.dumps(res) error = True return False # should now be registered if res['response']['status'] != 'registered': print "register not complete" print json.dumps(res) return False
def scenario(wallets, **kw): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data empty_key = ECPrivateKey().to_hex() wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", empty_key, empty_key, empty_key) 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) # 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 = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] payment_key = wallets[1].privkey # 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) no_key_postage = {'name': 'bar.test', 'zonefile': zonefile_txt} key_postage = dict(no_key_postage) key_postage['payment_key'] = payment_key key_postage['owner_key'] = new_key res = testlib.blockstack_REST_call('POST', '/v1/names', None, api_pass=api_pass, data=no_key_postage) if 'error' not in res['response']: print "Successfully registered user with should-have-been-bad keys" print res return False # let's do a small withdraw res = testlib.blockstack_REST_call( 'POST', '/v1/wallet/balance', None, api_pass=api_pass, data={ 'address': virtualchain.get_privkey_address(empty_key), 'amount': int(1e4), 'payment_key': payment_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.blockstack_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 if int(res['response']['balance']['satoshis']) <= 0: res['test'] = 'Wallet balance did not increment!' print json.dumps(res) error = True return False res = testlib.blockstack_REST_call('POST', '/v1/names', None, api_pass=api_pass, data=key_postage) if 'error' in res['response']: res['test'] = 'Failed to register user' print json.dumps(res) error = True return False print "Registering bar.test" for i in xrange(0, 6): testlib.next_block(**kw) 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(None, 'bar.test', 'register', None, api_pass=api_pass) 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(None, 'bar.test', 'update', None, api_pass=api_pass) if not res: print res print "update error in first update" return False for i in xrange(0, 6): testlib.next_block(**kw) res = testlib.blockstack_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'] # 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", None, api_pass=api_pass) 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()) != 3: 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), 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 # 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 # okay, now let's try to do an update. # make zonefile for recipient driver_urls = blockstack_client.storage.make_mutable_data_urls( 'bar.test', use_only=['http', 'disk']) zonefile = blockstack_client.zonefile.make_empty_zonefile( 'bar.test', wallets[3].pubkey_hex, urls=driver_urls) zonefile_txt = blockstack_zones.make_zone_file(zonefile, origin='bar.test', ttl=3600) # let's do this update. res = testlib.blockstack_REST_call('PUT', '/v1/names/bar.test/zonefile', None, api_pass=api_pass, data={ 'zonefile': zonefile_txt, 'owner_key': new_key, 'payment_key': payment_key }) if 'error' in res or res['http_status'] != 202: res['test'] = 'Failed to register user' print json.dumps(res) error = True return False else: print "Submitted update!" print res 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, api_pass=api_pass) if not res: print "update error in second update" print res return False for i in xrange(0, 6): testlib.next_block(**kw) # wait for zonefile to propagate time.sleep(10) res = testlib.blockstack_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'] # get the zonefile res = testlib.blockstack_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 # 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
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) wallet_keys_2 = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[9].privkey, wallets[7].privkey, wallets[8].privkey ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.blockstack_name_preorder( "bar.test", wallets[6].privkey, wallets[7].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.blockstack_name_register( "bar.test", wallets[6].privkey, wallets[7].addr ) testlib.next_block( **kw ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return res = testlib.migrate_profile( "bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2 ) if 'error' in res: res['test'] = 'Failed to initialize bar.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False data_pk = wallets[-1].privkey data_pub = wallets[-1].pubkey_hex config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) # make an index file index_file_path = "/tmp/name_preorder_register_update_app_auth.foo.test.index.html" with open(index_file_path, "w") as f: f.write(index_file_data) testlib.blockstack_client_set_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # register an application under foo.test res = testlib.blockstack_cli_app_publish("foo.test", "ping.app", "node_read", index_file_path, password="******" ) if 'error' in res: res['test'] = 'Failed to register foo.test/bar app' print json.dumps(res, indent=4, sort_keys=True) error = True return # activate bar.test testlib.blockstack_client_set_wallet( "0123456789abcdef", wallets[9].privkey, wallets[7].privkey, wallets[8].privkey ) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # sign in pk = 'ce100586279d3b127b7dcc137fcc2f18b272bb2b43bdaea3584d0ea17087ec0201' pubk = keylib.ECPrivateKey(pk).public_key().to_hex() res = testlib.blockstack_cli_app_signin("foo.test", pk, "ping.app", ["node_read"]) if 'error' in res: res['test'] = 'Failed to signin: {}'.format(res['error']) print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] res = testlib.blockstack_REST_call("GET", "/v1/ping", ses) if res['http_status'] != 200: print "failed to GET /api/v1/ping" print json.dumps(res, indent=4, sort_keys=True) error = True return False if res['response']['status'] != 'alive': print "failed to GET /api/v1/ping" print json.dumps(res, indent=4, sort_keys=True) error = True return False # access index.html res = testlib.blockstack_REST_call("GET", "/v1/resources/foo.test/ping.app?name=index.html&pubkey={}".format(wallets[4].pubkey_hex), ses) if 'error' in res or res['http_status'] != 200: print 'failed to GET /v1/resources?name=/index.html' print json.dumps(res) error = True return False if res['raw'] != index_file_data: print 'expected {}\ngot {}\n'.format(index_file_data, res['raw']) print json.dumps(res) error = True return False testlib.next_block( **kw )
def scenario(wallets, **kw): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data, wallet_balance wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[3].privkey, wallets[5].addr) testlib.next_block(**kw) register_resp = testlib.blockstack_name_register("foo.test", wallets[3].privkey, wallets[5].addr) testlib.next_block(**kw) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) config_dir = os.path.dirname(config_path) conf = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] # get utxos for the payer payer_utxos = testlib.blockstack_REST_call( 'GET', '/v1/blockchains/bitcoin/{}/unspent?min_confirmations=1'.format( wallets[3].addr), None, api_pass=api_pass) if 'error' in payer_utxos: payer_utxos['test'] = 'failed to get utxos' print json.dumps(payer_utxos) return False # have both the test wallet output and the one the NAME_REGISTRATION sent if len(payer_utxos['response']) != 1: payer_utxos['test'] = 'wrong utxos' print json.dumps(payer_utxos) return False # last transaction should be the register, and it should have been paid with the owner address (since that's how we sent it above) if payer_utxos['response'][0]['transaction_hash'] != register_resp[ 'transaction_hash'] or payer_utxos['response'][0][ 'confirmations'] != 1: payer_utxos['test'] = 'invalid utxos (tx_hash, confirmations)' print json.dumps(payer_utxos) return False # get utxos for the owner wallet owner_utxos = testlib.blockstack_REST_call( 'GET', '/v1/blockchains/bitcoin/{}/unspent?min_confirmations=1'.format( wallets[5].addr), None, api_pass=api_pass) if 'error' in owner_utxos: owner_utxos['test'] = 'failed to get utxos' print json.dumps(owner_utxos) return False # two utxos: one for the initial wallet fill-up from the test framework, and one from the registration if len(owner_utxos['response']) != 2: owner_utxos['test'] = 'wrong utxos' print json.dumps(owner_utxos) return False # last transaction should be the register found = False for utxo in owner_utxos['response']: if utxo['transaction_hash'] == register_resp[ 'transaction_hash'] and utxo['confirmations'] == 1: found = True if not found: owner_utxos['test'] = 'invalid utxos (tx_hash, confirmations)' print json.dumps(owner_utxos) return False # verify that min_confirmations=2 hides these transactions res = testlib.blockstack_REST_call( 'GET', '/v1/blockchains/bitcoin/{}/unspent?min_confirmations=2'.format( wallets[5].addr), None, api_pass=api_pass) if 'error' in res: res['test'] = 'failed to get utxos' print json.dumps(res) return False if len(res['response']) > 1: res['test'] = 'got more UTXOs than we expected' print json.dumps(res) return False # count UTXOs in wallets[1] res = testlib.blockstack_REST_call( 'GET', '/v1/blockchains/bitcoin/{}/unspent?min_confirmations=0'.format( wallets[1].addr), None, api_pass=api_pass) if 'error' in res: res['test'] = 'failed to get utxos' print json.dumps(res) return False initial_utxos = res['response'] if len(initial_utxos) == 0: res['test'] = 'test bug: no UTXOs for wallet' print json.dumps(res) return False # send money from one wallet to another fund_tx = testlib.send_funds_tx(wallets[0].privkey, 10**8, wallets[1].addr) res = testlib.blockstack_REST_call('POST', '/v1/blockchains/bitcoin/txs', None, data={'tx': fund_tx}, api_pass=api_pass) if 'error' in res: res['test'] = 'failed to send {}'.format(fund_tx) print json.dumps(res) return False if not res['response'].has_key('transaction_hash'): res['test'] = 'response is missing transaction hash' print json.dumps(res) return False # verify that it's in the UTXO set with min_confirmations=0 res = testlib.blockstack_REST_call( 'GET', '/v1/blockchains/bitcoin/{}/unspent?min_confirmations=0'.format( wallets[1].addr), None, api_pass=api_pass) if 'error' in res: res['test'] = 'failed to get utxos' print json.dumps(res) return False if len(res['response']) != len(initial_utxos) + 1: res['test'] = 'missing UTXO' print json.dumps(res) return False current_utxos = res['response'] # verify that with min_confirmations=1, we have what we started with res = testlib.blockstack_REST_call( 'GET', '/v1/blockchains/bitcoin/{}/unspent?min_confirmations=1'.format( wallets[1].addr), None, api_pass=api_pass) if 'error' in res: res['test'] = 'failed to get utxos' print json.dumps(res) return False if res['response'] != initial_utxos: res['test'] = 'initial utxos do not match current utxos' print json.dumps(res) print json.dumps(initial_utxos) return False # confirm everything for i in xrange(0, 10): testlib.next_block(**kw) # verify that we have what we started with res = testlib.blockstack_REST_call( 'GET', '/v1/blockchains/bitcoin/{}/unspent'.format(wallets[1].addr), None, api_pass=api_pass) if 'error' in res: res['test'] = 'failed to get utxos' print json.dumps(res) return False current_utxos_no_confirmation = [ dict([(k, v) for ( k, v) in filter(lambda (x, y): x != 'confirmations', utxo.items()) ]) for utxo in current_utxos ]
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data, wallet_balance wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[3].privkey, wallets[5].addr ) testlib.next_block( **kw ) register_resp = testlib.blockstack_name_register( "foo.test", wallets[3].privkey, wallets[5].addr ) testlib.next_block( **kw ) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) config_dir = os.path.dirname(config_path) conf = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] # get utxos for the payer payer_utxos = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/{}/unspent?min_confirmations=1'.format(wallets[3].addr), None, api_pass=api_pass) if 'error' in payer_utxos: payer_utxos['test'] = 'failed to get utxos' print json.dumps(payer_utxos) return False # have both the test wallet output and the one the NAME_REGISTRATION sent if len(payer_utxos['response']) != 1: payer_utxos['test'] = 'wrong utxos' print json.dumps(payer_utxos) return False # last transaction should be the register, and it should have been paid with the owner address (since that's how we sent it above) if payer_utxos['response'][0]['transaction_hash'] != register_resp['transaction_hash'] or payer_utxos['response'][0]['confirmations'] != 1: payer_utxos['test'] = 'invalid utxos (tx_hash, confirmations)' print json.dumps(payer_utxos) return False # get utxos for the owner wallet owner_utxos = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/{}/unspent?min_confirmations=1'.format(wallets[5].addr), None, api_pass=api_pass) if 'error' in owner_utxos: owner_utxos['test'] = 'failed to get utxos' print json.dumps(owner_utxos) return False # two utxos: one for the initial wallet fill-up from the test framework, and one from the registration if len(owner_utxos['response']) != 2: owner_utxos['test'] = 'wrong utxos' print json.dumps(owner_utxos) return False # last transaction should be the register found = False for utxo in owner_utxos['response']: if utxo['transaction_hash'] == register_resp['transaction_hash'] and utxo['confirmations'] == 1: found = True if not found: owner_utxos['test'] = 'invalid utxos (tx_hash, confirmations)' print json.dumps(owner_utxos) return False # verify that min_confirmations=2 hides these transactions res = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/{}/unspent?min_confirmations=2'.format(wallets[5].addr), None, api_pass=api_pass) if 'error' in res: res['test'] = 'failed to get utxos' print json.dumps(res) return False if len(res['response']) > 1: res['test'] = 'got more UTXOs than we expected' print json.dumps(res) return False # count UTXOs in wallets[1] res = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/{}/unspent?min_confirmations=0'.format(wallets[1].addr), None, api_pass=api_pass) if 'error' in res: res['test'] = 'failed to get utxos' print json.dumps(res) return False initial_utxos = res['response'] if len(initial_utxos) == 0: res['test'] = 'test bug: no UTXOs for wallet' print json.dumps(res) return False # send money from one wallet to another fund_tx = testlib.send_funds_tx(wallets[0].privkey, 10**8, wallets[1].addr) res = testlib.blockstack_REST_call('POST', '/v1/blockchains/bitcoin/txs', None, data={'tx': fund_tx}, api_pass=api_pass) if 'error' in res: res['test'] = 'failed to send {}'.format(fund_tx) print json.dumps(res) return False if not res['response'].has_key('transaction_hash'): res['test'] = 'response is missing transaction hash' print json.dumps(res) return False # verify that it's in the UTXO set with min_confirmations=0 res = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/{}/unspent?min_confirmations=0'.format(wallets[1].addr), None, api_pass=api_pass) if 'error' in res: res['test'] = 'failed to get utxos' print json.dumps(res) return False if len(res['response']) != len(initial_utxos) + 1: res['test'] = 'missing UTXO' print json.dumps(res) return False current_utxos = res['response'] # verify that with min_confirmations=1, we have what we started with res = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/{}/unspent?min_confirmations=1'.format(wallets[1].addr), None, api_pass=api_pass) if 'error' in res: res['test'] = 'failed to get utxos' print json.dumps(res) return False if res['response'] != initial_utxos: res['test'] = 'initial utxos do not match current utxos' print json.dumps(res) print json.dumps(initial_utxos) return False # confirm everything for i in xrange(0, 10): testlib.next_block(**kw) # verify that we have what we started with res = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/{}/unspent'.format(wallets[1].addr), None, api_pass=api_pass) if 'error' in res: res['test'] = 'failed to get utxos' print json.dumps(res) return False current_utxos_no_confirmation = [dict([(k, v) for (k, v) in filter(lambda (x, y): x != 'confirmations', utxo.items())]) for utxo in current_utxos]
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) # 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_write']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] # let's set the key to skip the transfer. config_dir = os.path.dirname(config_path) conf = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] new_payment_key = { 'private_key' : wallets[1].privkey, 'persist_change' : True } res = testlib.blockstack_REST_call('PUT', '/v1/wallet/keys/payment', None, api_pass=api_pass, data=new_payment_key) if res['http_status'] != 200 or 'error' in res: print 'failed to set payment key' print res return False testlib.stop_api() testlib.start_api('0123456789abcdef') res = testlib.blockstack_REST_call('GET', '/v1/wallet/payment_address', None, api_pass = api_pass) if res['http_status'] != 200 or 'error' in res: res['test'] = 'Failed to get payment address' print res return False if res['response']['address'] != wallets[1].addr: res['test'] = 'Got wrong payer address, expected {}, got {}'.format( wallets[1].addr, res['response']['address']) print res return False res = testlib.blockstack_REST_call('PUT', '/v1/wallet/keys/owner', None, api_pass=api_pass, data=new_key) if res['http_status'] != 200 or 'error' in res: print 'failed to set owner key' print res return False # 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 ) # leaving the call format of this one the same to make sure that our registrar correctly # detects that the requested TRANSFER is superfluous # register the name bar.test res = testlib.blockstack_REST_call('POST', '/v1/names', ses, data={'name': 'bar.test', 'zonefile': zonefile_txt, 'owner_address': new_addr }) 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, 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(ses, '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(ses, 'bar.test', 'update', None ) if not res: return False for i in xrange(0, 4): 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 res: print res print "Wrongly issued a TRANSFER" return False for i in xrange(0, 4): 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()) != 3: 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
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[3].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 ) # migrate profiles, but no data key in the zone file res = testlib.migrate_profile( "foo.test", zonefile_has_data_key=False, proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) # 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', 'user_read']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] # register the name bar.test. autogenerate the rest old_user_zonefile = blockstack_client.zonefile.make_empty_zonefile('bar.test', None) old_user_zonefile_txt = blockstack_zones.make_zone_file(old_user_zonefile) res = testlib.blockstack_REST_call('POST', '/v1/names', ses, data={'name': 'bar.test', 'zonefile': old_user_zonefile_txt, 'make_profile': True} ) 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, 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/update 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, 4): testlib.next_block( **kw ) # wait for register to go through print 'Wait for zonefile to replicate' 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 old_expire_block = res['response']['expire_block'] # get the zonefile res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test/zonefile", ses ) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name zonefile' print json.dumps(res) return False # zonefile must not have a public key listed zonefile_txt = res['response']['zonefile'] print zonefile_txt parsed_zonefile = blockstack_zones.parse_zone_file(zonefile_txt) if parsed_zonefile.has_key('txt'): print 'have txt records' print parsed_zonefile return False # renew it, but put the *current* owner key as the zonefile's *new* public key new_user_zonefile = blockstack_client.zonefile.make_empty_zonefile('bar.test', wallets[3].pubkey_hex ) new_user_zonefile_txt = blockstack_zones.make_zone_file(new_user_zonefile) res = testlib.blockstack_REST_call("POST", "/v1/names", ses, data={'name': 'bar.test', 'zonefile': new_user_zonefile_txt} ) 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(ses, 'bar.test', 'renew', None ) if not res: return False for i in xrange(0, 4): testlib.next_block( **kw ) # new expire block 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 print res new_expire_block = res['response']['expire_block'] # 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 bar.test" print json.dumps(res) return False # valid history? hist = res['response'] if len(hist.keys()) != 3: 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", ses ) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name zonefile' print json.dumps(res) return False # zonefile must have old owner key zonefile_txt = res['response']['zonefile'] parsed_zonefile = blockstack_zones.parse_zone_file(zonefile_txt) if not parsed_zonefile.has_key('txt'): print 'missing txt' print parsed_zonefile return False found = False for txtrec in parsed_zonefile['txt']: if txtrec['name'] == 'pubkey' and txtrec['txt'] == 'pubkey:data:{}'.format(wallets[3].pubkey_hex): found = True if not found: print 'missing public key {}'.format(wallets[3].pubkey_hex) return False # profile lookup must work res = testlib.blockstack_REST_call("GET", "/v1/users/bar.test", ses) if 'error' in res or res['http_status'] != 200: res['text'] = 'failed to get profile for bar.test' print json.dumps(res) return False print '' print json.dumps(res['response'], indent=4, sort_keys=True) print '' # verify pushed back if old_expire_block + 10 > 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 scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # migrate profiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) # 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', 'update']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] # for funsies, get the price of .test res = testlib.blockstack_REST_call('GET', '/v1/prices/namespaces/test', ses ) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get price of .test' print json.dumps(res) return False test_price = res['response']['satoshis'] print '\n\n.test costed {} satoshis\n\n'.format(test_price) # get the price for bar.test res = testlib.blockstack_REST_call('GET', '/v1/prices/names/bar.test', ses ) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get price of bar.test' print json.dumps(res) return False bar_price = res['response']['total_estimated_cost']['satoshis'] print "\n\nbar.test will cost {} satoshis\n\n".format(bar_price) # register the name bar.test. autogenerate the rest res = testlib.blockstack_REST_call('POST', '/v1/names', ses, data={'name': 'bar.test'} ) 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, 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(ses, '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(ses, 'bar.test', 'update', None ) if not res: return False for i in xrange(0, 12): testlib.next_block( **kw ) print 'Wait for update 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'] # 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 bar.test" print json.dumps(res) return False # valid history? hist = res['response'] if len(hist.keys()) != 3: 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 # now, let's set a new zonefile zf_str = "$ORIGIN bar.test\n$TTL 3600\nmy_vote TXT \"045a501e341fbf1b403ce3a6e66836a3a40a\"" res = testlib.blockstack_REST_call("PUT", "/v1/names/bar.test/zonefile/", ses, ses, data={'zonefile' : zf_str}) # 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, 4): testlib.next_block( **kw ) res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test/zonefile/?raw=1", ses ) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name zonefile' print json.dumps(res) return False if res['raw'] != zf_str: print "Zonefile wasn't updated." print "Expected: {}".format(zf_str) print "Received: {}".format(res['response']['zonefile'])
def scenario( wallets, **kw ): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy( test_proxy ) testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.blockstack_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # 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 ) data_pk = wallets[-1].privkey data_pub = wallets[-1].pubkey_hex 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', 'transfer', 'prices', 'zonefiles', 'blockchain', 'node_read']) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] # register the name bar.test res = testlib.blockstack_REST_call('POST', '/v1/names', ses, data={'name': 'bar.test'}) 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 update 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'] # transfer it res = testlib.blockstack_REST_call("PUT", "/v1/names/bar.test/owner", ses, data={'owner': wallets[7].addr}) if 'error' in res or res['http_status'] != 202: res['test'] = 'Failed to transfer name' print json.dumps(res) return False # 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 'waiting for transfer to get confirmed' time.sleep(10) # poll res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test", ses ) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to query name' print json.dumps(res) error = True return False # new owner? if not res['response'].has_key('address'): res['test'] = 'No address given' print json.dumps(res) return False address_testnet = virtualchain.address_reencode(str(res['response']['address']), network='testnet') if address_testnet != wallets[7].addr: res['test'] = 'Failed to transfer name to new address {}'.format(wallets[7].addr) res['owner_address_testnet'] = address_testnet 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
def scenario(wallets, **kw): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey) wallet_keys_2 = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[9].privkey, wallets[7].privkey, wallets[8].privkey) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_preorder("bar.test", wallets[6].privkey, wallets[7].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.blockstack_name_register("bar.test", wallets[6].privkey, wallets[7].addr) testlib.next_block(**kw) # migrate profiles res = testlib.migrate_profile("foo.test", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return res = testlib.migrate_profile("bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2) if 'error' in res: res['test'] = 'Failed to initialize bar.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False data_pk = wallets[-1].privkey data_pub = wallets[-1].pubkey_hex config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) # make an index file index_file_path = "/tmp/name_preorder_register_update_app_auth.foo.test.index.html" with open(index_file_path, "w") as f: f.write(index_file_data) testlib.blockstack_client_set_wallet("0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # register an application under foo.test res = testlib.blockstack_cli_app_publish("foo.test", "ping.app", "node_read", index_file_path, password="******") if 'error' in res: res['test'] = 'Failed to register foo.test/bar app' print json.dumps(res, indent=4, sort_keys=True) error = True return # activate bar.test testlib.blockstack_client_set_wallet("0123456789abcdef", wallets[9].privkey, wallets[7].privkey, wallets[8].privkey) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # sign in pk = 'ce100586279d3b127b7dcc137fcc2f18b272bb2b43bdaea3584d0ea17087ec0201' pubk = keylib.ECPrivateKey(pk).public_key().to_hex() res = testlib.blockstack_cli_app_signin("foo.test", pk, "ping.app", ["node_read"]) if 'error' in res: res['test'] = 'Failed to signin: {}'.format(res['error']) print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] res = testlib.blockstack_REST_call("GET", "/v1/ping", ses) if res['http_status'] != 200: print "failed to GET /api/v1/ping" print json.dumps(res, indent=4, sort_keys=True) error = True return False if res['response']['status'] != 'alive': print "failed to GET /api/v1/ping" print json.dumps(res, indent=4, sort_keys=True) error = True return False # access index.html res = testlib.blockstack_REST_call( "GET", "/v1/resources/foo.test/ping.app?name=index.html&pubkey={}".format( wallets[4].pubkey_hex), ses) if 'error' in res or res['http_status'] != 200: print 'failed to GET /v1/resources?name=/index.html' print json.dumps(res) error = True return False if res['raw'] != index_file_data: print 'expected {}\ngot {}\n'.format(index_file_data, res['raw']) print json.dumps(res) error = True return False testlib.next_block(**kw)
def scenario(wallets, **kw): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) # migrate profiles res = testlib.migrate_profile("foo.test", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) config_dir = os.path.dirname(config_path) conf = blockstack_client.get_config(config_path) assert conf api_pass = conf['api_password'] # make sure we can do REST calls res = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/pending', None, api_pass=api_pass) if 'error' in res: res['test'] = 'Failed to get queues' print json.dumps(res) return False # make sure we can do REST calls with different app names and user names res = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/pending', None, api_pass=api_pass) if 'error' in res: res['test'] = 'Failed to get queues' print json.dumps(res) return False # can we even get to the wallet? res = testlib.blockstack_REST_call('POST', '/v1/wallet/balance', None, api_pass=api_pass, data={ 'address': wallets[4].addr, 'amount': 100000 }) if res['http_status'] != 200: res['test'] = 'failed to transfer funds' # make zonefile for recipient driver_urls = blockstack_client.storage.make_mutable_data_urls( 'foo.test', use_only=['dht', 'disk']) zonefile = blockstack_client.zonefile.make_empty_zonefile( 'foo.test', wallets[4].pubkey_hex, urls=driver_urls) zonefile_txt = blockstack_zones.make_zone_file(zonefile, origin='foo.test', ttl=3600) # register the name bar.test, with min 3 confirmations on its UTXOs data = { 'name': 'bar.test', 'zonefile': zonefile_txt, 'owner_address': wallets[4].addr, 'min_confs': 3 } # should fail res = testlib.blockstack_REST_call('POST', '/v1/names', None, api_pass=api_pass, data=data) if res['http_status'] == 200: res['test'] = 'succeeded in sending bar.test' print json.dumps(res) error = True return False # wait for confirmations for i in xrange(0, 3): testlib.next_block(**kw) # should succeed res = testlib.blockstack_REST_call('POST', '/v1/names', None, api_pass=api_pass, data=data) if 'error' in res or 'error' in res['response']: res['test'] = 'failed to send bar.test' print json.dumps(res) error = True return False # wait for update to get confirmed for i in xrange(0, 48): if i % 12 == 0: print "waiting for RPC daemon to catch up" time.sleep(10) testlib.next_block(**kw) res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test", None, api_pass=api_pass) if 'error' in res: res['test'] = 'Failed to query name' print json.dumps(res) error = True return False if res['http_status'] != 200: res['test'] = 'HTTP status {}, response = {}'.format( res['http_status'], res['response']) print json.dumps(res) error = True return False # should now be registered if res['response']['status'] != 'registered': print "register not complete" print json.dumps(res) return False
def scenario(wallets, **kw): 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): 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, 12): testlib.next_block(**kw) print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge update" time.sleep(10) # let's make sure the zonefile propagates... res = testlib.blockstack_REST_call("GET", "/v1/names/foo.test", None) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get name bar.test' print json.dumps(res) return False response_json = json.loads(res['raw']) # assert that we're getting a mainnet address if response_json['address'] != "1K4SCfqffVHTnHvqsW2whH1Jn57dDjDdQA": print "Address returned to REST call isn't converted to mainnet!" print "Returned: {}, Expected: {}".format( response_json['address'], "1K4SCfqffVHTnHvqsW2whH1Jn57dDjDdQA") return False
def scenario(wallets, **kw): global wallet_keys, wallet_keys_2, error, index_file_data, resource_data wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey) test_proxy = testlib.TestAPIProxy() blockstack_client.set_default_proxy(test_proxy) testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) # 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) data_pk = wallets[-1].privkey data_pub = wallets[-1].pubkey_hex 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', 'update', 'prices', 'zonefiles', 'blockchain', 'node_read' ]) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) error = True return ses = res['token'] # register the name bar.test res = testlib.blockstack_REST_call('POST', '/v1/names', ses, data={'name': 'bar.test'}) 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, 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(ses, '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(ses, 'bar.test', 'update', None) if not res: return False for i in xrange(0, 3): testlib.next_block(**kw) # should have 9 confirmations res = testlib.get_queue(ses, 'update') if 'error' in res: print res return False if len(res) != 1: print res return False reg = res[0] confs = blockstack_client.get_tx_confirmations(reg['tx_hash']) if confs != 9: print 'wrong number of confs for {} (expected 9): {}'.format( reg['tx_hash'], confs) return False # stop the API server testlib.stop_api() # advance blockchain testlib.next_block(**kw) testlib.next_block(**kw) confs = blockstack_client.get_tx_confirmations(reg['tx_hash']) if confs != 11: print 'wrong number of confs for {} (expected 11): {}'.format( reg['tx_hash'], confs) return False # make the registrar skip the first few steps, so the only thing it does is clear out confirmed updates # (i.e. we want to make sure that the renewal's zonefile gets processed even if the blockchain goes too fast) os.environ[ 'BLOCKSTACK_TEST_REGISTRAR_FAULT_INJECTION_SKIP_UPDATE_REPLICATION'] = '1' testlib.start_api("0123456789abcdef") # wait a while print 'Wait to verify that clearing out confirmed transactions does NOT remove zonefiles' time.sleep(10) # verify that this is still in the queue res = testlib.get_queue(ses, 'update') if 'error' in res: print res return False if len(res) != 1: print res return False # clear the fault print 'Clearing update replication fault' testlib.blockstack_test_setenv( "BLOCKSTACK_TEST_REGISTRAR_FAULT_INJECTION_SKIP_UPDATE_REPLICATION", "0") # now the renewal zonefile should replicate print 'Wait for first zonefile to replicate' 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 first_zonefile_hash = res['response']['zonefile_hash'] # update res = testlib.blockstack_REST_call("PUT", "/v1/names/bar.test/zonefile", ses, data={'zonefile_hash': '11' * 20}) if 'error' in res or res['http_status'] != 202: res['test'] = 'failed to update zonefile hash' print json.dumps(res) return False # 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, 3): testlib.next_block(**kw) # should have 9 confirmations res = testlib.get_queue(ses, 'update') if 'error' in res: print res return False if len(res) != 1: print res return False reg = res[0] confs = blockstack_client.get_tx_confirmations(reg['tx_hash']) if confs != 9: print 'wrong number of confs for {} (expected 9): {}'.format( reg['tx_hash'], confs) return False # stop the API server testlib.stop_api() # advance blockchain testlib.next_block(**kw) testlib.next_block(**kw) confs = blockstack_client.get_tx_confirmations(reg['tx_hash']) if confs != 11: print 'wrong number of confs for {} (expected 11): {}'.format( reg['tx_hash'], confs) return False # make the registrar skip the first few steps, so the only thing it does is clear out confirmed updates # (i.e. we want to make sure that the renewal's zonefile gets processed even if the blockchain goes too fast) os.environ[ 'BLOCKSTACK_TEST_REGISTRAR_FAULT_INJECTION_SKIP_UPDATE_REPLICATION'] = '1' testlib.start_api("0123456789abcdef") # wait a while print 'Wait to verify that clearing out confirmed transactions does NOT remove zonefiles' time.sleep(10) # verify that it is NOT in the queue, since there is no zone file res = testlib.get_queue(ses, 'update') if 'error' not in res: print res return False # clear the fault print 'Clearing update replication fault' testlib.blockstack_test_setenv( "BLOCKSTACK_TEST_REGISTRAR_FAULT_INJECTION_SKIP_UPDATE_REPLICATION", "0") 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 # update set? if res['response']['zonefile_hash'] != '11' * 20: res['test'] = 'failed to set zonefile hash' print json.dumps(res) return False # update with nonstandard zonefile res = testlib.blockstack_REST_call("PUT", "/v1/names/bar.test/zonefile", ses, data={'zonefile': 'hello world'}) if 'error' in res or res['http_status'] != 202: res['test'] = 'failed to update zonefile hash' print json.dumps(res) return False # wait for third 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, 3): testlib.next_block(**kw) # should have 9 confirmations res = testlib.get_queue(ses, 'update') if 'error' in res: print res return False if len(res) != 1: print res return False reg = res[0] confs = blockstack_client.get_tx_confirmations(reg['tx_hash']) if confs != 9: print 'wrong number of confs for {} (expected 9): {}'.format( reg['tx_hash'], confs) return False # stop the API server testlib.stop_api() # advance blockchain testlib.next_block(**kw) testlib.next_block(**kw) confs = blockstack_client.get_tx_confirmations(reg['tx_hash']) if confs != 11: print 'wrong number of confs for {} (expected 11): {}'.format( reg['tx_hash'], confs) return False # make the registrar skip the first few steps, so the only thing it does is clear out confirmed updates # (i.e. we want to make sure that the renewal's zonefile gets processed even if the blockchain goes too fast) os.environ[ 'BLOCKSTACK_TEST_REGISTRAR_FAULT_INJECTION_SKIP_UPDATE_REPLICATION'] = '1' testlib.start_api("0123456789abcdef") # wait a while print 'Wait to verify that clearing out confirmed transactions does NOT remove zonefiles' time.sleep(10) # verify that this is still in the queue res = testlib.get_queue(ses, 'update') if 'error' in res: print res return False if len(res) != 1: print res return False # clear the fault print 'Clearing update replication fault' testlib.blockstack_test_setenv( "BLOCKSTACK_TEST_REGISTRAR_FAULT_INJECTION_SKIP_UPDATE_REPLICATION", "0") print 'Wait for third update 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 last_zonefile_hash = res['response']['zonefile_hash'] # 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()) != 5: res['test'] = 'Failed to get update history' res['history'] = hist print json.dumps(res, indent=4, sort_keys=True) return False # get the historic zonefile res = testlib.blockstack_REST_call( "GET", "/v1/names/bar.test/zonefile/{}".format(first_zonefile_hash), ses) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get first zonefile' print json.dumps(res) return False # get the latest zonefile res = testlib.blockstack_REST_call( "GET", "/v1/names/bar.test/zonefile/{}?raw=1".format(last_zonefile_hash), ses) if 'error' in res or res['http_status'] != 200: res['test'] = 'Failed to get last zonefile' print json.dumps(res) return False if res['raw'] != 'hello world': res['test'] = 'Failed to set zonefile data' print json.dumps(res) return False