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 )
Example #2
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("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 update_block
    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_register("foo.test", wallets[2].privkey,
                                     wallets[3].addr)

    # should be rejected
    testlib.blockstack_name_update('foo.test',
                                   '11' * 20,
                                   wallets[3].privkey,
                                   safety_checks=False,
                                   tx_fee=30000)

    testlib.next_block(**kw)
    update_block = testlib.get_current_block(**kw)
    testlib.expect_snv_fail_at('foo.test', update_block)
Example #4
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("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)

    testlib.blockstack_name_renew("foo.test", wallets[3].privkey)
    testlib.next_block(**kw)
Example #5
0
def scenario(wallets, **kw):

    global snv_consensus, snv_block_id, last_consensus, last_block_id

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

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

    last_block_id = testlib.get_current_block()
    last_consensus = testlib.get_consensus_at(last_block_id)
Example #6
0
def scenario(wallets, **kw):

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

    testlib.blockstack_namespace_reveal(
        "test",
        wallets[1].addr,
        52595,
        250,
        4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        10,
        10,
        wallets[0].privkey,
        version_bits=blockstack.NAMESPACE_VERSION_PAY_WITH_STACKS)
    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)
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 )
Example #8
0
def scenario(wallets, **kw):

    # make some zonefiles
    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)

    zfhashes = []

    for j in range(0, 5):
        for i in range(0, 20):
            big_zonefile = make_big_zonefile(i + 20 * j)
            zonefile_hash = blockstack.lib.storage.get_zonefile_data_hash(
                big_zonefile)
            testlib.blockstack_name_update("foo.test", zonefile_hash,
                                           wallets[3].privkey)

            zfhashes.append(zonefile_hash)

        testlib.next_block(**kw)

        for i in range(0, 20):
            big_zonefile = make_big_zonefile(i + 20 * j)
            res = blockstack.lib.client.put_zonefiles(
                'http://localhost:16264', [base64.b64encode(big_zonefile)])
            assert res['saved'][0] == 1

        print '\n\ntest with {} zone files\n\n'.format(20 * j + i)
        res = blockstack.lib.client.get_zonefiles('http://localhost:16264',
                                                  zfhashes)
        assert 'error' not in res, res

        for zfh in zfhashes:
            assert zfh in res['zonefiles'], 'missing {}, got {}'.format(
                zfh, res['zonefiles'].keys())
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 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 )
Example #11
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( "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 do_interleaving( name, namerecs, order ):
    
    # order should be a string of "u", "t", and "r"
    order = list(order)
    
    for i in xrange(0, len(order)):
    
        op = order[i]

        if op == 'r':
            # renew
            print "\nrenew '%s' with %s\n" % (name, pybitcoin.make_pay_to_address_script( namerecs[name][0].addr ))
            resp = testlib.blockstack_name_renew( name, namerecs[name][0].privkey, register_addr=namerecs[name][0].addr )
            if 'error' in resp:
                print json.dumps( resp, indent=4 )

        elif op == 'u':
            # update
            resp = testlib.blockstack_name_update( name, ("%s%s" % (i, i)) * 20, namerecs[name][0].privkey )
            if 'error' in resp:
                print json.dumps( resp, indent=4 )

        elif op == 't':
            # transfer and exchange wallets 
            print "\ntransfer '%s' from %s to %s" % (name, pybitcoin.make_pay_to_address_script( namerecs[name][0].addr ), pybitcoin.make_pay_to_address_script( namerecs[name][1].addr ))
            resp = testlib.blockstack_name_transfer( name, namerecs[name][1].addr, True, namerecs[name][0].privkey )
            if 'error' in resp:
                print json.dumps( resp, indent=4 )

            tmp = namerecs[name][0]
            namerecs[name][0] = namerecs[name][1]
            namerecs[name][1] = tmp
Example #13
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)

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

    testlib.next_block(**kw)

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

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

        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 )

        testlib.next_block( **kw )

        if i == 10:
            break

        testlib.next_block( **kw )
Example #15
0
def scenario(wallets, **kw):

    global update_blocks, transfer_blocks, update_hashes, transfer_recipients

    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)

    # preorder, register, update, expire (multiple times)
    for i in xrange(2, 5):
        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)

        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)

        testlib.next_block(**kw)

        update_blocks.append(testlib.get_current_block(**kw))
        update_hashes.append(("%02x" % i) * 20)

        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)

        testlib.next_block(**kw)

        transfer_blocks.append(testlib.get_current_block(**kw))
        transfer_recipients.append(wallets[i].addr)

        if i == 4:
            break

        for j in xrange(0, 2 * NAMESPACE_LIFETIME_MULTIPLIER - 1):
            testlib.next_block(**kw)
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, 6, 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)

    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 a bit...
    for i in xrange(0, 6 * NAMESPACE_LIFETIME_MULTIPLIER - 4):
        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)
    testlib.next_block(**kw)

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

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

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

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

    global update_block 

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

    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 a bit...
    for i in xrange(0, 6):
        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 )

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

    testlib.next_block( **kw )

    update_block = testlib.get_current_block( **kw )

    # expire
    for i in xrange(0, 6 * 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 )
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))
Example #19
0
def scenario(wallets, **kw):

    global update_hashes, update_blocks

    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, update, expire (multiple times)
    # take into account the new namespace lifetime multipler
    for i in xrange(2, 11):
        resp = testlib.blockstack_name_preorder("foo.test",
                                                wallets[i].privkey,
                                                wallets[(i + 1) % 11].addr,
                                                safety_checks=False)
        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,
                                                safety_checks=False)
        if 'error' in resp:
            print json.dumps(resp, indent=4)

        testlib.next_block(**kw)

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

        testlib.next_block(**kw)

        update_blocks.append(testlib.get_current_block(**kw))
        update_hashes.append(("%02x" % i) * 20)

        # wait for expiration
        for j in xrange(0, NAMESPACE_LIFETIME_MULTIPLIER - 2):
            testlib.next_block(**kw)

        if i == 10:
            break

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

    txids = []

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

    txids.append(res['transaction_hash'])

    res = testlib.blockstack_namespace_reveal(
        "test",
        wallets[1].addr,
        52595,
        250,
        4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        10,
        10,
        wallets[0].privkey,
        version_bits=blockstack.NAMESPACE_VERSION_PAY_WITH_STACKS)
    testlib.next_block(**kw)

    txids.append(res['transaction_hash'])

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

    txids.append(res['transaction_hash'])

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

    txids.append(res['transaction_hash'])

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

    txids.append(res['transaction_hash'])

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

    txids.append(res['transaction_hash'])

    for txid in txids:
        # fetch and parse them all.  Make sure the use the alternative testnet ID
        rawtx = testlib.getrawtransaction(txid, 0)
        print str(rawtx)
        tx = virtualchain.btc_tx_deserialize(str(rawtx))
        nullout = tx['outs'][0]
        script = nullout['script']
        script_parts = virtualchain.btc_script_deserialize(script)
        payload = script_parts[1]
        assert payload.decode('hex')[0:2] == 'di', rawtx
def scenario( wallets, **kw ):

    global snv_block_id_foo, snv_txid_bar, snv_txid_baz, last_consensus 

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

    snv_block_id_foo = testlib.get_current_block()

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

    testlib.next_block( **kw )

    resp = testlib.blockstack_name_import( "baz.test", wallets[6].addr, "33" * 20, wallets[1].privkey )
    if '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_transfer( "bar.test", wallets[4].addr, True, wallets[5].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    snv_txid_bar = resp['transaction_hash']
    testlib.next_block( **kw )

    resp = testlib.blockstack_name_update( "baz.test", "22" * 20, wallets[6].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

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

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

    testlib.next_block(**kw)

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

    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 )
def scenario(wallets, **kw):

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

    testlib.blockstack_namespace_reveal(
        "test", wallets[1].addr, 2, 250, 4,
        [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10,
        wallets[0].privkey)
    testlib.next_block(**kw)

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

    # preorder, register, update, expire (multiple times)
    # do NOT take into account the new namespace lifetime multipler
    for i in xrange(2, 4):
        resp = testlib.blockstack_name_preorder("foo.test",
                                                wallets[i].privkey,
                                                wallets[(i + 1) % 11].addr,
                                                safety_checks=False)
        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,
                                                safety_checks=False)
        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) + 1)

        testlib.next_block(**kw)

        if i == 3:
            break

        resp = testlib.blockstack_name_update("foo.test", ("%02x" % i) * 20,
                                              wallets[(i + 1) % 11].privkey,
                                              safety_checks=False)
        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) + 1)

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

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

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

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

    testlib.next_block( **kw )

    resp = testlib.blockstack_name_update( "foo.test", "11" * 20, wallets[4].privkey )
    if debug or '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, 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)
    if 'error' in resp:
        print json.dumps(resp)

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

    resp = testlib.blockstack_name_revoke("foo.test", wallets[3].privkey)
    if 'error' in resp:
        print json.dumps(resp)
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 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 )

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

    testlib.next_block( **kw )

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

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

    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_transfer("foo.test", wallets[4].addr, True,
                                            wallets[3].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

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

    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 a bit...
    for i in xrange(0, 6 * NAMESPACE_LIFETIME_MULTIPLIER - 4):
        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 )
    testlib.next_block( **kw )
    
    # transfer 
    resp = testlib.blockstack_name_transfer( "foo.test", wallets[4].addr, True, wallets[3].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

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

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

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

    print '\nactivating segwit\n'

    virtualchain.set_features("segwit", True)

    print '\nsegwit state: {}\n'.format(virtualchain.get_features('segwit'))

    # 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_name_import("foo.test", wallets[9].addr,
                                          "11" * 20, wallets[1].privkey)
    if '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_update("foo.test", "22" * 20,
                                          wallets[9].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

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

    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 )
    
    global snv_consensus, snv_block_id 
    snv_block_id = testlib.get_current_block()
    snv_consensus = testlib.get_consensus_at( snv_block_id )
def scenario( wallets, **kw ):

    global update_blocks, transfer_blocks, update_hashes, transfer_recipients
    
    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 )

    # preorder, register, update, expire (multiple times)
    for i in xrange(2, 5):
        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 )

        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 )

        testlib.next_block( **kw )

        update_blocks.append( testlib.get_current_block( **kw )) 
        update_hashes.append( ("%02x" % i) * 20 )

        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 )

        testlib.next_block( **kw )
         
        transfer_blocks.append( testlib.get_current_block( **kw ) )
        transfer_recipients.append( wallets[i].addr )

        if i == 4:
            break

        for j in xrange(0, 2 * NAMESPACE_LIFETIME_MULTIPLIER - 1):
            testlib.next_block( **kw )
Example #35
0
def scenario(wallets, **kw):

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

    testlib.blockstack_namespace_reveal(
        "test", wallets[1].addr, 2, 250, 4,
        [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10,
        wallets[0].privkey)
    testlib.next_block(**kw)

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

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

        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)

        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)

        testlib.next_block(**kw)

        if i == 10:
            break

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

    global put_result, legacy_profile, zonefile_hash, zonefile_hash_2, 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 )

    # give foo.test a nonstandard zonefile (as something that serializes to JSON)
    nonstandard_zonefile_json = {'nonstandard': 'true', 'error': 'nonstandard'}
    nonstandard_zonefile_txt = json.dumps(nonstandard_zonefile_json, sort_keys=True)
    nonstandard_zonefile_raw = binascii.unhexlify( "".join(["%02x" % i for i in xrange(0, 256)]))

    zf_data = [nonstandard_zonefile_txt, nonstandard_zonefile_raw]
    for zi in xrange(0, len(zf_data)):
        nonstandard_zonefile = zf_data[zi]
        nonstandard_hash = blockstack.lib.storage.get_zonefile_data_hash(zf_data[i])
        resp = testlib.blockstack_name_update("foo.test", nonstandard_hash, wallets[3].privkey)
        if 'error' in resp:
            print "failed to put nonstandard zonefile '%s'" % nonstandard_zonefile
            print json.dumps(resp, indent=4, sort_keys=True)
            return False

        testlib.next_block(**kw)
        testlib.blockstack_put_zonefile(nonstandard_zonefile)

        # getting zonefile should still work...
        resp = testlib.blockstack_cli_get_name_zonefile( "foo.test")
        if 'error' in resp:
            print "failed to get zonefile %s" % zi
            print json.dumps(resp, indent=4, sort_keys=True)
            return False 

        if resp != nonstandard_zonefile:
            print "failed to load nonstandard zonefile json"
            print "expected:\n%s\n\ngot:\n%s" % (nonstandard_zonefile.encode('hex'), resp.encode('hex'))
            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, 3, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey )
    testlib.next_block( **kw )

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

    # preorder, register, update, expire (multiple times)
    # only the first round should succeed, due to the namespace lifetime multipler 
    # introduced in 0.14
    for i in xrange(2, 4):
        resp = testlib.blockstack_name_preorder( "foo.test", wallets[i].privkey, wallets[(i+1)%11].addr, safety_checks=False )
        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, safety_checks=False )
        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, safety_checks=False )
        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, safety_checks=False )
        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 )
def do_interleaving(name, namerecs, order):

    # order should be a string of "u", "t", and "r"
    order = list(order)

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

        op = order[i]

        if op == 'r':
            # renew
            print "\nrenew '%s' with %s\n" % (
                name,
                pybitcoin.make_pay_to_address_script(namerecs[name][0].addr))
            resp = testlib.blockstack_name_renew(
                name,
                namerecs[name][0].privkey,
                register_addr=namerecs[name][0].addr,
                safety_checks=False)
            if 'error' in resp:
                print json.dumps(resp, indent=4)

        elif op == 'u':
            # update
            resp = testlib.blockstack_name_update(name, ("%s%s" % (i, i)) * 20,
                                                  namerecs[name][0].privkey,
                                                  safety_checks=False)
            if 'error' in resp:
                print json.dumps(resp, indent=4)

        elif op == 't':
            # transfer and exchange wallets
            print "\ntransfer '%s' from %s to %s" % (
                name,
                pybitcoin.make_pay_to_address_script(namerecs[name][0].addr),
                pybitcoin.make_pay_to_address_script(namerecs[name][1].addr))
            resp = testlib.blockstack_name_transfer(name,
                                                    namerecs[name][1].addr,
                                                    True,
                                                    namerecs[name][0].privkey,
                                                    safety_checks=False)
            if 'error' in resp:
                print json.dumps(resp, indent=4)

            tmp = namerecs[name][0]
            namerecs[name][0] = namerecs[name][1]
            namerecs[name][1] = tmp
def scenario( wallets, **kw ):

    global update_hashes, update_blocks

    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, update, expire (multiple times)
    # take into account the new namespace lifetime multipler
    for i in xrange(2, 11):
        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 )

        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 )

        testlib.next_block( **kw )

        update_blocks.append( testlib.get_current_block( **kw )) 
        update_hashes.append( ("%02x" % i) * 20 )
        
        # wait for expiration 
        for j in xrange(0, NAMESPACE_LIFETIME_MULTIPLIER - 2):
            testlib.next_block( **kw)

        if i == 10:
            break

        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 _send_batch(zf_default_url, seq):
        zf_template = "$ORIGIN {}\n$TTL 3600\n{}"

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

        return zonefiles
def scenario( wallets, **kw ):

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

    testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 2, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey )
    testlib.next_block( **kw )

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

    # preorder, register, update, expire (multiple times)
    # do NOT take into account the new namespace lifetime multipler
    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 )

        if i == 3:
            break

        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 )
def scenario( wallets, **kw ):

    global put_result, wallet_keys, legacy_profile, zonefile_hash, zonefile_hash_2


    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 )

    test_proxy = testlib.TestAPIProxy()
    blockstack_client.set_default_proxy( test_proxy )
    wallet_keys = blockstack_client.make_wallet_keys( owner_privkey=wallets[3].privkey, payment_privkey=wallets[8].privkey )
    wallet_keys_2 = blockstack_client.make_wallet_keys( owner_privkey=wallets[6].privkey, payment_privkey=wallets[9].privkey )

    # 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( None, result_1['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt )
    assert rc is not None

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

    testlib.next_block( **kw )

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

    zonefile_hash = res['zonefile_hash']

    res = testlib.migrate_profile( "bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2 )
    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'] )

    # see that put_immutable works
    put_result = blockstack_client.put_immutable( "foo.test", "hello_world_immutable", {"hello": "world"}, proxy=test_proxy, wallet_keys=wallet_keys )
    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'] )

    # see that put_mutable works
    put_result = blockstack_client.put_mutable( "bar.test", "hello_world_mutable", {"hello": "world"}, proxy=test_proxy, wallet_keys=wallet_keys_2 )
    if 'error' in put_result:
        print json.dumps(put_result, indent=4, sort_keys=True )
    
    testlib.next_block( **kw )
def scenario( wallets, **kw ):

    global put_result, wallet_keys, legacy_profile, zonefile_hash, zonefile_hash_2


    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 )

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

    # 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( None, result_1['transaction_hash'], data_hash=legacy_hash, data_text=legacy_txt )
    assert rc is not None

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

    testlib.next_block( **kw )

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

    zonefile_hash = res['zonefile_hash']

    res = testlib.migrate_profile( "bar.test", proxy=test_proxy, wallet_keys=wallet_keys_2 )
    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']

    testlib.next_block( **kw )

    # see that put_immutable works
    put_result = blockstack_client.put_immutable( "foo.test", "hello_world_immutable", {"hello": "world"}, 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 )

    # see that put_mutable works
    put_result = blockstack_client.put_mutable( "bar.test", "hello_world_mutable", {"hello": "world"}, proxy=test_proxy, wallet_keys=wallet_keys_2 )
    if 'error' in put_result:
        print json.dumps(put_result, indent=4, sort_keys=True )
    
    testlib.next_block( **kw )
Example #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, wallet=wallets[3] )
    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, wallet=wallets[3] )
    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 )

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

    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 --> transfer
    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
    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 )
def scenario( wallets, **kw ):

    global last_consensus, snv_block_id

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

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

    resp = testlib.blockstack_name_preorder_multi( names, wallets[2].privkey, [wallets[5].addr, wallets[6].addr, wallets[7].addr])
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        sys.exit(1)
   
    testlib.next_block( **kw )

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

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

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

    testlib.next_block( **kw )
    snv_block_id = testlib.get_current_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 + 1) * 40, register_wallet.privkey )
        if debug or  'error' in resp:
            print json.dumps( resp, indent=4 )

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

    testlib.next_block( **kw )

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

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

    testlib.next_block( **kw )

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

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

    last_consensus = testlib.get_consensus_at( testlib.get_current_block( **kw ), **kw )
Example #47
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)

    assert testlib.blockstack_put_zonefile(zonefiles['foo1.test'])
    assert testlib.blockstack_put_zonefile(zonefiles['foo2.test'])
    assert testlib.blockstack_put_zonefile(zonefiles['foo3.test'])

    # send two sequence=1 updates, but withhold the first batch.  send the second batch now, and then send the first batch later to confirm
    # that each subdomain's history gets reorganized.

    # first sequence=1 update (withheld)
    zf_template = "$ORIGIN {}\n$TTL 3600\n{}"
    zf_default_url = '_https._tcp URI 10 1 "https://test.com/withheld?index={}"'.format(
        1)
    zf_default_url_reorg = zf_default_url

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

    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)

    # second sequence=1 update (sent now)
    zf_template = "$ORIGIN {}\n$TTL 3600\n{}"
    zf_default_url = '_https._tcp URI 10 1 "https://test.com/?index={}"'.format(
        1)
    zf_default_url_seq1 = zf_default_url

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

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

    # sequence=2 (send now)
    zf_template = "$ORIGIN {}\n$TTL 3600\n{}"
    zf_default_url = '_https._tcp URI 10 1 "https://test.com/?index={}"'.format(
        1)

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

    def _query_subdomains():
        # query each subdomain.  Should get the latest
        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

        return True

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

    # query each subdomain history.  sequence=1 should have test.com, but not 'withheld'
    for i in xrange(1, 4):
        fqn = 'bar.foo{}.test'.format(i)
        proxy = testlib.make_proxy()
        res = client.get_name_record(fqn, proxy=proxy, include_history=True)
        if 'error' in res:
            print res
            return False

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

        # find historic
        historic_blocks = res['history'].keys()
        historic_blocks.sort()
        historic_zfhash = res['history'][str(
            historic_blocks[1])][0]['value_hash']

        # historic zone file (sequence=1) should NOT be withheld
        zf = testlib.blockstack_get_zonefile(historic_zfhash, parse=False)
        if not zf:
            print 'no zone file {} for sequence=1 in atlas'.format(
                res['value_hash'])
            return False

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

    # reorg each zonefile's history
    assert testlib.blockstack_put_zonefile(zonefiles_reorg['foo1.test'])
    assert testlib.blockstack_put_zonefile(zonefiles_reorg['foo2.test'])
    assert testlib.blockstack_put_zonefile(zonefiles_reorg['foo3.test'])

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

    # query each subdomain history.  sequence=1 should have test.com, but with 'withheld' present in the URL
    for i in xrange(1, 4):
        fqn = 'bar.foo{}.test'.format(i)
        proxy = testlib.make_proxy()
        res = client.get_name_record(fqn, proxy=proxy, include_history=True)
        if 'error' in res:
            print res
            return False

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

        # find historic
        historic_blocks = res['history'].keys()
        historic_blocks.sort()
        historic_zfhash = res['history'][str(
            historic_blocks[1])][0]['value_hash']

        # historic zone file (sequence=1) should NOT be withheld
        zf = testlib.blockstack_get_zonefile(historic_zfhash, parse=False)
        if not zf:
            print 'no zone file {} for sequence=1 in atlas'.format(
                res['value_hash'])
            return False

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

    # reindex
    assert testlib.check_subdomain_db(**kw)
def scenario( wallets, **kw ):

    global last_consensus, snv_block_id

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

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

    resp = testlib.blockstack_name_preorder_multi( names, wallets[2].privkey, [wallets[5].addr, wallets[6].addr, wallets[7].addr])
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        sys.exit(1)
   
    testlib.next_block( **kw )

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

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

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

    testlib.next_block( **kw )
    snv_block_id = testlib.get_current_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 + 1) * 40, register_wallet.privkey )
        if debug or  'error' in resp:
            print json.dumps( resp, indent=4 )

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

    testlib.next_block( **kw )

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

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

    testlib.next_block( **kw )

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

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

    last_consensus = testlib.get_consensus_at( testlib.get_current_block( **kw ), **kw )
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 )
    
    # 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]]

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

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

        resp = testlib.blockstack_name_import( name, register_wallet.addr, str(9 - i) * 40, wallets[1].privkey )
        if debug or  'error' in resp:
            print json.dumps( resp, indent=4 )

   
    testlib.next_block( **kw )

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

    # 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 + 1) * 40, register_wallet.privkey )
        if debug or  'error' in resp:
            print json.dumps( resp, indent=4 )

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

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

    # iterate the blocks a few times 
    for i in xrange(0, 5):
        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", wallets[2].addr, "11" * 20, wallets[1].privkey )
    if 'error' in resp:
        print json.dumps(resp, indent=4 )

    testlib.next_block( **kw )

    print "\nImport 25 names for %s" % wallets[3].addr

    # try to exceed quota (currently 25): order 25, and try to register a 26th
    for i in xrange(0, 25):
        resp = testlib.blockstack_name_import( "foo%s.test" % i, wallets[3].addr, "22" * 20, wallets[1].privkey )
        if 'error' in resp:
            print json.dumps(resp, indent=4 )

    testlib.next_block( **kw )

    print "\nImport 27 names for %s" % wallets[4].addr

    # try to exceed quota (currently 25): order 26, and try to update one of them (and try to transfer one too).
    for i in xrange(0, 27):
        resp = testlib.blockstack_name_import( "bar%s.test" % i, 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 )

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

    testlib.next_block( **kw )

    # should fail 
    resp = testlib.blockstack_name_register( "foofail.test",wallets[3].privkey,  wallets[1].addr )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

    # should succeed
    resp = testlib.blockstack_name_update( "foo0.test", '55' * 20, wallets[3].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

    # should fail (exceeded quota)
    resp = testlib.blockstack_name_register( "barfail.test", wallets[4].privkey, wallets[2].addr )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

    # should fail (exceeded quota--have to revoke or give names away)
    resp = testlib.blockstack_name_update( "bar0.test", '44' * 20, wallets[4].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

    # should succeed (give a name away)
    resp = testlib.blockstack_name_transfer( "bar0.test", wallets[1].addr, True, wallets[4].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

    # should fail (exceeded quota--have to revoke or give names away)
    resp = testlib.blockstack_name_update( "bar0.test", '44' * 20, wallets[4].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

    # should succeed (revoke a name)
    resp = testlib.blockstack_name_revoke( "bar2.test", wallets[4].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

    # should succeed (now under quota)
    resp = testlib.blockstack_name_update( "bar1.test", '66' * 20, wallets[4].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

    testlib.expect_snv_fail( "foofail.test" )
    testlib.expect_snv_fail( "barfail.test" )
def scenario( wallets, **kw ):

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

    testlib.next_block( **kw )

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

    # should get rejected (NOTE: the underlying mock utxo provider doesn't handle double-spends!)
    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, safety_checks=False )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

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

    # should get rejected (but only because the namespace isn't revealed until the block goes through)
    resp = testlib.blockstack_namespace_ready( "test", wallets[1].privkey, safety_checks=False )
    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, safety_checks=False )
    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, safety_checks=False )
    if debug or  'error' in resp:
        print json.dumps( resp, indent=4 )
   
    testlib.next_block( **kw )

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

    # should get rejected (NOTE: the underlying mock utxo provider doesn't handle double-spends!)
    resp = testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr, safety_checks=False )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    # don't SNV-check these 
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block( **kw )+1 )
    testlib.next_block( **kw )
    
    # should succeed
    resp = testlib.blockstack_name_register( "foo.test", wallets[2].privkey, wallets[3].addr, safety_checks=False )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

    # (this should succeed)
    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 )

    # (this should also succeed)
    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 )

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

    # (this should also succeed)
    resp = testlib.blockstack_name_update( "foo.test", "22" * 20, wallets[4].privkey, safety_checks=False )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

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

    testlib.next_block( **kw )
   
    # lots of updates 
    for i in xrange(0, 9):
        resp = testlib.blockstack_name_update( "foo.test", ("%s%s" % (i,i)) * 20, wallets[3].privkey, safety_checks=False )
        if 'error' in resp:
            print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

    # transfer loop
    for i in xrange(0, 5):

        #resp = testlib.blockstack_name_transfer( "foo.test", wallets[3].addr, True, wallets[4].privkey )
        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 )

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

    
    testlib.next_block( **kw )

    # update/transfer/update/transfer
    for i in xrange(0, 5):

        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 )

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

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

        resp = testlib.blockstack_name_update("foo.test", "bb" * 20, wallets[3].privkey, safety_checks=False )
        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 ):

    subsidy_wallet = wallets[5]
    
    print json.dumps( testlib.getrawtransaction( "28f78fbae22d2273341af231a2ac049d74958e1e6ce6ae622cd48d8f0fef591e", 1 ), indent=4 )

    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 )

    # subsidized transactions...
    resp = testlib.blockstack_name_preorder( "foo.test", None, wallets[3].addr, subsidy_key=subsidy_wallet.privkey )
    if debug or  'error' in resp:
        print json.dumps( resp, indent=4 )
  
    # (already subsidized...)
    send_subsidized( None, resp, **kw )
    testlib.next_block( **kw )

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

    # (already subsidized...)
    send_subsidized( None, resp, **kw )
    testlib.next_block( **kw )

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

    send_subsidized( wallets[3].privkey, resp, **kw )
    testlib.next_block( **kw )

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

    send_subsidized( wallets[3].privkey, resp, **kw )
    testlib.next_block( **kw )

    resp = testlib.blockstack_name_revoke( "foo.test", None, user_public_key=wallets[4].pubkey_hex, subsidy_key=subsidy_wallet.privkey )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    send_subsidized( wallets[4].privkey, resp, **kw )
    
    # advance a bit 
    for i in xrange(0, 5):
        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, 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 )
    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 )
    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 )
    testlib.expect_snv_fail_at( "foo.test", testlib.get_current_block(**kw))

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

    # verify that operations continue to fail (BUG in 0.13: THIS SUCCEEDS WHEN IT SHOULD 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))

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

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

    testlib.blockstack_namespace_reveal(
        "test", wallets[1].addr, 3, 250, 4,
        [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10,
        wallets[0].privkey)
    testlib.next_block(**kw)

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

    # preorder, register, update, expire (multiple times)
    # only the first round should succeed, due to the namespace lifetime multipler
    # introduced in 0.14
    for i in xrange(2, 4):
        resp = testlib.blockstack_name_preorder("foo.test",
                                                wallets[i].privkey,
                                                wallets[(i + 1) % 11].addr,
                                                safety_checks=False)
        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,
                                                safety_checks=False)
        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,
                                              safety_checks=False)
        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,
                                                safety_checks=False)
        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)
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, False, wallets[3].privkey ) 
    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 )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    resp = testlib.blockstack_name_transfer( "foo.test", wallets[4].addr, False, wallets[5].privkey )
    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 )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    resp = testlib.blockstack_name_transfer( "foo.test", wallets[4].addr, False, wallets[5].privkey )
    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 )
    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 )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    resp = testlib.blockstack_name_transfer( "foo.test", wallets[4].addr, False, wallets[5].privkey )
    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 )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    resp = testlib.blockstack_name_transfer( "foo.test", wallets[4].addr, False, wallets[5].privkey )
    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 )
    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 )
    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 )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    resp = testlib.blockstack_name_update( "foo.test", "33" * 20, wallets[4].privkey )
    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 )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    resp = testlib.blockstack_name_transfer( "foo.test", wallets[5].addr, False, wallets[4].privkey )
    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 )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    resp = testlib.blockstack_name_update( "foo.test", "55" * 20, wallets[4].privkey )
    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 )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

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

    resp = testlib.blockstack_name_update( "foo.test", "11" * 20, wallets[5].privkey )
    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 )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    resp = testlib.blockstack_name_update( "foo.test", "33" * 20, wallets[4].privkey )
    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 )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    resp = testlib.blockstack_name_transfer( "foo.test", wallets[5].addr, False, wallets[4].privkey )
    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 )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

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

    global debug

    # TODO: insert delayed consensus hashes

    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 )

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

    resp = testlib.blockstack_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr, wallet=wallets[3], consensus_hash=consensus_hash )
    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, wallet=wallets[3] )
    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 ) 
    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 )
    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 )
    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 )
    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 )
    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 )
    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, consensus_hash=consensus_hash )
    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, consensus_hash=consensus_hash )
    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, consensus_hash=consensus_hash )
    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, consensus_hash=consensus_hash )
    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, consensus_hash=consensus_hash )
    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 )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

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

    resp = testlib.blockstack_name_update( "foo.test", "33" * 20, wallets[4].privkey )
    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 )
    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, consensus_hash=consensus_hash )
    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, consensus_hash=consensus_hash )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

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

    testlib.next_block( **kw )

    # update --> transfer --> update --> transfer
    resp = testlib.blockstack_name_update( "foo.test", "66" * 20, wallets[4].privkey )
    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 )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    resp = testlib.blockstack_name_update( "foo.test", "11" * 20, wallets[5].privkey )
    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, consensus_hash=consensus_hash )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )