From 3af6a07d7bc040d2bc33794301ecec2fd625a868 Mon Sep 17 00:00:00 2001 From: Jude Nelson Date: Mon, 6 Feb 2017 15:17:06 -0500 Subject: [PATCH] update nonstandard zonefile tests to use the latest CLI API --- ...er_register_update_nonstandard_zonefile.py | 90 ++++++++++--------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/integration_tests/blockstack_integration_tests/scenarios/name_preorder_register_update_nonstandard_zonefile.py b/integration_tests/blockstack_integration_tests/scenarios/name_preorder_register_update_nonstandard_zonefile.py index 7d8c3eeb7..c47028e5c 100644 --- a/integration_tests/blockstack_integration_tests/scenarios/name_preorder_register_update_nonstandard_zonefile.py +++ b/integration_tests/blockstack_integration_tests/scenarios/name_preorder_register_update_nonstandard_zonefile.py @@ -95,6 +95,11 @@ def scenario( wallets, **kw ): global put_result, wallet_keys, legacy_profile, zonefile_hash, zonefile_hash_2, error + wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[8].privkey, wallets[3].privkey, wallets[4].privkey ) + + test_proxy = testlib.TestAPIProxy() + blockstack_client.set_default_proxy( test_proxy ) + testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) @@ -111,16 +116,21 @@ def scenario( wallets, **kw ): testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) - test_proxy = testlib.TestAPIProxy() - blockstack_client.set_default_proxy( test_proxy ) - wallet_keys = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey, data_privkey=wallets[4].privkey, payment_privkey=wallets[8].privkey ) - # set up legacy profile hash legacy_txt = json.dumps(legacy_profile,sort_keys=True) legacy_hash = pybitcoin.hex_hash160( legacy_txt ) + + result_1 = testlib.blockstack_cli_update("foo.test", legacy_txt, '0123456789abcdef') + if 'error' in result_1: + print json.dumps(result_1, indent=4, sort_keys=True) + return False - result_1 = testlib.blockstack_name_update( "foo.test", legacy_hash, wallets[3].privkey ) - testlib.next_block( **kw ) + # wait for it to go through... + for i in xrange(0, 12): + testlib.next_block(**kw) + + print "wait 10 seconds for update to go through" + time.sleep(10) rc = blockstack_client.storage.put_immutable_data( None, result_1['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt ) assert rc is not None @@ -132,8 +142,7 @@ def scenario( wallets, **kw ): if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) - error = True - return + return False testlib.next_block( **kw ) @@ -142,8 +151,6 @@ def scenario( wallets, **kw ): nonstandard_zonefile_txt = json.dumps(nonstandard_zonefile_json, sort_keys=True) nonstandard_zonefile_raw = binascii.unhexlify( "".join(["%02x" % i for i in xrange(0, 256)])) - testlib.blockstack_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey'] ) - zf_data = [nonstandard_zonefile_txt, nonstandard_zonefile_raw] for zi in xrange(0, len(zf_data)): nonstandard_zonefile = zf_data[zi] @@ -152,8 +159,7 @@ def scenario( wallets, **kw ): if 'error' in resp: print "failed to put nonstandard zonefile '%s'" % nonstandard_zonefile print json.dumps(resp, indent=4, sort_keys=True) - error = True - return + return False testlib.expect_atlas_zonefile(resp['value_hash']) @@ -168,69 +174,67 @@ def scenario( wallets, **kw ): if 'error' in resp: print "failed to get zonefile %s" % zi print json.dumps(resp, indent=4, sort_keys=True) - error = True - return + return False if 'warning' not in resp: print "no non-standard warning:\n%s" % json.dumps(resp, indent=4, sort_keys=True) - error = True - return + return False if resp['zonefile'] != nonstandard_zonefile: print "failed to load nonstandard zonefile json" print "expected:\n%s\n\ngot:\n%s" % (nonstandard_zonefile, resp['zonefile']) - error = True - return + return False # the following should all fail dataplane_funcs = [ ("lookup", lambda: testlib.blockstack_cli_lookup( "foo.test" )), - ("put_immutable", lambda: testlib.blockstack_cli_put_immutable( "foo.test", "fail", '{"Fail": "Yes"}' )), + ("put_immutable", lambda: testlib.blockstack_cli_put_immutable( "foo.test", "fail", '{"Fail": "Yes"}', password='0123456789abcdef' )), ("get_immutable", lambda: testlib.blockstack_cli_get_immutable( "foo.test", "fail" )), - ("put_mutable", lambda: testlib.blockstack_cli_put_mutable( "foo.test", "fail", '{"fail": "yes"}' )), + ("put_mutable", lambda: testlib.blockstack_cli_put_mutable( "foo.test", "fail", '{"fail": "yes"}', password='0123456789abcdef' )), ("get_mutable", lambda: testlib.blockstack_cli_get_mutable( "foo.test", "fail" )), - ("delete_immutable", lambda: testlib.blockstack_cli_delete_immutable( "foo.test", "00" * 32 )), - ("delete_mutable", lambda: testlib.blockstack_cli_delete_mutable( "foo.test", "fail" )) + ("delete_immutable", lambda: testlib.blockstack_cli_delete_immutable( "foo.test", "00" * 32, password='0123456789abcdef' )), + ("delete_mutable", lambda: testlib.blockstack_cli_delete_mutable( "foo.test", "fail", password='0123456789abcdef' )) ] for data_func_name, data_func in dataplane_funcs: resp = data_func() if 'error' not in resp: print "%s succeeded when it should not have:\n%s" % (data_func_name, json.dumps(resp, indent=4, sort_keys=True)) - error = True - return + return False # this should succeed zf_hist = testlib.blockstack_cli_list_zonefile_history( "foo.test" ) if len(zf_hist) != 2*(zi+1)+1: print "missing zonefile history: %s (expected %s items, got %s)" % (zf_hist, zi+3, len(zf_hist)) - error = True - return + return False + update_hist = testlib.blockstack_cli_list_update_history( "foo.test" ) + if len(update_hist) != 2*(zi+1)+1: + print 'missing zonefile history: %s (expected %s items, got %s)' % (zf_hist, zi+3, len(zf_hist)) + return False + + name_hist = testlib.blockstack_cli_get_name_blockchain_history("foo.test") + if zf_hist[-1] != nonstandard_zonefile: print "invalid zonefile: expected\n%s\ngot\n%s\n" % (nonstandard_zonefile, zf_hist[-1]) - error = True - return + return False # this should work, but with "non-standard zonefiles" hist = testlib.blockstack_cli_list_immutable_data_history("foo.test", "fail") if len(hist) != 2*(zi+1)+1: print "missing immutable data history: %s (expected %s items, got %s)" % (hist, zi+3, len(hist)) - error = True - return + return False if hist[-1] != 'non-standard zonefile': print "not a non-standard zonefile: %s" % hist[-1] - error = True - return + return False # verify that we can migrate it back resp = testlib.blockstack_cli_migrate( "foo.test", "0123456789abcdef", force=True ) if 'error' in resp: print "failed to migrate" print json.dumps(resp, indent=4, sort_keys=True) - error = True - return + return False zonefile_hash = resp['zonefile_hash'] @@ -241,9 +245,10 @@ def scenario( wallets, **kw ): time.sleep(3) # see that put_immutable works - put_result = blockstack_client.put_immutable( "foo.test", "hello_world_immutable", {"hello": "world"}, proxy=test_proxy, wallet_keys=wallet_keys ) + put_result = testlib.blockstack_cli_put_immutable("foo.test", "hello_world_immutable", json.dumps({'hello': 'world'}), password='0123456789abcdef') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) + return False testlib.expect_atlas_zonefile(put_result['zonefile_hash']) @@ -254,11 +259,12 @@ def scenario( wallets, **kw ): # wait for confirmation for i in xrange(0, 12): testlib.next_block( **kw ) + print "waiting for confirmation" time.sleep(3) # see that put_mutable works - put_result = blockstack_client.put_mutable( "foo.test", "hello_world_mutable", {"hello": "world"}, proxy=test_proxy, wallet_keys=wallet_keys_2 ) + put_result = testlib.blockstack_cli_put_mutable("foo.test", "hello_world_mutable", json.dumps({'hello': 'world'}), password='0123456789abcdef') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) @@ -310,7 +316,7 @@ def check( state_engine ): return False # zonefile is NOT legacy - user_zonefile = blockstack_client.profile.load_name_zonefile( name, zonefile_hash ) + user_zonefile = blockstack_client.zonefile.load_name_zonefile( name, zonefile_hash ) if 'error' in user_zonefile: print json.dumps(user_zonefile, indent=4, sort_keys=True) return False @@ -321,7 +327,7 @@ def check( state_engine ): return False # still have a profile with data - user_profile = blockstack_client.profile.load_name_profile( name, user_zonefile, wallets[wallet_data_pubkey].addr, wallets[wallet_owner].addr ) + user_profile = blockstack_client.profile.get_name_profile( name, user_zonefile=user_zonefile ) if user_profile is None or 'error' in user_profile: if user_profile is not None: print json.dumps(user_profile, indent=4, sort_keys=True) @@ -331,7 +337,7 @@ def check( state_engine ): return False # still have immutable data - immutable_data_by_name = blockstack_client.get_immutable_by_name( "foo.test", "hello_world_immutable" ) + immutable_data_by_name = testlib.get_immutable_by_name('foo.test', 'hello_world_immutable') if immutable_data_by_name is None: print "No data received by name for dataset %s" % i return False @@ -344,13 +350,13 @@ def check( state_engine ): print "Misisng data\n%s" % json.dumps(immutable_data_by_name, indent=4, sort_keys=True) return False - data_json = immutable_data_by_name['data'] + data_json = json.loads(immutable_data_by_name['data']) if data_json != {'hello': 'world'}: print "did not get dataset hello_world_immutable\ngot %s\nexpected %s" % (data_json, {'hello': 'world'}) return False # still have mutable data - dat = blockstack_client.get_mutable( "foo.test", "hello_world_mutable" ) + dat = testlib.blockstack_cli_get_mutable( 'foo.test', 'hello_world_mutable' ) if dat is None: print "No hello_world_mutable" return False @@ -359,7 +365,7 @@ def check( state_engine ): print json.dumps(dat, indent=4, sort_keys=True) return False - if dat['data'] != {'hello': 'world'}: + if json.loads(dat['data']) != {'hello': 'world'}: print "did not get mutable dataset" return False