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

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

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

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

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

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

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

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

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

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

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

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

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

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

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

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

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

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

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

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

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

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

    # 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, 3):
        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)

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

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

    global import_block_1, import_block_2

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

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

    import_block_1 = testlib.get_current_block( **kw )

    testlib.next_block( **kw )

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

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

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

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

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

    testlib.blockstack_name_register( "foo.test", wallets[7].privkey, wallets[8].addr )
    testlib.next_block( **kw )
Beispiel #8
0
def scenario(wallets, **kw):

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

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

    # import different block from namespace-ready
    resp = testlib.blockstack_name_import("foo_import.test", wallets[3].addr,
                                          "22" * 20, wallets[1].privkey)
    if 'error' in resp:
        print resp
        return False

    testlib.next_block(**kw)

    # import same block as namespace-ready
    resp = testlib.blockstack_name_import("foo.test", wallets[3].addr,
                                          "11" * 20, wallets[1].privkey)
    if 'error' in resp:
        print resp
        return False

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

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

    # should be rejected
    testlib.blockstack_name_register("foo.test",
                                     wallets[2].privkey,
                                     wallets[4].addr,
                                     safety_checks=False)
    testlib.next_block(**kw)
    testlib.expect_snv_fail_at('foo.test', testlib.get_current_block(**kw))
def scenario( wallets, **kw ):

    global register_block, revoke_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 )

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

    testlib.next_block( **kw )

    revoke_block = testlib.get_current_block( **kw )

    # wait for it to 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 )

    register_block = testlib.get_current_block( **kw )
Beispiel #10
0
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)

    # revoke it
    resp = testlib.blockstack_name_revoke("foo.test", 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)

    # can't import once ready
    resp = testlib.blockstack_name_import("foo.test",
                                          wallets[1].addr,
                                          "11" * 20,
                                          wallets[0].privkey,
                                          safety_checks=False)
    if 'error' in resp:
        print json.dumps(resp, indent=4)

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

    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 )

    # 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, 3):
        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)

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

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

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

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

    testlib.next_block( **kw )

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

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

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

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

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

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

    testlib.next_block( **kw )

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

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

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

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

    testlib.next_block( **kw )

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

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

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

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

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

    namespace_balance = testlib.get_balance(namespace_rec['address'])

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

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

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

    testlib.blockstack_name_renew("foo.test", wallets[3].privkey, recipient_addr=wallets[4].addr, zonefile_hash='22' * 20)
    testlib.next_block(**kw)

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

    if new_namespace_balance - namespace_balance != 2*name_cost:
        print 'address {} did not get credited'.format(namespace_rec['address'])
        print '{} != {} + {}'.format(new_namespace_balance, namespace_balance, 2*name_cost)
        return False
Beispiel #19
0
def scenario(wallets, **kw):

    global first_name_block

    # make a test namespace
    resp = testlib.blockstack_namespace_preorder("test", wallets[1].addr,
                                                 wallets[0].privkey)
    if 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)
    first_name_block = testlib.get_current_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, 10):
        testlib.next_block(**kw)

    # renew; expect different fee
    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)
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 )

    # can't import once ready
    resp = testlib.blockstack_name_import( "foo.test", wallets[1].addr, "11" * 20, wallets[0].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )
    testlib.expect_snv_fail("foo.test" )
def scenario( wallets, **kw ):

    global first_name_block

    # make a test namespace
    resp = testlib.blockstack_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey )
    if 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 )
    first_name_block = testlib.get_current_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, 10):
        testlib.next_block( **kw )

    # renew; expect different fee
    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 )
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_name_import( "foo.test", wallets[2].addr, "11" * 20, wallets[1].privkey )
    testlib.blockstack_name_import( "bar.test", wallets[3].addr, "22" * 20, wallets[1].privkey )
    testlib.blockstack_name_import( "baz.test", wallets[4].addr, "33" * 20, wallets[1].privkey )
    testlib.next_block( **kw )
    
    testlib.blockstack_namespace_ready( "test", wallets[1].privkey )
    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, 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_update( "foo.test", "22" * 20, wallets[4].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )
Beispiel #24
0
def scenario(wallets, **kw):
    pubk = virtualchain.lib.ecdsalib.ecdsa_private_key(
        wallets[1].privkey, compressed=True).public_key().to_hex()
    addrhash = virtualchain.lib.hashing.bin_hash160(
        pubk.decode('hex')).encode('hex')
    addrscript = 'a914' + addrhash + '87'
    a = virtualchain.script_hex_to_address(addrscript)

    namespace_preorder_name_hash = blockstack.lib.hashing.hash_name(
        'test', virtualchain.make_payment_script(wallets[0].addr),
        wallets[2].addr)
    print 'hash of {} + {} + {} = {}'.format(
        'test', virtualchain.make_payment_script(wallets[0].addr),
        wallets[2].addr, namespace_preorder_name_hash)

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

    resp = testlib.blockstack_namespace_reveal(
        "test", wallets[2].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)

    # should fail
    resp = testlib.blockstack_name_import("foo.test",
                                          wallets[0].addr,
                                          "11" * 20,
                                          wallets[2].privkey,
                                          safety_checks=False)
    testlib.next_block(**kw)
    testlib.expect_snv_fail_at('foo.test', testlib.get_current_block(**kw))

    resp = testlib.blockstack_namespace_ready('test',
                                              wallets[2].privkey,
                                              safety_checks=False)
    testlib.next_block(**kw)
def scenario(wallets, **kw):

    global import_block
    global failed_blocks

    # 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, 2, 250, 4,
        [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10,
        wallets[0].privkey)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

    import_block = testlib.get_current_block(**kw)

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

    testlib.next_block(**kw)

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

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

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

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

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

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

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

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

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

    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" )
Beispiel #27
0
def scenario(wallets, **kw):

    global first_name_block

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

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

    # 4-block lifetime in practice
    resp = testlib.blockstack_namespace_reveal(
        "test", wallets[1].addr, 2, 250, 4,
        [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10,
        wallets[0].privkey)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)  # 690

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

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

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

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

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

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

    print whois

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

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

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

    print whois

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

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

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

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

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

    print whois

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

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

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

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

    print whois

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

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

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

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

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

    print whois

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

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

    virtualchain_dir = kw['working_dir']
    assert virtualchain_dir

    privkey = keylib.ECPrivateKey(wallets[4].privkey).to_hex()
    config_file = os.path.join(virtualchain_dir, 'snapshots.ini')
    privkey_path = os.path.join(virtualchain_dir, 'snapshots.pkey')
    snapshot_dir = os.path.join(virtualchain_dir, 'snapshots')

    with open(privkey_path, 'w') as f:
        f.write(privkey)

    with open(config_file, 'w') as f:
        f.write("""
[blockstack-snapshots]
private_key = {}
logfile = {}
""".format(privkey_path, os.path.join(virtualchain_dir, 'snapshots.log')))

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

    assert take_snapshot(config_file, virtualchain_dir, snapshot_dir, 3)

    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)

    assert take_snapshot(config_file, virtualchain_dir, snapshot_dir, 3)

    zonefile = blockstack_client.zonefile.make_empty_zonefile(
        "foo.test", wallets[0].pubkey_hex)
    zonefile_txt = blockstack_zones.make_zone_file(zonefile)
    zonefile_hash = blockstack_client.storage.get_zonefile_data_hash(
        zonefile_txt)

    value_hashes.append(zonefile_hash)

    namespace_ids.append('test')

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

    testlib.next_block(**kw)

    # store zonefile
    res = testlib.blockstack_put_zonefile(zonefile_txt)
    assert res

    assert take_snapshot(config_file, virtualchain_dir, snapshot_dir, 3)

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

    assert take_snapshot(config_file, virtualchain_dir, snapshot_dir, 3)

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

    assert take_snapshot(config_file, virtualchain_dir, snapshot_dir, 3)

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

    assert take_snapshot(config_file, virtualchain_dir, snapshot_dir, 3)

    zonefile = blockstack_client.zonefile.make_empty_zonefile(
        "foo.test", wallets[0].pubkey_hex)
    zonefile_txt = blockstack_zones.make_zone_file(zonefile)
    zonefile_hash = blockstack_client.storage.get_zonefile_data_hash(
        zonefile_txt)

    value_hashes.append(zonefile_hash)

    testlib.blockstack_name_update('foo.test', zonefile_hash,
                                   wallets[3].privkey)
    testlib.next_block(**kw)

    time.sleep(1.0)

    # store zonefile
    res = testlib.blockstack_put_zonefile(zonefile_txt)
    assert res

    # there must be three snapshots
    res = os.listdir(snapshot_dir)
    assert len(res) == 4
    assert 'snapshot.bsk' in res

    assert take_snapshot(config_file, virtualchain_dir, snapshot_dir, 1)

    # now there's only one
    res = os.listdir(snapshot_dir)
    assert len(res) == 2
    assert 'snapshot.bsk' in res

    # restore it
    restore_dir = os.path.join(snapshot_dir, 'test_restore')
    res = restore(virtualchain_dir, os.path.join(snapshot_dir, 'snapshot.bsk'),
                  restore_dir, [wallets[4].pubkey_hex], 1)
    assert res
def scenario( wallets, **kw ):

    global import_block_1, import_block_2

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

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

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

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

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

    testlib.next_block( **kw )

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

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

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

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

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

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

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

    testlib.blockstack_name_register( "foo.test", wallets[7].privkey, wallets[8].addr )
    testlib.next_block( **kw )
def scenario( wallets, **kw ):

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

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

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

    testlib.next_block( **kw )

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

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

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

    # should send to namespace burn address
    res = testlib.blockstack_name_renew('foo.test', wallets[3].privkey)
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)

    # should send to namespace burn address
    res = testlib.blockstack_name_renew('foo.test', wallets[3].privkey)
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)

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

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

    # should be rejected if not burned
    res = testlib.blockstack_name_renew('foo.test', wallets[3].privkey, burn_addr=namespace_rec['address'], expect_fail=True)
    if 'error' not in res:
        print res
        return False

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

    testlib.next_block(**kw)

    # should have been rejected
    name_rec_2 = testlib.get_name_blockchain_record('foo.test')
    if name_rec_2['last_renewed'] != name_rec['last_renewed']:
        print 'accidentally renewed'
        return False

    # renew, but correctly (with proper burn address)
    res = testlib.blockstack_name_renew('foo.test', wallets[3].privkey)
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)

    name_rec_2 = testlib.get_name_blockchain_record('foo.test')
    if name_rec_2['last_renewed'] <= name_rec['last_renewed']:
        print 'did not renew'
        return False

    # must have burned
    new_burn_balance = testlib.get_balance(blockstack.lib.config.BLOCKSTACK_BURN_ADDRESS)
    if new_burn_balance - name_cost != burn_balance:
        print 'did not burn fee'
        print '{} != {} + {}'.format(new_burn_balance, burn_balance, name_cost)
        return False
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_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)

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

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

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

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

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

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

    resp = testlib.blockstack_name_import("foo.test", 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 ):

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

    # 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 import_block 
    global failed_blocks

    # 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, 2, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey )
    if debug or 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

    import_block = testlib.get_current_block( **kw )

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

    testlib.next_block( **kw )

    # wait for expiration (with multipler)...
    for i in xrange(0, 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))
Beispiel #36
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_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)

    # consensus hash should be None
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] is not None:
        print 'wrong consensus hash: expected None'
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

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

    testlib.next_block(**kw)

    # consensus hash should be the one from the last NAME_TRANSFER
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != testlib.get_consensus_at(
            testlib.get_current_block(**kw) - 1):
        print 'wrong consensus hash: expected {}'.format(
            testlib.get_consensus_at(testlib.get_current_block(**kw) - 1))
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    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)

    testlib.next_block(**kw)

    # consensus hash should be the one from the last NAME_TRANSFER
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != testlib.get_consensus_at(
            testlib.get_current_block(**kw) - 1):
        print 'wrong consensus hash: expected {}'.format(
            testlib.get_consensus_at(testlib.get_current_block(**kw) - 1))
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    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)

    # consensus hash should be the one from the last NAME_TRANSFER
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != testlib.get_consensus_at(
            testlib.get_current_block(**kw) - 1):
        print 'wrong consensus hash: expected {}'.format(
            testlib.get_consensus_at(testlib.get_current_block(**kw) - 1))
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    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)

    testlib.next_block(**kw)

    # consensus hash should be the one from the last NAME_TRANSFER
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != testlib.get_consensus_at(
            testlib.get_current_block(**kw) - 1):
        print 'wrong consensus hash: expected {}'.format(
            testlib.get_consensus_at(testlib.get_current_block(**kw) - 1))
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    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)

    # consensus hash should be the one from the last NAME_TRANSFER
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != testlib.get_consensus_at(
            testlib.get_current_block(**kw) - 1):
        print 'wrong consensus hash: expected {}'.format(
            testlib.get_consensus_at(testlib.get_current_block(**kw) - 1))
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

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

    testlib.next_block(**kw)

    # consensus hash should be the one from the last NAME_UPDATE
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != testlib.get_consensus_at(
            testlib.get_current_block(**kw) - 1):
        print 'wrong consensus hash: expected {}'.format(
            testlib.get_consensus_at(testlib.get_current_block(**kw) - 1))
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    update_ch = name_rec['consensus_hash']

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

    testlib.next_block(**kw)

    # consensus hash should be the one from the last NAME_UPDATE
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != update_ch:
        print 'wrong consensus hash: expected {}'.format(update_ch)
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    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)

    # consensus hash should be the one from the last NAME_UPDATE
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != update_ch:
        print 'wrong consensus hash: expected {}'.format(update_ch)
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    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)

    testlib.next_block(**kw)

    # consensus hash should be the one from the last NAME_UPDATE
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != update_ch:
        print 'wrong consensus hash: expected {}'.format(update_ch)
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    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)

    # consensus hash should be the one from the last NAME_UPDATE
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != update_ch:
        print 'wrong consensus hash: expected {}'.format(update_ch)
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    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)

    testlib.next_block(**kw)

    # consensus hash should be the one from the last NAME_UPDATE
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != update_ch:
        print 'wrong consensus hash: expected {}'.format(update_ch)
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

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

    # consensus hash should be the one from the last NAME_UPDATE
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != testlib.get_consensus_at(
            testlib.get_current_block(**kw) - 1):
        print 'wrong consensus hash: expected {}'.format(
            testlib.get_consensus_at(testlib.get_current_block(**kw) - 1))
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    update_ch = testlib.get_consensus_at(testlib.get_current_block(**kw) - 1)

    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)

    # consensus hash should be the one from the last NAME_UPDATE
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != update_ch:
        print 'wrong consensus hash: expected {}'.format(update_ch)
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    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)

    # consensus hash should be the one from the last NAME_UPDATE
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != testlib.get_consensus_at(
            testlib.get_current_block(**kw) - 1):
        print 'wrong consensus hash: expected {}'.format(
            testlib.get_consensus_at(testlib.get_current_block(**kw) - 1))
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    update_ch = testlib.get_consensus_at(testlib.get_current_block(**kw) - 1)

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

    testlib.next_block(**kw)

    # consensus hash should be the one from the last NAME_UPDATE
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != testlib.get_consensus_at(
            testlib.get_current_block(**kw) - 1):
        print 'wrong consensus hash: expected {}'.format(
            testlib.get_consensus_at(testlib.get_current_block(**kw) - 1))
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    update_ch = testlib.get_consensus_at(testlib.get_current_block(**kw) - 1)

    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)

    testlib.next_block(**kw)

    # consensus hash should be the one from the last NAME_UPDATE
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != update_ch:
        print 'wrong consensus hash: expected {}'.format(
            testlib.get_consensus_at(testlib.get_current_block(**kw) - 1))
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    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)

    # consensus hash should be the one from the last NAME_UPDATE
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != update_ch:
        print 'wrong consensus hash: expected {}'.format(
            testlib.get_consensus_at(testlib.get_current_block(**kw) - 1))
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    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)

    # consensus hash should be the one from the last NAME_UPDATE
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != testlib.get_consensus_at(
            testlib.get_current_block(**kw) - 1):
        print 'wrong consensus hash: expected {}'.format(
            testlib.get_consensus_at(testlib.get_current_block(**kw) - 1))
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    update_ch = testlib.get_consensus_at(testlib.get_current_block(**kw) - 1)

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

    testlib.next_block(**kw)

    # consensus hash should be the one from the last NAME_UPDATE
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != testlib.get_consensus_at(
            testlib.get_current_block(**kw) - 1):
        print 'wrong consensus hash: expected {}'.format(
            testlib.get_consensus_at(testlib.get_current_block(**kw) - 1))
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    update_ch = testlib.get_consensus_at(testlib.get_current_block(**kw) - 1)

    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)

    testlib.next_block(**kw)

    # consensus hash should be the one from the last NAME_UPDATE
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != update_ch:
        print 'wrong consensus hash: expected {}'.format(update_ch)
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    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)

    # consensus hash should be the one from the last NAME_UPDATE
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != testlib.get_consensus_at(
            testlib.get_current_block(**kw) - 1):
        print 'wrong consensus hash: expected {}'.format(
            testlib.get_consensus_at(testlib.get_current_block(**kw) - 1))
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False

    update_ch = testlib.get_consensus_at(testlib.get_current_block(**kw) - 1)

    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)

    # consensus hash should be the one from the last NAME_UPDATE
    db = testlib.get_state_engine()
    name_rec = db.get_name('foo.test')
    if name_rec['consensus_hash'] != update_ch:
        print 'wrong consensus hash: expected {}'.format(update_ch)
        print json.dumps(name_rec, indent=4, sort_keys=True)
        return False
def scenario( wallets, **kw ):

    global first_name_block

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

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

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

    testlib.next_block( **kw ) # 690

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

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

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

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

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

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

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

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

    print whois

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

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

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

    last_transaction_height = whois['last_transaction_height']

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    print '\nactivating segwit\n'

    virtualchain.set_features("segwit", True)

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

    testlib.blockstack_namespace_preorder("test", wallets[1].addr,
                                          wallets[5].privkey)
    testlib.blockstack_namespace_preorder("mult", wallets[2].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[5].privkey)
    testlib.blockstack_namespace_reveal(
        "mult",
        wallets[2].addr,
        52595,
        250,
        4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        10,
        10,
        wallets[0].privkey,
        version_bits=2)
    testlib.next_block(**kw)

    private_keychain = keychain.PrivateKeychain.from_private_key(
        wallets[2].privkey)
    private_keys = [
        wallets[2].privkey
    ]  # NOTE: always start with the reveal key, then use children
    for i in xrange(0, 4):
        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)

    # should succeed
    resp = testlib.blockstack_name_import("foo.mult", wallets[2].addr,
                                          '00' * 20, private_keys[0])
    if 'error' in resp:
        print json.dumps(resp, indent=4, sort_keys=True)
        return False

    testlib.next_block(**kw)

    # should succeed
    resp = testlib.blockstack_name_import("bar.mult", wallets[3].addr,
                                          "11" * 20, private_keys[1])
    if 'error' in resp:
        print json.dumps(resp, indent=4, sort_keys=True)
        return False

    # should succeed
    resp = testlib.blockstack_name_import("baz.mult", wallets[4].addr,
                                          "22" * 20, private_keys[2])
    if 'error' in resp:
        print json.dumps(resp, indent=4, sort_keys=True)
        return False

    # should succeed
    resp = testlib.blockstack_name_import("goo.mult", wallets[5].addr,
                                          "33" * 20, private_keys[3])
    if 'error' in resp:
        print json.dumps(resp, indent=4, sort_keys=True)
        return False

    testlib.next_block(**kw)

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

    namespace_balance = testlib.get_balance(wallets[0].addr)

    # get prices
    hello_cost = testlib.blockstack_get_name_cost('hello.mult')
    world_cost = testlib.blockstack_get_name_cost('world.mult')
    foo_cost = testlib.blockstack_get_name_cost('foo.mult')

    # register/renew
    res = testlib.blockstack_name_preorder("hello.mult", wallets[1].privkey,
                                           wallets[2].addr)
    if 'error' in res:
        print res
        return False

    res = testlib.blockstack_name_preorder('world.mult',
                                           wallets[6].privkey,
                                           wallets[7].addr,
                                           wallet=wallets[7])
    if 'error' in res:
        print res
        return False

    res = testlib.blockstack_name_renew('foo.mult', wallets[2].privkey)
    if 'error' in res:
        print res
        return False

    testlib.next_block(**kw)

    new_namespace_balance = testlib.get_balance(wallets[0].addr)

    if new_namespace_balance != namespace_balance + hello_cost + world_cost + foo_cost:
        print 'wrong balance'
        print new_namespace_balance
        print namespace_balance
        print hello_cost
        print foo_cost
        return False

    res = testlib.blockstack_name_register("hello.mult", wallets[1].privkey,
                                           wallets[2].addr)
    if 'error' in res:
        print res
        return False

    res = testlib.blockstack_name_register('world.mult',
                                           wallets[6].privkey,
                                           wallets[7].addr,
                                           wallet=wallets[7],
                                           zonefile_hash='44' * 20)
    if 'error' in res:
        print res
        return False

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

    global first_name_block

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

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

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

    testlib.next_block( **kw ) # 690

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    testlib.next_block(**kw) # 699

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

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

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

    if whois['owner_address'] != wallets[4].addr:
        print 'wrong owner; expected {}'.format(wallets[4].addr)
        print whois
        return False
def scenario(wallets, **kw):

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

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

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

    testlib.next_block(**kw)

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

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

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

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

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

    testlib.next_block(**kw)

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

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

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

    testlib.next_block(**kw)

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

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

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

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

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

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

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

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

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

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

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

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

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

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

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

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

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

    # burn address should have received the fee for the second name
    if new_burn_balance - name_cost_2 != burn_balance:
        print 'null burn address did not get credited'
        print '{} != {} + {}'.format(new_burn_balance, burn_balance,
                                     name_cost_2)
        return False
def scenario( wallets, **kw ):

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

    # will all be rejected trivially, since the first import must come from the importer's address
    testlib.blockstack_name_import("foo.test", wallets[4].addr, "11" * 20,
                                   wallets[2].privkey)
    testlib.blockstack_name_import("bar.test", wallets[2].addr, "22" * 20,
                                   wallets[3].privkey)
    testlib.blockstack_name_import("baz.test", wallets[3].addr, "33" * 20,
                                   wallets[4].privkey)

    testlib.next_block(**kw)

    # will be accepted
    testlib.blockstack_name_import("goo.test", wallets[2].addr, "11" * 20,
                                   wallets[1].privkey)

    # will all be rejected because they weren't sent from a importer-derived key
    testlib.blockstack_name_import("foo.test", wallets[4].addr, "11" * 20,
                                   wallets[2].privkey)
    testlib.blockstack_name_import("bar.test", wallets[2].addr, "22" * 20,
                                   wallets[3].privkey)
    testlib.blockstack_name_import("baz.test", wallets[3].addr, "33" * 20,
                                   wallets[4].privkey)

    testlib.next_block(**kw)

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

    testlib.expect_snv_fail("foo.test")
    testlib.expect_snv_fail("bar.test")
    testlib.expect_snv_fail("baz.test")
def scenario(wallets, **kw):

    global first_name_block

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

    testlib.next_block(**kw)  # 689

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

    testlib.next_block(**kw)  # 690

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

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

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

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

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

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

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

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

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

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

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

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

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

    testlib.next_block(**kw)  # 697

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

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

    testlib.next_block(**kw)  # 698

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

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

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

    testlib.next_block(**kw)  # 703

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

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

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

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

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

    testlib.next_block( **kw )

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

    # import thrice in the same block 
    resp = testlib.blockstack_name_import( "baz.test", wallets[5].addr, "44" * 20, wallets[1].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

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

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

    # import all three in the same block 
    resp = testlib.blockstack_name_import( "foo.test", wallets[5].addr, "66" * 20, wallets[1].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

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

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

    testlib.next_block( **kw )
    
    # import thrice in the same block, again
    resp = testlib.blockstack_name_import( "baz.test", wallets[5].addr, "44" * 20, wallets[1].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

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

    resp = testlib.blockstack_name_import( "baz.test", wallets[5].addr, "66" * 20, wallets[1].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
    
    testlib.next_block( **kw )
    
    # import all three in the same block, again 
    resp = testlib.blockstack_name_import( "foo.test", wallets[5].addr, "66" * 20, wallets[1].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

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

    resp = testlib.blockstack_name_import( "baz.test", wallets[4].addr, "88" * 20, wallets[1].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 '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 ):

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

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

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

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


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

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

        resp = testlib.blockstack_name_import( name, register_wallet.addr, str(9 - i) * 40, import_key, safety_checks=False )
        if 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 + 2) * 40, register_wallet.privkey )
        if debug or  'error' in resp:
            print json.dumps( resp, indent=4 )

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