def scenario( wallets, **kw ):

    testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey )
    testlib.next_block( **kw ) # 689

    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 ) # 690

    testlib.blockstack_namespace_ready( "test", wallets[1].privkey )
    testlib.next_block( **kw ) # 691

    testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr )
    testlib.next_block( **kw ) # 692

    testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr )
    testlib.next_block( **kw ) # 693

    whois = testlib.blockstack_cli_whois("foo.test")
    if 'error' in whois:
        print whois
        return False

    # should fail (safety checks stop it)
    resp = testlib.blockstack_name_renew( "foo.test", wallets[3].privkey, zonefile_hash='22' * 20, recipient_addr=wallets[0].addr )
    if 'error' not in resp:
        print resp
        return False

    # should succeed in being sent
    resp = testlib.blockstack_name_renew( "foo.test", wallets[3].privkey, zonefile_hash='22' * 20, recipient_addr=wallets[0].addr, safety_checks=False, tx_fee=10000 * 5 )
    if 'error' in resp:
        print resp
        return False

    # should fail to get accepted
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))
    testlib.next_block( **kw ) # 694

    # should NOT have been renewed 
    whois2 = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois2['block_renewed_at'] != whois['block_renewed_at']:
        print 'accidentally renewed'
        print whois
        print whois2
        return False

    # activate epoch 3
    testlib.next_block( **kw ) # 695

    # should succeed
    resp = testlib.blockstack_name_renew( "foo.test", wallets[3].privkey, zonefile_hash='22' * 20, recipient_addr=wallets[0].addr )
    if 'error' in resp:
        print resp
        return False

    testlib.next_block( **kw ) # 696
Ejemplo n.º 2
0
def scenario(wallets, **kw):

    testlib.blockstack_namespace_preorder("test", wallets[1].addr,
                                          wallets[0].privkey)
    testlib.next_block(**kw)  # 689

    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)  # 690

    testlib.blockstack_namespace_ready("test", wallets[1].privkey)
    testlib.next_block(**kw)  # 691

    testlib.blockstack_name_preorder("foo.test", wallets[2].privkey,
                                     wallets[3].addr)
    testlib.next_block(**kw)  # 692

    # should fail (safety checks stop it)
    resp = testlib.blockstack_name_register('foo.test',
                                            wallets[2].privkey,
                                            wallets[3].addr,
                                            zonefile_hash='22' * 20)
    if 'error' not in resp:
        print resp
        return False

    # should succeed in being sent, but will be rejected
    resp = testlib.blockstack_name_register('foo.test',
                                            wallets[2].privkey,
                                            wallets[3].addr,
                                            zonefile_hash='22' * 20,
                                            safety_checks=False,
                                            tx_fee=300 * 5)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw)  # 693
    testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw))

    # must NOT be registered
    resp = testlib.blockstack_cli_whois('foo.test')
    if 'error' not in resp:
        print resp
        return False

    # epoch 3 now active.
    # try again, and it should succeed
    resp = testlib.blockstack_name_register('foo.test',
                                            wallets[2].privkey,
                                            wallets[3].addr,
                                            zonefile_hash='22' * 20)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw)  # 694
Ejemplo n.º 3
0
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)

    testlib.blockstack_name_register("foo1.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='11' * 20)
    testlib.blockstack_name_register("foo2.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='22' * 20)
    testlib.blockstack_name_register("foo3.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='33' * 20)
    testlib.next_block(**kw)

    # 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'] != '{}{}'.format(i, i) * 20:
            print res
            return False

        if res['owner_address'] != wallets[3].addr:
            print res
            return False
def check(state_engine):

    # not revealed, but ready
    ns = state_engine.get_namespace_reveal("test")
    if ns is not None:
        print "namespace reveal exists"
        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

    # 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 "name does not exist"
        return False

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

    # renewed
    res = testlib.blockstack_cli_whois('foo.test')
    if 'error' in res:
        print res
        return False

    if res['block_renewed_at'] != renew_block:
        print 'wrong renew block: expected {}'.format(renew_block)
        print res
        return False

    return True
Ejemplo n.º 5
0
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)

    zonefiles = {
        'foo1.test': 'foo1.test abcd',
        'foo2.test': 'foo2.test abcd',
        'foo3.test': 'foo3.test abcd',
    }

    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)

    testlib.blockstack_name_register(
        "foo1.test",
        wallets[2].privkey,
        wallets[3].addr,
        zonefile_hash=blockstack.lib.storage.get_zonefile_data_hash(
            zonefiles['foo1.test']))
    testlib.blockstack_name_register(
        "foo2.test",
        wallets[2].privkey,
        wallets[3].addr,
        zonefile_hash=blockstack.lib.storage.get_zonefile_data_hash(
            zonefiles['foo2.test']))
    testlib.blockstack_name_register(
        "foo3.test",
        wallets[2].privkey,
        wallets[3].addr,
        zonefile_hash=blockstack.lib.storage.get_zonefile_data_hash(
            zonefiles['foo3.test']))
    testlib.next_block(**kw)

    # put zonefiles

    # 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'] != blockstack.lib.storage.get_zonefile_data_hash(
                    zonefiles[name]):
            print res
            return False

        if res['owner_address'] != wallets[3].addr:
            print res
            return False
Ejemplo n.º 6
0
def scenario( wallets, **kw ):
    
    global last_block
    testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey )
    testlib.next_block( **kw )

    testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 1, 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_register( "foo.test", wallets[2].privkey, wallets[3].addr, zonefile_hash = '11' * 20 )

    testlib.next_block( **kw )

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['owner_address'] != wallets[3].addr:
        print 'wrong owner'
        print whois
        return False

    if whois['zonefile_hash'] != '11' * 20:
        print 'wrong value hash'
        return False

    testlib.next_block( **kw )
    testlib.next_block( **kw )
    testlib.next_block( **kw )

    # different owner
    testlib.blockstack_name_preorder( "foo.test", wallets[3].privkey, wallets[2].addr )
    testlib.blockstack_name_register( "foo.test", wallets[3].privkey, wallets[2].addr, zonefile_hash = '22' * 20 )
    
    testlib.next_block( **kw )

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['owner_address'] != wallets[2].addr:
        print 'wrong owner'
        print whois
        return False

    if whois['zonefile_hash'] != '22' * 20:
        print 'wrong value hash'
        return False
        
    testlib.next_block( **kw )
    testlib.next_block( **kw )
    testlib.next_block( **kw )
    
    # same owner
    testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr )
    testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr, zonefile_hash = '33' * 20 )

    testlib.next_block( **kw )

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['owner_address'] != wallets[3].addr:
        print 'wrong owner'
        print whois
        return False

    if whois['zonefile_hash'] != '33' * 20:
        print 'wrong value hash'
        return False

    testlib.next_block( **kw )
    testlib.next_block( **kw )
    testlib.next_block( **kw )

    # different owner
    testlib.blockstack_name_preorder( "foo.test", wallets[3].privkey, wallets[4].addr )
    testlib.blockstack_name_register( "foo.test", wallets[3].privkey, wallets[4].addr, zonefile_hash = '44' * 20 )
    
    testlib.next_block( **kw )

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['owner_address'] != wallets[4].addr:
        print 'wrong owner'
        print whois
        return False

    if whois['zonefile_hash'] != '44' * 20:
        print 'wrong value hash'
        return False
        
    testlib.next_block( **kw )
    testlib.next_block( **kw )
    testlib.next_block( **kw )

    # same owner
    testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr )
    testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr, zonefile_hash = '55' * 20 )

    testlib.next_block( **kw )

    last_block = testlib.get_current_block(**kw)
def scenario( wallets, **kw ):

    global first_name_block

    # make a test namespace
    resp = testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        return False

    testlib.next_block( **kw ) # end of 689

    resp = testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 2, 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 resp:
        print json.dumps( resp, indent=4 )
        return False

    testlib.next_block( **kw ) # 690

    resp = testlib.blockstack_name_import( "foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        return False

    testlib.next_block( **kw ) # 691
    first_name_block = testlib.get_current_block( **kw )

    resp = testlib.blockstack_namespace_ready( "test", wallets[1].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        return False

    testlib.next_block( **kw ) # end of 692 (epoch 3 should be active)

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print 'failed to whois foo.test'
        print json.dumps(whois, indent=4)
        return False

    # epoch 3 should be active...
    if whois['expire_block'] != testlib.get_current_block(**kw) + 4:
        print 'wrong expire block (should be 4 away)'
        print whois
        return False

    resp = testlib.blockstack_name_renew( 'foo.test', wallets[3].privkey, zonefile_hash='22'*20, recipient_addr=wallets[2].addr)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw) # end of 693 (new epoch)

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['expire_block'] != testlib.get_current_block(**kw) + 4:
        print 'expire block: {}'.format(whois['expire_block'])
        print 'current block + 4: {}'.format(testlib.get_current_block(**kw) + 4)
        return False

    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 9:
        print 'renewal deadline: {}'.format(whois['renewal_deadline'])
        print 'current block + 9: {}'.format(testlib.get_current_block(**kw) + 9)
        return False

    # expire it again (block 694-698)
    for i in xrange(0, 4):
        testlib.next_block(**kw)

    lookup = testlib.blockstack_cli_lookup('foo.test')
    if 'error' not in lookup:
        print lookup
        return False

    if 'name is expired' not in lookup['error'].lower():
        print lookup
        return False

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['expire_block'] != testlib.get_current_block(**kw):
        print 'expire block: {}'.format(whois['expire_block'])
        print 'current block: {}'.format(testlib.get_current_block(**kw))
        return False

    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 5:
        print 'renewal deadline: {}'.format(whois['renewal_deadline'])
        print 'current block + 4: {}'.format(testlib.get_current_block(**kw) + 5)
        return False

    # renew
    resp = testlib.blockstack_name_renew( 'foo.test', wallets[2].privkey, zonefile_hash='33'*20, recipient_addr=wallets[4].addr)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw) # 699

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['expire_block'] != testlib.get_current_block(**kw) + 4:
        print 'expire block: {}'.format(whois['expire_block'])
        print 'current block + 4: {}'.format(testlib.get_current_block(**kw) + 4)
        return False

    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 9:
        print 'renewal deadline: {}'.format(whois['renewal_deadline'])
        print 'current block + 9: {}'.format(testlib.get_current_block(**kw) + 9)
        return False

    if whois['owner_address'] != wallets[4].addr:
        print 'wrong owner; expected {}'.format(wallets[4].addr)
        print whois
        return False
Ejemplo n.º 8
0
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,
        version_bits=2)
    testlib.next_block(**kw)

    testlib.blockstack_namespace_ready("test", wallets[1].privkey)
    testlib.next_block(**kw)

    namespace_rec = testlib.blockstack_cli_get_namespace_blockchain_record(
        "test")
    if 'error' in namespace_rec:
        print namespace_rec
        return False

    namespace_balance = testlib.get_balance(namespace_rec['address'])
    burn_balance = testlib.get_balance(
        blockstack_client.constants.BLOCKSTACK_BURN_ADDRESS)

    res = testlib.blockstack_name_preorder("foo.test", wallets[2].privkey,
                                           wallets[3].addr)
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)

    res = testlib.blockstack_name_register("foo.test", wallets[2].privkey,
                                           wallets[3].addr)
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)

    new_namespace_balance = testlib.get_balance(namespace_rec['address'])
    name_rec = testlib.get_name_blockchain_record('foo.test')
    name_cost = name_rec['op_fee']

    if new_namespace_balance - namespace_balance != name_cost:
        print 'address {} did not get credited'.format(
            namespace_rec['address'])
        print '{} != {} + {}'.format(new_namespace_balance, namespace_balance,
                                     name_cost)
        return False

    # should send to null burn address
    res = testlib.blockstack_name_preorder("foo2.test", wallets[2].privkey,
                                           wallets[3].addr)
    if 'error' in res:
        print res
        return False

    # preorder should send to the null burn address now.
    # try forcing it to the namespace burn address, to verify that it fails
    res = testlib.blockstack_name_preorder("foo_fail.test",
                                           wallets[2].privkey,
                                           wallets[3].addr,
                                           burn_addr=namespace_rec['address'])
    if 'error' not in res:
        print res
        return False

    res = testlib.blockstack_name_preorder("foo_fail.test",
                                           wallets[2].privkey,
                                           wallets[3].addr,
                                           burn_addr=namespace_rec['address'],
                                           safety_checks=False,
                                           tx_fee=10000 * 5)
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)

    # should be rejected
    res = testlib.blockstack_name_register("foo_fail.test", wallets[2].privkey,
                                           wallets[3].addr)
    if 'error' in res:
        print res
        return False

    # should be accepted
    res = testlib.blockstack_name_register("foo2.test", wallets[2].privkey,
                                           wallets[3].addr)
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)
    testlib.expect_snv_fail_at('foo_fail.test',
                               testlib.get_current_block(**kw))

    # should have been rejected due to wrong burn address
    whois = testlib.blockstack_cli_whois('foo_fail.test')
    if 'error' not in whois:
        print whois
        return False

    new_burn_balance = testlib.get_balance(
        blockstack_client.constants.BLOCKSTACK_BURN_ADDRESS)
    new_namespace_balance = testlib.get_balance(namespace_rec['address'])
    name_rec_2 = testlib.get_name_blockchain_record('foo2.test')
    name_cost_2 = name_rec_2['op_fee']

    # namespace should NOT have gotten the fee for foo_fail.  It should only have gotten it for foo.test
    if new_namespace_balance - namespace_balance != name_cost + 5500:
        print 'address {} got credited after fee capture period'.format(
            namespace_rec['address'])
        print '{} != {} + {}'.format(new_namespace_balance, namespace_balance,
                                     name_cost)
        return False

    # burn address should have received the fee for the second name
    if new_burn_balance - name_cost_2 != burn_balance:
        print 'null burn address did not get credited'
        print '{} != {} + {}'.format(new_burn_balance, burn_balance,
                                     name_cost_2)
        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, 2, 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.blockstack_name_register("foo1.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='11' * 20)
    testlib.blockstack_name_register("foo2.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='22' * 20)
    testlib.blockstack_name_register("foo3.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='33' * 20)
    testlib.next_block(**kw)

    def name_rec_equal(r1, r2):
        keys = set(r1.keys() + r2.keys())
        for k in keys:
            if k in r1 and k in r2:
                if r1[k] != r2[k]:
                    return False
        return True

    # dids for each of these names
    dids = [
        'did:stack:v0:{}-0'.format(wallets[3].addr),
        'did:stack:v0:{}-1'.format(wallets[3].addr),
        'did:stack:v0:{}-2'.format(wallets[3].addr)
    ]

    # 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'] != '{}{}'.format(i, i) * 20:
            print res
            return False

        if res['owner_address'] != wallets[3].addr:
            print res
            return False

    # DIDs
    old_recs = []

    for i in xrange(0, 3):
        name = 'foo{}.test'.format(i + 1)
        res = blockstack.lib.client.get_name_DID(
            name,
            hostport='http://localhost:{}'.format(
                blockstack.lib.config.RPC_SERVER_PORT))
        if 'error' in res:
            print res
            return False

        if res != dids[i]:
            print 'DID mismatch: expected {}, got {}'.format(dids[i], res)
            return False

        res = blockstack.lib.client.get_name_record(
            name,
            hostport='http://localhost:{}'.format(
                blockstack.lib.client.RPC_SERVER_PORT))
        if 'error' in res:
            print res
            return False

        name_rec = res

        res = blockstack.lib.client.get_DID_record(
            dids[i],
            hostport='http://localhost:{}'.format(
                blockstack.lib.client.RPC_SERVER_PORT))
        if 'error' in res:
            print res
            return False

        did_rec = res

        if not name_rec_equal(name_rec, did_rec):
            print 'record mismatch'
            print json.dumps(name_rec, sort_keys=True)
            print json.dumps(did_rec, sort_keys=True)
            return False

        old_recs.append(name_rec)

    # expire.  Reregister under the same owner
    testlib.next_block(**kw)
    testlib.next_block(**kw)
    testlib.next_block(**kw)
    testlib.next_block(**kw)
    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.blockstack_name_register("foo1.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='1a' * 20)
    testlib.blockstack_name_register("foo2.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='2a' * 20)
    testlib.blockstack_name_register("foo3.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='3a' * 20)
    testlib.next_block(**kw)

    # 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'] != '{}a'.format(i) * 20:
            print res
            return False

        if res['owner_address'] != wallets[3].addr:
            print res
            return False

    # dids for each of these names
    new_dids = [
        'did:stack:v0:{}-3'.format(wallets[3].addr),
        'did:stack:v0:{}-4'.format(wallets[3].addr),
        'did:stack:v0:{}-5'.format(wallets[3].addr)
    ]

    # new DIDs
    for i in xrange(0, 3):
        name = 'foo{}.test'.format(i + 1)
        res = blockstack.lib.client.get_name_DID(
            name,
            hostport='http://localhost:{}'.format(
                blockstack.lib.config.RPC_SERVER_PORT))
        if 'error' in res:
            print res
            return False

        if res != new_dids[i]:
            print 'DID mismatch: expected {}, got {}'.format(new_dids[i], res)
            return False

        res = blockstack.lib.client.get_name_record(
            name,
            hostport='http://localhost:{}'.format(
                blockstack.lib.client.RPC_SERVER_PORT))
        if 'error' in res:
            print res
            return False

        name_rec = res

        res = blockstack.lib.client.get_DID_record(
            new_dids[i],
            hostport='http://localhost:{}'.format(
                blockstack.lib.client.RPC_SERVER_PORT))
        if 'error' in res:
            print res
            return False

        did_rec = res

        if not name_rec_equal(name_rec, did_rec):
            print 'record mismatch'
            print json.dumps(name_rec, sort_keys=True)
            print json.dumps(did_rec, sort_keys=True)
            return False

    # old DIDs
    for i in xrange(0, 3):
        res = blockstack.lib.client.get_DID_record(
            dids[i],
            hostport='http://localhost:{}'.format(
                blockstack.lib.client.RPC_SERVER_PORT))
        if 'error' in res:
            print res
            return False

        did_rec = res

        if not name_rec_equal(did_rec, old_recs[i]):
            print 'old record mismatch'
            print json.dumps(did_rec, sort_keys=True)
            print json.dumps(old_recs[i], sort_keys=True)
            return False
Ejemplo n.º 10
0
def scenario(wallets, **kw):

    global preorder_info, register_info, update_info, balance_before, balance_after, names_owned_before, names_owned_after, whois, blockchain_record, deposit_info, price_info
    global blockchain_history, zonefile_info, all_names_info, namespace_names_info, wallet_info, lookup_info, update_history, zonefile_history, names_info

    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)

    balance_before = testlib.blockstack_cli_balance()
    deposit_info = testlib.blockstack_cli_deposit()
    price_info = testlib.blockstack_cli_price("foo.test",
                                              password="******")
    wallet_info = testlib.blockstack_cli_wallet("0123456789abcdef")

    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, 5):
        testlib.next_block(**kw)

    # queued?
    preorder_info = testlib.blockstack_cli_info()
    names_owned_before = testlib.blockstack_cli_get_names_owned_by_address(
        wallets[3].addr)

    for i in xrange(0, 7):
        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, 5):
        testlib.next_block(**kw)

    # registered?
    register_info = testlib.blockstack_cli_info()
    names_info = testlib.blockstack_cli_names()

    for i in xrange(0, 7):
        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, 5):
        testlib.next_block(**kw)

    update_info = testlib.blockstack_cli_info()
    names_owned_after = testlib.blockstack_cli_get_names_owned_by_address(
        wallets[3].addr)
    whois = testlib.blockstack_cli_whois("foo.test")

    for i in xrange(0, 7):
        testlib.next_block(**kw)

    print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge update"
    time.sleep(10)

    # put some immutable data
    put_immutable_info = testlib.blockstack_cli_put_immutable(
        "foo.test", "hello_world", '{"hello": "world"}')
    if 'error' in put_immutable_info:
        print "put_immutable failed"
        print json.dumps(put_immutable_info, indent=4, sort_keys=True)
        return False

    # wait for update to be confirmed
    for i in xrange(0, 12):
        testlib.next_block(**kw)

    print >> sys.stderr, "Waiting 10 seconds for backend to acknowledge put-immutable update"
    time.sleep(10)

    balance_after = testlib.blockstack_cli_balance()
    blockchain_history = testlib.blockstack_cli_get_name_blockchain_history(
        "foo.test")
    zonefile_info = testlib.blockstack_cli_get_name_zonefile("foo.test",
                                                             json=False)
    all_names_info = testlib.blockstack_cli_get_all_names(0)
    namespace_names_info = testlib.blockstack_cli_get_names_in_namespace(
        "test", 0)
    lookup_info = testlib.blockstack_cli_lookup("foo.test")
    update_history = testlib.blockstack_cli_list_update_history("foo.test")
    zonefile_history = testlib.blockstack_cli_list_zonefile_history("foo.test")
    blockchain_record = testlib.blockstack_cli_get_name_blockchain_record(
        "foo.test")
def scenario( wallets, **kw ):

    global import_block_1, import_block_2

    # make a test namespace
    resp = testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

    resp = testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 5, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

    resp = testlib.blockstack_name_import( "foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    # for funsies, pass the namespace lifetime
    for i in xrange(0, 10):
        testlib.next_block( **kw )

    # 269--next epoch
    import_block_1 = testlib.get_current_block( **kw )

    testlib.next_block( **kw )

    resp = testlib.blockstack_name_import( "foo.test", wallets[4].addr, "22" * 20, wallets[1].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )
    
    import_block_2 = testlib.get_current_block( **kw )

    testlib.next_block( **kw )

    resp = testlib.blockstack_namespace_ready( "test", wallets[1].privkey )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

    # name should definitely not be expired 
    res = testlib.blockstack_cli_whois('foo.test')
    if 'error' in res:
        print "name is expired unexpectedly"
        print json.dumps(res, indent=4, sort_keys=True)
        return False

    # wait for expiration (with multipler)...
    for i in xrange(0, 5 * blockstack.config.get_epoch_namespace_lifetime_multiplier( testlib.get_current_block(**kw), "test" ) ):
        testlib.next_block( **kw )

    # name should definitely be expired 
    res = testlib.blockstack_cli_whois('foo.test')
    if 'error' not in res:
        print json.dumps(res, indent=4, sort_keys=True)
        return False

    # re-register (should work)
    testlib.blockstack_name_preorder( "foo.test", wallets[7].privkey, wallets[8].addr )
    testlib.next_block( **kw )

    testlib.blockstack_name_register( "foo.test", wallets[7].privkey, wallets[8].addr )
    testlib.next_block( **kw )
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 first_name_block

    # make a test namespace
    resp = testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        return False

    testlib.next_block( **kw ) # 689

    resp = testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 2, 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 resp:
        print json.dumps( resp, indent=4 )
        return False

    testlib.next_block( **kw ) # 690

    resp = testlib.blockstack_namespace_ready( "test", wallets[1].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        return False

    testlib.next_block( **kw ) # 691

    # should succeed
    resp = testlib.blockstack_name_preorder('foo.test', wallets[2].privkey, wallets[3].addr)
    if 'error' in resp:
        print json.dumps(resp)
        return False

    # should succeed
    resp = testlib.blockstack_name_preorder('foo.test', wallets[1].privkey, wallets[2].addr, safety_checks=False, tx_fee=500*5)
    if 'error' in resp:
        print resp
        return False

    first_name_block = testlib.get_current_block( **kw )

    testlib.next_block( **kw ) # 692
 
    # should go through
    resp = testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw) # 693; begin epoch 2

    # should go through, but be rejected
    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, safety_checks=False, tx_fee=500*5)
    if 'error' in resp:
        print resp
        return False

    # begin epoch 2
    testlib.next_block(**kw) # 694
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print 'failed to whois foo.test'
        print json.dumps(whois, indent=4)
        return False
   
    if whois['owner_address'] != wallets[3].addr:
        print 'accidentally registered'
        print json.dumps(whois)
        return False

    # this should be the last block 
    if whois['expire_block'] != testlib.get_current_block(**kw) + 3:
        print 'wrong expire block (expect 2 more)'
        print whois
        return False

    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 3:
        print 'wrong renewal block (expect 2 more)'
        print whois
        return False
 
    # should go through, but be rejected
    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, safety_checks=False, tx_fee=500*5)
    if 'error' in resp:
        print resp
        return False

    print whois

    testlib.next_block(**kw) # 695 (epoch 3 begins)
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print 'failed to whois foo.test'
        print json.dumps(whois, indent=4)
        return False

    if whois['owner_address'] != wallets[3].addr:
        print 'accidentally registered'
        print json.dumps(whois)
        return False

    # should go through, but be rejected
    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, safety_checks=False, tx_fee=500*5)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw) # 696
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    # this should be the expire block 
    if whois['expire_block'] != testlib.get_current_block(**kw) + 1:
        print 'wrong expire block (now at {})'.format(testlib.get_current_block(**kw))
        print whois
        return False
 
    # should now be a grace period 
    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 5:
        print 'wrong renewal block (now at {})'.format(testlib.get_current_block(**kw))
        print whois
        return False

    if whois['owner_address'] != wallets[3].addr:
        print 'accidentally registered'
        print json.dumps(whois)
        return False

    last_transaction_height = whois['last_transaction_height']

    # should go through, but be rejected
    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, safety_checks=False, tx_fee=500*5)
    if 'error' in resp:
        print resp
        return False

    # should go through, and be acccepted
    resp = testlib.blockstack_name_preorder('foo.test', wallets[3].privkey, wallets[0].addr, safety_checks=False, tx_fee=500*5)
    if 'error' in resp:
        print resp
        return False

    # begin epoch 3 (grace period)
    testlib.next_block(**kw) # 697
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois

    if whois['owner_address'] != wallets[3].addr:
        print 'accidentally registered'
        print json.dumps(whois)
        return False

    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, expect_fail=True)
    if 'error' not in resp:
        print resp
        return False

    # should go through, but be rejected
    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, safety_checks=False, tx_fee=500*5)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw) # 698
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))

    # should NOT have gone through 
    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['owner_address'] != wallets[3].addr:
        print 'accidentally registered'
        print json.dumps(whois)
        return False

    if whois['last_transaction_height'] != last_transaction_height:
        print 'accidentally registered'
        return False

    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20, expect_fail=True)
    if 'error' not in resp:
        print resp
        return False

    # should go through, but be rejected
    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20, safety_checks=False, tx_fee=500*5)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw) # 699
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['owner_address'] != wallets[3].addr:
        print 'accidentally registered'
        print json.dumps(whois)
        return False

    if whois['last_transaction_height'] != last_transaction_height:
        print 'accidentally registered'
        return False

    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20, expect_fail=True)
    if 'error' not in resp:
        print resp
        return False

    # should go through, but be rejected
    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20, safety_checks=False, tx_fee=500*5)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw) # 700
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['owner_address'] != wallets[3].addr:
        print 'accidentally registered'
        print json.dumps(whois)
        return False

    if whois['last_transaction_height'] != last_transaction_height:
        print 'accidentally registered'
        return False

    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20, expect_fail=True)
    if 'error' not in resp:
        print resp
        return False

    # should go through, but be rejected
    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20, safety_checks=False, tx_fee=500*5)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw) # 701 (end of grace period)
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))
 
    '''
    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False
    
    if whois['owner_address'] != wallets[3].addr:
        print 'accidentally registered'
        print json.dumps(whois)
        return False

    if whois['last_transaction_height'] != last_transaction_height:
        print 'accidentally registered'
        return False
    '''
   
    '''
    # DEPRECATED: the new CLI correctly allows this through, since it's possible that, now that the grace period has passed, that someone has correctly preoredered and is now registering this name
    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20, expect_fail=True)
    if 'error' not in resp:
        print resp
        return False
    '''

    # should go through, but be rejected
    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20, safety_checks=False, tx_fee=500*5)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw) # 702
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' not in whois:
        print whois
        return False

    # should go through, but be rejected
    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20)
    if 'error' in resp:
        print resp
        return False
    
    testlib.next_block(**kw) # 703
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))
    
    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' not in whois:
        print whois
        return False

    # should go through, but be rejected
    resp = testlib.blockstack_name_register("foo.test", wallets[3].privkey, wallets[0].addr, zonefile_hash='44' * 20)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw) # 704
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))
 
    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' not in whois:
        print whois
        return False
Ejemplo n.º 14
0
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{}'
    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 "http://localhost:4000/hub/{}/profile.json'
    zf_default_url_2 = '_file URI 20 1 "http://localhost:4000/hub/{}/profile.json'

    subdomain_zonefiles = {
        'bar.foo1.test':
        sub_zf_template.format(
            'bar.foo1.test',
            zf_default_url.format(
                virtualchain.address_reencode(wallets[0].addr,
                                              network='mainnet'))),
        'bar.foo2.test':
        sub_zf_template.format(
            'bar.foo2.test',
            zf_default_url.format(
                virtualchain.address_reencode(wallets[1].addr,
                                              network='mainnet'))),
        'bar.foo3.test':
        sub_zf_template.format(
            'bar.foo3.test',
            zf_default_url.format(
                virtualchain.address_reencode(wallets[2].addr,
                                              network='mainnet'))),
    }

    zonefiles = {
        'foo1.test':
        zf_template.format(
            'foo1.test',
            subdomains.make_subdomain_txt('bar.foo1.test', 'foo1.test',
                                          wallets[0].addr, 0,
                                          subdomain_zonefiles['bar.foo1.test'],
                                          wallets[0].privkey)),
        'foo2.test':
        zf_template.format(
            'foo2.test',
            subdomains.make_subdomain_txt('bar.foo2.test', 'foo2.test',
                                          wallets[1].addr, 0,
                                          subdomain_zonefiles['bar.foo2.test'],
                                          wallets[1].privkey)),
        'foo3.test':
        zf_template.format(
            'foo3.test',
            subdomains.make_subdomain_txt('bar.foo3.test', 'foo3.test',
                                          wallets[2].addr, 0,
                                          subdomain_zonefiles['bar.foo3.test'],
                                          wallets[2].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 i, subd in enumerate(
        ['bar.foo1.test', 'bar.foo2.test', 'bar.foo3.test']):
        profile_data = {
            'type': 'Person',
            'name': subd,
        }
        profile_jwt = testlib.blockstack_make_profile(profile_data,
                                                      wallets[i].privkey)
        testlib.blockstack_put_profile(None, profile_jwt, wallets[i].privkey,
                                       'http://localhost:4000')

    # 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':
        sub_zf_template.format(
            'bar.foo1.test',
            zf_default_url_2.format(
                virtualchain.address_reencode(wallets[0].addr,
                                              network='mainnet'))),
        'bar.foo2.test':
        sub_zf_template.format(
            'bar.foo2.test',
            zf_default_url_2.format(
                virtualchain.address_reencode(wallets[1].addr,
                                              network='mainnet'))),
        'bar.foo3.test':
        sub_zf_template.format(
            'bar.foo3.test',
            zf_default_url_2.format(
                virtualchain.address_reencode(wallets[2].addr,
                                              network='mainnet'))),
    }

    zonefiles = {
        'foo1.test':
        zf_template.format(
            'foo1.test',
            subdomains.make_subdomain_txt('bar.foo1.test', 'foo1.test',
                                          wallets[0].addr, 1,
                                          subdomain_zonefiles['bar.foo1.test'],
                                          wallets[0].privkey)),
        'foo2.test':
        zf_template.format(
            'foo2.test',
            subdomains.make_subdomain_txt('bar.foo2.test', 'foo2.test',
                                          wallets[1].addr, 1,
                                          subdomain_zonefiles['bar.foo2.test'],
                                          wallets[1].privkey)),
        'foo3.test':
        zf_template.format(
            'foo3.test',
            subdomains.make_subdomain_txt('bar.foo3.test', 'foo3.test',
                                          wallets[2].addr, 1,
                                          subdomain_zonefiles['bar.foo3.test'],
                                          wallets[2].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)

    # query each subdomain
    # test 301 redirects.
    res = testlib.blockstack_REST_call('GET',
                                       '/v1/names/baz.foo1.test',
                                       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))
        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))
        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[i - 1].addr)
        if 'error' in res:
            print 'failed to get subdomains owned by {}'.format(
                wallets[i - 1].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[i - 1].addr))
        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))
        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))
                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)
Ejemplo n.º 15
0
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, 3, 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 )

    # wait for a bit...
    for i in xrange(0, 2):
        testlib.next_block( **kw )

    # name must still exist 
    name_rec = testlib.blockstack_cli_whois('foo.test')
    if 'error' in name_rec:
        print name_rec
        return False
    
    if name_rec['owner_address'] != wallets[3].addr:
        print name_rec
        print 'wrong addr'
        return False

    # must still be renewable
    resp = testlib.blockstack_name_renew( "foo.test", wallets[3].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        return False

    # wait for a bit...
    for i in xrange(0, 5):
        testlib.next_block(**kw)

    # must be gone
    name_rec = testlib.blockstack_cli_whois('foo.test')
    if 'error' not in name_rec:
        print name_rec
        return False

    # re-register under different address 
    testlib.blockstack_name_preorder( "foo.test", wallets[3].privkey, wallets[2].addr )
    testlib.next_block( **kw )

    testlib.blockstack_name_register( "foo.test", wallets[3].privkey, wallets[2].addr )
    testlib.next_block( **kw )

    # wait for a bit...
    for i in xrange(0, 2):
        testlib.next_block( **kw )

    # name must still exist 
    name_rec = testlib.blockstack_cli_whois('foo.test')
    if 'error' in name_rec:
        print name_rec
        return False
    
    if name_rec['owner_address'] != wallets[2].addr:
        print name_rec
        print 'wrong addr'
        return False

    # must still be renewable
    resp = testlib.blockstack_name_renew( "foo.test", wallets[2].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        return False

    testlib.next_block( **kw )
    testlib.next_block( **kw )
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( "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 )

    resp = testlib.blockstack_name_renew( "foo.test", wallets[3].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        return False

    testlib.next_block( **kw )

    # whois
    res = testlib.blockstack_cli_whois('foo.test')
    if 'error' in res:
        print res
        return False

    if res.has_key('zonefile_hash'):
        print res
        return False

    if res['owner_address'] != wallets[3].addr:
        print res
        return False
    
    resp = testlib.blockstack_name_renew( "foo.test", wallets[3].privkey, zonefile_hash='11' * 20 )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

    # whois
    res = testlib.blockstack_cli_whois('foo.test')
    if 'error' in res:
        print res
        return False

    if not res.has_key('zonefile_hash') or res['zonefile_hash'] != '11' * 20:
        print res
        return False

    if res['owner_address'] != wallets[3].addr:
        print res
        return False

    # update/transfer

    resp = testlib.blockstack_name_renew( "foo.test", wallets[3].privkey, zonefile_hash='22' * 20, recipient_addr=wallets[0].addr )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

    # whois
    res = testlib.blockstack_cli_whois('foo.test')
    if 'error' in res:
        print res
        return False

    if not res.has_key('zonefile_hash') or res['zonefile_hash'] != '22' * 20:
        print res
        return False

    if res['owner_address'] != wallets[0].addr:
        print res
        return False

    # transfer 
    resp = testlib.blockstack_name_renew( "foo.test", wallets[0].privkey, recipient_addr=wallets[1].addr )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

    # whois
    res = testlib.blockstack_cli_whois('foo.test')
    if 'error' in res:
        print res
        return False

    if not res.has_key('zonefile_hash') or res['zonefile_hash'] != '22' * 20:
        print res
        return False

    if res['owner_address'] != wallets[1].addr:
        print res
        return False
def scenario(wallets, **kw):

    global first_name_block

    # make a test namespace
    resp = testlib.blockstack_namespace_preorder("test", wallets[1].addr,
                                                 wallets[0].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # end of 689

    resp = testlib.blockstack_namespace_reveal(
        "test", wallets[1].addr, 2, 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 resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # 690

    # make a zonefile and a profile
    resp = testlib.blockstack_import_user('foo.test', wallets[1].privkey,
                                          wallets[3].privkey, **kw)  # 691

    # try lookup
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' in res:
        print res
        return False

    first_name_block = testlib.get_current_block(**kw)

    resp = testlib.blockstack_namespace_ready("test", wallets[1].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    # try lookup
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)  # end of 692

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print 'failed to whois foo.test'
        print json.dumps(whois, indent=4)
        return False

    # this should be the second-to-last block
    if whois['expire_block'] != testlib.get_current_block(**kw) + 2:
        print 'wrong expire block (expect 2 more)'
        print whois
        return False

    # try lookup
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)  # end of 693; begin epoch 2
    # begin epoch 2

    # try lookup
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)  # 694

    # try lookup
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' in res:
        print res
        return False

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print 'failed to whois foo.test'
        print json.dumps(whois, indent=4)
        return False

    # this should be the last block
    if whois['expire_block'] != testlib.get_current_block(**kw) + 2:
        print 'wrong expire block (expect 2 more)'
        print whois
        return False

    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 2:
        print 'wrong renewal block (expect 2 more)'
        print whois
        return False

    print whois

    testlib.next_block(**kw)  # 695 (epoch 3 begins)

    # try lookup
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)  # end of 696

    # try lookup (should fail)
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' not in res:
        print res
        return False

    if 'expired' not in res['error']:
        print res
        return False

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    # this should be the expire block
    if whois['expire_block'] != testlib.get_current_block(**kw):
        print 'wrong expire block (now at {})'.format(
            testlib.get_current_block(**kw))
        print whois
        return False

    # should now be a grace period
    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 5:
        print 'wrong renewal block (now at {})'.format(
            testlib.get_current_block(**kw))
        print whois
        return False

    last_transaction_height = whois['last_transaction_height']

    # begin epoch 3 (grace period)
    testlib.next_block(**kw)  # end of 697

    # try lookup (should fail)
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' not in res:
        print res
        return False

    if 'expired' not in res['error']:
        print res
        return False

    testlib.next_block(**kw)  # 698

    # try lookup (should fail)
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' not in res:
        print res
        return False

    if 'expired' not in res['error']:
        print res
        return False

    testlib.next_block(**kw)  # 699

    # try lookup (should fail)
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' not in res:
        print res
        return False

    if 'expired' not in res['error']:
        print res
        return False

    testlib.next_block(**kw)  # 700

    # try lookup (should fail)
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' not in res:
        print res
        return False

    if 'expired' not in res['error']:
        print res
        return False

    testlib.blockstack_renew_user('foo.test', wallets[3].privkey,
                                  wallets[0].privkey,
                                  **kw)  # end of 701 (end of grace period)

    # try lookup (should succeed again)
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)  # 702 (name can be registered again)
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,
        3,
        250,
        4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        10,
        10,
        wallets[0].privkey,
        version_bits=2)
    testlib.next_block(**kw)

    resp = testlib.blockstack_name_import("foo.test", wallets[3].addr,
                                          "11" * 20, wallets[1].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)

    testlib.blockstack_namespace_ready("test", wallets[1].privkey)
    testlib.next_block(**kw)

    namespace_rec = testlib.blockstack_cli_get_namespace_blockchain_record(
        "test")
    if 'error' in namespace_rec:
        print namespace_rec
        return False

    namespace_balance = testlib.get_balance(namespace_rec['address'])
    burn_balance = testlib.get_balance(
        blockstack.lib.config.BLOCKSTACK_BURN_ADDRESS)

    testlib.next_block(**kw)
    testlib.next_block(**kw)
    testlib.next_block(**kw)
    testlib.next_block(**kw)  # expired

    res = testlib.blockstack_name_preorder("foo.test", wallets[2].privkey,
                                           wallets[3].addr)  # +name_cost
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)

    res = testlib.blockstack_name_register("foo.test", wallets[2].privkey,
                                           wallets[3].addr)
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)
    testlib.next_block(**kw)
    testlib.next_block(**kw)
    testlib.next_block(**kw)
    testlib.next_block(**kw)  # expired

    res = testlib.blockstack_name_preorder("foo.test", wallets[3].privkey,
                                           wallets[4].addr)  # +name_cost
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)

    res = testlib.blockstack_name_register("foo.test", wallets[3].privkey,
                                           wallets[4].addr)
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)
    testlib.next_block(**kw)

    res = testlib.blockstack_name_renew("foo.test",
                                        wallets[4].privkey)  # +name_cost
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)
    testlib.next_block(**kw)
    testlib.next_block(**kw)
    testlib.next_block(**kw)
    testlib.next_block(**kw)  # expired

    res = testlib.blockstack_name_preorder("foo.test", wallets[2].privkey,
                                           wallets[3].addr)  # +name_cost
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)

    res = testlib.blockstack_name_register("foo.test", wallets[2].privkey,
                                           wallets[3].addr)
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)

    new_namespace_balance = testlib.get_balance(namespace_rec['address'])
    name_rec = testlib.get_name_blockchain_record('foo.test')
    name_cost = name_rec['op_fee']

    testlib.next_block(**kw)
    testlib.next_block(**kw)  # stop fee collection
    testlib.next_block(**kw)
    testlib.next_block(**kw)  # expired

    if new_namespace_balance - namespace_balance != 4 * name_cost:
        print 'address {} did not get credited'.format(
            namespace_rec['address'])
        print '{} != {} + 4*{}'.format(new_namespace_balance,
                                       namespace_balance, name_cost)
        return False

    # preorder should send to the null burn address now.
    res = testlib.blockstack_name_preorder(
        "foo2.test", wallets[4].privkey,
        wallets[0].addr)  # does not pay to namespace
    if 'error' in res:
        print res
        return False

    # try forcing it to the namespace burn address, to verify that it fails
    res = testlib.blockstack_name_preorder(
        "foo_fail.test",
        wallets[4].privkey,
        wallets[0].addr,
        burn_addr=namespace_rec['address'],
        expect_fail=True)  # does not pay to namespace (command fails)
    if 'error' not in res:
        print res
        return False

    res = testlib.blockstack_name_preorder("foo_fail.test",
                                           wallets[4].privkey,
                                           wallets[0].addr,
                                           burn_addr=namespace_rec['address'],
                                           price={
                                               'units': 'BTC',
                                               'amount': name_cost
                                           },
                                           safety_checks=False,
                                           tx_fee=10000 * 5)  # +name_cost
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)
    testlib.expect_snv_fail_at('foo_fail.test',
                               testlib.get_current_block(**kw))

    # should be accepted
    res = testlib.blockstack_name_register("foo2.test", wallets[4].privkey,
                                           wallets[0].addr)
    if 'error' in res:
        print res
        return False

    # should be rejected
    res = testlib.blockstack_name_register("foo_fail.test",
                                           wallets[4].privkey,
                                           wallets[0].addr,
                                           safety_checks=False)
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)
    testlib.expect_snv_fail_at('foo_fail.test',
                               testlib.get_current_block(**kw))

    # should have been rejected due to wrong burn address
    whois = testlib.blockstack_cli_whois('foo_fail.test')
    if 'error' not in whois:
        print whois
        return False

    new_burn_balance = testlib.get_balance(
        blockstack.lib.config.BLOCKSTACK_BURN_ADDRESS)
    new_namespace_balance = testlib.get_balance(namespace_rec['address'])
    name_rec_2 = testlib.get_name_blockchain_record('foo2.test')
    name_cost_2 = name_rec_2['op_fee']

    # namespace should NOT have gotten the fee for foo_fail.  It should only have gotten it for foo.test
    if new_namespace_balance - namespace_balance < 5 * name_cost or new_namespace_balance - namespace_balance > 6 * name_cost:
        print 'address {} got credited after fee capture period'.format(
            namespace_rec['address'])
        print '{} != {} + 5*{}'.format(new_namespace_balance,
                                       namespace_balance, name_cost)
        return False

    # burn address should have received the fee for the second name
    if new_burn_balance - name_cost_2 != burn_balance:
        print 'null burn address did not get credited'
        print '{} != {} + {}'.format(new_burn_balance, burn_balance,
                                     name_cost_2)
        return False
Ejemplo n.º 19
0
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, 2, 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)

    testlib.blockstack_name_register("foo1.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='11' * 20)
    testlib.blockstack_name_register("foo2.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='22' * 20)
    testlib.blockstack_name_register("foo3.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='33' * 20)
    testlib.next_block(**kw)

    def name_rec_equal(r1, r2):
        keys = set(r1.keys() + r2.keys())
        for k in keys:
            if k in r1 and k in r2:
                if r1[k] != r2[k]:
                    return False
        return True

    # dids for each of these names
    dids = [
        'did:stack:v0:{}-0'.format(wallets[3].addr),
        'did:stack:v0:{}-1'.format(wallets[3].addr),
        'did:stack:v0:{}-2'.format(wallets[3].addr)
    ]

    # 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'] != '{}{}'.format(i, i) * 20:
            print res
            return False

        if res['owner_address'] != wallets[3].addr:
            print res
            return False

    # DIDs
    for i in xrange(0, 3):
        name = 'foo{}.test'.format(i + 1)
        res = blockstack.lib.client.get_name_DID(
            name,
            hostport='http://localhost:{}'.format(
                blockstack.lib.config.RPC_SERVER_PORT))
        if 'error' in res:
            print res
            return False

        if res != dids[i]:
            print 'DID mismatch: expected {}, got {}'.format(dids[i], res)
            return False

        res = blockstack.lib.client.get_name_record(
            name,
            hostport='http://localhost:{}'.format(
                blockstack.lib.client.RPC_SERVER_PORT))
        if 'error' in res:
            print res
            return False

        name_rec = res

        res = blockstack.lib.client.get_DID_record(
            dids[i],
            hostport='http://localhost:{}'.format(
                blockstack.lib.client.RPC_SERVER_PORT))
        if 'error' in res:
            print res
            return False

        did_rec = res

        if not name_rec_equal(name_rec, did_rec):
            print 'record mismatch'
            print json.dumps(name_rec, sort_keys=True)
            print json.dumps(did_rec, sort_keys=True)
            return False

    # do stuff with these names
    testlib.blockstack_name_update("foo1.test", "1b" * 20, wallets[3].privkey)
    testlib.blockstack_name_update("foo2.test", "2b" * 20, wallets[3].privkey)
    testlib.blockstack_name_update("foo3.test", "3b" * 20, wallets[3].privkey)

    testlib.blockstack_name_revoke("foo1.test", wallets[3].privkey)
    testlib.blockstack_name_transfer("foo2.test", wallets[4].addr, True,
                                     wallets[3].privkey)
    testlib.blockstack_name_transfer("foo3.test", wallets[4].addr, True,
                                     wallets[3].privkey)
    testlib.next_block(**kw)

    name_recs = {
        'foo1.test':
        blockstack.lib.client.get_name_record(
            'foo1.test',
            hostport='http://localhost:{}'.format(
                blockstack.lib.client.RPC_SERVER_PORT)),
        'foo2.test':
        blockstack.lib.client.get_name_record(
            'foo2.test',
            hostport='http://localhost:{}'.format(
                blockstack.lib.client.RPC_SERVER_PORT)),
        'foo3.test':
        blockstack.lib.client.get_name_record(
            'foo3.test',
            hostport='http://localhost:{}'.format(
                blockstack.lib.client.RPC_SERVER_PORT)),
    }

    assert name_recs['foo1.test']['revoked']
    assert virtualchain.address_reencode(str(
        name_recs['foo2.test']['address'])) == virtualchain.address_reencode(
            str(wallets[4].addr))
    assert virtualchain.address_reencode(str(
        name_recs['foo3.test']['address'])) == virtualchain.address_reencode(
            str(wallets[4].addr))

    # expire.  Reregister under the same owner
    testlib.next_block(**kw)
    testlib.next_block(**kw)
    testlib.next_block(**kw)
    testlib.next_block(**kw)
    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)

    testlib.blockstack_name_register("foo1.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='1a' * 20)
    testlib.blockstack_name_register("foo2.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='2a' * 20)
    testlib.blockstack_name_register("foo3.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='3a' * 20)
    testlib.next_block(**kw)

    # 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'] != '{}a'.format(i) * 20:
            print res
            return False

        if res['owner_address'] != wallets[3].addr:
            print res
            return False

    # dids for each of these names
    new_dids = [
        'did:stack:v0:{}-3'.format(wallets[3].addr),
        'did:stack:v0:{}-4'.format(wallets[3].addr),
        'did:stack:v0:{}-5'.format(wallets[3].addr)
    ]

    # new DIDs
    for i in xrange(0, 3):
        name = 'foo{}.test'.format(i + 1)
        res = blockstack.lib.client.get_name_DID(
            name,
            hostport='http://localhost:{}'.format(
                blockstack.lib.config.RPC_SERVER_PORT))
        if 'error' in res:
            print res
            return False

        if res != new_dids[i]:
            print 'DID mismatch: expected {}, got {}'.format(new_dids[i], res)
            return False

        res = blockstack.lib.client.get_name_record(
            name,
            hostport='http://localhost:{}'.format(
                blockstack.lib.client.RPC_SERVER_PORT))
        if 'error' in res:
            print res
            return False

        name_rec = res

        res = blockstack.lib.client.get_DID_record(
            new_dids[i],
            hostport='http://localhost:{}'.format(
                blockstack.lib.client.RPC_SERVER_PORT))
        if 'error' in res:
            print res
            return False

        did_rec = res

        if not name_rec_equal(name_rec, did_rec):
            print 'record mismatch'
            print json.dumps(name_rec, sort_keys=True)
            print json.dumps(did_rec, sort_keys=True)
            return False

    # old DIDs
    for i in xrange(0, 3):
        name = 'foo{}.test'.format(i + 1)
        res = blockstack.lib.client.get_DID_record(
            dids[i],
            hostport='http://localhost:{}'.format(
                blockstack.lib.client.RPC_SERVER_PORT))

        did_rec = res
        old_rec = name_recs[name]
        if old_rec.get('revoked') and 'error' not in did_rec:
            print 'revoked did is sitll valid: {}'.format(dids[i])
            print did_rec
            return False

        elif not name_rec_equal(did_rec, old_rec):
            print 'old record mismatch'
            print json.dumps(did_rec, sort_keys=True)
            print json.dumps(old_rec, sort_keys=True)
            return False
def scenario( wallets, **kw ):

    global preorder_info, register_info, update_info, balance_before, balance_after, names_owned_before, names_owned_after, whois, blockchain_record, deposit_info, price_info
    global blockchain_history, zonefile_info, all_names_info, namespace_names_info, wallet_info, lookup_info, update_history, zonefile_history, names_info

    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 )

    balance_before = testlib.blockstack_cli_balance()
    deposit_info = testlib.blockstack_cli_deposit()
    price_info = testlib.blockstack_cli_price( "foo.test", password="******" )
    wallet_info = testlib.blockstack_cli_wallet( "0123456789abcdef" ) 

    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, 5):
        testlib.next_block( **kw )

    # queued?
    preorder_info = testlib.blockstack_cli_info()
    names_owned_before = testlib.blockstack_cli_get_names_owned_by_address( wallets[3].addr )

    for i in xrange(0, 7):
        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, 5):
        testlib.next_block( **kw )

    # registered?
    register_info = testlib.blockstack_cli_info()
    names_info = testlib.blockstack_cli_names()

    for i in xrange(0, 7):
        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, 5):
        testlib.next_block( **kw )

    update_info = testlib.blockstack_cli_info()
    names_owned_after = testlib.blockstack_cli_get_names_owned_by_address( wallets[3].addr )
    whois = testlib.blockstack_cli_whois( "foo.test" )

    for i in xrange(0, 7):
        testlib.next_block( **kw )

    print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge update"
    time.sleep(10)

    # put some immutable data 
    put_immutable_info = testlib.blockstack_cli_put_immutable( "foo.test", "hello_world", '{"hello": "world"}' )    
    if 'error' in put_immutable_info:
        print "put_immutable failed"
        print json.dumps(put_immutable_info, indent=4, sort_keys=True)
        return False

    # wait for update to be confirmed 
    for i in xrange(0, 12):
        testlib.next_block( **kw )

    print >> sys.stderr, "Waiting 10 seconds for backend to acknowledge put-immutable update"
    time.sleep(10)

    balance_after = testlib.blockstack_cli_balance()
    blockchain_history = testlib.blockstack_cli_get_name_blockchain_history( "foo.test" )
    zonefile_info = testlib.blockstack_cli_get_name_zonefile( "foo.test", json=False )
    all_names_info = testlib.blockstack_cli_get_all_names(0)
    namespace_names_info = testlib.blockstack_cli_get_names_in_namespace("test", 0)
    lookup_info = testlib.blockstack_cli_lookup( "foo.test" )
    update_history = testlib.blockstack_cli_list_update_history( "foo.test" )
    zonefile_history = testlib.blockstack_cli_list_zonefile_history( "foo.test" )
    blockchain_record = testlib.blockstack_cli_get_name_blockchain_record( "foo.test" )
def scenario(wallets, **kw):

    global renew_block

    testlib.blockstack_namespace_preorder("test", wallets[1].addr,
                                          wallets[0].privkey)
    testlib.next_block(**kw)

    testlib.blockstack_namespace_reveal(
        "test", wallets[1].addr, 4, 4, 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)

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    print json.dumps(whois, indent=4, sort_keys=True)

    # push to grace period
    testlib.next_block(**kw)
    testlib.next_block(**kw)
    testlib.next_block(**kw)

    # can't update
    res = testlib.blockstack_name_update("foo.test", '22' * 20,
                                         wallets[3].privkey)
    if 'error' not in res:
        print res
        return False

    res = testlib.blockstack_name_update("foo.test",
                                         '22' * 20,
                                         wallets[3].privkey,
                                         safety_checks=False,
                                         tx_fee=300 * 5)
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)
    testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw))

    # should not have gone through
    res = testlib.blockstack_cli_whois('foo.test')
    if 'error' in res:
        print res
        return False

    if res.has_key('zonefile_hash'):
        print res
        return False

    # can't transfer
    res = testlib.blockstack_name_transfer('foo.test', wallets[4].addr, True,
                                           wallets[3].privkey)
    if 'error' not in res:
        print res
        return False

    res = testlib.blockstack_name_transfer('foo.test',
                                           wallets[4].addr,
                                           True,
                                           wallets[3].privkey,
                                           safety_checks=False,
                                           tx_fee=300 * 5)
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)
    testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw))

    # should not have gone through
    res = testlib.blockstack_cli_whois('foo.test')
    if 'error' in res:
        print res
        return False

    if res['owner_address'] != wallets[3].addr:
        print res
        return False

    # can't revoke
    res = testlib.blockstack_name_revoke('foo.test', wallets[3].privkey)
    if 'error' not in res:
        print res
        return False

    res = testlib.blockstack_name_revoke('foo.test',
                                         wallets[3].privkey,
                                         safety_checks=False,
                                         tx_fee=300 * 5)
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)
    testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw))

    # should not have gone through
    res = testlib.blockstack_cli_whois('foo.test')
    if 'error' in res:
        print res
        return False

    # can renew
    res = testlib.blockstack_name_renew('foo.test', wallets[3].privkey)
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)
    renew_block = testlib.get_current_block(**kw)
Ejemplo n.º 22
0
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)

    zf_template = "$ORIGIN {}\n$TTL 3600\n{}"
    zf_default_url = '_https._tcp URI 10 1 "https://raw.githubusercontent.com/nobody/content/profile.md"'

    zonefiles = {
        'foo1.test':
        zf_template.format(
            'foo1.test',
            subdomains.make_subdomain_txt(
                'bar.foo1.test', 'foo1.test', wallets[4].addr, 0,
                zf_template.format('bar.foo1.test', zf_default_url),
                wallets[4].privkey)),
        'foo2.test':
        zf_template.format(
            'foo2.test',
            subdomains.make_subdomain_txt(
                'bar.foo2.test', 'foo2.test', wallets[4].addr, 0,
                zf_template.format('bar.foo2.test', zf_default_url),
                wallets[4].privkey)),
        'foo3.test':
        zf_template.format(
            'foo3.test',
            subdomains.make_subdomain_txt(
                'bar.foo3.test', 'foo3.test', wallets[4].addr, 0,
                zf_template.format('bar.foo3.test', zf_default_url),
                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)

    # 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])

    # kick off subdomain indexing
    testlib.next_block(**kw)

    # query each subdomain
    proxy = testlib.make_proxy()
    for i in xrange(1, 4):
        fqn = 'bar.foo{}.test'.format(i)
        res = client.get_name_record(fqn, proxy=proxy)
        if 'error' in res:
            print res
            return False

        expected_zonefile = zf_template.format(fqn, zf_default_url)
        if base64.b64decode(res['zonefile']) != expected_zonefile:
            print 'zonefile mismatch'
            print 'expected\n{}'.format(expected_zonefile)
            print 'got\n{}'.format(base64.b64decode(res['zonefile']))
            return False

        # should be in atlas as well
        zf = testlib.blockstack_get_zonefile(res['value_hash'], parse=False)
        if not zf:
            print 'no zone file {} in atlas'.format(res['value_hash'])
            return False

        if zf != expected_zonefile:
            print 'zonefile mismatch in atlas'
            print 'expected\n{}'.format(expected_zonefile)
            print 'got\n{}'.format(base64.b64decode(res['zonefile']))
            return False

    # reindex
    assert testlib.check_subdomain_db(**kw)
Ejemplo n.º 23
0
def scenario(wallets, **kw):

    global first_name_block

    # make a test namespace
    resp = testlib.blockstack_namespace_preorder("test", wallets[1].addr,
                                                 wallets[0].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # end of 689

    # 4-block lifetime in practice
    resp = testlib.blockstack_namespace_reveal(
        "test", wallets[1].addr, 2, 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 resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # 690

    resp = testlib.blockstack_name_import("foo.test", wallets[3].addr,
                                          "11" * 20, wallets[1].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # 691
    first_name_block = testlib.get_current_block(**kw)

    resp = testlib.blockstack_namespace_ready("test", wallets[1].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # end of 692.  epoch 2 activates now

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print 'failed to whois foo.test'
        print json.dumps(whois, indent=4)
        return False

    # this should be the second-to-last block
    if whois['expire_block'] != testlib.get_current_block(**kw) + 2:
        print 'wrong expire block (now: {})'.format(
            testlib.get_current_block(**kw))
        print whois
        return False

    print whois

    testlib.next_block(**kw)  # end of 693

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print 'failed to whois foo.test'
        print json.dumps(whois, indent=4)
        return False

    # we should have 3 more block to go now.
    if whois['expire_block'] != testlib.get_current_block(**kw) + 3:
        print 'wrong expire block (should be 3 blocks away from {})'.format(
            testlib.get_current_block(**kw))
        print whois
        return False

    print whois

    resp = testlib.blockstack_name_transfer('foo.test', wallets[4].addr, True,
                                            wallets[3].privkey)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw)  # end of 694, begin epoch 3

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print 'failed to whois foo.test'
        print json.dumps(whois, indent=4)
        return False

    # we should have 2 more blocks to go now.
    if whois['expire_block'] != testlib.get_current_block(**kw) + 2:
        print 'wrong expire block'
        print whois
        return False

    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 2:
        print 'wrong renewal deadline'
        print whois
        return False

    print whois

    testlib.next_block(**kw)  # end of 695

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print 'failed to whois foo.test'
        print json.dumps(whois, indent=4)
        return False

    # we should have 1 more blocks to go now.
    if whois['expire_block'] != testlib.get_current_block(**kw) + 1:
        print 'wrong expire block'
        print whois
        return False

    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 6:
        print 'wrong renewal deadline'
        print whois
        return False

    print whois

    testlib.next_block(**kw)  # end of 696.  Name should be expired

    # update should be impossible, since we're now in the renewal period
    resp = testlib.blockstack_name_update('foo.test',
                                          '66' * 20,
                                          wallets[4].privkey,
                                          expect_fail=True)
    if 'error' not in resp:
        print resp
        return False

    # renew should work
    resp = testlib.blockstack_name_renew('foo.test',
                                         wallets[4].privkey,
                                         zonefile_hash='22' * 20,
                                         recipient_addr=wallets[2].addr)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw)  # end of 697

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    print whois

    if whois['expire_block'] != testlib.get_current_block(**kw) + 4:
        print 'expire block: {}'.format(whois['expire_block'])
        print 'current block + 4: {}'.format(
            testlib.get_current_block(**kw) + 4)
        return False

    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 9:
        print 'renewal deadline: {}'.format(whois['renewal_deadline'])
        print 'current block + 9: {}'.format(
            testlib.get_current_block(**kw) + 9)
        return False
Ejemplo n.º 24
0
def scenario(wallets, **kw):

    global first_name_block

    # make a test namespace
    resp = testlib.blockstack_namespace_preorder("test", wallets[1].addr,
                                                 wallets[0].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # end of 689

    resp = testlib.blockstack_namespace_reveal(
        "test", wallets[1].addr, 2, 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 resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # 690

    resp = testlib.blockstack_name_import("foo.test", wallets[2].addr,
                                          "11" * 20, wallets[1].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # 691
    first_name_block = testlib.get_current_block(**kw)

    resp = testlib.blockstack_namespace_ready("test", wallets[1].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # end of 692

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print 'failed to whois foo.test'
        print json.dumps(whois, indent=4)
        return False

    # this should be the second-to-last block
    if whois['expire_block'] != testlib.get_current_block(**kw) + 2:
        print 'wrong expire block (expect 2 more)'
        print whois
        return False

    testlib.next_block(**kw)  # end of 693; begin epoch 2
    # begin epoch 2
    testlib.next_block(**kw)  # 694

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print 'failed to whois foo.test'
        print json.dumps(whois, indent=4)
        return False

    # this should be the last block
    if whois['expire_block'] != testlib.get_current_block(**kw) + 2:
        print 'wrong expire block (expect 2 more)'
        print whois
        return False

    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 2:
        print 'wrong renewal block (expect 2 more)'
        print whois
        return False

    print whois

    resp = testlib.blockstack_name_transfer('foo.test', wallets[0].addr, True,
                                            wallets[2].privkey)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw)  # 695 (epoch 3 begins)
    testlib.next_block(**kw)  # end of 696

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    # this should be the expire block
    if whois['expire_block'] != testlib.get_current_block(**kw):
        print 'wrong expire block (now at {})'.format(
            testlib.get_current_block(**kw))
        print whois
        return False

    # should now be a grace period
    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 5:
        print 'wrong renewal block (now at {})'.format(
            testlib.get_current_block(**kw))
        print whois
        return False

    # safety checks should NOT allow the preorder to go through
    resp = testlib.blockstack_name_preorder('foo.test',
                                            wallets[3].privkey,
                                            wallets[4].addr,
                                            expect_fail=True)
    if 'error' not in resp:
        print resp
        return False

    # begin epoch 3 (grace period)
    testlib.next_block(**kw)  # end of 697

    # safety checks should NOT allow the preorder to go through
    resp = testlib.blockstack_name_preorder('foo.test',
                                            wallets[3].privkey,
                                            wallets[4].addr,
                                            expect_fail=True)
    if 'error' not in resp:
        print resp
        return False

    testlib.next_block(**kw)  # 698

    # safety checks should NOT allow the preorder to go through
    resp = testlib.blockstack_name_preorder('foo.test',
                                            wallets[3].privkey,
                                            wallets[4].addr,
                                            expect_fail=True)
    if 'error' not in resp:
        print resp
        return False

    testlib.next_block(**kw)  # 699

    # safety checks should NOT allow the preorder to go through
    resp = testlib.blockstack_name_preorder('foo.test',
                                            wallets[3].privkey,
                                            wallets[4].addr,
                                            expect_fail=True)
    if 'error' not in resp:
        print resp
        return False

    testlib.next_block(**kw)  # 700

    # safety checks should NOT allow the preorder to go through
    resp = testlib.blockstack_name_preorder('foo.test',
                                            wallets[3].privkey,
                                            wallets[4].addr,
                                            expect_fail=True)
    if 'error' not in resp:
        print resp
        return False

    testlib.next_block(**kw)  # end of 701

    # safety checks SHOULD allow the preorder to go through (will be incorporated into block 702)
    resp = testlib.blockstack_name_preorder('foo.test', wallets[3].privkey,
                                            wallets[4].addr)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw)  # 702

    resp = testlib.blockstack_name_register("foo.test",
                                            wallets[3].privkey,
                                            wallets[4].addr,
                                            zonefile_hash='33' * 20)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw)  # 703
def scenario(wallets, **kw):

    global first_name_block

    # make a test namespace
    resp = testlib.blockstack_namespace_preorder("test", wallets[1].addr,
                                                 wallets[0].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # 689

    resp = testlib.blockstack_namespace_reveal(
        "test", wallets[1].addr, 2, 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 resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # 690

    resp = testlib.blockstack_name_import("foo.test", wallets[3].addr,
                                          "11" * 20, wallets[1].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # 691
    first_name_block = testlib.get_current_block(**kw)

    resp = testlib.blockstack_namespace_ready("test", wallets[1].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # 692
    testlib.next_block(**kw)  # end of 693

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print 'failed to whois foo.test'
        print json.dumps(whois, indent=4)
        return False

    # this should be the penultimate block
    if whois['expire_block'] != testlib.get_current_block(**kw) + 1:
        print 'wrong expire block (got {}, expected {})'.format(
            whois['expire_block'], testlib.get_current_block(**kw))
        print whois
        return False

    resp = testlib.blockstack_name_renew('foo.test', wallets[3].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # end of 694 (epoch 2 is now active)
    testlib.next_block(**kw)  # 695

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['expire_block'] != testlib.get_current_block(**kw) + 3:
        print 'wrong expire block: {} != {} + 3'.format(
            whois['expire_block'], testlib.get_current_block(**kw))
        return False

    testlib.next_block(**kw)  # end of 696 (epoch 3 is now active)

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['expire_block'] != testlib.get_current_block(**kw) + 2:
        print 'wrong expire block: {} != {} + 2'.format(
            whois['expire_block'], testlib.get_current_block(**kw))
        return False

    testlib.next_block(**kw)  # 697

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['expire_block'] != testlib.get_current_block(**kw) + 1:
        print 'wrong expire block: {} != {} + 1'.format(
            whois['expire_block'], testlib.get_current_block(**kw))
        return False

    testlib.next_block(**kw)  # 698

    if whois['expire_block'] != testlib.get_current_block(**kw):
        print 'wrong expire block: {} != {}'.format(
            whois['expire_block'], testlib.get_current_block(**kw))
        return False

    testlib.next_block(**kw)  # end of 699 (expired now)
    testlib.next_block(**kw)  # 700
    testlib.next_block(**kw)  # 701
    testlib.next_block(**kw)  # 702

    resp = testlib.blockstack_name_renew('foo.test',
                                         wallets[3].privkey,
                                         zonefile_hash='22' * 20,
                                         recipient_addr=wallets[2].addr)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw)  # 703

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['expire_block'] != testlib.get_current_block(**kw) + 4:
        print 'expire block: {}'.format(whois['expire_block'])
        print 'current block + 4: {}'.format(
            testlib.get_current_block(**kw) + 4)
        return False

    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 9:
        print 'renewal deadline: {}'.format(whois['renewal_deadline'])
        print 'current block + 9: {}'.format(
            testlib.get_current_block(**kw) + 9)
        return False
def scenario(wallets, **kw):

    global first_name_block

    # make a test namespace
    resp = testlib.blockstack_namespace_preorder("test", wallets[1].addr,
                                                 wallets[0].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # end of 689

    resp = testlib.blockstack_namespace_reveal(
        "test", wallets[1].addr, 2, 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 resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # 690

    resp = testlib.blockstack_name_import("foo.test", wallets[3].addr,
                                          "11" * 20, wallets[1].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # 691
    first_name_block = testlib.get_current_block(**kw)

    resp = testlib.blockstack_namespace_ready("test", wallets[1].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # end of 692 (epoch 3 should be active)

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print 'failed to whois foo.test'
        print json.dumps(whois, indent=4)
        return False

    # epoch 3 should be active...
    if whois['expire_block'] != testlib.get_current_block(**kw) + 4:
        print 'wrong expire block (should be 4 away)'
        print whois
        return False

    resp = testlib.blockstack_name_renew('foo.test',
                                         wallets[3].privkey,
                                         zonefile_hash='22' * 20,
                                         recipient_addr=wallets[2].addr)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw)  # end of 693 (new epoch)

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['expire_block'] != testlib.get_current_block(**kw) + 4:
        print 'expire block: {}'.format(whois['expire_block'])
        print 'current block + 4: {}'.format(
            testlib.get_current_block(**kw) + 4)
        return False

    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 9:
        print 'renewal deadline: {}'.format(whois['renewal_deadline'])
        print 'current block + 9: {}'.format(
            testlib.get_current_block(**kw) + 9)
        return False
def scenario( wallets, **kw ):

    global first_name_block

    # make a test namespace
    resp = testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        return False

    testlib.next_block( **kw ) # end of 689

    resp = testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 2, 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 resp:
        print json.dumps( resp, indent=4 )
        return False

    testlib.next_block( **kw ) # 690

    resp = testlib.blockstack_name_import( "foo.test", wallets[3].addr, "11" * 20, wallets[1].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        return False

    testlib.next_block( **kw ) # 691
    first_name_block = testlib.get_current_block( **kw )

    resp = testlib.blockstack_namespace_ready( "test", wallets[1].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        return False

    testlib.next_block( **kw ) # end of 692

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print 'failed to whois foo.test'
        print json.dumps(whois, indent=4)
        return False

    # this should be the second-to-last block 
    if whois['expire_block'] != testlib.get_current_block(**kw) + 2:
        print 'wrong expire block (expect 2 more)'
        print whois
        return False

    testlib.next_block(**kw) # end of 693; begin epoch 2
    # begin epoch 2
    testlib.next_block(**kw) # 694
 
    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print 'failed to whois foo.test'
        print json.dumps(whois, indent=4)
        return False
   
    # this should be the last block 
    if whois['expire_block'] != testlib.get_current_block(**kw) + 2:
        print 'wrong expire block (expect 2 more)'
        print whois
        return False

    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 2:
        print 'wrong renewal block (expect 2 more)'
        print whois
        return False

    print whois

    testlib.next_block(**kw) # 695 (epoch 3 begins)
    testlib.next_block(**kw) # end of 696

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    # this should be the expire block 
    if whois['expire_block'] != testlib.get_current_block(**kw):
        print 'wrong expire block (now at {})'.format(testlib.get_current_block(**kw))
        print whois
        return False
 
    # should now be a grace period 
    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 5:
        print 'wrong renewal block (now at {})'.format(testlib.get_current_block(**kw))
        print whois
        return False

    last_transaction_height = whois['last_transaction_height']

    # should go through
    resp = testlib.blockstack_name_preorder('foo.test', wallets[3].privkey, wallets[0].addr, safety_checks=False, tx_fee=500*5)
    if 'error' in resp:
        print resp
        return False

    # should go through
    resp = testlib.blockstack_name_preorder('foo.test', wallets[1].privkey, wallets[2].addr, safety_checks=False, tx_fee=500*5)
    if 'error' in resp:
        print resp
        return False

    # begin epoch 3 (grace period)
    testlib.next_block(**kw) # end of 697

    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20)
    if 'error' not in resp:
        print resp
        return False

    # should go through, but be rejected
    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20, safety_checks=False, tx_fee=500*5)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw) # 698
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))

    # should NOT have gone through 
    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['last_transaction_height'] != last_transaction_height:
        print 'accidentally registered'
        return False

    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20)
    if 'error' not in resp:
        print resp
        return False

    # should go through, but be rejected
    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20, safety_checks=False, tx_fee=500*5)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw) # 699
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['last_transaction_height'] != last_transaction_height:
        print 'accidentally registered'
        return False

    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20)
    if 'error' not in resp:
        print resp
        return False

    # should go through, but be rejected
    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20, safety_checks=False, tx_fee=500*5)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw) # 700
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['last_transaction_height'] != last_transaction_height:
        print 'accidentally registered'
        return False

    # should go through, but be rejected (expired preorder)
    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20, safety_checks=False)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw) # end of 701 (end of grace period)
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))
   
    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' not in whois:
        print whois
        return False

    # should go through, and be rejected (expired preorder)
    resp = testlib.blockstack_name_register("foo.test", wallets[1].privkey, wallets[2].addr, zonefile_hash='44' * 20)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw) # 702 (name can be registered again)
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' not in whois:
        print whois
        return False

    # should go through, but fail (expired preorder) 
    resp = testlib.blockstack_name_register("foo.test", wallets[3].privkey, wallets[0].addr, zonefile_hash='33' * 20)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw) # 703
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))
    
    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' not in whois:
        print whois
        return False
def scenario(wallets, **kw):

    global first_name_block
    test_proxy = testlib.make_proxy()

    # make a test namespace
    resp = testlib.blockstack_namespace_preorder("test", wallets[1].addr,
                                                 wallets[0].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # end of 689

    resp = testlib.blockstack_namespace_reveal(
        "test", wallets[1].addr, 2, 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 resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # 690

    # make a zonefile and a profile
    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=4200)

    # make a new keyfile as well
    user_profile = blockstack_client.user.make_empty_user_profile()
    '''
    res = blockstack_client.key_file.make_initial_key_file(user_profile, wallets[3].privkey)
    if 'error' in res:
        print res
        return res

    keyfile_txt = res['key_file']
    '''
    zonefile_hash = blockstack_client.get_zonefile_data_hash(zonefile_txt)

    resp = testlib.blockstack_name_import("foo.test", wallets[3].addr,
                                          zonefile_hash, wallets[1].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # 691

    # broadcast zonefile
    res = testlib.blockstack_cli_sync_zonefile('foo.test',
                                               zonefile_string=zonefile_txt)
    if 'error' in res:
        print res
        return False
    '''
    # upload keyfile
    res = blockstack_client.key_file.key_file_put('foo.test', keyfile_txt)
    if 'error' in res:
        print res
        return False
    '''

    rc = blockstack_client.profile.put_profile(
        'foo.test',
        user_profile,
        blockchain_id='foo.test',
        user_data_privkey=wallets[4].privkey,
        user_zonefile=zonefile,
        proxy=test_proxy)
    if not rc:
        print 'failed to put profile'
        return False

    # try lookup
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' in res:
        print res
        return False

    first_name_block = testlib.get_current_block(**kw)

    resp = testlib.blockstack_namespace_ready("test", wallets[1].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    # try lookup
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)  # end of 692

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print 'failed to whois foo.test'
        print json.dumps(whois, indent=4)
        return False

    # this should be the second-to-last block
    if whois['expire_block'] != testlib.get_current_block(**kw) + 2:
        print 'wrong expire block (expect 2 more)'
        print whois
        return False

    # try lookup
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)  # end of 693; begin epoch 2
    # begin epoch 2

    # try lookup
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)  # 694

    # try lookup
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' in res:
        print res
        return False

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print 'failed to whois foo.test'
        print json.dumps(whois, indent=4)
        return False

    # this should be the last block
    if whois['expire_block'] != testlib.get_current_block(**kw) + 2:
        print 'wrong expire block (expect 2 more)'
        print whois
        return False

    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 2:
        print 'wrong renewal block (expect 2 more)'
        print whois
        return False

    print whois

    testlib.next_block(**kw)  # 695 (epoch 3 begins)

    # try lookup
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)  # end of 696

    # try lookup (should fail)
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' not in res:
        print res
        return False

    if 'expired' not in res['error']:
        print res
        return False

    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    # this should be the expire block
    if whois['expire_block'] != testlib.get_current_block(**kw):
        print 'wrong expire block (now at {})'.format(
            testlib.get_current_block(**kw))
        print whois
        return False

    # should now be a grace period
    if whois['renewal_deadline'] != testlib.get_current_block(**kw) + 5:
        print 'wrong renewal block (now at {})'.format(
            testlib.get_current_block(**kw))
        print whois
        return False

    last_transaction_height = whois['last_transaction_height']

    # begin epoch 3 (grace period)
    testlib.next_block(**kw)  # end of 697

    # try lookup (should fail)
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' not in res:
        print res
        return False

    if 'expired' not in res['error']:
        print res
        return False

    testlib.next_block(**kw)  # 698

    # try lookup (should fail)
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' not in res:
        print res
        return False

    if 'expired' not in res['error']:
        print res
        return False

    testlib.next_block(**kw)  # 699

    # try lookup (should fail)
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' not in res:
        print res
        return False

    if 'expired' not in res['error']:
        print res
        return False

    testlib.next_block(**kw)  # 700

    # try lookup (should fail)
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' not in res:
        print res
        return False

    if 'expired' not in res['error']:
        print res
        return False

    # make a zonefile and a profile
    driver_urls = blockstack_client.storage.make_mutable_data_urls(
        'foo.test', use_only=['dht', 'disk'])
    new_zonefile = blockstack_client.zonefile.make_empty_zonefile(
        'foo.test', wallets[4].pubkey_hex, urls=driver_urls)
    new_zonefile_txt = blockstack_zones.make_zone_file(new_zonefile,
                                                       origin='foo.test',
                                                       ttl=4200)

    # make a new keyfile as well
    new_user_profile = blockstack_client.user.make_empty_user_profile()
    new_user_profile['new_user'] = True
    '''
    res = blockstack_client.key_file.make_initial_key_file(new_user_profile, wallets[0].privkey)
    if 'error' in res:
        print res
        return res

    new_keyfile_txt = res['key_file']
    '''
    new_zonefile_hash = blockstack_client.get_zonefile_data_hash(
        new_zonefile_txt)

    rc = blockstack_client.profile.put_profile(
        'foo.test',
        new_user_profile,
        blockchain_id='foo.test',
        user_data_privkey=wallets[4].privkey,
        user_zonefile=new_zonefile,
        proxy=test_proxy)
    if not rc:
        print 'failed to put profile'
        return False

    # renew/xfer/update
    resp = testlib.blockstack_name_renew('foo.test',
                                         wallets[3].privkey,
                                         zonefile_hash=new_zonefile_hash,
                                         recipient_addr=wallets[0].addr)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw)  # end of 701 (end of grace period)

    # try lookup (should succeed again)
    res = testlib.blockstack_cli_lookup('foo.test')
    if 'error' in res:
        print res
        return False

    if res['zonefile'] != new_zonefile_txt:
        print 'wrong zonefile'
        print new_zonefile_txt
        print res
        return False

    testlib.next_block(**kw)  # 702 (name can be registered again)