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 )

    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 )

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

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

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

    global reveal_blocks, reveal_block

    for count in xrange(0, 3):
        resp = testlib.blockstack_namespace_preorder( "test", wallets[count+1].addr, wallets[count].privkey )
        if 'error' in resp:
            print json.dumps(resp, indent=4)

        testlib.next_block( **kw )

        # reveal it  
        buckets = [count] * 16
        testlib.blockstack_namespace_reveal( "test", wallets[count+1].addr, count + 1, count + 1, count + 1, buckets, count + 1, count + 1, wallets[count].privkey )
        testlib.next_block( **kw )

        reveal_blocks.append( testlib.get_current_block(**kw) )

        # expire it (2 blocks later)
        for i in xrange(0, 3): 
            testlib.next_block( **kw )

        # try to ready it (should fail)
        resp = testlib.blockstack_namespace_ready( "test", wallets[count+1].privkey )
        if 'error' in resp:
            print json.dumps(resp, indent=4)

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

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

    # NOTE: names expire in 5 * NAMESPACE_LIFETIME_MULTIPLER blocks
    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 )
    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 )

    first_preorder = testlib.get_current_block( **kw )

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

    for i in xrange(0, 5 * blockstack_server.config.get_epoch_namespace_lifetime_multiplier( testlib.get_current_block(**kw), "test" )):
        testlib.next_block( **kw )

    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 )

    last_first_block = testlib.get_current_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 )

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

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

    testlib.next_block( **kw )

    global snv_consensus, snv_block_id
    snv_block_id = testlib.get_current_block()
    snv_consensus = testlib.get_consensus_at( snv_block_id )

    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 )

    # update and transfer back and forth a few times
    for i in xrange(0, 5):

        result = testlib.blockstack_name_update( "foo.test", str(i) * 40, wallets[3 + (i%2)].privkey )
        update_hashes.append( str(i) * 40 )
        testlib.next_block( **kw )

        result = testlib.blockstack_name_transfer( "foo.test", wallets[3 + ((i+1)%2)].addr, True, wallets[3 + (i%2)].privkey )
        testlib.next_block( **kw )
def scenario( wallets, **kw ):

    global snv_block_id, last_consensus

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

    # NOTE: names expire in 13 blocks
    testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 13, 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 )

    snv_block_id = testlib.get_current_block()
    
    for i in xrange(0, 15):
        testlib.next_block( **kw )

    last_consensus = testlib.get_consensus_at( testlib.get_current_block() )
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 )

    # will all be rejected trivially, since the first import must come from the importer's address
    testlib.blockstack_name_import( "foo.test", wallets[4].addr, "11" * 20, wallets[2].privkey )
    testlib.blockstack_name_import( "bar.test", wallets[2].addr, "22" * 20, wallets[3].privkey )
    testlib.blockstack_name_import( "baz.test", wallets[3].addr, "33" * 20, wallets[4].privkey )
    testlib.next_block( **kw )
   
    # will be accepted 
    testlib.blockstack_name_import( "goo.test", wallets[2].addr, "11" * 20, wallets[1].privkey )
    
    # will all be rejected because they weren't sent from a importer-derived key
    testlib.blockstack_name_import( "foo.test", wallets[4].addr, "11" * 20, wallets[2].privkey )
    testlib.blockstack_name_import( "bar.test", wallets[2].addr, "22" * 20, wallets[3].privkey )
    testlib.blockstack_name_import( "baz.test", wallets[3].addr, "33" * 20, wallets[4].privkey )
    testlib.next_block( **kw )
    
    testlib.blockstack_namespace_ready( "test", wallets[1].privkey )
    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 )

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

    testlib.next_block( **kw )

    resp = testlib.blockstack_name_import( "foo.test", addr_reencode("1ARVjrtKnUVWt2GNrpuFLnNCL2WGUhKdkW"), "33" * 20, wallets[3].privkey )    # derived child 2
    if 'error' in resp:
        print json.dumps(resp, indent=4 )

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )
    
    testlib.blockstack_namespace_ready( "test", wallets[1].privkey )
    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 )

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

    # has to be the same key that registered...
    resp = testlib.blockstack_name_renew( "foo.test", wallets[4].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

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

    global snv_block_id, last_consensus

    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 )
    
    snv_block_id = testlib.get_current_block()

    resp = testlib.blockstack_name_revoke( "foo.test", wallets[3].privkey )
    testlib.next_block( **kw )

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

    global put_result, wallet_keys, datasets, zonefile_hash, dataset_change

    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 )

    test_proxy = testlib.TestAPIProxy()
    blockstack_client.set_default_proxy( test_proxy )
    wallet_keys = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey )

    # migrate profile
    res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys )
    if 'error' in res:
        res['test'] = 'Failed to initialize foo.test profile'
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return 
    else:
        zonefile_hash = res['zonefile_hash']

    testlib.next_block( **kw )

    put_result = blockstack_client.put_mutable( "foo.test", "hello_world_1", datasets[0], proxy=test_proxy, wallet_keys=wallet_keys )
    if 'error' in put_result:
        print json.dumps(put_result, indent=4, sort_keys=True)

    testlib.next_block( **kw )

    put_result = blockstack_client.put_mutable( "foo.test", "hello_world_2", datasets[1], proxy=test_proxy, wallet_keys=wallet_keys )
    if 'error' in put_result:
        print json.dumps(put_result, indent=4, sort_keys=True)

    put_result = blockstack_client.put_mutable( "foo.test", "hello_world_3", datasets[2], proxy=test_proxy, wallet_keys=wallet_keys )
    if 'error' in put_result:
        print json.dumps(put_result, indent=4, sort_keys=True)

    # increment version too
    datasets[0]['buf'] = []
    for i in xrange(0, 5):
        datasets[0]["dataset_change"] = dataset_change
        datasets[0]['buf'].append(i)

        put_result = blockstack_client.put_mutable( "foo.test", "hello_world_1", datasets[0], proxy=test_proxy, wallet_keys=wallet_keys )
        if 'error' in put_result:
            print json.dumps(put_result, indent=4, sort_keys=True )

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

    global txids
    global consensuses

    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 )

    testlib.next_block( **kw )
    # do a sequence of updates, every other block
    for i in xrange( 0, 20 ):

        if (i % 2) != 0:
            update_hash = ("%02x" % (i)) * 20
            resp = testlib.blockstack_name_update( "foo.test", update_hash, wallets[3].privkey )

            txids[ update_hash ] = resp['transaction_hash']
            consensuses[ update_hash ] = testlib.get_consensus_at( testlib.get_current_block( **kw ), **kw )

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

    testlib.blockstack_name_update( "foo.test", "11" * 20, wallets[3].privkey )
    testlib.next_block( **kw )

    consensus_hash = testlib.get_consensus_at( testlib.get_current_block( **kw ), **kw )

    # lots of blocks later...
    for i in xrange(0, 50):
        testlib.next_block( **kw )

    # update with stale consensus hash (should fail)
    print "\n\nsend update with consensus hash %s\n\n" % consensus_hash
    testlib.blockstack_name_update( "foo.test", "22" * 20, wallets[3].privkey, consensus_hash=consensus_hash )
    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 )

    testlib.blockstack_name_update( "foo.test", "11" * 20, wallets[3].privkey )
    testlib.next_block( **kw )

    # should fail--can't give a name to yourself
    testlib.blockstack_name_transfer( "foo.test", wallets[4].addr, True, wallets[4].privkey ) 
    testlib.next_block( **kw )
    
    # should fail--can't steal a name
    testlib.blockstack_name_transfer( "foo.test", wallets[4].addr, True, wallets[0].privkey ) 
    testlib.next_block( **kw )
def scenario( wallets, **kw ):

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

    testlib.blockstack_namespace_reveal( "id", 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( "id", wallets[1].privkey )
    testlib.next_block( **kw )

    testlib.blockstack_name_preorder( "judecn.id", wallets[2].privkey, wallets[3].addr )
    testlib.next_block( **kw )

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

    resp = testlib.blockstack_announce( "hello world!", wallets[3].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

    resp = testlib.blockstack_announce( "This should not appear", wallets[4].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

    # save...
    working_dir = testlib.get_working_dir( **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 )

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

    testlib.next_block( **kw )

    # wait for it to expire (takes a day) 
    for i in xrange(0, 145):
        testlib.next_block( **kw )

    # re-preorder it 
    resp = testlib.blockstack_name_preorder( "foo.test", wallets[3].privkey, wallets[4].addr )
    if 'error' in resp:
        print json.dumps( resp )

    testlib.next_block( **kw )

    # register it 
    resp = testlib.blockstack_name_register( "foo.test", wallets[3].privkey, wallets[4].addr )
    if 'error' in resp:
        print json.dumps( resp )

    testlib.next_block( **kw )
def scenario( wallets, **kw ): 
    resp = testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey )
    if 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block( **kw )

    # reveal it  
    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 )

    # import some names
    testlib.blockstack_name_import( "foo.test", wallets[2].addr, "11" * 20, wallets[1].privkey )
    testlib.blockstack_name_import( "bar.test", wallets[3].addr, "22" * 20, wallets[1].privkey )
    testlib.blockstack_name_import( "baz.test", wallets[4].addr, "33" * 20, wallets[1].privkey )
    testlib.next_block( **kw )

    # expire it (1 day later)
    for i in xrange(0, 145): 
        testlib.next_block( **kw )

    # try to ready it (should fail)
    resp = testlib.blockstack_namespace_ready( "test", wallets[1].privkey )
    if 'error' in resp:
        print json.dumps(resp, indent=4)

    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, 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 )

    # preorder, register, expire (multiple times)
    for i in xrange(2, 5):
        resp = testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr )
        if 'error' in resp:
            print json.dumps( resp, indent=4 )

        testlib.next_block( **kw )
    
        resp = testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr )
        if 'error' in resp:
            print json.dumps( resp, indent=4 )

        testlib.next_block( **kw )

        if i == 4:
            break

        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, 10, 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 )
    consensus_hash = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw)
    testlib.next_block( **kw )
    testlib.next_block( **kw )

    # preorder, register, update, expire (multiple times)
    for i in xrange(2, 11):
        resp = testlib.blockstack_name_preorder( "foo.test", wallets[i].privkey, wallets[(i+1)%11].addr, consensus_hash=consensus_hash )
        if 'error' in resp:
            print json.dumps( resp, indent=4 )

        testlib.next_block( **kw )
        consensus_hash = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw)
        testlib.next_block( **kw )
        testlib.next_block( **kw )
   
        resp = testlib.blockstack_name_register( "foo.test", wallets[i].privkey, wallets[(i+1)%11].addr )
        if 'error' in resp:
            print json.dumps( resp, indent=4 )

        testlib.next_block( **kw )
        consensus_hash = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw)
        testlib.next_block( **kw )
        testlib.next_block( **kw )

        resp = testlib.blockstack_name_transfer( "foo.test", wallets[i].addr, True, wallets[(i+1)%11].privkey, consensus_hash=consensus_hash )
        if 'error' in resp:
            print json.dumps( resp, indent=4 )

        testlib.next_block( **kw )
        consensus_hash = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw)
        testlib.next_block( **kw )
        testlib.next_block( **kw )
        
        resp = testlib.blockstack_name_update( "foo.test", ("%02x" % i) * 20, wallets[i].privkey, consensus_hash=consensus_hash )
        if 'error' in resp:
            print json.dumps( resp, indent=4 )

        testlib.next_block( **kw )
        consensus_hash = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw)
        testlib.next_block( **kw )
        testlib.next_block( **kw )

        if i == 10:
            break

        testlib.next_block( **kw )
        consensus_hash = testlib.get_consensus_at( testlib.get_current_block(**kw), **kw)
        testlib.next_block( **kw )
        testlib.next_block( **kw )
def scenario( wallets, **kw ):

    global fail_blocks

    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( "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 it to expire...
    for i in xrange(0, 2 * NAMESPACE_LIFETIME_MULTIPLIER + 1):
        testlib.next_block( **kw )

    # verify that operations fail
    resp = testlib.blockstack_name_update( "foo.test", "11" * 20, wallets[3].privkey, safety_checks=False )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

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

    # should fail
    resp = testlib.blockstack_name_transfer( "foo.test", wallets[4].addr, True, wallets[3].privkey, safety_checks=False )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

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

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

    testlib.next_block( **kw )
    fail_blocks.append( testlib.get_current_block( **kw ) )
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))
    
    # should fail 
    resp = testlib.blockstack_name_revoke( "foo.test", wallets[3].privkey, safety_checks=False )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )
    fail_blocks.append( testlib.get_current_block( **kw ))
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))
def scenario( wallets, **kw ):

    global wallet_keys, wallet_keys_2, key_names, error


    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 )

    test_proxy = testlib.TestAPIProxy()
    blockstack_client.set_default_proxy( test_proxy )
    wallet_keys = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey, data_privkey=wallets[4].privkey )

    # migrate profiles 
    res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys )
    if 'error' in res:
        res['test'] = 'Failed to initialize foo.test profile'
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return 

    testlib.next_block( **kw )

    # make an account 
    res = blockstack_client.put_account("foo.test", "serviceFoo", "serviceFooID", "foo://bar.com", proxy=test_proxy, wallet_keys=wallet_keys, foofield="foo!" )
    if 'error' in res:
        res['test'] = 'Failed to create foo.test account'
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return 

    res = blockstack_client.put_account("foo.test", "deletedService", "deletedServiceID", "foo://deleted", proxy=test_proxy, wallet_keys=wallet_keys, barfield="bar!") 
    if 'error' in res:
        res['test'] = 'Failed to create foo.test deletedService account'
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return 

    # delete an account 
    res = blockstack_client.delete_account("foo.test", "deletedService", "deletedServiceID", proxy=test_proxy, wallet_keys=wallet_keys )
    if 'error' in res:
        res['test'] = 'Failed to delete foo.test deletedService'
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return

    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, 4, 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 )

    # preorder, register, update, expire (twice; should fail the second time)
    for i in xrange(2, 4):
        resp = testlib.blockstack_name_preorder( "foo.test", wallets[i].privkey, wallets[(i+1)%11].addr )
        if 'error' in resp:
            print json.dumps( resp, indent=4 )

        testlib.next_block( **kw )
   
        resp = testlib.blockstack_name_register( "foo.test", wallets[i].privkey, wallets[(i+1)%11].addr )
        if 'error' in resp:
            print json.dumps( resp, indent=4 )

        if i == 3:
           testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))

        testlib.next_block( **kw )

        resp = testlib.blockstack_name_update( "foo.test", ("%02x" % i) * 20, wallets[(i+1)%11].privkey )
        if 'error' in resp:
            print json.dumps( resp, indent=4 )

        if i == 3:
           testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))

        testlib.next_block( **kw )

        resp = testlib.blockstack_name_transfer( "foo.test", wallets[i].addr, True, wallets[(i+1)%11].privkey )
        if 'error' in resp:
            print json.dumps( resp, indent=4 )

        if i == 3:
           testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))

        testlib.next_block( **kw )
       
        resp = testlib.blockstack_name_renew( "foo.test", wallets[i].privkey )
        if 'error' in resp:
            print json.dumps( resp, indent=4 )

        if i == 3:
           testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))

        if i == 3:
            break

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

    global zonefile_hash

    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, None )
    resp = testlib.blockstack_rpc_register( "foo.test", "0123456789abcdef" )
    if 'error' in resp:
        print >> sys.stderr, json.dumps(resp, indent=4, sort_keys=True)
        return False
   
    # wait for the preorder to get confirmed
    for i in xrange(0, 12):
        testlib.next_block( **kw )

    # wait for the poller to pick it up
    print >> sys.stderr, "Waiting 10 seconds for the backend to submit the register"
    time.sleep(10)

    # wait for the register to get confirmed 
    for i in xrange(0, 12):
        testlib.next_block( **kw )

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

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

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

    # transfer to a new address 
    resp = testlib.blockstack_rpc_transfer( "foo.test", wallets[4].addr, "0123456789abcdef" )

    if 'error' in resp:
        print >> sys.stderr, "transfer error: %s" % resp['error']
        return False

    # wait for it to go through 
    for i in xrange(0, 12):
        testlib.next_block( **kw )

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

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

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

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

    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 )

    # can't re-create test 
    resp = testlib.blockstack_namespace_preorder( "test", wallets[3].addr, wallets[4].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

    # can't re-reveal test
    resp = testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 252, 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 )

    testlib.next_block( **kw )

    # can't re-ready test 
    resp = testlib.blockstack_namespace_ready( "test", wallets[1].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )
    
    # warn the serialization checker that this changes behavior from 0.13
    print "BLOCKSTACK_SERIALIZATION_CHANGE_BEHAVIOR"
    sys.stdout.flush()
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 )

    wallet = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey )
    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, 12):
        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, 12):
        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, 12):
        testlib.next_block( **kw )

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

    # let's make sure the zonefile propagates...

    res = testlib.blockstack_REST_call("GET", "/v1/names/foo.test", None)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get name bar.test'
        print json.dumps(res)
        return False

    response_json = json.loads(res['raw'])

    # assert that we're getting a mainnet address
    if response_json['address'] != "1K4SCfqffVHTnHvqsW2whH1Jn57dDjDdQA":
        print "Address returned to REST call isn't converted to mainnet!"
        print "Returned: {}, Expected: {}".format(response_json['address'], "1K4SCfqffVHTnHvqsW2whH1Jn57dDjDdQA")
        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, 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 )

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

    testlib.next_block( **kw )

    # no name operations should work on this name, except register
    resp = testlib.blockstack_name_update( "foo.test", "11" * 20, wallets[3].privkey, safety_checks=False )
    if 'error' in resp:
        print json.dumps(resp)

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

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

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

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

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

    # try both addresses (should both fail)
    resp = testlib.blockstack_name_revoke( "foo.test", wallets[4].privkey, safety_checks=False)
    if 'error' in resp:
        print json.dumps(resp)

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

    resp = testlib.blockstack_name_revoke( "foo.test", wallets[3].privkey, safety_checks=False )
    if 'error' in resp:
        print json.dumps(resp)
   
    testlib.next_block( **kw )
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))
def scenario( wallets, **kw ):

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

    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 )

    snv_block_id_foo = testlib.get_current_block()

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

    bar_preorder = testlib.blockstack_name_preorder( "bar.test", wallets[4].privkey, wallets[5].addr )
    testlib.next_block( **kw )
    
    snv_serial_number_bar = "%s-%s" % (testlib.get_current_block(), 0 )
    snv_txid_bar = bar_preorder['transaction_hash']

    testlib.blockstack_name_register( "bar.test", wallets[4].privkey, wallets[5].addr )
    testlib.next_block( **kw )

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

    baz_preorder = testlib.blockstack_name_preorder( "baz.test", wallets[6].privkey, wallets[7].addr )
    testlib.next_block( **kw )
    
    snv_serial_number_baz = "%s-%s" % (testlib.get_current_block(), 0 )
    snv_txid_baz = baz_preorder['transaction_hash']

    testlib.blockstack_name_register( "baz.test", wallets[6].privkey, wallets[7].addr )
    testlib.next_block( **kw )

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

    global reveal_block
    global preorder_block 

    testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey )
    preorder_block = testlib.get_current_block( **kw ) + 1
    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 )
    reveal_block = testlib.get_current_block( **kw ) + 1

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

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

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

    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 )

    # can't re-create test 
    resp = testlib.blockstack_namespace_preorder( "test", wallets[3].addr, wallets[4].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

    # can't re-reveal test
    resp = testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 252, 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 )

    testlib.next_block( **kw )

    # can't re-ready test 
    resp = testlib.blockstack_namespace_ready( "test", wallets[1].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )
Exemple #31
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 )
    
    # will send these later
    initial_zonefiles = zonefiles

    # send updates too
    for i in range(0, 3):
        zf_template = "$ORIGIN {}\n$TTL 3600\n{}"
        zf_default_url = '_https._tcp URI 10 1 "https://test.com/?index={}"'.format(i+1)

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

        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 (nothing should happen)
    testlib.next_block(**kw)
    
    # send initial zonefiles
    assert testlib.blockstack_put_zonefile(initial_zonefiles['foo1.test'])
    assert testlib.blockstack_put_zonefile(initial_zonefiles['foo2.test'])
    assert testlib.blockstack_put_zonefile(initial_zonefiles['foo3.test'])

    # now kick it off again
    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)
Exemple #32
0
def scenario(wallets, **kw):

    global wallet_keys, wallet_keys_2, error, index_file_data, resource_data

    wallet_keys = testlib.blockstack_client_initialize_wallet(
        "0123456789abcdef", wallets[5].privkey, wallets[3].privkey,
        wallets[4].privkey)
    test_proxy = testlib.TestAPIProxy()
    blockstack_client.set_default_proxy(test_proxy)

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

    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)

    # migrate profiles
    res = testlib.migrate_profile("foo.test",
                                  proxy=test_proxy,
                                  wallet_keys=wallet_keys)
    if 'error' in res:
        res['test'] = 'Failed to initialize foo.test profile'
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return

    # tell serialization-checker that value_hash can be ignored here
    print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
    sys.stdout.flush()

    testlib.next_block(**kw)

    config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None)

    # make a session
    datastore_pk = keylib.ECPrivateKey(wallets[-1].privkey).to_hex()
    res = testlib.blockstack_cli_app_signin(
        "foo.test", datastore_pk, 'register.app', [
            'names', 'register', 'prices', 'zonefiles', 'blockchain',
            'node_read'
        ])
    if 'error' in res:
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return

    ses = res['token']

    # for funsies, get the price of .test
    res = testlib.blockstack_REST_call('GET', '/v1/prices/namespaces/test',
                                       ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get price of .test'
        print json.dumps(res)
        return False

    test_price = res['response']['satoshis']
    print '\n\n.test costed {} satoshis\n\n'.format(test_price)

    # get the price for bar.test
    res = testlib.blockstack_REST_call('GET', '/v1/prices/names/bar.test', ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get price of bar.test'
        print json.dumps(res)
        return False

    bar_price = res['response']['total_estimated_cost']['satoshis']
    print "\n\nbar.test will cost {} satoshis\n\n".format(bar_price)

    # register the name bar.test. autogenerate the rest
    res = testlib.blockstack_REST_call('POST',
                                       '/v1/names',
                                       ses,
                                       data={'name': 'bar.test'})
    if 'error' in res:
        res['test'] = 'Failed to register user'
        print json.dumps(res)
        error = True
        return False

    print res
    tx_hash = res['response']['transaction_hash']

    # wait for preorder to get confirmed...
    for i in xrange(0, 6):
        testlib.next_block(**kw)

    res = testlib.verify_in_queue(ses, 'bar.test', 'preorder', tx_hash)
    if not res:
        return False

    # wait for the preorder to get confirmed
    for i in xrange(0, 6):
        testlib.next_block(**kw)

    # wait for register to go through
    print 'Wait for register to be submitted'
    time.sleep(10)

    # wait for the register to get confirmed
    for i in xrange(0, 6):
        testlib.next_block(**kw)

    res = testlib.verify_in_queue(ses, 'bar.test', 'register', None)
    if not res:
        return False

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

    print 'Wait for update to be submitted'
    time.sleep(10)

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

    res = testlib.verify_in_queue(ses, 'bar.test', 'update', None)
    if not res:
        return False

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

    print 'Wait for update to be confirmed'
    time.sleep(10)

    res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test", ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get name bar.test'
        print json.dumps(res)
        return False

    zonefile_hash = res['response']['zonefile_hash']
    old_expire_block = res['response']['expire_block']

    # renew it
    res = testlib.blockstack_REST_call("POST",
                                       "/v1/names",
                                       ses,
                                       data={'name': 'bar.test'})
    if 'error' in res or res['http_status'] != 202:
        res['test'] = 'Failed to transfer name'
        print json.dumps(res)
        return False

    # verify in renew queue
    for i in xrange(0, 6):
        testlib.next_block(**kw)

    res = testlib.verify_in_queue(ses, 'bar.test', 'renew', None)
    if not res:
        return False

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

    # new expire block
    res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test", ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get name bar.test'
        print json.dumps(res)
        return False

    new_expire_block = res['response']['expire_block']

    # do we have the history for the name?
    res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test/history",
                                       ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = "Failed to get name history for bar.test"
        print json.dumps(res)
        return False

    # valid history?
    hist = res['response']
    if len(hist.keys()) != 4:
        res['test'] = 'Failed to get update history'
        res['history'] = hist
        print json.dumps(res, indent=4, sort_keys=True)
        return False

    # get the zonefile
    res = testlib.blockstack_REST_call(
        "GET", "/v1/names/bar.test/zonefile/{}".format(zonefile_hash), ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get name zonefile'
        print json.dumps(res)
        return False

    # verify pushed back
    if old_expire_block + 12 >= new_expire_block:
        # didn't go through
        print >> sys.stderr, "Renewal didn't work: %s --> %s" % (
            old_expire_block, new_expire_block)
        return False
Exemple #33
0
def scenario( wallets, **kw ):

    global debug

    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 )
    consensus_hash = testlib.get_consensus_at( testlib.get_current_block( **kw ), **kw )
    testlib.next_block( **kw )
    testlib.next_block( **kw )

    resp = 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 )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )
    consensus_hash = testlib.get_consensus_at( testlib.get_current_block( **kw ), **kw )
    testlib.next_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 )
    consensus_hash = testlib.get_consensus_at( testlib.get_current_block( **kw ), **kw )
    testlib.next_block( **kw )
    testlib.next_block( **kw )

    resp = testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr, consensus_hash=consensus_hash )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )
    consensus_hash = testlib.get_consensus_at( testlib.get_current_block( **kw ), **kw )
    testlib.next_block( **kw )
    testlib.next_block( **kw )
    
    resp = testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )
    consensus_hash = testlib.get_consensus_at( testlib.get_current_block( **kw ), **kw )
    testlib.next_block( **kw )
    testlib.next_block( **kw )

    resp = testlib.blockstack_name_transfer( "foo.test", wallets[4].addr, True, wallets[3].privkey, consensus_hash=consensus_hash ) 
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )
    consensus_hash = testlib.get_consensus_at( testlib.get_current_block( **kw ), **kw )
    testlib.next_block( **kw )
    testlib.next_block( **kw )

    resp = testlib.blockstack_name_update( "foo.test", "11" * 20, wallets[4].privkey, consensus_hash=consensus_hash )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )
    testlib.next_block( **kw )
    testlib.next_block( **kw )
Exemple #34
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

    testlib.blockstack_name_update( "foo1.test", '1a' * 20, wallets[3].privkey)
    testlib.blockstack_name_update( "foo2.test", '2a' * 20, wallets[3].privkey)
    testlib.blockstack_name_update( "foo3.test", '3a' * 20, wallets[3].privkey)
    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

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

    global wallet_keys, error, index_file_data, resource_data

    test_proxy = testlib.TestAPIProxy()
    blockstack_client.set_default_proxy(test_proxy)
    wallet_keys = blockstack_client.make_wallet_keys(
        owner_privkey=wallets[3].privkey,
        data_privkey=wallets[4].privkey,
        payment_privkey=wallets[5].privkey)
    testlib.blockstack_client_set_wallet("0123456789abcdef",
                                         wallet_keys['payment_privkey'],
                                         wallet_keys['owner_privkey'],
                                         wallet_keys['data_privkey'])

    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)

    # migrate profiles
    res = testlib.migrate_profile("foo.test",
                                  proxy=test_proxy,
                                  wallet_keys=wallet_keys)
    if 'error' in res:
        res['test'] = 'Failed to initialize foo.test profile'
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return

    res = testlib.start_api("0123456789abcdef")
    if 'error' in res:
        print 'failed to start API: {}'.format(res)
        return False

    # tell serialization-checker that value_hash can be ignored here
    print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
    sys.stdout.flush()

    testlib.next_block(**kw)

    # sign in and make a token
    datastore_pk = keylib.ECPrivateKey(wallets[-1].privkey).to_hex()
    res = testlib.blockstack_cli_app_signin(
        "foo.test", datastore_pk, 'http://localhost:8888',
        ['store_read', 'store_write', 'store_admin'])
    if 'error' in res:
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return

    # export to environment
    blockstack_client.set_secret("BLOCKSTACK_API_SESSION", res['token'])

    ses = res['token']

    datastore_id_res = testlib.blockstack_cli_datastore_get_id(datastore_pk)
    datastore_id = datastore_id_res['datastore_id']

    # use random data for file
    file_data = None
    with open('/dev/urandom', 'r') as f:
        file_data = f.read(16384)

    # make datastore
    res = testlib.blockstack_cli_create_datastore('foo.test', datastore_pk,
                                                  ['disk'], ses)
    if 'error' in res:
        print "failed to create datastore: {}".format(res['error'])
        return False

    # make directories
    for dpath in ['/dir1', '/dir2', '/dir1/dir3', '/dir1/dir3/dir4']:
        print 'mkdir {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_mkdir("foo.test", datastore_pk,
                                                     dpath, ses)
        if 'error' in res:
            print 'failed to mkdir {}: {}'.format(dpath, res['error'])
            return False

    # make directories again (should fail with EEXIST)
    for dpath in ['/dir1', '/dir2', '/dir1/dir3', '/dir1/dir3/dir4']:
        print 'mkdir {} (should fail)'.format(dpath)
        res = testlib.blockstack_cli_datastore_mkdir("foo.test", datastore_pk,
                                                     dpath, ses)
        if 'error' not in res:
            print 'accidentally succeeded to mkdir {}: {}'.format(dpath, res)
            return False

        if not res.has_key('errno'):
            print 'no errno in error {}'.format(res)
            return False

        if res['errno'] != errno.EEXIST:
            print 'wrong errno in error {}'.format(res)
            return False

    # stat directories
    for dpath in ['/dir1', '/dir2', '/dir1/dir3', '/dir1/dir3/dir4']:
        print 'stat {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_stat("foo.test", datastore_id,
                                                    dpath, None)
        if 'error' in res:
            print 'failed to stat {}: {}'.format(dpath, res['error'])
            return False

        if res['type'] != blockstack_client.schemas.MUTABLE_DATUM_DIR_TYPE:
            print 'not a directory: {}, {}'.format(dpath, res)
            return False

    # list directories
    for dpath, expected in [('/', ['dir1', 'dir2']), ('/dir1', ['dir3']),
                            ('/dir1/dir3', ['dir4']), ('/dir1/dir3/dir4', [])]:
        print 'listdir {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_listdir("foo.test",
                                                       datastore_id, dpath,
                                                       None)
        if 'error' in res:
            print 'failed to listdir {}: {}'.format(dpath, res['error'])
            return False

        print res
        if len(res['children'].keys()) != len(expected):
            print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format(
                expected, res)
            return False

        for child in expected:
            if not res['children'].has_key(child):
                print 'invalid directory: missing {} in {}'.format(child, res)
                return False

    # put files
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'putfile {}'.format(dpath)
        data = '{} hello {}'.format(file_data, dpath)
        res = testlib.blockstack_cli_datastore_putfile("foo.test",
                                                       datastore_pk, dpath,
                                                       data, ses)
        if 'error' in res:
            print 'failed to putfile {}: {}'.format(dpath, res['error'])
            return False

    # stat files
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'stat {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_stat("foo.test", datastore_id,
                                                    dpath, None)
        if 'error' in res:
            print 'failed to stat {}: {}'.format(dpath, res['error'])
            return False

        if res['type'] != blockstack_client.schemas.MUTABLE_DATUM_FILE_TYPE:
            print 'not a file: {}, {}'.format(dpath, res)
            return False

    # list directories again
    for dpath, expected in [('/', ['dir1', 'dir2', 'file1', 'file2']),
                            ('/dir1', ['dir3', 'file3']),
                            ('/dir1/dir3', ['dir4', 'file4']),
                            ('/dir1/dir3/dir4', ['file5'])]:
        print 'listdir {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_listdir("foo.test",
                                                       datastore_id, dpath,
                                                       None)
        if 'error' in res:
            print 'failed to listdir {}: {}'.format(dpath, res['error'])
            return False

        if len(res['children'].keys()) != len(expected):
            print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format(
                expected, res)
            return False

        for child in expected:
            if not res['children'].has_key(child):
                print 'invalid directory: missing {} in {}'.format(child, res)
                return False

    # get files
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'getfile {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_getfile("foo.test",
                                                       datastore_id, dpath,
                                                       None)
        if 'error' in res:
            print 'failed to getfile {}: {}'.format(dpath, res['error'])
            return False

        if res != '{} hello {}'.format(file_data, dpath):
            print 'failed to read {}'.format(dpath)
            return False

    # put files again!
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'putfile {}'.format(dpath)
        data = '{} hello 2 {}'.format(file_data, dpath)
        res = testlib.blockstack_cli_datastore_putfile("foo.test",
                                                       datastore_pk, dpath,
                                                       data, ses)
        if 'error' in res:
            print 'failed to putfile {}: {}'.format(dpath, res['error'])
            return False

    # get files again!
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'getfile {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_getfile("foo.test",
                                                       datastore_id, dpath,
                                                       None)
        if 'error' in res:
            print 'failed to getfile {}: {}'.format(dpath, res['error'])
            return False

        if res != '{} hello 2 {}'.format(file_data, dpath):
            print 'failed to read {}'.format(dpath)
            return False

    # remove files
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'deletefile {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_deletefile(
            "foo.test", datastore_pk, dpath, ses)
        if 'error' in res:
            print 'failed to deletefile {}: {}'.format(dpath, res['error'])
            return False

    # stat files (should all fail)
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'stat {} (expect failure)'.format(dpath)
        res = testlib.blockstack_cli_datastore_stat("foo.test", datastore_id,
                                                    dpath, None)
        if 'error' not in res or 'errno' not in res:
            print 'accidentally succeeded to stat {}: {}'.format(dpath, res)
            return False

        if res['errno'] != errno.ENOENT:
            print 'wrong errno: {}'.format(res)
            return False

    # get files (should all fail)
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'getfile {} (expect failure)'.format(dpath)
        res = testlib.blockstack_cli_datastore_getfile("foo.test",
                                                       datastore_id, dpath,
                                                       None)
        if 'error' not in res or 'errno' not in res:
            print 'accidentally succeeded to get {}: {}'.format(dpath, res)
            return False

        if res['errno'] != errno.ENOENT:
            print 'wrong errno: {}'.format(res)
            return False

    # list directories, 3rd time
    for dpath, expected in [('/', ['dir1', 'dir2']), ('/dir1', ['dir3']),
                            ('/dir1/dir3', ['dir4']), ('/dir1/dir3/dir4', [])]:
        print 'listdir {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_listdir("foo.test",
                                                       datastore_id, dpath,
                                                       None)
        if 'error' in res:
            print 'failed to listdir {}: {}'.format(dpath, res['error'])
            return False

        if len(res['children'].keys()) != len(expected):
            print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format(
                expected, res)
            return False

        for child in expected:
            if not res['children'].has_key(child):
                print 'invalid directory: missing {} in {}'.format(child, res)
                return False

    # remove directories
    for dpath in ['/dir1/dir3/dir4', '/dir1/dir3', '/dir2', '/dir1']:
        print 'rmdir {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_rmdir("foo.test", datastore_pk,
                                                     dpath, ses)
        if 'error' in res:
            print 'failed to rmdir {}: {}'.format(dpath, res['error'])
            return False

    # stat directories (should all fail)
    for dpath in ['/dir1/dir3/dir4', '/dir1/dir3', '/dir2', '/dir1']:
        print 'stat {} (expect failure)'.format(dpath)
        res = testlib.blockstack_cli_datastore_stat("foo.test", datastore_id,
                                                    dpath, None)
        if 'error' not in res or 'errno' not in res:
            print 'accidentally succeeded to stat {}: {}'.format(dpath, res)
            return False

        if res['errno'] != errno.ENOENT:
            print 'wrong errno: {}'.format(res)
            return False

    # list directories (should all fail)
    for dpath, expected in [('/dir1', ['dir3']), ('/dir1/dir3', ['dir4']),
                            ('/dir1/dir3/dir4', [])]:
        print 'listdir {} (expect failure)'.format(dpath)
        res = testlib.blockstack_cli_datastore_listdir("foo.test",
                                                       datastore_id, dpath,
                                                       None)
        if 'error' not in res or 'errno' not in res:
            print 'accidentally succeeded to list {}: {}'.format(dpath, res)
            return False

        if res['errno'] != errno.ENOENT:
            print 'wrong errno: {}'.format(res)
            return False

    # remove directories again (should fail)
    for dpath in ['/dir1/dir3/dir4', '/dir1/dir3', '/dir2', '/dir1']:
        print 'rmdir {} (expect failure)'.format(dpath)
        res = testlib.blockstack_cli_datastore_rmdir("foo.test", datastore_pk,
                                                     dpath, ses)
        if 'error' not in res:
            print 'accidentally succeeded to rmdir twice: {}'.format(res)
            return False

        if res.get('errno') != errno.ENOENT:
            print 'wrong errno on rmdir: {}'.format(res)
            return False

    # root should be empty
    print 'listdir {}'.format('/')
    res = testlib.blockstack_cli_datastore_listdir("foo.test", datastore_id,
                                                   '/', None)
    if 'error' in res:
        print 'failed to listdir /: {}'.format(res['error'])
        return False

    if len(res['children'].keys()) > 0:
        print 'root still has children: {}'.format(res['children'].keys())
        return False

    # delete datastore
    print 'delete datastore'
    res = testlib.blockstack_cli_delete_datastore("foo.test", datastore_pk,
                                                  ses)
    if 'error' in res:
        print 'failed to delete foo-app.com datastore'
        print json.dumps(res)
        return False

    # no more data in disk driver
    names = os.listdir("/tmp/blockstack-disk/mutable")
    if names != ['foo.test']:
        print 'improper cleanup'
        return False

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

    global zonefile_hash

    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)
    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, 12):
        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(15)

    # wait for the register to get confirmed
    for i in xrange(0, 12):
        # warn the serialization checker that this changes behavior from 0.13
        print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
        sys.stdout.flush()

        testlib.next_block(**kw)

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

    # wait for initial update to get confirmed
    for i in xrange(0, 12):
        # warn the serialization checker that this changes behavior from 0.13
        print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
        sys.stdout.flush()

        testlib.next_block(**kw)

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

    # wait for zonefile posting
    for i in xrange(0, 12):
        # warn the serialization checker that this changes behavior from 0.13
        print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
        sys.stdout.flush()

        testlib.next_block(**kw)

    print >> sys.stderr, "Waiting 10 seconds for the backend to send zonefile"
    time.sleep(15)

    # what's the name's renewal block?
    proxy = testlib.make_proxy()
    res = blockstack_client.get_name_blockchain_record("foo.test", proxy=proxy)
    if 'error' in res:
        print >> sys.stderr, json.dumps(res, indent=4, sort_keys=True)
        return False

    old_expire_block = res['expire_block']

    # send an update, changing the zonefile
    data_pubkey = wallet['data_pubkey']
    zonefile = blockstack_client.zonefile.make_empty_zonefile(
        "foo.test", data_pubkey)
    blockstack_client.user.put_immutable_data_zonefile(
        zonefile,
        "testdata",
        blockstack_client.get_data_hash("testdata"),
        data_url="file:///testdata")
    zonefile_json = json.dumps(zonefile)

    resp = testlib.blockstack_cli_update("foo.test", zonefile_json,
                                         "0123456789abcdef")

    if 'error' in resp:
        print >> sys.stderr, "update error: %s" % resp['error']
        return False

    zonefile_hash = resp['zonefile_hash']

    # wait for it to go through
    for i in xrange(0, 12):
        # warn the serialization checker that this changes behavior from 0.13
        print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
        sys.stdout.flush()

        testlib.next_block(**kw)

    print >> sys.stderr, "Waiting 10 seconds for the backend to acknowedge the update"
    time.sleep(15)
    # wait for it to go through
    for i in xrange(0, 12):
        # warn the serialization checker that this changes behavior from 0.13
        print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
        sys.stdout.flush()

        testlib.next_block(**kw)

    # revoke it
    resp = testlib.blockstack_cli_revoke("foo.test", "0123456789abcdef")
    if 'error' in resp:
        print >> sys.stderr, "Revoke request failed:\n%s" % json.dumps(
            resp, indent=4, sort_keys=True)
        return False

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

    # wait for it to go through
    for i in xrange(0, 12):
        testlib.next_block(**kw)
Exemple #37
0
def scenario( wallets, **kw ):

    global wallet_keys, wallet_keys_2, error, index_file_data, resource_data, wallet_balance

    wallet_keys = testlib.blockstack_client_initialize_wallet( "0123456789abcdef", wallets[5].privkey, wallets[3].privkey, wallets[4].privkey )
    test_proxy = testlib.TestAPIProxy()
    blockstack_client.set_default_proxy( test_proxy )

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

    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 )
    
    # migrate profiles 
    res = testlib.migrate_profile( "foo.test", proxy=test_proxy, wallet_keys=wallet_keys )
    if 'error' in res:
        res['test'] = 'Failed to initialize foo.test profile'
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return 

    # tell serialization-checker that value_hash can be ignored here
    print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
    sys.stdout.flush()
    
    testlib.next_block( **kw )
    
    config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None)
    config_dir = os.path.dirname(config_path)
 
    conf = blockstack_client.get_config(config_path)
    assert conf

    api_pass = conf['api_password']

    # make sure we can do REST calls
    res = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/pending', None, api_pass=api_pass )
    if 'error' in res:
        res['test'] = 'Failed to get queues'
        print json.dumps(res)
        return False

    # make sure we can do REST calls with different app names and user names
    res = testlib.blockstack_REST_call('GET', '/v1/blockchains/bitcoin/pending', None, api_pass=api_pass )
    if 'error' in res:
        res['test'] = 'Failed to get queues'
        print json.dumps(res)
        return False

    # what's the balance?
    res = testlib.blockstack_REST_call('GET', '/v1/wallet/balance', None, api_pass=api_pass )
    if res['http_status'] != 200:
        res['test'] = 'failed to query wallet'
        print json.dumps(res)
        return False

    wallet_balance = res['response']['balance']['satoshis']
    balance_before = testlib.get_balance(wallets[8].addr)

    # can we move the funds?
    res = testlib.blockstack_REST_call('POST', '/v1/wallet/balance', None, api_pass=api_pass, data={'address': wallets[8].addr, 'amount': wallet_balance / 2, 'message': "hello world!"})
    if res['http_status'] != 200:
        res['test'] = 'failed to transfer funds'
        print json.dumps(res)
        return False

    if not res['response'].has_key('transaction_hash'):
        res['test'] = 'missing tx hash'
        print json.dumps(res)
        return False

    print "\n\nTransaction: {}\n\n".format(res['response']['transaction_hash'])

    # confirm it
    for i in xrange(0, 12):
        testlib.next_block(**kw)
  
    new_balance = testlib.get_balance(wallets[5].addr)
    balance_after = testlib.get_balance(wallets[8].addr)

    print "wallet balance: {}".format(wallet_balance)
    print "new balance {}: {}".format(wallets[5].addr, new_balance)
    print "balance after {}: {}".format(wallets[8].addr, balance_after)
    print "balance before {}: {}".format(wallets[8].addr, balance_before)

    if new_balance > wallet_balance / 2:
        print 'new balance of {} is {}'.format(wallets[5].addr, new_balance)
        return False

    if abs(balance_after - balance_before) > abs(wallet_balance / 2) + 54500:
        print "{} - {} != {}".format(balance_after, balance_before, wallet_balance / 2)
        return False
Exemple #38
0
def scenario(wallets, **kw):

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

    resp = 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)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)

    # import 3 names in the same block: foo.test, bar.test, baz.test
    names = ['foo.test', 'bar.test', 'baz.test']
    name_preorder_wallets = [wallets[2], wallets[3], wallets[4]]
    name_register_wallets = [wallets[5], wallets[6], wallets[7]]
    name_transfer_wallets = [wallets[6], wallets[7], wallets[5]]

    # derive importer keys and do imports
    # NOTE: breaks consensus trace from 0.14.0
    private_keychain = keychain.PrivateKeychain.from_private_key(
        wallets[1].privkey)
    private_keys = [
        wallets[1].privkey
    ]  # NOTE: always start with the reveal key, then use children
    for i in xrange(0, len(names) - 1):
        import_key = private_keychain.child(i).private_key()

        print "fund {} (child {})".format(import_key, i)
        res = testlib.send_funds(
            wallets[1].privkey, 100000000,
            virtualchain.BitcoinPrivateKey(import_key).public_key().address())
        if 'error' in res:
            print json.dumps(res, indent=4, sort_keys=True)
            return False

        testlib.next_block(**kw)
        private_keys.append(import_key)

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

        name = names[i]
        register_wallet = name_register_wallets[i]
        import_key = private_keys[i]

        resp = testlib.blockstack_name_import(name,
                                              register_wallet.addr,
                                              str(9 - i) * 40,
                                              import_key,
                                              safety_checks=False)
        if 'error' in resp:
            print json.dumps(resp, indent=4)
            return False

    testlib.next_block(**kw)

    # namespace ready...
    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)

    # update 3 names in the same block
    for i in xrange(0, len(names)):

        name = names[i]
        register_wallet = name_register_wallets[i]

        resp = testlib.blockstack_name_update(name,
                                              str(i + 2) * 40,
                                              register_wallet.privkey)
        if 'error' in resp:
            print json.dumps(resp, indent=4)
            return False

    testlib.next_block(**kw)

    # update 3 names in the same block, again
    for i in xrange(0, len(names)):

        name = names[i]
        register_wallet = name_register_wallets[i]

        resp = testlib.blockstack_name_update(name,
                                              str(i + 1) * 40,
                                              register_wallet.privkey)
        if 'error' in resp:
            print json.dumps(resp, indent=4)
            return False

    testlib.next_block(**kw)

    # transfer 3 names in the same block
    for i in xrange(0, len(names)):

        name = names[i]
        register_wallet = name_register_wallets[i]
        transfer_wallet = name_transfer_wallets[i]

        resp = testlib.blockstack_name_transfer(name, transfer_wallet.addr,
                                                True, register_wallet.privkey)
        if 'error' in resp:
            print json.dumps(resp, indent=4)
            return False

    testlib.next_block(**kw)

    # exchange after transfer...
    tmp = name_register_wallets
    name_register_wallets = name_transfer_wallets
    name_transfer_wallets = tmp

    # revoke 3 names in the same block
    for i in xrange(0, len(names)):

        name = names[i]
        register_wallet = name_register_wallets[i]

        resp = testlib.blockstack_name_revoke(name, register_wallet.privkey)
        if 'error' in resp:
            print json.dumps(resp, indent=4)
            return False

    # iterate the blocks a few times
    for i in xrange(0, 5):
        testlib.next_block(**kw)
def scenario(wallets, **kw):

    global wallet_keys, wallet_keys_2, error, index_file_data, resource_data

    wallet_keys = testlib.blockstack_client_initialize_wallet(
        "0123456789abcdef", wallets[5].privkey, wallets[3].privkey,
        wallets[4].privkey)
    test_proxy = testlib.TestAPIProxy()
    blockstack_client.set_default_proxy(test_proxy)

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

    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)

    # tell serialization-checker that value_hash can be ignored here
    print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
    sys.stdout.flush()

    testlib.next_block(**kw)

    config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None)
    conf = blockstack_client.get_config(config_path)
    assert conf

    api_pass = conf['api_password']

    # register the name bar.test. autogenerate the rest
    postage = {
        'name': 'bar.test',
        'owner_key': owner_key,
        'payment_key': payment_key
    }
    res = testlib.blockstack_REST_call('POST',
                                       '/v1/names',
                                       None,
                                       api_pass=api_pass,
                                       data=postage)
    if 'error' in res:
        res['test'] = 'Failed to register user'
        print json.dumps(res)
        error = True
        return False

    print res
    tx_hash = res['response']['transaction_hash']

    # wait for preorder to get confirmed...
    for i in xrange(0, 6):
        testlib.next_block(**kw)

    res = testlib.verify_in_queue(None, 'bar.test', 'preorder', tx_hash)
    if not res:
        return False

    # wait for the preorder to get confirmed
    for i in xrange(0, 4):
        testlib.next_block(**kw)

    # wait for register to go through
    print 'Wait for register to be submitted'
    time.sleep(10)

    # wait for the register to get confirmed
    for i in xrange(0, 6):
        testlib.next_block(**kw)

    res = testlib.verify_in_queue(None, 'bar.test', 'register', None)
    if not res:
        return False

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

    print 'Wait for update to be submitted'
    time.sleep(10)

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

    res = testlib.verify_in_queue(None, 'bar.test', 'update', None)
    if not res:
        return False

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

    print 'Wait for update to be confirmed'
    time.sleep(10)

    res = testlib.blockstack_REST_call("GET",
                                       "/v1/names/bar.test",
                                       None,
                                       api_pass=api_pass)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get name bar.test'
        print json.dumps(res)
        return False

    zonefile_hash = res['response']['zonefile_hash']
    old_expire_block = res['response']['expire_block']

    # renew it
    res = testlib.blockstack_REST_call('POST',
                                       '/v1/names',
                                       None,
                                       api_pass=api_pass,
                                       data=postage)
    if 'error' in res or res['http_status'] != 202:
        res['test'] = 'Failed to renew name'
        print json.dumps(res)
        return False

    # verify in renew queue
    for i in xrange(0, 6):
        testlib.next_block(**kw)

    res = testlib.verify_in_queue(None, 'bar.test', 'renew', None)
    if not res:
        return False

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

    # new expire block
    res = testlib.blockstack_REST_call("GET",
                                       "/v1/names/bar.test",
                                       None,
                                       api_pass=api_pass)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get name bar.test'
        print json.dumps(res)
        return False

    new_expire_block = res['response']['expire_block']

    # do we have the history for the name?
    res = testlib.blockstack_REST_call("GET",
                                       "/v1/names/bar.test/history",
                                       None,
                                       api_pass=api_pass)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = "Failed to get name history for bar.test"
        print json.dumps(res)
        return False

    # valid history?
    hist = res['response']
    if len(hist.keys()) != 4:
        res['test'] = 'Failed to get update history'
        res['history'] = hist
        print json.dumps(res, indent=4, sort_keys=True)
        return False

    # get the zonefile
    res = testlib.blockstack_REST_call(
        "GET",
        "/v1/names/bar.test/zonefile/{}".format(zonefile_hash),
        None,
        api_pass=api_pass)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get name zonefile'
        print json.dumps(res)
        return False

    # verify pushed back
    if old_expire_block + 12 >= new_expire_block:
        # didn't go through
        print >> sys.stderr, "Renewal didn't work: %s --> %s" % (
            old_expire_block, new_expire_block)
        return False
def scenario(wallets, **kw):

    global wallet_keys, error, index_file_data, resource_data

    test_proxy = testlib.TestAPIProxy()
    blockstack_client.set_default_proxy(test_proxy)
    wallet_keys = blockstack_client.make_wallet_keys(
        owner_privkey=wallets[3].privkey,
        data_privkey=wallets[4].privkey,
        payment_privkey=wallets[5].privkey)
    testlib.blockstack_client_set_wallet("0123456789abcdef",
                                         wallet_keys['payment_privkey'],
                                         wallet_keys['owner_privkey'],
                                         wallet_keys['data_privkey'])

    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)

    # migrate profiles
    res = testlib.migrate_profile("foo.test",
                                  proxy=test_proxy,
                                  wallet_keys=wallet_keys)
    if 'error' in res:
        res['test'] = 'Failed to initialize foo.test profile'
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return

    # tell serialization-checker that value_hash can be ignored here
    print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
    sys.stdout.flush()

    testlib.next_block(**kw)

    res = testlib.start_api("0123456789abcdef")
    if 'error' in res:
        print 'failed to start API: {}'.format(res)
        return False

    # sign in and make a token
    datastore_pk = keylib.ECPrivateKey(wallets[-1].privkey).to_hex()
    res = testlib.blockstack_cli_app_signin(
        "foo.test", datastore_pk, 'http://localhost:8888',
        ['store_read', 'store_write', 'store_admin'])
    if 'error' in res:
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return

    # export to environment
    blockstack_client.set_secret("BLOCKSTACK_API_SESSION", res['token'])
    ses = res['token']

    datastore_id_res = testlib.blockstack_cli_datastore_get_id(datastore_pk)
    datastore_id = datastore_id_res['datastore_id']

    # use random data for file
    file_data = None
    with open('/dev/urandom', 'r') as f:
        file_data = f.read(16384)

    # make datastore with two storage drivers
    res = testlib.blockstack_cli_create_datastore('foo.test', datastore_pk,
                                                  ['disk', 'test'], ses)
    if 'error' in res:
        print "failed to create datastore: {}".format(res['error'])
        return False

    # simulate a failure in the 'test' driver
    res = testlib.blockstack_test_setenv(
        'BLOCKSTACK_INTEGRATION_TEST_STORAGE_FAILURE', '1')
    if 'error' in res:
        print 'failed to setenv: {}'.format(res)
        return False

    # make directories (should all fail, since 'test' is offline; however, 'disk' will have worked)
    for dpath in ['/dir1', '/dir2', '/dir1/dir3', '/dir1/dir3/dir4']:
        print 'mkdir {} (expect failure)'.format(dpath)
        res = testlib.blockstack_cli_datastore_mkdir('foo.test', datastore_pk,
                                                     dpath, ses)
        if 'error' not in res:
            print 'accidentally succeeded to mkdir {}: {}'.format(dpath, res)
            return False

    # stat directories (should all fail locally due to ENOENT, since the parent directory will not have been updated)
    for dpath in ['/dir1/dir3/dir4', '/dir1/dir3', '/dir2', '/dir1']:
        print 'stat {} (expect failure)'.format(dpath)
        res = testlib.blockstack_cli_datastore_stat('foo.test', datastore_id,
                                                    dpath, ses)
        if 'error' not in res or 'errno' not in res:
            print 'accidentally succeeded to stat {}: {}'.format(dpath, res)
            return False

        if res['errno'] != errno.ENOENT:
            print 'wrong errno: {}'.format(res)
            return False

    # list directories (all the ones we tried to create should fail due to ENOENT)
    for dpath, expected in [('/dir1', ['dir3']), ('/dir1/dir3', ['dir4']),
                            ('/dir1/dir3/dir4', [])]:
        print 'listdir {} (expect failure)'.format(dpath)
        res = testlib.blockstack_cli_datastore_listdir('foo.test',
                                                       datastore_id, dpath,
                                                       ses)
        if 'error' not in res or 'errno' not in res:
            print 'accidentally succeeded to list {}: {}'.format(dpath, res)
            return False

        if res['errno'] != errno.ENOENT:
            print 'wrong errno: {}'.format(res)
            return False

    # restore driver
    res = testlib.blockstack_test_setenv(
        'BLOCKSTACK_INTEGRATION_TEST_STORAGE_FAILURE', '0')
    if 'error' in res:
        print 'failed to setenv: {}'.format(res)
        return False

    # make directories (should succeed)
    for dpath in ['/dir1', '/dir2', '/dir1/dir3', '/dir1/dir3/dir4']:
        print 'mkdir {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_mkdir('foo.test', datastore_pk,
                                                     dpath, ses)
        if 'error' in res:
            print 'failed to mkdir {}: {}'.format(dpath, res['error'])
            return False

    # make directories (should fail with EEXIST)
    for dpath in ['/dir1', '/dir2', '/dir1/dir3', '/dir1/dir3/dir4']:
        print 'mkdir {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_mkdir('foo.test', datastore_pk,
                                                     dpath, ses)
        if 'error' not in res:
            print 'accidentally succeeded to mkdir {}: {}'.format(dpath, res)
            return False

        if not res.has_key('errno'):
            print 'no errno in error {}'.format(res)
            return False

        if res['errno'] != errno.EEXIST:
            print 'wrong errno in error {}'.format(res)
            return False

    # stat directories (should succeed)
    for dpath in ['/dir1', '/dir2', '/dir1/dir3', '/dir1/dir3/dir4']:
        print 'stat {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_stat('foo.test', datastore_id,
                                                    dpath, ses)
        if 'error' in res:
            print 'failed to stat {}: {}'.format(dpath, res['error'])
            return False

        if res['type'] != blockstack_client.schemas.MUTABLE_DATUM_DIR_TYPE:
            print 'not a directory: {}, {}'.format(dpath, res)
            return False

    # list directories (should succeed)
    for dpath, expected in [('/', ['dir1', 'dir2']), ('/dir1', ['dir3']),
                            ('/dir1/dir3', ['dir4']), ('/dir1/dir3/dir4', [])]:
        print 'listdir {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_listdir('foo.test',
                                                       datastore_id, dpath,
                                                       ses)
        if 'error' in res:
            print 'failed to listdir {}: {}'.format(dpath, res['error'])
            return False

        if len(res['children'].keys()) != len(expected):
            print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format(
                expected, res)
            return False

        for child in expected:
            if not res['children'].has_key(child):
                print 'invalid directory: missing {} in {}'.format(child, res)
                return False

    # put files
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'putfile {}'.format(dpath)
        data = '{} hello {}'.format(file_data, dpath)
        res = testlib.blockstack_cli_datastore_putfile('foo.test',
                                                       datastore_pk, dpath,
                                                       data, ses)
        if 'error' in res:
            print 'failed to putfile {}: {}'.format(dpath, res['error'])
            return False

    # simulate a failure in the 'test' driver
    res = testlib.blockstack_test_setenv(
        'BLOCKSTACK_INTEGRATION_TEST_STORAGE_FAILURE', '1')
    if 'error' in res:
        print 'failed to setenv: {}'.format(res)
        return False

    # stat files (should succeed)
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'stat {} (should still work)'.format(dpath)
        res = testlib.blockstack_cli_datastore_stat('foo.test', datastore_id,
                                                    dpath, ses)
        if 'error' in res:
            print 'failed to stat {}: {}'.format(dpath, res['error'])
            return False

        if res['type'] != blockstack_client.schemas.MUTABLE_DATUM_FILE_TYPE:
            print 'not a file: {}, {}'.format(dpath, res)
            return False

    # list directories again (should succeed)
    for dpath, expected in [('/', ['dir1', 'dir2', 'file1', 'file2']),
                            ('/dir1', ['dir3', 'file3']),
                            ('/dir1/dir3', ['dir4', 'file4']),
                            ('/dir1/dir3/dir4', ['file5'])]:
        print 'listdir {} (should still work)'.format(dpath)
        res = testlib.blockstack_cli_datastore_listdir('foo.test',
                                                       datastore_id, dpath,
                                                       ses)
        if 'error' in res:
            print 'failed to listdir {}: {}'.format(dpath, res['error'])
            return False

        if len(res['children'].keys()) != len(expected):
            print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format(
                expected, res)
            return False

        for child in expected:
            if not res['children'].has_key(child):
                print 'invalid directory: missing {} in {}'.format(child, res)
                return False

    # get files (should succeed and return latest data)
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'getfile {} (should still work)'.format(dpath)
        res = testlib.blockstack_cli_datastore_getfile('foo.test',
                                                       datastore_id, dpath,
                                                       ses)
        if 'error' in res:
            print 'failed to getfile {}: {}'.format(dpath, res['error'])
            return False

        if res != '{} hello {}'.format(file_data, dpath):
            print 'failed to read {}'.format(dpath)
            return False

    # put files (should succeed with 'disk', but fail overall since we have a failed driver)
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'putfile {} (expect failure)'.format(dpath)
        data = '{} hello 2 {}'.format(file_data, dpath)
        res = testlib.blockstack_cli_datastore_putfile('foo.test',
                                                       datastore_pk, dpath,
                                                       data, ses)
        if 'error' not in res or 'errno' not in res:
            print 'accidentally succeeded to putfile {}: {}'.format(
                dpath, res['error'])
            return False

    # get files (should get the new data, despite the failed service)
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'getfile {} (should still work)'.format(dpath)
        res = testlib.blockstack_cli_datastore_getfile('foo.test',
                                                       datastore_id, dpath,
                                                       ses)
        if 'error' in res:
            print 'failed to getfile {}: {}'.format(dpath, res['error'])
            return False

        if res != '{} hello 2 {}'.format(file_data, dpath):
            print 'failed to read {}'.format(dpath)
            return False

    # restore test driver
    res = testlib.blockstack_test_setenv(
        'BLOCKSTACK_INTEGRATION_TEST_STORAGE_FAILURE', '0')
    if 'error' in res:
        print 'failed to setenv: {}'.format(res)
        return False

    # put files (should succeed now)
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'putfile {}'.format(dpath)
        data = '{} hello 2 {}'.format(file_data, dpath)
        res = testlib.blockstack_cli_datastore_putfile('foo.test',
                                                       datastore_pk, dpath,
                                                       data, ses)
        if 'error' in res:
            print 'failed to putfile {}: {}'.format(dpath, res['error'])
            return False

    # get files again! should see results of last put
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'getfile {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_getfile('foo.test',
                                                       datastore_id, dpath,
                                                       ses)
        if 'error' in res:
            print 'failed to getfile {}: {}'.format(dpath, res['error'])
            return False

        if res != '{} hello 2 {}'.format(file_data, dpath):
            print 'failed to read {}'.format(dpath)
            return False

    # simulate a failure in the 'test' driver
    res = testlib.blockstack_test_setenv(
        'BLOCKSTACK_INTEGRATION_TEST_STORAGE_FAILURE', '1')
    if 'error' in res:
        print 'failed to setenv: {}'.format(res)
        return False

    # remove files (should fail since 'test' driver is disabled)
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'deletefile {} (expect failure)'.format(dpath)
        res = testlib.blockstack_cli_datastore_deletefile(
            'foo.test', datastore_pk, dpath, ses)
        if 'error' not in res:
            print 'accidentally failed to deletefile {}: {}'.format(
                dpath, res['error'])
            return False

    # get files (should fail, since the idata was removed from 'disk')
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'getfile {} (should fail)'.format(dpath)
        res = testlib.blockstack_cli_datastore_getfile('foo.test',
                                                       datastore_id, dpath,
                                                       ses)
        if 'error' not in res:
            print 'accidentally got {}: {}'.format(dpath, res)
            return False

        if res['errno'] != errno.EREMOTEIO:
            print 'wrong errno: {}'.format(res)
            return False

    # stat files (should still work)
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'stat {} (should still work)'.format(dpath)
        res = testlib.blockstack_cli_datastore_stat('foo.test', datastore_id,
                                                    dpath, ses)
        if 'error' in res:
            print 'failed to stat {}: {}'.format(path, res)
            return False

    # restore test driver
    res = testlib.blockstack_test_setenv(
        'BLOCKSTACK_INTEGRATION_TEST_STORAGE_FAILURE', '0')
    if 'error' in res:
        print 'failed to setenv: {}'.format(res)
        return False

    # stat files (should still work)
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'stat {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_stat('foo.test', datastore_id,
                                                    dpath, ses)
        if 'error' in res:
            print 'failed to stat {}: {}'.format(path, res)
            return False

    # remove files (should work now)
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'deletefile {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_deletefile(
            'foo.test', datastore_pk, dpath, ses)
        if 'error' in res:
            print 'failed to deletefile {}: {}'.format(dpath, res)
            return False

    # put file data (should succeed on both 'disk' and 'test')
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'putfile {}'.format(dpath)
        data = '{} hello 3 {}'.format(file_data, dpath)
        res = testlib.blockstack_cli_datastore_putfile('foo.test',
                                                       datastore_pk, dpath,
                                                       data, ses)
        if 'error' in res:
            print 'failed to putfile {}: {}'.format(dpath, res['error'])
            return False

    # get files again! should see results of last put
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'getfile {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_getfile('foo.test',
                                                       datastore_id, dpath,
                                                       ses)
        if 'error' in res:
            print 'failed to getfile {}: {}'.format(dpath, res['error'])
            return False

        if res != '{} hello 3 {}'.format(file_data, dpath):
            print 'failed to read {}'.format(dpath)
            return False

    # cause 'test' to fail
    res = testlib.blockstack_test_setenv(
        'BLOCKSTACK_INTEGRATION_TEST_STORAGE_FAILURE', '1')
    if 'error' in res:
        print 'failed to setenv: {}'.format(res)
        return False

    # put file data (should fail, but succeed on 'disk')
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'putfile {} (expect failure)'.format(dpath)
        data = '{} hello 4 {}'.format(file_data, dpath)
        res = testlib.blockstack_cli_datastore_putfile('foo.test',
                                                       datastore_pk, dpath,
                                                       data, ses)
        if 'error' not in res:
            print 'accidentally succeeded to putfile {}: {}'.format(dpath, res)
            return False

        if res['errno'] != errno.EREMOTEIO:
            print 'wrong errno: {}'.format(res)
            return False

    # get files again! should see results of last put
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'getfile {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_getfile('foo.test',
                                                       datastore_id, dpath,
                                                       ses)
        if 'error' in res:
            print 'failed to getfile {}: {}'.format(dpath, res['error'])
            return False

        if res != '{} hello 4 {}'.format(file_data, dpath):
            print 'failed to read {}'.format(dpath)
            return False

    # restore 'test'
    res = testlib.blockstack_test_setenv(
        'BLOCKSTACK_INTEGRATION_TEST_STORAGE_FAILURE', '0')
    if 'error' in res:
        print 'failed to setenv: {}'.format(res)
        return False

    # get files again! should see results of last put
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'getfile {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_getfile('foo.test',
                                                       datastore_id, dpath,
                                                       ses)
        if 'error' in res:
            print 'failed to getfile {}: {}'.format(dpath, res['error'])
            return False

        if res != '{} hello 4 {}'.format(file_data, dpath):
            print 'failed to read {}'.format(dpath)
            return False

    # remove files (should succeed)
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'deletefile {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_deletefile(
            'foo.test', datastore_pk, dpath, ses)
        if 'error' in res:
            print 'failed to deletefile {}: {}'.format(dpath, res['error'])
            return False

    # stat files (should all fail)
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'stat {} (expect failure)'.format(dpath)
        res = testlib.blockstack_cli_datastore_stat('foo.test', datastore_id,
                                                    dpath, ses)
        if 'error' not in res or 'errno' not in res:
            print 'accidentally succeeded to stat {}: {}'.format(dpath, res)
            return False

        if res['errno'] != errno.ENOENT:
            print 'wrong errno: {}'.format(res)
            return False

    # get files (should all fail)
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'getfile {} (expect failure)'.format(dpath)
        res = testlib.blockstack_cli_datastore_getfile('foo.test',
                                                       datastore_id, dpath,
                                                       ses)
        if 'error' not in res or 'errno' not in res:
            print 'accidentally succeeded to get {}: {}'.format(dpath, res)
            return False

        if res['errno'] != errno.ENOENT:
            print 'wrong errno: {}'.format(res)
            return False

    # list directories
    for dpath, expected in [('/', ['dir1', 'dir2']), ('/dir1', ['dir3']),
                            ('/dir2', []), ('/dir1/dir3', ['dir4']),
                            ('/dir1/dir3/dir4', [])]:
        print 'listdir {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_listdir('foo.test',
                                                       datastore_id, dpath,
                                                       ses)
        if 'error' in res:
            print 'failed to listdir {}: {}'.format(dpath, res['error'])
            return False

        if len(res['children'].keys()) != len(expected):
            print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format(
                expected, res)
            return False

        for child in expected:
            if not res['children'].has_key(child):
                print 'invalid directory: missing {} in {}'.format(child, res)
                return False

    # break 'test'
    res = testlib.blockstack_test_setenv(
        'BLOCKSTACK_INTEGRATION_TEST_STORAGE_FAILURE', '1')
    if 'error' in res:
        print 'failed to setenv: {}'.format(res)
        return False

    # stat files (should all fail)
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'stat {} (expect failure)'.format(dpath)
        res = testlib.blockstack_cli_datastore_stat('foo.test', datastore_id,
                                                    dpath, ses)
        if 'error' not in res or 'errno' not in res:
            print 'accidentally succeeded to stat {}: {}'.format(dpath, res)
            return False

        if res['errno'] != errno.ENOENT:
            print 'wrong errno: {}'.format(res)
            return False

    # get files (should all fail)
    for dpath in [
            '/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4',
            '/dir1/dir3/dir4/file5'
    ]:
        print 'getfile {} (expect failure)'.format(dpath)
        res = testlib.blockstack_cli_datastore_getfile('foo.test',
                                                       datastore_id, dpath,
                                                       ses)
        if 'error' not in res or 'errno' not in res:
            print 'accidentally succeeded to get {}: {}'.format(dpath, res)
            return False

        if res['errno'] != errno.ENOENT:
            print 'wrong errno: {}'.format(res)
            return False

    # list directories
    for dpath, expected in [('/', ['dir1', 'dir2']), ('/dir1', ['dir3']),
                            ('/dir2', []), ('/dir1/dir3', ['dir4']),
                            ('/dir1/dir3/dir4', [])]:
        print 'listdir {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_listdir('foo.test',
                                                       datastore_id, dpath,
                                                       ses)
        if 'error' in res:
            print 'failed to listdir {}: {}'.format(dpath, res['error'])
            return False

        if len(res['children'].keys()) != len(expected):
            print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format(
                expected, res)
            return False

        for child in expected:
            if not res['children'].has_key(child):
                print 'invalid directory: missing {} in {}'.format(child, res)
                return False

    # remove directories (should fail, but '/dir2' and '/dir1/dir3/dir4''s idata should be gone)
    for dpath in ['/dir1/dir3/dir4', '/dir1/dir3', '/dir2', '/dir1']:
        print 'rmdir {} (expect failure)'.format(dpath)
        res = testlib.blockstack_cli_datastore_rmdir('foo.test', datastore_pk,
                                                     dpath, ses)
        if 'error' not in res:
            print 'accidentally succeeded to rmdir {}: {}'.format(dpath, res)
            return False

        if dpath not in ['/dir1/dir3/dir4', '/dir2']:
            if res.get('errno') != errno.ENOTEMPTY:
                print 'wrong errno for deleting {}'.format(res)
                return False

    # list directories (should fail for /dir1/dir3/dir4 and /dir2 since its idata got deleted, but it should still work for everyone else)
    for dpath, expected in [('/dir2', []), ('/dir1/dir3/dir4', [])]:
        print 'listdir {} (expect failure)'.format(dpath)
        res = testlib.blockstack_cli_datastore_listdir('foo.test',
                                                       datastore_id, dpath,
                                                       ses)
        if 'error' not in res or 'errno' not in res:
            print 'accidentally succeeded to list {}: {}'.format(dpath, res)
            return False

        if res['errno'] != errno.EREMOTEIO:
            print 'wrong errno: {}'.format(res)
            return False

    # these should still work
    for dpath, expected in [('/', ['dir1', 'dir2']), ('/dir1', ['dir3']),
                            ('/dir1/dir3', ['dir4'])]:
        print 'listdir {} (should still work)'.format(dpath)
        res = testlib.blockstack_cli_datastore_listdir('foo.test',
                                                       datastore_id, dpath,
                                                       ses)
        if 'error' in res:
            print 'failed to listdir {}: {}'.format(dpath, res['error'])
            return False

        if len(res['children'].keys()) != len(expected):
            print 'invalid directory: expected:\n{}\ngot:\n{}\n'.format(
                expected, res)
            return False

        for child in expected:
            if not res['children'].has_key(child):
                print 'invalid directory: missing {} in {}'.format(child, res)
                return False

    # restore service
    res = testlib.blockstack_test_setenv(
        'BLOCKSTACK_INTEGRATION_TEST_STORAGE_FAILURE', '0')
    if 'error' in res:
        print 'failed to setenv: {}'.format(res)
        return False

    # remove directories (should succeed)
    for dpath in ['/dir1/dir3/dir4', '/dir1/dir3', '/dir2', '/dir1']:
        print 'rmdir {}'.format(dpath)
        res = testlib.blockstack_cli_datastore_rmdir('foo.test', datastore_pk,
                                                     dpath, ses)
        if 'error' in res:
            print 'failed to rmdir {}: {}'.format(dpath, res['error'])
            return False

    # stat directories (should all fail)
    for dpath in ['/dir1/dir3/dir4', '/dir1/dir3', '/dir2', '/dir1']:
        print 'stat {} (expect failure)'.format(dpath)
        res = testlib.blockstack_cli_datastore_stat('foo.test', datastore_id,
                                                    dpath, ses)
        if 'error' not in res or 'errno' not in res:
            print 'accidentally succeeded to stat {}: {}'.format(dpath, res)
            return False

        if res['errno'] != errno.ENOENT:
            print 'wrong errno: {}'.format(res)
            return False

    # list directories (should all fail)
    for dpath, expected in [('/dir2', []), ('/dir1', ['dir3']),
                            ('/dir1/dir3', ['dir4']), ('/dir1/dir3/dir4', [])]:
        print 'listdir {} (expect failure)'.format(dpath)
        res = testlib.blockstack_cli_datastore_listdir('foo.test',
                                                       datastore_id, dpath,
                                                       ses)
        if 'error' not in res or 'errno' not in res:
            print 'accidentally succeeded to list {}: {}'.format(dpath, res)
            return False

        if res['errno'] != errno.ENOENT:
            print 'wrong errno: {}'.format(res)
            return False

    # root should be empty
    print 'listdir {}'.format('/')
    res = testlib.blockstack_cli_datastore_listdir('foo.test', datastore_id,
                                                   '/', ses)
    if 'error' in res:
        print 'failed to listdir /: {}'.format(res['error'])
        return False

    if len(res['children'].keys()) > 0:
        print 'root still has children: {}'.format(res['children'].keys())
        return False

    # simulate a failure in the 'test' driver
    res = testlib.blockstack_test_setenv(
        'BLOCKSTACK_INTEGRATION_TEST_STORAGE_FAILURE', '1')
    if 'error' in res:
        print 'failed to setenv: {}'.format(res)
        return False

    # delete datastore (should fail)
    print 'delete datastore (expect failure)'
    res = testlib.blockstack_cli_delete_datastore('foo.test', datastore_pk,
                                                  ses)
    if 'error' not in res:
        print 'accidentally succeeded to delete datastore'
        print json.dumps(res)
        return False

    # restore service
    res = testlib.blockstack_test_setenv(
        'BLOCKSTACK_INTEGRATION_TEST_STORAGE_FAILURE', '0')
    if 'error' in res:
        print 'failed to setenv: {}'.format(res)
        return False

    print 'delete datastore'
    res = testlib.blockstack_cli_delete_datastore('foo.test', datastore_pk,
                                                  ses)
    if 'error' in res:
        print 'failed to delete foo-app.com datastore'
        print json.dumps(res)
        return False

    # no more data in test-disk driver
    names = os.listdir("/tmp/blockstack-integration-test-storage/mutable")
    if names != ['foo.test']:
        print 'improper cleanup on test'
        return False

    # due to our failed mkdir of /dir1 and /dir2, these
    # will have leaked. Expect 5 entries (including foo.test):
    # an idata and inode header for both dirs
    names = os.listdir("/tmp/blockstack-disk/mutable")
    if len(names) != 5:
        print 'imporper cleanup on disk'
        return False

    if 'foo.test' not in names:
        print 'missing foo.test'
        return False

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

    global wallet_keys, wallet_keys_2, error, index_file_data, resource_data

    wallet_keys = testlib.blockstack_client_initialize_wallet(
        "0123456789abcdef", wallets[5].privkey, wallets[3].privkey,
        wallets[4].privkey)
    test_proxy = testlib.TestAPIProxy()
    blockstack_client.set_default_proxy(test_proxy)

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

    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)

    # migrate profiles
    res = testlib.migrate_profile("foo.test",
                                  proxy=test_proxy,
                                  wallet_keys=wallet_keys)
    if 'error' in res:
        res['test'] = 'Failed to initialize foo.test profile'
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return

    # tell serialization-checker that value_hash can be ignored here
    print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
    sys.stdout.flush()

    testlib.next_block(**kw)

    config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None)
    conf = blockstack_client.get_config(config_path)
    assert conf

    api_pass = conf['api_password']

    config_dir = os.path.dirname(config_path)

    # make sure we can do REST calls
    res = testlib.blockstack_REST_call('GET',
                                       '/v1/blockchains/bitcoin/pending',
                                       None,
                                       api_pass=api_pass)
    if 'error' in res:
        res['test'] = 'Failed to get queues'
        print json.dumps(res)
        return False

    # make sure we can do REST calls with different app names and user names
    res = testlib.blockstack_REST_call('GET',
                                       '/v1/blockchains/bitcoin/pending',
                                       None,
                                       api_pass=api_pass)
    if 'error' in res:
        res['test'] = 'Failed to get queues'
        print json.dumps(res)
        return False

    # register the name bar.test
    res = testlib.blockstack_REST_call('POST',
                                       '/v1/names',
                                       None,
                                       api_pass=api_pass,
                                       data={'name': 'bar.test'})
    if 'error' in res:
        res['test'] = 'Failed to register user'
        print json.dumps(res)
        error = True
        return False

    # wait for update to get confirmed
    for i in xrange(0, 48):
        if i % 12 == 0:
            print "waiting for RPC daemon to catch up"
            time.sleep(10)

        testlib.next_block(**kw)

    res = testlib.blockstack_REST_call("GET",
                                       "/v1/names/bar.test",
                                       None,
                                       api_pass=api_pass)
    if 'error' in res:
        res['test'] = 'Failed to query name'
        print json.dumps(res)
        error = True
        return False

    if res['http_status'] != 200:
        res['test'] = 'HTTP status {}, response = {}'.format(
            res['http_status'], res['response'])
        print json.dumps(res)
        error = True
        return False

    # should now be registered
    if res['response']['status'] != 'registered':
        print "register not complete"
        print json.dumps(res)
        return False
Exemple #42
0
def scenario(wallets, **kw):

    global wallet_keys, wallet_keys_2, error

    wallet_keys = testlib.blockstack_client_initialize_wallet(
        "0123456789abcdef", wallets[5].privkey, wallets[3].privkey,
        wallets[4].privkey)
    test_proxy = testlib.TestAPIProxy()
    blockstack_client.set_default_proxy(test_proxy)

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

    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)

    print
    print wallet_keys
    print

    # migrate profiles
    res = testlib.migrate_profile("foo.test",
                                  proxy=test_proxy,
                                  wallet_keys=wallet_keys)
    if 'error' in res:
        res['test'] = 'Failed to initialize foo.test profile'
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return

    # tell serialization-checker that value_hash can be ignored here
    print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
    sys.stdout.flush()

    testlib.next_block(**kw)

    data_pk = wallets[-1].privkey
    data_pub = wallets[-1].pubkey_hex

    config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None)

    # make a session
    datastore_pk = keylib.ECPrivateKey(wallets[-1].privkey).to_hex()
    res = testlib.blockstack_cli_app_signin(
        "foo.test", datastore_pk, 'register.app', [
            'names', 'register', 'update', 'prices', 'zonefiles', 'blockchain',
            'node_read'
        ])
    if 'error' in res:
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return

    ses = res['token']

    # register the name bar.test
    res = testlib.blockstack_REST_call('POST',
                                       '/v1/names',
                                       ses,
                                       data={'name': 'bar.test'})
    if 'error' in res:
        res['test'] = 'Failed to register user'
        print json.dumps(res)
        error = True
        return False

    print res
    tx_hash = res['response']['transaction_hash']

    # wait for preorder to get confirmed...
    for i in xrange(0, 6):
        testlib.next_block(**kw)

    res = testlib.verify_in_queue(ses, 'bar.test', 'preorder', tx_hash)
    if not res:
        return False

    # wait for the preorder to get confirmed
    for i in xrange(0, 4):
        testlib.next_block(**kw)

    # wait for register to go through
    print 'Wait for register to be submitted'
    time.sleep(10)

    # wait for the register/update to get confirmed
    for i in xrange(0, 6):
        testlib.next_block(**kw)

    res = testlib.verify_in_queue(ses, 'bar.test', 'register', None)
    if not res:
        return False

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

    # should have nine confirmations now
    res = testlib.get_queue(ses, 'register')
    if 'error' in res:
        print res
        return False

    if len(res) != 1:
        print res
        return False

    reg = res[0]
    confs = blockstack_client.get_tx_confirmations(reg['tx_hash'])
    if confs != 9:
        print 'wrong number of confs for {} (expected 9): {}'.format(
            reg['tx_hash'], confs)
        return False

    # stop the API server
    testlib.stop_api()

    # advance blockchain
    testlib.next_block(**kw)
    testlib.next_block(**kw)

    confs = blockstack_client.get_tx_confirmations(reg['tx_hash'])
    if confs != 11:
        print 'wrong number of confs for {} (expected 11): {}'.format(
            reg['tx_hash'], confs)
        return False

    # make sure the registrar does not process reg/up zonefile replication
    # (i.e. we want to make sure that the zonefile gets processed even if the blockchain goes too fast)
    os.environ[
        'BLOCKSTACK_TEST_REGISTRAR_FAULT_INJECTION_SKIP_REGUP_REPLICATION'] = '1'
    testlib.start_api("0123456789abcdef")

    print 'Wait to verify that we do not remove the zone file just because the tx is confirmed'
    time.sleep(10)

    # verify that this is still in the queue
    res = testlib.get_queue(ses, 'register')
    if 'error' in res:
        print res
        return False

    if len(res) != 1:
        print res
        return False

    # clear the fault
    print 'Clearing regup replication fault'
    testlib.blockstack_test_setenv(
        "BLOCKSTACK_TEST_REGISTRAR_FAULT_INJECTION_SKIP_REGUP_REPLICATION",
        "0")

    print 'Wait for zonefile to be replicated'
    time.sleep(10)
    '''
    print 'Wait for update to be submitted'
    time.sleep(10)

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

    res = testlib.verify_in_queue(ses, 'bar.test', 'update', None )
    if not res:
        return False

    for i in xrange(0, 6):
        testlib.next_block( **kw )
  
    print 'Wait for update to be confirmed'
    time.sleep(10)
    '''

    res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test", ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get name bar.test'
        print json.dumps(res)
        return False

    first_zonefile_hash = res['response']['zonefile_hash']

    # update
    res = testlib.blockstack_REST_call("PUT",
                                       "/v1/names/bar.test/zonefile",
                                       ses,
                                       data={'zonefile_hash': '11' * 20})
    if 'error' in res or res['http_status'] != 202:
        res['test'] = 'failed to update zonefile hash'
        print json.dumps(res)
        return False

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

    res = testlib.verify_in_queue(ses, 'bar.test', 'update', None)
    if not res:
        return False

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

    print 'Wait for second update to be confirmed'
    time.sleep(10)

    res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test", ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get name bar.test'
        print json.dumps(res)
        return False

    # update set?
    if res['response']['zonefile_hash'] != '11' * 20:
        res['test'] = 'failed to set zonefile hash'
        print json.dumps(res)
        return False

    # update with nonstandard zonefile
    res = testlib.blockstack_REST_call("PUT",
                                       "/v1/names/bar.test/zonefile",
                                       ses,
                                       data={'zonefile': 'hello world'})
    if 'error' in res or res['http_status'] != 202:
        res['test'] = 'failed to update zonefile hash'
        print json.dumps(res)
        return False

    # wait for third update to get confirmed
    for i in xrange(0, 6):
        testlib.next_block(**kw)

    res = testlib.verify_in_queue(ses, 'bar.test', 'update', None)
    if not res:
        return False

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

    # should have 9 confirmations
    res = testlib.get_queue(ses, 'update')
    if 'error' in res:
        print res
        return False

    if len(res) != 1:
        print res
        return False

    reg = res[0]
    confs = blockstack_client.get_tx_confirmations(reg['tx_hash'])
    if confs != 9:
        print 'wrong number of confs for {} (expected 9): {}'.format(
            reg['tx_hash'], confs)
        return False

    # stop the API server
    testlib.stop_api()

    # advance blockchain
    testlib.next_block(**kw)
    testlib.next_block(**kw)

    confs = blockstack_client.get_tx_confirmations(reg['tx_hash'])
    if confs != 11:
        print 'wrong number of confs for {} (expected 11): {}'.format(
            reg['tx_hash'], confs)
        return False

    # make the registrar skip the first few steps, so the only thing it does is clear out confirmed updates
    # (i.e. we want to make sure that the renewal's zonefile gets processed even if the blockchain goes too fast)
    os.environ[
        'BLOCKSTACK_TEST_REGISTRAR_FAULT_INJECTION_SKIP_UPDATE_REPLICATION'] = '1'
    testlib.start_api("0123456789abcdef")

    # wait a while
    print 'Wait to verify that clearing out confirmed transactions does NOT remove zonefiles'
    time.sleep(10)

    # verify that this is still in the queue
    res = testlib.get_queue(ses, 'update')
    if 'error' in res:
        print res
        return False

    if len(res) != 1:
        print res
        return False

    # clear the fault
    print 'Clearing update replication fault'
    testlib.blockstack_test_setenv(
        "BLOCKSTACK_TEST_REGISTRAR_FAULT_INJECTION_SKIP_UPDATE_REPLICATION",
        "0")

    print 'Wait for third update to be confirmed'
    time.sleep(10)

    res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test", ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get name bar.test'
        print json.dumps(res)
        return False

    last_zonefile_hash = res['response']['zonefile_hash']

    # do we have the history for the name?
    res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test/history",
                                       ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = "Failed to get name history for foo.test"
        print json.dumps(res)
        return False

    # valid history?
    hist = res['response']
    if len(hist.keys()) != 4:
        res['test'] = 'Failed to get update history'
        res['history'] = hist
        print json.dumps(res, indent=4, sort_keys=True)
        return False

    # get the historic zonefile
    res = testlib.blockstack_REST_call(
        "GET", "/v1/names/bar.test/zonefile/{}".format(first_zonefile_hash),
        ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get first zonefile'
        print json.dumps(res)
        return False

    # get the latest zonefile
    res = testlib.blockstack_REST_call(
        "GET",
        "/v1/names/bar.test/zonefile/{}?raw=1".format(last_zonefile_hash), ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get last zonefile'
        print json.dumps(res)
        return False

    if res['raw'] != 'hello world':
        res['test'] = 'Failed to set zonefile data'
        print json.dumps(res)
        return False
def scenario(wallets, **kw):

    global last_first_block, first_preorder

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

    # NOTE: names expire in 5 * NAMESPACE_LIFETIME_MULTIPLER blocks
    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)
    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)

    first_preorder = testlib.get_current_block(**kw)

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

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

    # epoch shifts here
    # 698

    testlib.next_block(**kw)

    testlib.blockstack_name_preorder("foo.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     safety_checks=False)
    testlib.next_block(**kw)

    # should fail
    testlib.blockstack_name_register("foo.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     safety_checks=False)
    testlib.next_block(**kw)

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

    # verify it failed
    rec = testlib.blockstack_cli_get_name_blockchain_record("foo.test")
    if 'error' in rec:
        print json.dumps(rec, indent=4, sort_keys=True)
        return False

    if rec['first_registered'] != 693:
        print "invalid first registered"
        print json.dumps(rec, indent=4, sort_keys=True)
        return False

    # actually expire
    for i in xrange(
            0, 5 *
            blockstack_server.config.get_epoch_namespace_lifetime_multiplier(
                testlib.get_current_block(**kw), "test") - 5 - 3):
        testlib.next_block(**kw)

    # should work
    testlib.blockstack_name_preorder("foo.test",
                                     wallets[3].privkey,
                                     wallets[4].addr,
                                     safety_checks=False)
    testlib.next_block(**kw)

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

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

    global put_result, wallet_keys, wallet_keys_2, legacy_profile, zonefile_hash, zonefile_hash_2

    wallet_keys = testlib.blockstack_client_initialize_wallet(
        "0123456789abcdef", wallets[8].privkey, wallets[3].privkey, None)
    wallet_keys_2 = testlib.blockstack_client_initialize_wallet(
        "0123456789abcdef", wallets[9].privkey, wallets[6].privkey, None)

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

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

    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.blockstack_name_preorder("bar.test", wallets[5].privkey,
                                     wallets[6].addr)
    testlib.next_block(**kw)

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

    # set up legacy profile hash
    legacy_txt = json.dumps(legacy_profile, sort_keys=True)
    legacy_hash = pybitcoin.hex_hash160(legacy_txt)

    result_1 = testlib.blockstack_name_update("foo.test", legacy_hash,
                                              wallets[3].privkey)
    result_2 = testlib.blockstack_name_update("bar.test", legacy_hash,
                                              wallets[6].privkey)
    testlib.next_block(**kw)

    rc = blockstack_client.storage.put_immutable_data(
        legacy_txt, result_1['transaction_hash'], data_hash=legacy_hash)
    assert rc is not None

    rc = blockstack_client.storage.put_immutable_data(
        legacy_txt, result_2['transaction_hash'], data_hash=legacy_hash)
    assert rc is not None

    testlib.next_block(**kw)

    # migrate profiles, but no zone file keys
    res = testlib.migrate_profile("foo.test",
                                  proxy=test_proxy,
                                  wallet_keys=wallet_keys,
                                  zonefile_has_data_key=False)
    if 'error' in res:
        res['test'] = 'Failed to initialize foo.test profile'
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return

    zonefile_hash = res['zonefile_hash']

    res = testlib.migrate_profile("bar.test",
                                  proxy=test_proxy,
                                  wallet_keys=wallet_keys_2,
                                  zonefile_has_data_key=False)
    if 'error' in res:
        res['test'] = 'Failed to initialize bar.test profile'
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return

    zonefile_hash_2 = res['zonefile_hash']

    # tell serialization-checker that value_hash can be ignored here
    print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
    sys.stdout.flush()

    testlib.next_block(**kw)

    testlib.blockstack_client_set_wallet("0123456789abcdef",
                                         wallet_keys['payment_privkey'],
                                         wallet_keys['owner_privkey'],
                                         wallet_keys['data_privkey'])

    res = testlib.start_api("0123456789abcdef")
    if 'error' in res:
        print 'failed to start API: {}'.format(res)
        return False

    # see that put_immutable works
    put_result = testlib.blockstack_cli_put_immutable(
        'foo.test',
        'hello_world_immutable',
        json.dumps({'hello': 'world_immutable'}, sort_keys=True),
        password='******')
    if 'error' in put_result:
        print json.dumps(put_result, indent=4, sort_keys=True)

    testlib.expect_atlas_zonefile(put_result['zonefile_hash'])

    # tell serialization-checker that value_hash can be ignored here
    print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
    sys.stdout.flush()

    # wait for confirmation
    for i in xrange(0, 12):
        testlib.next_block(**kw)
    print "waiting for confirmation"
    time.sleep(10)

    testlib.blockstack_client_set_wallet("0123456789abcdef",
                                         wallet_keys_2['payment_privkey'],
                                         wallet_keys_2['owner_privkey'],
                                         wallet_keys_2['data_privkey'])

    res = testlib.start_api("0123456789abcdef")
    if 'error' in res:
        print 'failed to start API: {}'.format(res)
        return False

    # put_mutable should fail on its own, since we have no privat ekey
    put_result = testlib.blockstack_cli_put_mutable(
        "bar.test",
        "hello_world_mutable",
        json.dumps({'hello': 'world'}, sort_keys=True),
        password='******')
    if 'error' not in put_result:
        print json.dumps(put_result, indent=4, sort_keys=True)
        print "accidentally succeeded to put_mutable with no public key in zone file"
        return False

    # see that put_mutable works, if we give a private key
    put_result = testlib.blockstack_cli_put_mutable(
        "bar.test",
        "hello_world_mutable",
        json.dumps({'hello': 'world'}, sort_keys=True),
        password='******',
        private_key=wallet_keys_2['data_privkey'])

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

    testlib.next_block(**kw)
Exemple #45
0
def scenario(wallets, **kw):

    global debug

    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, 52595, 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_namespace_ready("test", wallets[1].privkey)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

    resp = testlib.blockstack_name_preorder("foo.test", wallets[2].privkey,
                                            wallets[3].addr)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

    resp = testlib.blockstack_name_register("foo.test", wallets[2].privkey,
                                            wallets[3].addr)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

    # ping-ping a bit... 3 --> 4 --> 5 --> 4 --> 5 --> 4
    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[4].addr,
                                            True,
                                            wallets[3].privkey,
                                            safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[5].addr,
                                            True,
                                            wallets[4].privkey,
                                            safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[4].addr,
                                            True,
                                            wallets[5].privkey,
                                            safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[5].addr,
                                            True,
                                            wallets[4].privkey,
                                            safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[4].addr,
                                            True,
                                            wallets[5].privkey,
                                            safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

    # update (4)
    resp = testlib.blockstack_name_update("foo.test",
                                          "11" * 20,
                                          wallets[4].privkey,
                                          safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    # ping-ping a bit... 4 --> 5 --> 4 --> 5 --> 4 --> 5
    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[5].addr,
                                            True,
                                            wallets[4].privkey,
                                            safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[4].addr,
                                            True,
                                            wallets[5].privkey,
                                            safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[5].addr,
                                            True,
                                            wallets[4].privkey,
                                            safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[4].addr,
                                            True,
                                            wallets[5].privkey,
                                            safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[5].addr,
                                            True,
                                            wallets[4].privkey,
                                            safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    # now update (5)
    resp = testlib.blockstack_name_update("foo.test",
                                          "22" * 20,
                                          wallets[5].privkey,
                                          safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

    # transfer and update
    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[4].addr,
                                            True,
                                            wallets[5].privkey,
                                            safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    resp = testlib.blockstack_name_update("foo.test",
                                          "33" * 20,
                                          wallets[4].privkey,
                                          safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

    # update, transfer, transfer, update
    resp = testlib.blockstack_name_update("foo.test",
                                          "44" * 20,
                                          wallets[4].privkey,
                                          safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[5].addr,
                                            True,
                                            wallets[4].privkey,
                                            safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[4].addr,
                                            True,
                                            wallets[5].privkey,
                                            safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    resp = testlib.blockstack_name_update("foo.test",
                                          "55" * 20,
                                          wallets[4].privkey,
                                          safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

    # update, transfer, update
    resp = testlib.blockstack_name_update("foo.test",
                                          "66" * 20,
                                          wallets[4].privkey,
                                          safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[5].addr,
                                            True,
                                            wallets[4].privkey,
                                            safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    resp = testlib.blockstack_name_update("foo.test",
                                          "11" * 20,
                                          wallets[5].privkey,
                                          safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

    # transfer and update
    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[4].addr,
                                            True,
                                            wallets[5].privkey,
                                            safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    resp = testlib.blockstack_name_update("foo.test",
                                          "33" * 20,
                                          wallets[4].privkey,
                                          safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

    # update, transfer
    resp = testlib.blockstack_name_update("foo.test",
                                          "99" * 20,
                                          wallets[4].privkey,
                                          safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[5].addr,
                                            True,
                                            wallets[4].privkey,
                                            safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

    # transfer
    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[4].addr,
                                            True,
                                            wallets[5].privkey,
                                            safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)
Exemple #46
0
def scenario(wallets, **kw):

    global wallet_keys, wallet_keys_2, error, index_file_data, resource_data

    wallet_keys = testlib.blockstack_client_initialize_wallet(
        "0123456789abcdef", wallets[5].privkey, wallets[3].privkey,
        wallets[4].privkey)
    test_proxy = testlib.TestAPIProxy()
    blockstack_client.set_default_proxy(test_proxy)

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

    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)

    # migrate profiles
    res = testlib.migrate_profile("foo.test",
                                  proxy=test_proxy,
                                  wallet_keys=wallet_keys)
    if 'error' in res:
        res['test'] = 'Failed to initialize foo.test profile'
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return

    # tell serialization-checker that value_hash can be ignored here
    print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
    sys.stdout.flush()

    testlib.next_block(**kw)

    config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None)

    # make a session
    datastore_pk = keylib.ECPrivateKey(wallets[-1].privkey).to_hex()
    res = testlib.blockstack_cli_app_signin(
        "foo.test", datastore_pk, 'register.app', [
            'names', 'register', 'prices', 'zonefiles', 'blockchain',
            'node_read', 'wallet_write'
        ])
    if 'error' in res:
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return

    ses = res['token']

    # let's set the key to skip the transfer.

    config_dir = os.path.dirname(config_path)
    conf = blockstack_client.get_config(config_path)
    assert conf

    api_pass = conf['api_password']

    new_payment_key = {
        'private_key': wallets[1].privkey,
        'persist_change': True
    }

    res = testlib.blockstack_REST_call('PUT',
                                       '/v1/wallet/keys/payment',
                                       None,
                                       api_pass=api_pass,
                                       data=new_payment_key)
    if res['http_status'] != 200 or 'error' in res:
        print 'failed to set payment key'
        print res
        return False

    testlib.stop_api()
    testlib.start_api('0123456789abcdef')

    res = testlib.blockstack_REST_call('GET',
                                       '/v1/wallet/payment_address',
                                       None,
                                       api_pass=api_pass)
    if res['http_status'] != 200 or 'error' in res:
        res['test'] = 'Failed to get payment address'
        print res
        return False
    if res['response']['address'] != wallets[1].addr:
        res['test'] = 'Got wrong payer address, expected {}, got {}'.format(
            wallets[1].addr, res['response']['address'])
        print res
        return False

    res = testlib.blockstack_REST_call('PUT',
                                       '/v1/wallet/keys/owner',
                                       None,
                                       api_pass=api_pass,
                                       data=new_key)
    if res['http_status'] != 200 or 'error' in res:
        print 'failed to set owner key'
        print res
        return False

    # make zonefile for recipient
    driver_urls = blockstack_client.storage.make_mutable_data_urls(
        'bar.test', use_only=['dht', 'disk'])
    zonefile = blockstack_client.zonefile.make_empty_zonefile(
        'bar.test', wallets[4].pubkey_hex, urls=driver_urls)
    zonefile_txt = blockstack_zones.make_zone_file(zonefile,
                                                   origin='bar.test',
                                                   ttl=3600)

    # leaving the call format of this one the same to make sure that our registrar correctly
    #   detects that the requested TRANSFER is superfluous
    # register the name bar.test
    res = testlib.blockstack_REST_call('POST',
                                       '/v1/names',
                                       ses,
                                       data={
                                           'name': 'bar.test',
                                           'zonefile': zonefile_txt,
                                           'owner_address': new_addr
                                       })
    if 'error' in res:
        res['test'] = 'Failed to register user'
        print json.dumps(res)
        error = True
        return False

    print res
    tx_hash = res['response']['transaction_hash']

    # wait for preorder to get confirmed...
    for i in xrange(0, 6):
        testlib.next_block(**kw)

    res = testlib.verify_in_queue(ses, 'bar.test', 'preorder', tx_hash)
    if not res:
        return False

    # wait for the preorder to get confirmed
    for i in xrange(0, 4):
        testlib.next_block(**kw)

    # wait for register to go through
    print 'Wait for register to be submitted'
    time.sleep(10)

    # wait for the register to get confirmed
    for i in xrange(0, 6):
        testlib.next_block(**kw)

    res = testlib.verify_in_queue(ses, 'bar.test', 'register', None)
    if not res:
        return False

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

    print 'Wait for update to be submitted'
    time.sleep(10)

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

    res = testlib.verify_in_queue(ses, 'bar.test', 'update', None)
    if not res:
        return False

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

    print 'Wait for transfer to be submitted'
    time.sleep(10)

    # wait for transfer to get confirmed
    for i in xrange(0, 6):
        testlib.next_block(**kw)

    res = testlib.verify_in_queue(ses, 'bar.test', 'transfer', None)
    if res:
        print "Wrongly issued a TRANSFER"
        return False

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

    print 'Wait for transfer to be confirmed'
    time.sleep(10)

    res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test", ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get name bar.test'
        print json.dumps(res)
        return False

    zonefile_hash = res['response']['zonefile_hash']

    # should still be registered
    if res['response']['status'] != 'registered':
        print "register not complete"
        print json.dumps(res)
        return False

    # do we have the history for the name?
    res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test/history",
                                       ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = "Failed to get name history for foo.test"
        print json.dumps(res)
        return False

    # valid history?
    hist = res['response']
    if len(hist.keys()) != 3:
        res['test'] = 'Failed to get update history'
        res['history'] = hist
        print json.dumps(res, indent=4, sort_keys=True)
        return False

    # get the zonefile
    res = testlib.blockstack_REST_call(
        "GET", "/v1/names/bar.test/zonefile/{}".format(zonefile_hash), ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get name zonefile'
        print json.dumps(res)
        return False

    # same zonefile we put?
    if res['response']['zonefile'] != zonefile_txt:
        res['test'] = 'mismatched zonefile, expected\n{}\n'.format(
            zonefile_txt)
        print json.dumps(res)
        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, 10, 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)

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

    # can't do anything with the name for another 10 blocks
    resp = testlib.blockstack_name_update("foo.test", "11" * 20,
                                          wallets[3].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

    # should fail
    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[4].addr,
                                            True,
                                            wallets[3].privkey,
                                            safety_checks=False)
    if 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

    # wait for it to expire...
    for i in xrange(0, 8):
        testlib.next_block(**kw)

    # verify that operations continue to fail
    resp = testlib.blockstack_name_update("foo.test",
                                          "11" * 20,
                                          wallets[3].privkey,
                                          safety_checks=False)
    if 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

    # should fail
    resp = testlib.blockstack_name_transfer("foo.test",
                                            wallets[4].addr,
                                            True,
                                            wallets[3].privkey,
                                            safety_checks=False)
    if 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

    # re-preorder...
    resp = testlib.blockstack_name_preorder("foo.test", wallets[3].privkey,
                                            wallets[4].addr)
    if 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

    # re-register (different user)
    resp = testlib.blockstack_name_register("foo.test", wallets[3].privkey,
                                            wallets[4].addr)
    if 'error' in resp:
        print json.dumps(resp, indent=4)

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

    global debug, consensus, small_unspents

    res = check_utxo_consumption(
        "test", wallets[0], wallets[1], wallets[2],
        ['namespace_preorder', 'namespace_reveal', 'namespace_ready'],
        wallets[1].addr, **kw)
    if 'error' in res:
        return False

    expected_utxo_count = res['expected_utxo_count']

    # do the preorder
    resp = testlib.blockstack_namespace_preorder("test", wallets[1].addr,
                                                 wallets[0].privkey)
    if debug or 'error' in resp:
        print simplejson.dumps(resp, indent=4)

    testlib.next_block(**kw)

    # verify that all the small UTXOs are NOT consumed
    bitcoind = testlib.connect_bitcoind()
    bitcoind.ping()

    txdata = bitcoind.getrawtransaction(resp['transaction_hash'], 1)
    if len(txdata['vin']) != 1:
        print simplejson.dumps(txdata, indent=4)
        print "wrong number of inputs: {} != 1".format(len(txdata['vin']))
        return False

    if spent_small_transaction(resp['transaction_hash']):
        return False

    # finish ordering the namespace
    resp = 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)
    if debug or 'error' in resp:
        print simplejson.dumps(resp, indent=4)

    if spent_small_transaction(resp['transaction_hash']):
        return False

    testlib.next_block(**kw)

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

    if spent_small_transaction(resp['transaction_hash']):
        return False

    testlib.next_block(**kw)

    res = check_utxo_consumption(
        "foo.test", wallets[2], wallets[3], wallets[4],
        ['preorder', 'register', 'update', 'transfer'], wallets[4].addr, **kw)
    if 'error' in res:
        return False

    expected_utxo_count = res['expected_utxo_count']

    resp = testlib.blockstack_name_preorder("foo.test", wallets[2].privkey,
                                            wallets[3].addr)
    if debug or 'error' in resp:
        print simplejson.dumps(resp, indent=4)

    if spent_small_transaction(resp['transaction_hash']):
        return False

    testlib.next_block(**kw)

    # verify that all the small UTXOs are NOT consumed
    bitcoind = testlib.connect_bitcoind()
    bitcoind.ping()

    txdata = bitcoind.getrawtransaction(resp['transaction_hash'], 1)
    if len(txdata['vin']) != 1:
        print simplejson.dumps(txdata, indent=4)
        print "wrong number of inputs: {} != {}".format(
            len(txdata['vin']), expected_utxo_count)
        return False

    # proceed to register
    resp = testlib.blockstack_name_register("foo.test", wallets[2].privkey,
                                            wallets[3].addr)
    if debug or 'error' in resp:
        print simplejson.dumps(resp, indent=4)

    if spent_small_transaction(resp['transaction_hash']):
        return False

    testlib.next_block(**kw)

    # verify that all the UTXOs are consumed
    bitcoind = testlib.connect_bitcoind()
    bitcoind.ping()

    txdata = bitcoind.getrawtransaction(resp['transaction_hash'], 1)
    if len(txdata['vin']) != 1:
        print simplejson.dumps(txdata, indent=4)
        print "wrong number of inputs: {} != {}".format(
            len(txdata['vin']), expected_utxo_count)
        return False

    # make a few small UTXOs for the preorder payment addr
    for i in xrange(0, 3):
        res = testlib.send_funds(wallets[1].privkey, 10000,
                                 testlib.get_default_payment_wallet().addr)
        if 'error' in res:
            print simplejson.dumps(res, indent=4, sort_keys=True)
            return False

        testlib.next_block(**kw)
        small_unspents.append(res['transaction_hash'])

    utxos = testlib.get_utxos(testlib.get_default_payment_wallet().addr)
    assert len(utxos) > 3

    resp = testlib.blockstack_name_update("foo.test", "11" * 20,
                                          wallets[3].privkey)
    if debug or 'error' in resp:
        print simplejson.dumps(resp, indent=4)

    if spent_small_transaction(resp['transaction_hash']):
        return False

    consensus = testlib.get_consensus_at(testlib.get_current_block(**kw), **kw)
    testlib.next_block(**kw)

    # inspect the transaction: only 3 UTXOs should have been consumed (2 owner UTXOs and 1 payment UTXO)
    txdata = testlib.connect_bitcoind().getrawtransaction(
        resp['transaction_hash'], 1)
    if len(txdata['vin']) != 3:
        print simplejson.dumps(txdata, indent=4)
        print "too many inputs"
        return False

    # make a few more small UTXOs for the preorder payment addr
    for i in xrange(0, 3):
        res = testlib.send_funds(wallets[1].privkey, 10000,
                                 testlib.get_default_payment_wallet().addr)
        if 'error' in res:
            print simplejson.dumps(res, indent=4, sort_keys=True)
            return False

        testlib.next_block(**kw)
        small_unspents.append(res['transaction_hash'])

    utxos = testlib.get_utxos(testlib.get_default_payment_wallet().addr)
    assert len(utxos) > 3

    resp = testlib.blockstack_name_transfer("foo.test", wallets[4].addr, True,
                                            wallets[3].privkey)
    if debug or 'error' in resp:
        print simplejson.dumps(resp, indent=4)

    # inspect the transaction: only 2 UTXOs should have been consumed (1 owner UTXO and 1 payment UTXO)
    txdata = testlib.connect_bitcoind().getrawtransaction(
        resp['transaction_hash'], 1)
    if len(txdata['vin']) != 2:
        print simplejson.dumps(txdata, indent=4)
        print "too many inputs"
        return False

    if spent_small_transaction(resp['transaction_hash']):
        return False

    testlib.next_block(**kw)

    # make a few more small UTXOs for the preorder payment addr
    for i in xrange(0, 3):
        res = testlib.send_funds(wallets[1].privkey, 10000,
                                 testlib.get_default_payment_wallet().addr)
        if 'error' in res:
            print simplejson.dumps(res, indent=4, sort_keys=True)
            return False

        testlib.next_block(**kw)
        small_unspents.append(res['transaction_hash'])

    utxos = testlib.get_utxos(testlib.get_default_payment_wallet().addr)
    assert len(utxos) > 3

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

    # inspect the transaction: only 3 UTXOs should have been consumed (2 owner UTXO and 1 payment UTXO)
    # NOTE: produces two UTXOs: an "owner" utxo and the change for the owner address
    txdata = testlib.connect_bitcoind().getrawtransaction(
        resp['transaction_hash'], 1)
    if len(txdata['vin']) != 3:
        print simplejson.dumps(txdata, indent=4)
        print "too many inputs"
        return False

    if spent_small_transaction(resp['transaction_hash']):
        return False

    testlib.next_block(**kw)

    # make a few more small UTXOs for the preorder payment addr
    for i in xrange(0, 3):
        res = testlib.send_funds(wallets[1].privkey, 10000,
                                 testlib.get_default_payment_wallet().addr)
        if 'error' in res:
            print simplejson.dumps(res, indent=4, sort_keys=True)
            return False

        testlib.next_block(**kw)
        small_unspents.append(res['transaction_hash'])

    utxos = testlib.get_utxos(testlib.get_default_payment_wallet().addr)
    assert len(utxos) > 3

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

    # inspect the transaction: only 3 UTXOs should have been consumed (2 owner UTXO and 1 payment UTXO)
    txdata = testlib.connect_bitcoind().getrawtransaction(
        resp['transaction_hash'], 1)
    if len(txdata['vin']) != 3:
        print simplejson.dumps(txdata, indent=4)
        print "too many inputs"
        return False

    if spent_small_transaction(resp['transaction_hash']):
        return False

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

    global put_result, wallet_keys, datasets, zonefile_hash, dataset_change

    wallet = testlib.blockstack_client_initialize_wallet(
        "0123456789abcdef", wallets[5].privkey, wallets[3].privkey,
        wallets[4].privkey)
    test_proxy = testlib.TestAPIProxy()
    blockstack_client.set_default_proxy(test_proxy)
    wallet_keys = wallet

    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)

    # migrate profile
    res = testlib.migrate_profile("foo.test",
                                  proxy=test_proxy,
                                  wallet_keys=wallet_keys)
    if 'error' in res:
        res['test'] = 'Failed to initialize foo.test profile'
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return
    else:
        zonefile_hash = res['zonefile_hash']

    # tell serialization-checker that value_hash can be ignored here
    print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
    sys.stdout.flush()

    testlib.next_block(**kw)

    # sign some data
    for dataset in datasets:
        data_str = json.dumps(dataset, sort_keys=True)

        print "\nsign {} with {}, verify with {}\n".format(
            data_str, wallets[4].privkey, wallets[4].pubkey_hex)

        res = testlib.blockstack_cli_sign_data(data_str)
        if 'error' in res:
            print json.dumps(res, indent=4, sort_keys=True)
            return False

        res = testlib.blockstack_cli_verify_data("foo.test", res)
        if 'error' in res:
            print json.dumps(res, indent=4, sort_keys=True)
            return False

        print "\nsign {} with {}, verify with {}\n".format(
            data_str, wallets[0].privkey, wallets[0].pubkey_hex)

        # try with explicit keys
        res = testlib.blockstack_cli_sign_data(data_str,
                                               private_key=wallets[0].privkey)
        if 'error' in res:
            print json.dumps(res, indent=4, sort_keys=True)
            return False

        res = testlib.blockstack_cli_verify_data(
            "foo.test", res, public_key=wallets[0].pubkey_hex)
        if 'error' in res:
            print json.dumps(res, indent=4, sort_keys=True)
            return False

    testlib.next_block(**kw)
Exemple #50
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)  # 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
Exemple #51
0
def scenario(wallets, **kw):

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

    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)

    snv_block_id_foo = testlib.get_current_block()

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

    bar_preorder = testlib.blockstack_name_preorder("bar.test",
                                                    wallets[4].privkey,
                                                    wallets[5].addr)
    testlib.next_block(**kw)

    snv_serial_number_bar = "%s-%s" % (testlib.get_current_block(), 1)
    snv_txid_bar = bar_preorder['transaction_hash']

    testlib.blockstack_name_register("bar.test", wallets[4].privkey,
                                     wallets[5].addr)
    testlib.next_block(**kw)

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

    baz_preorder = testlib.blockstack_name_preorder("baz.test",
                                                    wallets[6].privkey,
                                                    wallets[7].addr)
    testlib.next_block(**kw)

    snv_serial_number_baz = "%s-%s" % (testlib.get_current_block(), 1)
    snv_txid_baz = baz_preorder['transaction_hash']

    testlib.blockstack_name_register("baz.test", wallets[6].privkey,
                                     wallets[7].addr)
    testlib.next_block(**kw)

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

    # 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, 52595, 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_namespace_ready("test", wallets[1].privkey)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

    # 6 names, for all interleavings of (u)pdate, (t)ransfer, and (r)enew
    # NOTE: the name encodes the interleaving order
    names = {
        "utr.test": [wallets[0], wallets[1]],
        "urt.test": [wallets[2], wallets[3]],
        "tur.test": [wallets[4], wallets[5]],
        "tru.test": [wallets[6], wallets[7]],
        "rut.test": [wallets[8], wallets[9]],
        "rtu.test": [wallets[10], wallets[11]]
    }

    # preorder them all
    for name in names.keys():

        resp = testlib.blockstack_name_preorder(name, names[name][1].privkey,
                                                names[name][0].addr)
        if debug or 'error' in resp:
            print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

    # regster them all
    for name in names.keys():

        resp = testlib.blockstack_name_register(name, names[name][1].privkey,
                                                names[name][0].addr)
        if debug or 'error' in resp:
            print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

    # test intra-block interleavings:
    # update/transfer/renew
    # update/renew/transfer
    # transfer/update/renew
    # transfer/renew/update
    # renew/update/transfer
    # renew/transfer/update
    for name in names.keys():

        do_interleaving(name, names, name[:-5])

    # iterate the blocks a few times
    for i in xrange(0, 5):
        testlib.next_block(**kw)
Exemple #53
0
def scenario( wallets, **kw ):

    global zonefile_hash

    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[0].privkey )
    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, 12):
        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(15)

    # wait for the register to get confirmed 
    for i in xrange(0, 12):
        # warn the serialization checker that this changes behavior from 0.13
        print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
        sys.stdout.flush()
        
        testlib.next_block( **kw )

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

    # wait for update to get confirmed 
    for i in xrange(0, 12):
        # warn the serialization checker that this changes behavior from 0.13
        print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
        sys.stdout.flush()
        
        testlib.next_block( **kw )

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

    # transfer to a new address 
    resp = testlib.blockstack_cli_transfer( "foo.test", wallets[4].addr, "0123456789abcdef" )

    if 'error' in resp:
        print >> sys.stderr, "transfer error: %s" % resp['error']
        return False

    # wait for it to go through 
    for i in xrange(0, 12):
        # warn the serialization checker that this changes behavior from 0.13
        print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
        sys.stdout.flush()

        testlib.next_block( **kw )

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

    testlib.next_block(**kw)
Exemple #54
0
def scenario(wallets, **kw):

    global owner_address

    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)

    legacy_wallet = testlib.make_legacy_wallet(wallets[2].privkey,
                                               "0123456789abcdef")
    testlib.store_wallet(legacy_wallet)

    res = testlib.blockstack_cli_setup_wallet("0123456789abcdef")
    if 'error' in res:
        print json.dumps(res, indent=4, sort_keys=True)
        return False

    if not res.has_key('backup_wallet'):
        print "no backup_wallet"
        print json.dumps(res, indent=4, sort_keys=True)
        return False

    if not os.path.exists(res['backup_wallet']):
        print "backup wallet doesn't exist"
        print json.dumps(res, indent=4, sort_keys=True)
        return False

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

    payment_address = str(res['payment_address'])
    owner_address = str(res['owner_address'])

    # fill wallet with 5 BTC
    res = testlib.send_funds(wallets[3].privkey, 5 * 10**8, payment_address)
    if 'error' in res:
        print "failed to fill wallet"
        print json.dumps(res)
        return False

    testlib.next_block(**kw)

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

    print >> sys.stderr, "Waiting 10 seconds for the backend to acknowledge update"
    time.sleep(10)
def scenario(wallets, **kw):

    global wallet_keys, wallet_keys_2, error, index_file_data, resource_data

    wallet_keys = testlib.blockstack_client_initialize_wallet(
        "0123456789abcdef", wallets[5].privkey, wallets[3].privkey,
        wallets[4].privkey)
    test_proxy = testlib.TestAPIProxy()
    blockstack_client.set_default_proxy(test_proxy)

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

    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)

    # migrate profiles
    res = testlib.migrate_profile("foo.test",
                                  proxy=test_proxy,
                                  wallet_keys=wallet_keys)
    if 'error' in res:
        res['test'] = 'Failed to initialize foo.test profile'
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return

    # tell serialization-checker that value_hash can be ignored here
    print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
    sys.stdout.flush()

    testlib.next_block(**kw)

    data_pk = wallets[-1].privkey
    data_pub = wallets[-1].pubkey_hex

    config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None)

    # make a session
    datastore_pk = keylib.ECPrivateKey(wallets[-1].privkey).to_hex()
    res = testlib.blockstack_cli_app_signin(
        "foo.test", datastore_pk, 'register.app', [
            'names', 'register', 'transfer', 'prices', 'zonefiles',
            'blockchain', 'node_read'
        ])
    if 'error' in res:
        print json.dumps(res, indent=4, sort_keys=True)
        error = True
        return

    ses = res['token']

    # register the name bar.test
    res = testlib.blockstack_REST_call('POST',
                                       '/v1/names',
                                       ses,
                                       data={'name': 'bar.test'})
    if 'error' in res:
        res['test'] = 'Failed to register user'
        print json.dumps(res)
        error = True
        return False

    print res
    tx_hash = res['response']['transaction_hash']

    # wait for preorder to get confirmed...
    for i in xrange(0, 6):
        testlib.next_block(**kw)

    res = testlib.verify_in_queue(ses, 'bar.test', 'preorder', tx_hash)
    if not res:
        return False

    # wait for the preorder to get confirmed
    for i in xrange(0, 6):
        testlib.next_block(**kw)

    # wait for register to go through
    print 'Wait for register to be submitted'
    time.sleep(10)

    # wait for the register to get confirmed
    for i in xrange(0, 6):
        testlib.next_block(**kw)

    res = testlib.verify_in_queue(ses, 'bar.test', 'register', None)
    if not res:
        return False

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

    print 'Wait for update to be submitted'
    time.sleep(10)

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

    res = testlib.verify_in_queue(ses, 'bar.test', 'update', None)
    if not res:
        return False

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

    print 'Wait for update to be confirmed'
    time.sleep(10)

    res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test", ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get name bar.test'
        print json.dumps(res)
        return False

    zonefile_hash = res['response']['zonefile_hash']

    # transfer it
    res = testlib.blockstack_REST_call("PUT",
                                       "/v1/names/bar.test/owner",
                                       ses,
                                       data={'owner': wallets[7].addr})
    if 'error' in res or res['http_status'] != 202:
        res['test'] = 'Failed to transfer name'
        print json.dumps(res)
        return False

    # wait for transfer to get confirmed
    for i in xrange(0, 6):
        testlib.next_block(**kw)

    res = testlib.verify_in_queue(ses, 'bar.test', 'transfer', None)
    if not res:
        return False

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

    print 'waiting for transfer to get confirmed'
    time.sleep(10)

    # poll
    res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test", ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to query name'
        print json.dumps(res)
        error = True
        return False

    # new owner?
    if not res['response'].has_key('address'):
        res['test'] = 'No address given'
        print json.dumps(res)
        return False

    if res['response']['address'] != wallets[7].addr:
        res['test'] = 'Failed to transfer name to new address {}'.format(
            wallets[7].addr)
        print json.dumps(res)
        return False

    # do we have the history for the name?
    res = testlib.blockstack_REST_call("GET", "/v1/names/bar.test/history",
                                       ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = "Failed to get name history for foo.test"
        print json.dumps(res)
        return False

    # valid history?
    hist = res['response']
    if len(hist.keys()) != 4:
        res['test'] = 'Failed to get update history'
        res['history'] = hist
        print json.dumps(res, indent=4, sort_keys=True)
        return False

    # get the zonefile
    res = testlib.blockstack_REST_call(
        "GET", "/v1/names/bar.test/zonefile/{}".format(zonefile_hash), ses)
    if 'error' in res or res['http_status'] != 200:
        res['test'] = 'Failed to get name zonefile'
        print json.dumps(res)
        return False
Exemple #56
0
def scenario(wallets, **kw):
    global pk, pk2, pk3

    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)

    # pay for a name in a v1 namespace with Stacks
    addr = virtualchain.address_reencode(virtualchain.get_privkey_address(pk))
    addr2 = virtualchain.address_reencode(
        virtualchain.get_privkey_address(pk2))
    addr3 = virtualchain.address_reencode(
        virtualchain.get_privkey_address(pk3))

    # calculate the cost of doing so
    namespace = testlib.get_state_engine().get_namespace('test')
    stacks_price = blockstack.lib.scripts.price_name_stacks(
        'foo', namespace, testlib.get_current_block(**kw))
    btc_price = blockstack.lib.scripts.price_name(
        'foo', namespace, testlib.get_current_block(**kw))

    # try to preorder/register using not enough Bitcoin and not enough Bitcoin (should fail)
    print ''
    print 'price of {} in Stacks is {}'.format('foo.test', stacks_price)
    print 'price of {} in BTC is {}'.format('foo.test', btc_price)
    print ''

    testlib.send_funds(wallets[0].privkey, btc_price * 4, addr)
    testlib.send_funds(wallets[0].privkey, btc_price * 3, addr2)
    testlib.send_funds(wallets[0].privkey, btc_price * 3, addr3)
    testlib.blockstack_send_tokens(addr, "STACKS", stacks_price,
                                   wallets[0].privkey)
    testlib.blockstack_send_tokens(addr2, "STACKS", stacks_price,
                                   wallets[0].privkey)
    testlib.blockstack_send_tokens(addr3, "STACKS", stacks_price,
                                   wallets[0].privkey)
    testlib.next_block(**kw)

    # try to preorder/register using the right amount of stacks, but not paying in BTC (should succeed)
    # try to preorder/register using the right amount of BTC, but not paying in Stacks (should succeed)
    testlib.blockstack_name_preorder("foo.test",
                                     pk3,
                                     addr,
                                     price={
                                         'units': 'STACKS',
                                         'amount': stacks_price
                                     })
    testlib.blockstack_name_preorder("bar.test",
                                     pk2,
                                     addr,
                                     price={
                                         'units': 'BTC',
                                         'amount': btc_price
                                     })
    testlib.next_block(**kw)

    testlib.blockstack_name_register("foo.test", pk3, addr)
    testlib.blockstack_name_register("bar.test", pk2, addr)
    testlib.next_block(**kw)

    # try to renew using not enough bitcoin (should fail)
    testlib.blockstack_name_renew('foo.test',
                                  pk,
                                  price={
                                      'units': 'BTC',
                                      'amount': btc_price - 1
                                  })
    testlib.next_block(**kw)
    testlib.expect_snv_fail_at('foo.test', testlib.get_current_block(**kw))

    # try to renew using not enough stacks
    testlib.blockstack_name_renew('foo.test',
                                  pk,
                                  price={
                                      'units': 'STACKS',
                                      'amount': stacks_price - 1
                                  },
                                  expect_fail=True)
    testlib.next_block(**kw)
    testlib.expect_snv_fail_at('foo.test', testlib.get_current_block(**kw))

    # try to renew using enough bitcoin and enough stacks
    testlib.blockstack_name_renew('foo.test',
                                  pk,
                                  price={
                                      'units': 'BTC',
                                      'amount': btc_price
                                  })
    testlib.blockstack_name_renew('bar.test',
                                  pk,
                                  price={
                                      'units': 'STACKS',
                                      'amount': stacks_price
                                  })
    testlib.next_block(**kw)
def scenario(wallets, **kw):

    start_subdomain_registrar()

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

    testlib.blockstack_namespace_reveal(
        "id", 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("id", wallets[1].privkey)
    testlib.next_block(**kw)

    resp = testlib.blockstack_name_preorder('foo.id', wallets[2].privkey,
                                            wallets[3].addr)
    testlib.next_block(**kw)

    zfdata = testlib.make_empty_zonefile('foo.id', wallets[3].addr)
    zfhash = blockstack.lib.storage.get_zonefile_data_hash(zfdata)

    resp = testlib.blockstack_name_register('foo.id',
                                            wallets[2].privkey,
                                            wallets[3].addr,
                                            zonefile_hash=zfhash)
    testlib.next_block(**kw)

    testlib.blockstack_put_zonefile(zfdata)

    # now, queue a subdomain registration.

    requests.post('http://localhost:3000/register',
                  json={
                      'zonefile': 'hello world',
                      'name': 'bar',
                      'owner_address': '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'
                  })

    # force a batch out of the subdomain registrar

    requests.post('http://localhost:3000/issue_batch',
                  headers={'Authorization': 'bearer tester129'})

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

    print >> sys.stderr, "Waiting 10 seconds for the backend to pickup first batch"
    time.sleep(10)

    # update the name on-chain
    testlib.blockstack_name_update('foo.id', '11' * 20, wallets[3].privkey)
    testlib.blockstack_name_update('foo.id', '22' * 20, wallets[3].privkey)
    testlib.blockstack_name_update('foo.id', '33' * 20, wallets[3].privkey)
    testlib.next_block(**kw)

    # now, queue another registration

    requests.post('http://localhost:3000/register',
                  json={
                      'zonefile': 'hello world',
                      'name': 'zap',
                      'owner_address': '1Ez69SnzzmePmZX3WpEzMKTrcBF2gpNQ55'
                  })

    res = testlib.blockstack_REST_call('GET', '/v1/names/zap.foo.id', None)

    if 'error' in res:
        res['test'] = 'Failed to query zap.foo.id'
        print json.dumps(res)
        return False

    if res['http_status'] != 200:
        res['test'] = 'HTTP status {}, response = {} on name lookup'.format(
            res['http_status'], res['response'])
        print json.dumps(res)
        return False

    name_info = res['response']
    try:
        if (name_info['zonefile'] != 'hello world' or
                name_info['address'] != '1Ez69SnzzmePmZX3WpEzMKTrcBF2gpNQ55'):
            res['test'] = 'Unexpected name info lookup for zap.foo.id'
            print 'zap.foo.id JSON:'
            print json.dumps(name_info)
            return False
    except:
        res['test'] = 'Unexpected name info lookup for zap.foo.id'
        print 'zap.foo.id JSON:'
        print json.dumps(name_info)
        return False

    # update the name on-chain again, but lots of times
    for i in range(0, 20):
        zonefile_pattern = '{:x}{:x}'.format(i / 16, i % 16)
        testlib.blockstack_name_update('foo.id', zonefile_pattern * 20,
                                       wallets[3].privkey)

    testlib.next_block(**kw)

    # should continue to work
    res = testlib.blockstack_REST_call('GET', '/v1/names/zap.foo.id', None)

    if res['http_status'] != 200:
        res['test'] = 'HTTP status {}, response = {} on name lookup'.format(
            res['http_status'], res['response'])
        print json.dumps(res)
        return False

    SUBDOMAIN_PROC.kill()
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

    # 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

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

    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

    testlib.next_block(**kw) # 694
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))
 
    # 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

    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) + 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.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) # end of 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):
        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

    # begin epoch 3 (grace period)
    testlib.next_block(**kw) # end of 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)
    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)
    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)
    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

    # 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

    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

    # should fail
    resp = testlib.blockstack_name_register("foo.test", wallets[3].privkey, wallets[0].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[3].privkey, wallets[0].addr, zonefile_hash='44' * 20, safety_checks=False, tx_fee=500*5)
    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, and be accepted
    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
    
    whois = testlib.blockstack_cli_whois('foo.test')
    if 'error' in whois:
        print whois
        return False

    if whois['owner_address'] != wallets[0].addr:
        print 'accidentally registered foo.test to {}'.format(whois['owner_address'])
        return False
Exemple #59
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)
    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
Exemple #60
0
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, 10, 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)

    testlib.next_block(**kw)

    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)

    # wait for expiration (with multipler)...
    for i in xrange(0, 10 * NAMESPACE_LIFETIME_MULTIPLIER):
        testlib.next_block(**kw)

    # re-register
    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)