示例#1
0
def check(state_engine):

    global snv_block_id, last_consensus

    # not revealed, but ready
    ns = state_engine.get_namespace_reveal("test")
    if ns is not None:
        return False

    ns = state_engine.get_namespace("test")
    if ns is None:
        return False

    if ns['namespace_id'] != 'test':
        return False

    # not preordered
    preorder = state_engine.get_name_preorder(
        "foo.test", virtualchain.make_payment_script(wallets[2].addr),
        wallets[3].addr)
    if preorder is not None:
        print "preorder exists"
        return False

    # registered
    name_rec = state_engine.get_name("foo.test")
    if name_rec is None:
        print "no such name"
        return False

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

    # revoked
    if not name_rec['revoked']:
        return False

    # snv lookup works
    test_proxy = testlib.TestAPIProxy()
    ysi_client.set_default_proxy(test_proxy)

    snv_rec = ysi_client.snv_lookup("foo.test",
                                    snv_block_id,
                                    last_consensus,
                                    proxy=test_proxy)
    if 'error' in snv_rec:
        print json.dumps(snv_rec, indent=4)
        return False

    print snv_rec

    return True
示例#2
0
def check( state_engine ):

    global last_consensus, snv_block_id

    # not revealed, but ready 
    ns = state_engine.get_namespace_reveal( "test" )
    if ns is not None:
        return False 

    ns = state_engine.get_namespace( "test" )
    if ns is None:
        return False 

    if ns['namespace_id'] != 'test':
        return False 

    # not preordered 
    for i in xrange(0, len(wallets)):
        preorder = state_engine.get_name_preorder( "foo.test", virtualchain.make_payment_script(wallets[i].addr), wallets[(i+1)%5].addr )
        if preorder is not None:
            print "preordered"
            return False

    # registered 
    name_rec = state_engine.get_name( "foo.test" )
    if name_rec is None:
        print "no name"
        return False 

    # updated, and data preserved
    if name_rec['value_hash'] != "22" * 20:
        print "wrong value hash"
        return False 

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

    # snv lookup works
    test_proxy = testlib.TestAPIProxy()
    ysi_client.set_default_proxy( test_proxy )
    spv_headers_path = test_proxy.spv_headers_path

    snv_rec = ysi_client.snv_lookup( "foo.test", snv_block_id, last_consensus, proxy=test_proxy )
    if 'error' in snv_rec:
        print json.dumps(snv_rec, indent=4 )
        return False

    print snv_rec 

    return True
def check(state_engine):

    global snv_block_id, last_consensus

    # not revealed, but ready
    ns = state_engine.get_namespace_reveal("test")
    if ns is not None:
        return False

    ns = state_engine.get_namespace("test")
    if ns is None:
        return False

    if ns['namespace_id'] != 'test':
        return False

    # not preordered
    preorder = state_engine.get_name_preorder(
        "foo.test", virtualchain.make_payment_script(wallets[2].addr),
        wallets[3].addr)
    if preorder is not None:
        return False

    # not registered
    name_rec = state_engine.get_name("foo.test")
    if name_rec is not None:
        print "Not expired:"
        print json.dumps(name_rec, indent=4)
        return False

    #  snv lookup works
    test_proxy = testlib.TestAPIProxy()
    ysi_client.set_default_proxy(test_proxy)

    snv_rec = ysi_client.snv_lookup("foo.test",
                                    snv_block_id,
                                    last_consensus,
                                    proxy=test_proxy)
    if 'error' in snv_rec:
        print json.dumps(snv_rec, indent=4)
        print "Expected (%s, %s) from (%s, %s)" % (snv_block_id, snv_consensus,
                                                   lastblock, lastconsensus)
        return False

    print snv_rec
    return True
def check(state_engine):

    global snv_block_id_foo, snv_txid_bar, last_consensus

    # not revealed, but ready
    ns = state_engine.get_namespace_reveal("test")
    if ns is not None:
        return False

    ns = state_engine.get_namespace("test")
    if ns is None:
        return False

    if ns['namespace_id'] != 'test':
        return False

    # not preordered
    for i in xrange(0, len(wallets)):
        for name in ["foo.test", "bar.test", "baz.test"]:
            preorder = state_engine.get_name_preorder(
                name, virtualchain.make_payment_script(wallets[i].addr),
                wallets[(i + 1) % 5].addr)
            if preorder is not None:
                print "preordered"
                return False

    # but still registered
    for name in ["foo.test", "bar.test", "baz.test"]:
        name_rec = state_engine.get_name(name)
        if name_rec is None:
            print "no name"
            return False

    # updated, and data preserved
    name_rec = state_engine.get_name("baz.test")
    if name_rec['value_hash'] != "22" * 20:
        print "wrong value hash"
        return False

    # transferred
    name_rec = state_engine.get_name("bar.test")
    if name_rec['address'] != wallets[4].addr or name_rec[
            'sender'] != virtualchain.make_payment_script(wallets[4].addr):
        print "wrong owner"
        return False

    # snv lookup works
    # NOTE: cannot use serial numbers here, since a NAME_IMPORT does not contain a consensus hash.
    test_proxy = testlib.TestAPIProxy()
    ysi_client.set_default_proxy(test_proxy)
    bitcoind = testlib.get_bitcoind()

    snv_rec = ysi_client.snv_lookup("foo.test",
                                    snv_block_id_foo,
                                    last_consensus,
                                    proxy=test_proxy)
    if 'error' in snv_rec:
        print json.dumps(snv_rec, indent=4)
        print "failed to look up foo.test from consensus hash %s" % last_consensus
        return False

    # can use bar.test's NAME_TRANSFER txid to verify foo.test, since it has a consensus hash
    snv_rec_bar_tx = ysi_client.snv_lookup("foo.test",
                                           snv_block_id_foo,
                                           snv_txid_bar,
                                           proxy=test_proxy)
    if 'error' in snv_rec_bar_tx:
        print json.dumps(snv_rec_bar_tx, indent=4)
        print "failed to look up foo.test from transaction %s" % snv_txid_bar
        return False

    if snv_rec != snv_rec_bar_tx:
        print "--------"
        print json.dumps(snv_rec, indent=4)
        print ""
        print json.dumps(snv_rec_bar_tx, indent=4)
        print ""
        print "Not equal"
        return False

    print snv_rec

    return True
def check(state_engine):

    global last_consensus, snv_block_id

    # not revealed, but ready
    ns = state_engine.get_namespace_reveal("test")
    if ns is not None:
        return False

    ns = state_engine.get_namespace("test")
    if ns is None:
        return False

    if ns['namespace_id'] != 'test':
        return False

    names = ['foo.test', 'bar.test', 'baz.test']
    name_preorder_wallets = [wallets[2], wallets[3], wallets[4]]
    name_register_wallets = [wallets[5], wallets[6], wallets[7]]
    name_transfer_wallets = [wallets[6], wallets[7], wallets[5]]

    test_proxy = testlib.TestAPIProxy()
    ysi_client.set_default_proxy(test_proxy)

    for i in xrange(0, len(names)):

        name = names[i]
        name_preorder_wallet = name_preorder_wallets[i]
        name_register_wallet = name_register_wallets[i]
        name_transfer_wallet = name_transfer_wallets[i]

        # not preordered
        preorder = state_engine.get_name_preorder(
            name,
            pybitcoin.make_pay_to_address_script(name_preorder_wallet.addr),
            name_register_wallet.addr)
        if preorder is not None:
            return False

        # registered
        name_rec = state_engine.get_name(name)
        if name_rec is None:
            return False

        # data is gone
        if name_rec['value_hash'] is not None:
            return False

        # owned by the right transfer wallet
        if name_rec['address'] != name_transfer_wallet.addr or name_rec[
                'sender'] != pybitcoin.make_pay_to_address_script(
                    name_transfer_wallet.addr):
            return False

        # renewed
        if name_rec['last_renewed'] == name_rec['first_registered']:
            return False

        # revoked
        if not name_rec['revoked']:
            return False

        # snv lookup works
        snv_rec = ysi_client.snv_lookup(name,
                                        snv_block_id,
                                        last_consensus,
                                        proxy=test_proxy)
        if 'error' in snv_rec:
            print json.dumps(snv_rec, indent=4)
            return False

    return True
def check( state_engine ):

    global last_consensus, snv_block_id

    # not revealed, but ready 
    ns = state_engine.get_namespace_reveal( "test" )
    if ns is not None:
        return False 

    ns = state_engine.get_namespace( "test" )
    if ns is None:
        return False 

    if ns['namespace_id'] != 'test':
        return False 

    # there won't be a preorder for an individual name...
    preorder = state_engine.get_name_preorder( "foo.test", pybitcoin.make_pay_to_address_script(wallets[2].addr), wallets[3].addr )
    if preorder is not None:
        print "found name preorder for 'foo.test'"
        return False
   
    # there won't be a preorder for all names either
    preorder = state_engine.get_name_preorder_multi( ['foo.test', 'bar.test', 'baz.test'], \
                                                     pybitcoin.make_pay_to_address_script(wallets[2].addr), \
                                                     [wallets[3].addr, wallets[4].addr, wallets[5].addr])

    if preorder is not None:
        print "Preorder found for foo.test, bar.test, baz.test"
        return False

    prev_name_rec = None
    
    test_proxy = testlib.TestAPIProxy()
    ysi_client.set_default_proxy( test_proxy )

    # each name will be registered 
    for name, wallet in [('foo.test', wallets[3]), \
                         ('bar.test', wallets[4]), \
                         ('baz.test', wallets[5])]:

        name_rec = state_engine.get_name( name )
        if name_rec is None:
            print "No name record for %s" % name
            return False 

        if name_rec['address'] != wallet.addr:
            print "'%s' not owned by '%s'" % (name, wallet.addr)
            return False 

        if name_rec['sender'] != pybitcoin.make_pay_to_address_script(wallet.addr):
            print "'%s' not controlled by '%s'" % (name, pybitcoin.make_pay_to_address_script(wallet.addr))
            return False

        if prev_name_rec is not None and prev_name_rec['history'] != name_rec['history']:
            print "'%s' does not have the same preorder as '%s'" % (prev_name_rec['name'], name_rec['name'])
            return False 

        prev_name_rec = name_rec

        # snv lookup works
        snv_rec = ysi_client.snv_lookup( name, snv_block_id, last_consensus, proxy=test_proxy )
        if 'error' in snv_rec:
            print json.dumps(snv_rec, indent=4 )
            return False

        return True
def check( state_engine ):

    global snv_block_id_foo
    global snv_serial_number_bar
    global snv_serial_number_baz
    global snv_txid_bar
    global snv_txid_baz
    global last_consensus

    # not revealed, but ready 
    ns = state_engine.get_namespace_reveal( "test" )
    if ns is not None:
        return False 

    ns = state_engine.get_namespace( "test" )
    if ns is None:
        return False 

    if ns['namespace_id'] != 'test':
        return False 

    # not preordered
    preorder = state_engine.get_name_preorder( "foo.test", virtualchain.make_payment_script(wallets[2].addr), wallets[3].addr )
    if preorder is not None:
        return False
    
    # registered 
    name_rec = state_engine.get_name( "foo.test" )
    if name_rec is None:
        return False 

    # owned by
    if name_rec['address'] != wallets[3].addr or name_rec['sender'] != virtualchain.make_payment_script(wallets[3].addr):
        return False 

    # not preordered
    preorder = state_engine.get_name_preorder( "bar.test", virtualchain.make_payment_script(wallets[4].addr), wallets[5].addr )
    if preorder is not None:
        return False
    
    # registered 
    name_rec = state_engine.get_name( "bar.test" )
    if name_rec is None:
        return False 

    # owned by
    if name_rec['address'] != wallets[5].addr or name_rec['sender'] != virtualchain.make_payment_script(wallets[5].addr):
        return False 

    # not preordered
    preorder = state_engine.get_name_preorder( "baz.test", virtualchain.make_payment_script(wallets[6].addr), wallets[7].addr )
    if preorder is not None:
        return False
    
    # registered 
    name_rec = state_engine.get_name( "baz.test" )
    if name_rec is None:
        return False 

    # owned by
    if name_rec['address'] != wallets[7].addr or name_rec['sender'] != virtualchain.make_payment_script(wallets[7].addr):
        return False 

    # snv lookup works
    test_proxy = testlib.TestAPIProxy()
    ysi_client.set_default_proxy( test_proxy )

    log.debug("use last consensus %s to verify foo.test at %s" % (last_consensus, snv_block_id_foo))
    snv_rec = ysi_client.snv_lookup( "foo.test", snv_block_id_foo, last_consensus, proxy=test_proxy ) 
    if 'error' in snv_rec:
        print json.dumps(snv_rec, indent=4 )
        return False

    # can use bar.test's serial number to verify foo.test
    log.debug("use bar.test's serial number %s to verify foo.test at %s" % (snv_serial_number_bar, snv_block_id_foo))
    snv_rec_bar = ysi_client.snv_lookup( "foo.test", snv_block_id_foo, snv_serial_number_bar, proxy=test_proxy )
    if 'error' in snv_rec_bar:
        print json.dumps(snv_rec_bar, indent=4 )
        return False 

    # can use baz.test's serial number to verify foo.test 
    log.debug("use baz.test's serial number %s to verify foo.test at %s" % (snv_serial_number_baz, snv_block_id_foo))
    snv_rec_baz = ysi_client.snv_lookup( "foo.test", snv_block_id_foo, snv_serial_number_baz, proxy=test_proxy )
    if 'error' in snv_rec_baz:
        print json.dumps( snv_rec_baz, indent=4 )
        return False 

    # can use bar.test's preorder txid to verify foo.test
    log.debug("use bar.test's preorder txid %s to verify foo.test at %s" % (snv_txid_bar, snv_block_id_foo))
    snv_rec_bar_tx = ysi_client.snv_lookup( "foo.test", snv_block_id_foo, snv_txid_bar, proxy=test_proxy )
    if 'error' in snv_rec_bar_tx:
        print json.dumps( snv_rec_bar_tx, indent=4 )
        return False 

    # can use baz.test's preorder txid to verify foo.test 
    log.debug("use baz.test's preorder txid %s to verify foo.test at %s" % (snv_txid_baz, snv_block_id_foo))
    snv_rec_baz_tx = ysi_client.snv_lookup( "foo.test", snv_block_id_foo, snv_txid_baz, proxy=test_proxy )
    if 'error' in snv_rec_baz_tx:
        print json.dumps( snv_rec_baz_tx, indent=4 )
        return False 

    # we have to have gotten the same record back in all cases
    for name, s1, s2 in [("snv_rec to snv_rec_bar", snv_rec, snv_rec_bar), \
                         ("snv_rec to snv_rec_baz", snv_rec, snv_rec_baz), \
                         ("snv_rec to snv_rec_bar_tx", snv_rec, snv_rec_bar_tx), \
                         ("snv_rec to snv_rec_baz_tx", snv_rec, snv_rec_baz_tx)]:
        if s1 != s2:
            print "--------"
            print name 
            print json.dumps(s1, indent=4 )
            print ""
            print json.dumps(s2, indent=4 )
            print ""
            print "Not equal"
            return False

    print snv_rec 
    return True