def scenario( wallets, **kw ): global put_result, wallet_keys, wallet_keys_2, legacy_profile, zonefile_hash, zonefile_hash_2 wallet_keys = testlib.ysi_client_initialize_wallet( "0123456789abcdef", wallets[8].privkey, wallets[3].privkey, None ) wallet_keys_2 = testlib.ysi_client_initialize_wallet( "0123456789abcdef", wallets[9].privkey, wallets[6].privkey, None ) test_proxy = testlib.TestAPIProxy() ysi_client.set_default_proxy( test_proxy ) testlib.ysi_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.ysi_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.ysi_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.ysi_name_preorder( "bar.test", wallets[5].privkey, wallets[6].addr ) testlib.next_block( **kw ) testlib.ysi_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.ysi_name_register( "bar.test", wallets[5].privkey, wallets[6].addr ) testlib.next_block( **kw ) # set up legacy profile hash legacy_txt = json.dumps(legacy_profile,sort_keys=True) legacy_hash = virtualchain.lib.hashing.hex_hash160( legacy_txt ) result_1 = testlib.ysi_name_update( "foo.test", legacy_hash, wallets[3].privkey ) result_2 = testlib.ysi_name_update( "bar.test", legacy_hash, wallets[6].privkey ) testlib.next_block( **kw ) rc = ysi_client.storage.put_immutable_data( legacy_txt, result_1['transaction_hash'], data_hash=legacy_hash ) assert rc is not None rc = ysi_client.storage.put_immutable_data( legacy_txt, result_2['transaction_hash'], data_hash=legacy_hash ) assert rc is not None testlib.next_block( **kw ) # migrate profiles, but no zone file keys res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys, zonefile_has_data_key=False ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return zonefile_hash = res['zonefile_hash'] res = testlib.migrate_profile( "bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2, zonefile_has_data_key=False ) if 'error' in res: res['test'] = 'Failed to initialize bar.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return zonefile_hash_2 = res['zonefile_hash'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) testlib.ysi_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey'] ) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # see that put_immutable works put_result = testlib.ysi_cli_put_immutable( 'foo.test', 'hello_world_immutable', json.dumps({'hello': 'world_immutable'}, sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) testlib.expect_atlas_zonefile(put_result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block( **kw ) print "waiting for confirmation" time.sleep(10) testlib.ysi_client_set_wallet( "0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], wallet_keys_2['data_privkey'] ) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # put_mutable should fail on its own, since we have no privat ekey put_result = testlib.ysi_cli_put_mutable( "bar.test", "hello_world_mutable", json.dumps({'hello': 'world'}, sort_keys=True), password='******') if 'error' not in put_result: print json.dumps(put_result, indent=4, sort_keys=True) print "accidentally succeeded to put_mutable with no public key in zone file" return False # see that put_mutable works, if we give a private key put_result = testlib.ysi_cli_put_mutable( "bar.test", "hello_world_mutable", json.dumps({'hello': 'world'}, sort_keys=True), password='******', private_key=wallet_keys_2['data_privkey']) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) return False testlib.next_block( **kw )
def scenario( wallets, **kw ): global put_result, wallet_keys, legacy_profile, zonefile_hash, zonefile_hash_2, error wallet_keys = testlib.ysi_client_initialize_wallet( "0123456789abcdef", wallets[8].privkey, wallets[3].privkey, wallets[4].privkey ) test_proxy = testlib.TestAPIProxy() ysi_client.set_default_proxy( test_proxy ) testlib.ysi_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.ysi_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.ysi_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.ysi_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # set up legacy profile hash legacy_txt = json.dumps(legacy_profile,sort_keys=True) legacy_hash = virtualchain.lib.hashing.hex_hash160( legacy_txt ) result_1 = testlib.ysi_cli_update("foo.test", legacy_txt, '0123456789abcdef') if 'error' in result_1: print json.dumps(result_1, indent=4, sort_keys=True) return False # wait for it to go through... for i in xrange(0, 12): testlib.next_block(**kw) print "wait 10 seconds for update to go through" time.sleep(10) rc = ysi_client.storage.put_immutable_data( legacy_txt, result_1['transaction_hash'], data_hash=legacy_hash ) assert rc is not None testlib.next_block( **kw ) # migrate profiles to standard zonefiles res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) return False testlib.next_block( **kw ) # give foo.test a nonstandard zonefile (as something that serializes to JSON) nonstandard_zonefile_json = {'nonstandard': 'true', 'error': 'nonstandard'} nonstandard_zonefile_txt = json.dumps(nonstandard_zonefile_json, sort_keys=True) nonstandard_zonefile_raw = binascii.unhexlify( "".join(["%02x" % i for i in xrange(0, 256)])) zf_data = [nonstandard_zonefile_txt, nonstandard_zonefile_raw] for zi in xrange(0, len(zf_data)): nonstandard_zonefile = zf_data[zi] resp = testlib.ysi_cli_update( "foo.test", nonstandard_zonefile, "0123456789abcdef", nonstandard=True ) if 'error' in resp: print "failed to put nonstandard zonefile '%s'" % nonstandard_zonefile print json.dumps(resp, indent=4, sort_keys=True) return False testlib.expect_atlas_zonefile(resp['zonefile_hash']) # wait for it to take effect for i in xrange(0, 12): testlib.next_block( **kw ) time.sleep(10) # getting zonefile should still work... resp = testlib.ysi_cli_get_name_zonefile( "foo.test", json=True, raw=False) if 'error' in resp: print "failed to get zonefile %s" % zi print json.dumps(resp, indent=4, sort_keys=True) return False if resp['zonefile'] != nonstandard_zonefile: print "failed to load nonstandard zonefile json" print "expected:\n%s\n\ngot:\n%s" % (nonstandard_zonefile, resp['zonefile']) return False # the following should all fail dataplane_funcs = [ ("lookup", lambda: testlib.ysi_cli_lookup( "foo.test" )), ("put_immutable", lambda: testlib.ysi_cli_put_immutable( "foo.test", "fail", '{"Fail": "Yes"}', password='******' )), ("get_immutable", lambda: testlib.ysi_cli_get_immutable( "foo.test", "fail" )), ("put_mutable", lambda: testlib.ysi_cli_put_mutable( "foo.test", "fail", '{"fail": "yes"}', password='******' )), ("get_mutable", lambda: testlib.ysi_cli_get_mutable( "foo.test", "fail" )), ("delete_immutable", lambda: testlib.ysi_cli_delete_immutable( "foo.test", "00" * 32, password='******' )), ("delete_mutable", lambda: testlib.ysi_cli_delete_mutable( "foo.test", "fail", password='******' )) ] for data_func_name, data_func in dataplane_funcs: resp = data_func() if 'error' not in resp: if data_func_name != 'lookup': print "%s succeeded when it should not have:\n%s" % (data_func_name, json.dumps(resp, indent=4, sort_keys=True)) return False elif 'error' not in resp['profile']: print "%s succeeded when it should not have:\n%s" % (data_func_name, json.dumps(resp, indent=4, sort_keys=True)) return False # this should succeed zf_hist = testlib.ysi_cli_list_zonefile_history( "foo.test" ) if len(zf_hist) != 2*(zi+1)+1: print "missing zonefile history: %s (expected %s items, got %s)" % (zf_hist, zi+3, len(zf_hist)) return False update_hist = testlib.ysi_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.ysi_cli_get_name_blockchain_history("foo.test") if zf_hist[-1] != nonstandard_zonefile: print "invalid zonefile: expected\n%s\ngot\n%s\n" % (nonstandard_zonefile, zf_hist[-1]) return False # this should work, but with "non-standard zonefiles" hist = testlib.ysi_cli_list_immutable_data_history("foo.test", "fail") if len(hist) != 2*(zi+1)+1: print "missing immutable data history: %s (expected %s items, got %s)" % (hist, zi+3, len(hist)) return False if hist[-1] != 'non-standard zonefile': print "not a non-standard zonefile: %s" % hist[-1] return False # verify that we can migrate it back resp = testlib.ysi_cli_migrate( "foo.test", "0123456789abcdef", force=True, interactive=False ) if 'error' in resp: print "failed to migrate" print json.dumps(resp, indent=4, sort_keys=True) return False zonefile_hash = resp['zonefile_hash'] # wait for it to take effect for i in xrange(0, 12): testlib.next_block( **kw ) time.sleep(10) # see that put_immutable works put_result = testlib.ysi_cli_put_immutable("foo.test", "hello_world_immutable", json.dumps({'hello': 'world'}), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) return False testlib.expect_atlas_zonefile(put_result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block( **kw ) print "waiting for confirmation" time.sleep(10) # see that put_mutable works put_result = testlib.ysi_cli_put_mutable("foo.test", "hello_world_mutable", json.dumps({'hello': 'world'}), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) testlib.next_block( **kw )
def scenario( wallets, **kw ): global put_result, wallet_keys, datasets, zonefile_hash, dataset_change wallet = testlib.ysi_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey ) test_proxy = testlib.TestAPIProxy() ysi_client.set_default_proxy( test_proxy ) wallet_keys = wallet testlib.ysi_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey ) testlib.next_block( **kw ) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey ) testlib.next_block( **kw ) testlib.ysi_namespace_ready( "test", wallets[1].privkey ) testlib.next_block( **kw ) testlib.ysi_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) testlib.ysi_name_register( "foo.test", wallets[2].privkey, wallets[3].addr ) testlib.next_block( **kw ) # migrate profile res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys ) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return else: zonefile_hash = res['zonefile_hash'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block( **kw ) put_result = testlib.ysi_cli_put_mutable( "foo.test", "hello_world_1", json.dumps(datasets[0]), password='******' ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) testlib.next_block( **kw ) put_result = testlib.ysi_cli_put_mutable( "foo.test", "hello_world_2", json.dumps(datasets[1]), password='******' ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) put_result = testlib.ysi_cli_put_mutable( "foo.test", "hello_world_3", json.dumps(datasets[2]), password='******' ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) # increment version too datasets[0]['buf'] = [] for i in xrange(0, 5): datasets[0]["dataset_change"] = dataset_change datasets[0]['buf'].append(i) put_result = testlib.ysi_cli_put_mutable( "foo.test", "hello_world_1", json.dumps(datasets[0]), password='******' ) if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True ) testlib.next_block( **kw )
def scenario(wallets, **kw): global put_result, wallet_keys, wallet_keys_2, datasets, zonefile_hash, dataset_change # make a storage gateway (will be port 16300) res = testlib.peer_setup(0) if 'error' in res: return res storage_gateway_working_dir = res['working_dir'] storage_gateway_config_path = res['config_path'] # make sure the storage gateway saves to disk # ysi_client.config. res = peer_start(storage_gateway_wd, args=['--foreground', '--no-indexer']) # start storage gateway # res = testlib.peer_start( # set up client wallet_keys = testlib.ysi_client_initialize_wallet("0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey) test_proxy = testlib.TestAPIProxy() ysi_client.set_default_proxy(test_proxy) testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.ysi_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) resp = testlib.ysi_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 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 for the backend to acknowledge registration" time.sleep(10) # wait for initial update to get confirmed for i in xrange(0, 12): # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) print >> sys.stderr, "Waiting for the backend to acknowledge update" time.sleep(10) # wait for zonefile/profile replication for i in xrange(0, 12): testlib.next_block(**kw) print >> sys.stderr, "Waiting for the backend to replicate zonefile and profile" time.sleep(10) # make a few accounts res = testlib.ysi_cli_put_account("foo.test", "serviceFoo", "serviceFooID", "foo://bar.com", "0123456789abcdef", extra_data='foofield=foo!', wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to create foo.test serviceFoo account' print json.dumps(res, indent=4, sort_keys=True) error = True return time.sleep(2) res = testlib.ysi_cli_put_account("foo.test", "serviceBar", "serviceBarID", "bar://baz.com", "0123456789abcdef", extra_data='barfield=bar!', wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to create foo.test serviceBar account' print json.dumps(res, indent=4, sort_keys=True) error = True return time.sleep(2) # put some data put_result = testlib.ysi_cli_put_mutable("foo.test", "hello_world_1", json.dumps(datasets[0]), password="******") if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False time.sleep(2) put_result = testlib.ysi_cli_put_mutable("foo.test", "hello_world_2", json.dumps(datasets[1]), password="******") if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False time.sleep(2) put_result = testlib.ysi_cli_put_mutable("foo.test", "hello_world_3", json.dumps(datasets[2]), password="******") if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False time.sleep(2) # increment data version too datasets[0]['buf'] = [] for i in xrange(0, 5): datasets[0]["dataset_change"] = dataset_change datasets[0]['buf'].append(i) put_result = testlib.ysi_cli_put_mutable("foo.test", "hello_world_1", json.dumps(datasets[0]), password="******") if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False time.sleep(2) testlib.next_block(**kw)
def scenario(wallets, **kw): global put_result, wallet_keys, wallet_keys_2, datasets, zonefile_hash, dataset_change # set up a second client config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None) assert config_path config_dir_2 = os.path.dirname(config_path) + '.2' os.makedirs(config_dir_2) config_path_2 = os.path.join(config_dir_2, 'client.ini') res = testlib.peer_make_config(16300, config_dir_2) if 'error' in res: print "failed to set up {}".format(config_dir_2) return False wallet_keys_2 = testlib.ysi_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[6].privkey, wallets[7].privkey) wallet_keys = testlib.ysi_client_initialize_wallet("0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey) test_proxy = testlib.TestAPIProxy() ysi_client.set_default_proxy(test_proxy) testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.ysi_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) resp = testlib.ysi_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 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 for the backend to acknowledge registration" time.sleep(10) # wait for initial update to get confirmed for i in xrange(0, 12): # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) print >> sys.stderr, "Waiting for the backend to acknowledge update" time.sleep(10) # wait for zonefile/profile replication for i in xrange(0, 12): testlib.next_block(**kw) print >> sys.stderr, "Waiting for the backend to replicate zonefile and profile" time.sleep(10) # make a few accounts res = testlib.ysi_cli_put_account("foo.test", "serviceFoo", "serviceFooID", "foo://bar.com", "0123456789abcdef", extra_data='foofield=foo!', wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to create foo.test serviceFoo account' print json.dumps(res, indent=4, sort_keys=True) error = True return time.sleep(2) res = testlib.ysi_cli_put_account("foo.test", "serviceBar", "serviceBarID", "bar://baz.com", "0123456789abcdef", extra_data='barfield=bar!', wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to create foo.test serviceBar account' print json.dumps(res, indent=4, sort_keys=True) error = True return time.sleep(2) # put some data put_result = testlib.ysi_cli_put_mutable("foo.test", "hello_world_1", json.dumps(datasets[0]), password="******") if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False time.sleep(2) put_result = testlib.ysi_cli_put_mutable("foo.test", "hello_world_2", json.dumps(datasets[1]), password="******") if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False time.sleep(2) put_result = testlib.ysi_cli_put_mutable("foo.test", "hello_world_3", json.dumps(datasets[2]), password="******") if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False time.sleep(2) # increment data version too datasets[0]['buf'] = [] for i in xrange(0, 5): datasets[0]["dataset_change"] = dataset_change datasets[0]['buf'].append(i) put_result = testlib.ysi_cli_put_mutable("foo.test", "hello_world_1", json.dumps(datasets[0]), password="******") if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False time.sleep(2) testlib.next_block(**kw)
def scenario(wallets, **kw): global datasets wallet_keys = testlib.ysi_client_initialize_wallet("0123456789abcdef", wallets[2].privkey, wallets[3].privkey, None) test_proxy = testlib.TestAPIProxy() ysi_client.set_default_proxy(test_proxy) testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.ysi_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.ysi_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) testlib.ysi_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.next_block(**kw) # migrate profile (but no data key) res = testlib.migrate_profile("foo.test", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) return False # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) # put immutable (with owner key) log.debug("put immutable 1 with owner key") testlib.ysi_client_set_wallet("0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], None) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False put_result = testlib.ysi_cli_put_immutable("foo.test", "hello_world_1_immutable", json.dumps(datasets[0], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.expect_atlas_zonefile(put_result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block(**kw) print "waiting for confirmation" time.sleep(10) # put immutable (with owner key) log.debug("put immutable 2 with owner key") testlib.ysi_cli_put_immutable("foo.test", "hello_world_2_immutable", json.dumps(datasets[1], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.expect_atlas_zonefile(put_result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block(**kw) print "waiting for confirmation" time.sleep(10) # put mutable (with owner key) log.debug("put mutable 1 with owner key") put_result = testlib.ysi_cli_put_mutable("foo.test", "hello_world_1_mutable", json.dumps(datasets[0], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False # put mutable (with owner key) log.debug("put mutable 2 with owner key") put_result = testlib.ysi_cli_put_mutable("foo.test", "hello_world_2_mutable", json.dumps(datasets[1], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.next_block(**kw) # add data signing key res = ysi_client.set_data_pubkey("foo.test", wallets[4].pubkey_hex, wallet_keys=wallet_keys, proxy=test_proxy) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) return False testlib.expect_atlas_zonefile(res['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block(**kw) print "waiting for confirmation" time.sleep(10) # put immutable (with new key) log.debug("put immutable with new key") # restart daemon wallet_keys = testlib.ysi_client_set_wallet("0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey']) res = testlib.start_api("0123456789abcdef") if 'error' in res: print 'failed to start API: {}'.format(res) return False # put immutable put_result = testlib.ysi_cli_put_immutable("foo.test", "hello_world_3_immutable", json.dumps(datasets[2], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.expect_atlas_zonefile(put_result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block(**kw) print "waiting for confirmation" time.sleep(10) # put mutable (with new key) log.debug("put mutable with new key") put_result = testlib.ysi_cli_put_mutable("foo.test", "hello_world_3_mutable", json.dumps(datasets[2], sort_keys=True), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.next_block(**kw) # delete immutable (new key) log.debug("delete immutable with new key") result = testlib.ysi_cli_delete_immutable("foo.test", "hello_world_1_immutable", password='******') if 'error' in result: print json.dumps(result, indent=4, sort_keys=True) return False testlib.expect_atlas_zonefile(result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block(**kw) print "waiting for confirmation" time.sleep(10) # delete mutable (new key) log.debug("delete mutable with new key") result = testlib.ysi_cli_delete_mutable("foo.test", "hello_world_1_mutable", password='******') if 'error' in result: print json.dumps(result, indent=4, sort_keys=True) return False testlib.next_block(**kw)
def scenario(wallets, **kw): global put_result, wallet_keys, legacy_profile, zonefile_hash, zonefile_hash_2, immutable_hash, datastore_name wallet_keys = testlib.ysi_client_initialize_wallet("0123456789abcdef", wallets[8].privkey, wallets[3].privkey, wallets[4].privkey) wallet_keys_2 = testlib.ysi_client_initialize_wallet( "0123456789abcdef", wallets[9].privkey, wallets[6].privkey, wallets[7].privkey) test_proxy = testlib.TestAPIProxy() ysi_client.set_default_proxy(test_proxy) testlib.ysi_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.ysi_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) testlib.next_block(**kw) testlib.ysi_namespace_ready("test", wallets[1].privkey) testlib.next_block(**kw) testlib.ysi_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr) testlib.ysi_name_preorder("bar.test", wallets[5].privkey, wallets[6].addr) testlib.next_block(**kw) testlib.ysi_name_register("foo.test", wallets[2].privkey, wallets[3].addr) testlib.ysi_name_register("bar.test", wallets[5].privkey, wallets[6].addr) testlib.next_block(**kw) # set up legacy profile hash legacy_txt = json.dumps(legacy_profile, sort_keys=True) legacy_hash = pybitcoin.hex_hash160(legacy_txt) result_1 = testlib.ysi_name_update("foo.test", legacy_hash, wallets[3].privkey) result_2 = testlib.ysi_name_update("bar.test", legacy_hash, wallets[6].privkey) testlib.next_block(**kw) rc = ysi_client.storage.put_immutable_data(None, result_1['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt) assert rc is not None rc = ysi_client.storage.put_immutable_data(None, result_2['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt) assert rc is not None testlib.next_block(**kw) # migrate res = testlib.migrate_profile("foo.test", proxy=test_proxy, wallet_keys=wallet_keys) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return else: zonefile_hash = res['zonefile_hash'] # migrate res = testlib.migrate_profile("bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2) if 'error' in res: res['test'] = 'Failed to initialize foo.test profile' print json.dumps(res, indent=4, sort_keys=True) error = True return else: zonefile_hash_2 = res['zonefile_hash'] # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) # start up RPC for 'foo.test' testlib.ysi_client_set_wallet("0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey']) # put immutable put_result = testlib.ysi_cli_put_immutable("foo.test", "hello_world_immutable", json.dumps({'hello': 'world'}), password='******') log.debug("put immutable for foo.test") if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) error = True return immutable_hash = put_result['immutable_data_hash'] testlib.expect_atlas_zonefile(put_result['zonefile_hash']) # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() # wait for confirmation for i in xrange(0, 12): testlib.next_block(**kw) print "waiting for confirmation" time.sleep(10) # start up RPC for 'bar.test' testlib.ysi_client_set_wallet("0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], wallet_keys_2['data_privkey']) log.debug("put mutable for bar.test") put_result = testlib.ysi_cli_put_mutable('bar.test', 'hello_world_mutable', json.dumps({'hello': 'world'}), password='******') if 'error' in put_result: print json.dumps(put_result, indent=4, sort_keys=True) return False testlib.next_block(**kw) # put mutable data again testlib.ysi_client_set_wallet("0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey']) res = testlib.ysi_cli_put_mutable('foo.test', 'foo_data2', json.dumps({'hello2': 'world2'}), password='******') if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) return False # put immutable data with the URL # start up RPC for 'foo.test' log.debug("put immutable for foo.test (2)") res = testlib.ysi_cli_put_immutable('foo.test', 'foo_immutable', json.dumps({'hello3': 'world3'}), password='******') if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) return False # tell serialization-checker that value_hash can be ignored here print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash" sys.stdout.flush() testlib.next_block(**kw) datastore_pk = keylib.ECPrivateKey(wallets[-1].privkey).to_hex() datastore_id_res = testlib.ysi_cli_datastore_get_id(datastore_pk) datastore_name = datastore_id_res['datastore_id'] # make datastore res = testlib.ysi_cli_create_datastore(datastore_pk) if 'error' in res: print "failed to create datastore: {}".format(res['error']) return False # put a file into the datastore data = 'hello datastore' log.debug("putfile") res = testlib.ysi_cli_datastore_putfile(datastore_pk, '/hello_datastore', data) if 'error' in res: print 'failed to putfile /hello_datastore: {}'.format(res['error']) return False # make a directory log.debug("mkdir") res = testlib.ysi_cli_datastore_mkdir(datastore_pk, '/hello_dir') if 'error' in res: print 'failed to mkdir /hello_dir: {}'.format(res['error']) return False # put a file into the directory data = 'hello dir datastore' log.debug("putfile in dir") res = testlib.ysi_cli_datastore_putfile(datastore_pk, '/hello_dir/hello_dir_datastore', data) if 'error' in res: print 'failed to putfile /hello_dir/hello_dir_datastore: {}'.format( res['error']) return False testlib.next_block(**kw)