Пример #1
0
def check( state_engine ):

    global wallet_keys, datasets, zonefile_hash

    if error:
        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 

    name = "foo.test"
    wallet_payer = 2
    wallet_owner = 3
    wallet_data_pubkey = 4

    # not preordered
    preorder = state_engine.get_name_preorder( name, virtualchain.make_payment_script(wallets[wallet_payer].addr), wallets[wallet_owner].addr )
    if preorder is not None:
        print "still have preorder"
        return False

    # registered 
    name_rec = state_engine.get_name( name )
    if name_rec is None:
        print "name does not exist"
        return False 

    # owned 
    if name_rec['address'] != wallets[wallet_owner].addr or name_rec['sender'] != virtualchain.make_payment_script(wallets[wallet_owner].addr):
        print "name has wrong owner"
        return False 

    # zonefile is NOT legacy 
    user_zonefile = ysi_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 

    if ysi_profiles.is_profile_in_legacy_format( user_zonefile ):
        print "legacy still"
        print json.dumps(user_zonefile, indent=4, sort_keys=True)
        return False

    # still have a profile with data
    user_profile = ysi_client.profile.get_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)
        else:
            print "\n\nprofile is None\n\n"
                    
        return False

    # still have immutable data
    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 

    if 'error' in immutable_data_by_name:
        print "No data received for dataset hello_world_immutable"
        return False 

    if not immutable_data_by_name.has_key('data'):
        print "Misisng data\n%s" % json.dumps(immutable_data_by_name, indent=4, sort_keys=True)
        return False 

    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 = testlib.ysi_cli_get_mutable( 'foo.test', 'hello_world_mutable' )
    if dat is None:
        print "No hello_world_mutable"
        return False 

    if 'error' in dat:
        print json.dumps(dat, indent=4, sort_keys=True)
        return False 

    if json.loads(dat['data']) != {'hello': 'world'}:
        print "did not get mutable dataset"
        return False

    return True
def check( state_engine ):

    global wallet_keys, datasets, zonefile_hash

    if error:
        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 

    name = "foo.test"
    wallet_payer = 2
    wallet_owner = 3
    wallet_data_pubkey = 4

    # not preordered
    preorder = state_engine.get_name_preorder( name, pybitcoin.make_pay_to_address_script(wallets[wallet_payer].addr), wallets[wallet_owner].addr )
    if preorder is not None:
        print "still have preorder"
        return False

    # registered 
    name_rec = state_engine.get_name( name )
    if name_rec is None:
        print "name does not exist"
        return False 

    # owned 
    if name_rec['address'] != wallets[wallet_owner].addr or name_rec['sender'] != pybitcoin.make_pay_to_address_script(wallets[wallet_owner].addr):
        print "name has wrong owner"
        return False 

    # zonefile is NOT legacy 
    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 

    if blockstack_profiles.is_profile_in_legacy_format( user_zonefile ):
        print "legacy still"
        print json.dumps(user_zonefile, indent=4, sort_keys=True)
        return False

    # still have a profile with data
    user_profile = blockstack_client.profile.get_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)
        else:
            print "\n\nprofile is None\n\n"
                    
        return False

    # still have immutable data
    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 

    if 'error' in immutable_data_by_name:
        print "No data received for dataset hello_world_immutable"
        return False 

    if not immutable_data_by_name.has_key('data'):
        print "Misisng data\n%s" % json.dumps(immutable_data_by_name, indent=4, sort_keys=True)
        return False 

    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 = testlib.blockstack_cli_get_mutable( 'foo.test', 'hello_world_mutable' )
    if dat is None:
        print "No hello_world_mutable"
        return False 

    if 'error' in dat:
        print json.dumps(dat, indent=4, sort_keys=True)
        return False 

    if json.loads(dat['data']) != {'hello': 'world'}:
        print "did not get mutable dataset"
        return False

    return True