Example #1
0
def scenario(wallets, **kw):

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

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

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

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

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

    testlib.ysi_name_transfer("foo.test", wallets[4].addr, False,
                              wallets[3].privkey)
    testlib.next_block(**kw)
Example #2
0
def scenario( wallets, **kw ):

    global snv_consensus, snv_block_id, last_consensus, last_block_id

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

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

    testlib.ysi_name_preorder( "foo.test", wallets[2].privkey, wallets[3].addr )
    testlib.next_block( **kw )
    
    testlib.ysi_name_register( "foo.test", wallets[2].privkey, wallets[3].addr )
    testlib.next_block( **kw )
    
    snv_block_id = testlib.get_current_block()
    snv_consensus = testlib.get_consensus_at( snv_block_id )

    testlib.ysi_name_update( "foo.test", "11" * 20, wallets[3].privkey )
    testlib.next_block( **kw )
    
    last_block_id = testlib.get_current_block()
    last_consensus = testlib.get_consensus_at( last_block_id )
def scenario(wallets, **kw):

    global debug, consensus

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

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

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

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

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

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

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

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

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

    global update_block 

    # make a test namespace
    resp = testlib.ysi_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.ysi_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.ysi_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.ysi_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.ysi_name_renew( "foo.test", wallets[3].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )

    update_block = testlib.get_current_block( **kw )

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

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

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

    global update_blocks, transfer_blocks, update_hashes, transfer_recipients

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

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

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

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

        testlib.next_block(**kw)

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

        testlib.next_block(**kw)

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

        testlib.next_block(**kw)

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

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

        testlib.next_block(**kw)

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

        if i == 4:
            break

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

    global update_hashes, update_blocks

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

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

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

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

        testlib.next_block(**kw)

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

        testlib.next_block(**kw)

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

        testlib.next_block(**kw)

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

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

        if i == 10:
            break

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

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

    resp = testlib.ysi_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)

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

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

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

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

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

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

    # preorder, register, update, expire (multiple times)
    # do NOT take into account the new namespace lifetime multipler
    for i in xrange(2, 4):
        resp = testlib.ysi_name_preorder("foo.test",
                                         wallets[i].privkey,
                                         wallets[(i + 1) % 11].addr,
                                         safety_checks=False)
        if 'error' in resp:
            print json.dumps(resp, indent=4)

        testlib.next_block(**kw)

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

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

        testlib.next_block(**kw)

        if i == 3:
            break

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

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

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

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

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

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

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

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

    # should fail--can't give a name to yourself
    testlib.ysi_name_transfer("foo.test",
                              wallets[4].addr,
                              True,
                              wallets[4].privkey,
                              safety_checks=False)
    testlib.next_block(**kw)
    testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw))

    # should fail--can't steal a name
    testlib.ysi_name_transfer("foo.test",
                              wallets[4].addr,
                              True,
                              wallets[0].privkey,
                              safety_checks=False)
    testlib.next_block(**kw)
    testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw))
Example #11
0
def scenario(wallets, **kw):

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

    # advance a bit
    for i in xrange(0, 5):
        testlib.next_block(**kw)
def scenario(wallets, **kw):

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

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

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

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

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

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

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

    # update with stale consensus hash (should fail)
    print "\n\nsend update with consensus hash %s\n\n" % consensus_hash
    testlib.ysi_name_update("foo.test",
                            "22" * 20,
                            wallets[3].privkey,
                            consensus_hash=consensus_hash,
                            safety_checks=False)
    testlib.next_block(**kw)
Example #13
0
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.ysi_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.ysi_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.ysi_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.ysi_namespace_ready("test", wallets[1].privkey)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

    resp = testlib.ysi_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.ysi_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)
Example #14
0
def scenario( wallets, **kw ):

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

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

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

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

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

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

        testlib.next_block( **kw )

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

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

        testlib.next_block( **kw )

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

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

        testlib.next_block( **kw )
Example #15
0
def do_interleaving(name, namerecs, order):

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

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

        op = order[i]

        if op == 'r':
            # renew
            print "\nrenew '%s' with %s\n" % (
                name, virtualchain.make_payment_script(namerecs[name][0].addr))
            resp = testlib.ysi_name_renew(name,
                                          namerecs[name][0].privkey,
                                          safety_checks=False,
                                          tx_fee=10000 * 5)
            if 'error' in resp:
                print json.dumps(resp, indent=4)

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

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

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

    global last_consensus, snv_block_id 
    
    # make a test namespace
    resp = testlib.ysi_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.ysi_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.ysi_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 = testlib.get_current_block()

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

    testlib.next_block( **kw )

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

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

    global txids
    global consensuses

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

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

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

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

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

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

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

        testlib.next_block(**kw)

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

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

    testlib.next_block(**kw)

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

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

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

        resp = testlib.ysi_name_preorder(name, preorder_wallet.privkey,
                                         register_wallet.addr)
        if debug or 'error' in resp:
            print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

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

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

        resp = testlib.ysi_name_register(name, preorder_wallet.privkey,
                                         register_wallet.addr)
        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.ysi_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.ysi_name_transfer(name, transfer_wallet.addr, True,
                                         register_wallet.privkey)
        if debug or 'error' in resp:
            print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

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

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

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

        resp = testlib.ysi_name_renew(name, register_wallet.privkey)
        if debug or 'error' in resp:
            print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

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

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

        resp = testlib.ysi_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)
Example #19
0
def scenario(wallets, **kw):

    # make a test namespace
    resp = testlib.ysi_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.ysi_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.ysi_name_import(name,
                                       register_wallet.addr,
                                       str(9 - i) * 40,
                                       import_key,
                                       safety_checks=False)
        if 'error' in resp:
            print json.dumps(resp, indent=4)
            return False

    testlib.next_block(**kw)

    # namespace ready...
    resp = testlib.ysi_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.ysi_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.ysi_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.ysi_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.ysi_name_revoke(name, register_wallet.privkey)
        if 'error' in resp:
            print json.dumps(resp, indent=4)
            return False

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

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

    testlib.ysi_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.ysi_name_import( "foo.test", wallets[2].addr, "11" * 20, wallets[1].privkey )
    if 'error' in resp:
        print json.dumps(resp, indent=4 )
        return False

    testlib.next_block( **kw )

    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.ysi_name_import( "foo%s.test" % i, wallets[3].addr, "22" * 20, wallets[1].privkey )
        if 'error' in resp:
            print json.dumps(resp, indent=4 )
            return False

        if i % 2 == 1:
            testlib.next_block( **kw )

    testlib.next_block( **kw )

    print "\nImport 26 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, 26):
        resp = testlib.ysi_name_import( "bar%s.test" % i, wallets[4].addr, "33" * 20, wallets[1].privkey, safety_checks=False )
        if 'error' in resp:
            print json.dumps(resp, indent=4 )
            return False
        
        if i % 2 == 1:
            testlib.next_block( **kw )

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

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

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

    # should succeed
    resp = testlib.ysi_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.ysi_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.ysi_name_register( "barfail.test", wallets[4].privkey, wallets[2].addr, safety_checks=False )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

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

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

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

    # should succeed (give a name away)
    resp = testlib.ysi_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.ysi_name_update( "bar0.test", '44' * 20, wallets[4].privkey, safety_checks=False )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

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

    # should succeed (revoke a name)
    resp = testlib.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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)
Example #22
0
def scenario(wallets, **kw):

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

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

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

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

        testlib.next_block(**kw)

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

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

        testlib.next_block(**kw)

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

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

        testlib.next_block(**kw)

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

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

        testlib.next_block(**kw)

        resp = testlib.ysi_name_renew("foo.test",
                                      wallets[i].privkey,
                                      safety_checks=False,
                                      tx_fee=10000 * 5)
        if 'error' in resp:
            print json.dumps(resp, indent=4)

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

        if i == 3:
            break

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

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

    testlib.next_block(**kw)

    # should get rejected
    resp = testlib.ysi_namespace_reveal(
        "test",
        wallets[1].addr,
        52595,
        250,
        4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        10,
        10,
        wallets[0].privkey,
        safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    # should get rejected (NOTE: the underlying mock utxo provider doesn't handle double-spends!)
    resp = testlib.ysi_namespace_reveal(
        "test",
        wallets[1].addr,
        52595,
        250,
        4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        10,
        10,
        wallets[0].privkey,
        safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

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

    # should get accepted
    resp = testlib.ysi_namespace_reveal(
        "test",
        wallets[1].addr,
        52595,
        250,
        4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        10,
        10,
        wallets[0].privkey,
        safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

    # should get rejected (but only because the namespace isn't revealed until the block goes through)
    resp = testlib.ysi_namespace_ready("test",
                                       wallets[1].privkey,
                                       safety_checks=False)
    if debug or 'error' in resp:
        print json.dumps(resp, indent=4)

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

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

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

    # don't SNV-check these
    testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw) + 1)
    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

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

    testlib.next_block(**kw)

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

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

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

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

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

    testlib.next_block(**kw)

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

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

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

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

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

    testlib.next_block(**kw)

    # warn the serialization checker that this changes behavior from 0.13
    print "BLOCKSTACK_SERIALIZATION_CHANGE_BEHAVIOR"
    sys.stdout.flush()
def scenario( wallets, **kw ):

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

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

    test_proxy = testlib.TestAPIProxy()
    ysi_client.set_default_proxy( test_proxy )
    
    testlib.ysi_namespace_preorder( "test", wallets[1].addr, wallets[0].privkey )
    testlib.next_block( **kw )

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

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

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

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

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

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

    testlib.next_block( **kw )

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

    zonefile_hash = res['zonefile_hash']

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

    zonefile_hash_2 = res['zonefile_hash']

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

    testlib.ysi_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey'] )
 
    res = testlib.start_api("0123456789abcdef")
    if 'error' in res:
        print 'failed to start API: {}'.format(res)
        return False

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

    testlib.expect_atlas_zonefile(put_result['zonefile_hash'])
    
    # tell serialization-checker that value_hash can be ignored here
    print "BLOCKSTACK_SERIALIZATION_CHECK_IGNORE value_hash"
    sys.stdout.flush()
    
    # wait for confirmation
    for i in xrange(0, 12):
        testlib.next_block( **kw )
    print "waiting for confirmation"
    time.sleep(10)

    testlib.ysi_client_set_wallet( "0123456789abcdef", wallet_keys_2['payment_privkey'], wallet_keys_2['owner_privkey'], wallet_keys_2['data_privkey'] )
 
    res = testlib.start_api("0123456789abcdef")
    if 'error' in res:
        print 'failed to start API: {}'.format(res)
        return False

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

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

    if 'error' in put_result:
        print json.dumps(put_result, indent=4, sort_keys=True )
        return False
    
    testlib.next_block( **kw )
def scenario(wallets, **kw):

    global value_hashes

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

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

    # register 10 names
    for i in xrange(0, 10):
        res = testlib.ysi_name_preorder("foo_{}.test".format(i),
                                        wallets[2].privkey, wallets[3].addr)
        if 'error' in res:
            print json.dumps(res)
            return False

    testlib.next_block(**kw)

    for i in xrange(0, 10):
        res = testlib.ysi_name_register("foo_{}.test".format(i),
                                        wallets[2].privkey, wallets[3].addr)
        if 'error' in res:
            print json.dumps(res)
            return False

    testlib.next_block(**kw)

    # make 10 empty zonefiles and propagate them
    for i in xrange(0, 10):
        data_pubkey = wallets[4].pubkey_hex
        empty_zonefile = ysi_client.zonefile.make_empty_zonefile(
            "foo_{}.test".format(i),
            data_pubkey,
            urls=["file:///tmp/foo_{}.test".format(i)])
        empty_zonefile_str = ysi_zones.make_zone_file(empty_zonefile)
        value_hash = ysi_client.hash_zonefile(empty_zonefile)

        res = testlib.ysi_name_update("foo_{}.test".format(i), value_hash,
                                      wallets[3].privkey)
        if 'error' in res:
            print json.dumps(res)
            return False

        testlib.next_block(**kw)

        # propagate
        res = testlib.ysi_cli_sync_zonefile('foo_{}.test'.format(i),
                                            zonefile_string=empty_zonefile_str)
        if 'error' in res:
            print json.dumps(res)
            return False

        value_hashes.append(value_hash)

    print 'waiting for all zone files to replicate'
    time.sleep(10)

    config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG")
    assert config_path
    restore_dir = os.path.join(os.path.dirname(config_path), "snapshot_dir")

    # snapshot the latest backup
    snapshot_path = os.path.join(os.path.dirname(config_path), "snapshot.bsk")
    rc = ysi.fast_sync_snapshot(snapshot_path, wallets[3].privkey, None)
    if not rc:
        print "Failed to fast_sync_snapshot"
        return False

    if not os.path.exists(snapshot_path):
        print "Failed to create snapshot {}".format(snapshot_path)
        return False

    # sign with more keys
    for i in xrange(4, 6):
        rc = ysi.fast_sync_sign_snapshot(snapshot_path, wallets[i].privkey)
        if not rc:
            print "Failed to sign with key {}".format(i)
            return False

    # restore!
    rc = restore(
        snapshot_path, restore_dir,
        [wallets[3].pubkey_hex, wallets[4].pubkey_hex, wallets[5].pubkey_hex],
        3)
    if not rc:
        print "failed to restore snapshot {}".format(snapshot_path)
        return False

    rc = restore(
        snapshot_path, restore_dir,
        [wallets[5].pubkey_hex, wallets[4].pubkey_hex, wallets[3].pubkey_hex],
        3)
    if not rc:
        print "failed to restore snapshot {}".format(snapshot_path)
        return False

    rc = restore(snapshot_path, restore_dir,
                 [wallets[3].pubkey_hex, wallets[4].pubkey_hex], 2)
    if not rc:
        print "failed to restore snapshot {}".format(snapshot_path)
        return False

    rc = restore(snapshot_path, restore_dir,
                 [wallets[3].pubkey_hex, wallets[5].pubkey_hex], 2)
    if not rc:
        print "failed to restore snapshot {}".format(snapshot_path)
        return False

    rc = restore(snapshot_path, restore_dir,
                 [wallets[4].pubkey_hex, wallets[5].pubkey_hex], 2)
    if not rc:
        print "failed to restore snapshot {}".format(snapshot_path)
        return False

    rc = restore(snapshot_path, restore_dir, [wallets[3].pubkey_hex], 1)
    if not rc:
        print "failed to restore snapshot {}".format(snapshot_path)
        return False

    rc = restore(snapshot_path, restore_dir,
                 [wallets[4].pubkey_hex, wallets[0].pubkey_hex], 1)
    if not rc:
        print "failed to restore snapshot {}".format(snapshot_path)
        return False

    rc = restore(
        snapshot_path, restore_dir,
        [wallets[0].pubkey_hex, wallets[1].pubkey_hex, wallets[5].pubkey_hex],
        1)
    if not rc:
        print "failed to restore snapshot {}".format(snapshot_path)
        return False

    # should fail
    rc = restore(snapshot_path, restore_dir, [wallets[3].pubkey_hex], 2)
    if rc:
        print "restored insufficient signatures snapshot {}".format(
            snapshot_path)
        return False

    shutil.rmtree(restore_dir)

    # should fail
    rc = restore(snapshot_path, restore_dir,
                 [wallets[3].pubkey_hex, wallets[4].pubkey_hex], 3)
    if rc:
        print "restored insufficient signatures snapshot {}".format(
            snapshot_path)
        return False

    shutil.rmtree(restore_dir)

    # should fail
    rc = restore(snapshot_path, restore_dir, [wallets[0].pubkey_hex], 1)
    if rc:
        print "restored wrongly-signed snapshot {}".format(snapshot_path)
        return False

    shutil.rmtree(restore_dir)

    # should fail
    rc = restore(snapshot_path, restore_dir,
                 [wallets[0].pubkey_hex, wallets[3].pubkey_hex], 2)
    if rc:
        print "restored wrongly-signed snapshot {}".format(snapshot_path)
        return False

    shutil.rmtree(restore_dir)

    # should fail
    rc = restore(
        snapshot_path, restore_dir,
        [wallets[0].pubkey_hex, wallets[3].pubkey_hex, wallets[4].pubkey_hex],
        3)
    if rc:
        print "restored wrongly-signed snapshot {}".format(snapshot_path)
        return False

    shutil.rmtree(restore_dir)
def scenario( wallets, **kw ):

    global synchronized

    import ysi_integration_tests.atlas_network as atlas_network

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

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

    # set up RPC daemon
    test_proxy = testlib.TestAPIProxy()
    ysi_client.set_default_proxy( test_proxy )
    wallet_keys = ysi_client.make_wallet_keys( owner_privkey=wallets[3].privkey, data_privkey=wallets[4].privkey, payment_privkey=wallets[5].privkey )
    testlib.ysi_client_set_wallet( "0123456789abcdef", wallet_keys['payment_privkey'], wallet_keys['owner_privkey'], wallet_keys['data_privkey'] )

    # register 10 names
    for i in xrange(0, 10):
        res = testlib.ysi_name_preorder( "foo_{}.test".format(i), wallets[2].privkey, wallets[3].addr )
        if 'error' in res:
            print json.dumps(res)
            return False

    testlib.next_block( **kw )
    
    for i in xrange(0, 10):
        res = testlib.ysi_name_register( "foo_{}.test".format(i), wallets[2].privkey, wallets[3].addr )
        if 'error' in res:
            print json.dumps(res)
            return False

    testlib.next_block( **kw )

    # start up a simple Atlas test network with two nodes: the main one doing the test, and a subordinate one that treats it as a seed peer.
    network_des = atlas_network.atlas_network_build( [17000], {17000: [16264]}, {}, os.path.join( testlib.working_dir(**kw), "atlas_network" ))
    atlas_network.atlas_network_start( network_des )

    time.sleep(5.0)
    
    # make 10 empty zonefiles and propagate them 
    for i in xrange(0, 10):
        data_pubkey = virtualchain.BitcoinPrivateKey(wallet_keys['data_privkey']).public_key().to_hex()
        empty_zonefile = ysi_client.zonefile.make_empty_zonefile( "foo_{}.test".format(i), data_pubkey, urls=["file:///tmp/foo_{}.test".format(i)] )
        empty_zonefile_str = ysi_zones.make_zone_file( empty_zonefile )
        value_hash = ysi_client.hash_zonefile( empty_zonefile )

        res = testlib.ysi_name_update( "foo_{}.test".format(i), value_hash, wallets[3].privkey )
        if 'error' in res:
            print json.dumps(res)
            return False

        testlib.next_block( **kw )

        # propagate 
        res = testlib.ysi_cli_sync_zonefile('foo_{}.test'.format(i), zonefile_string=empty_zonefile_str)
        if 'error' in res:
            print json.dumps(res)
            return False

    # wait at most 10 seconds for atlas network to converge
    synchronized = False
    for i in xrange(0, 10):
        atlas_network.atlas_print_network_state( network_des )
        if atlas_network.atlas_network_is_synchronized( network_des, testlib.last_block( **kw ) - 1, 1 ):
            print "Synchronized!"
            synchronized = True
            break

        else:
            time.sleep(1.0)
    
    # shut down 
    atlas_network.atlas_network_stop( network_des )
    return synchronized
def scenario(wallets, **kw):

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

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

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

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

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

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

    testlib.next_block(**kw)

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

    # can't do anything with the name for another 10 blocks
    resp = testlib.ysi_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)
    testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw))

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

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

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

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

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

    # verify that operations continue to fail
    resp = testlib.ysi_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)
    testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw))

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

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

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

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

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

    testlib.next_block(**kw)

    # re-register
    resp = testlib.ysi_name_register("foo.test",
                                     wallets[4].privkey,
                                     wallets[0].addr,
                                     safety_checks=False)
    if 'error' in resp:
        print json.dumps(resp, indent=4)

    testlib.next_block(**kw)

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

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

    global fail_blocks

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

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

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

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

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

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

    # verify that operations fail
    resp = testlib.ysi_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.ysi_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.ysi_name_renew("foo.test",
                                  wallets[3].privkey,
                                  safety_checks=False,
                                  tx_fee=10000 * 5)
    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.ysi_name_revoke("foo.test",
                                   wallets[3].privkey,
                                   safety_checks=False)
    if 'error' in resp:
        print json.dumps(resp, indent=4)

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

    global fail_blocks

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

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

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

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

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

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

    # can't do anything with the name for another 10 blocks
    resp = testlib.ysi_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)
    testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw))

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

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

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

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

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

    # verify that operations continue to fail (BUG in 0.13: THIS SUCCEEDS WHEN IT SHOULD FAIL)
    resp = testlib.ysi_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.ysi_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.ysi_name_renew("foo.test",
                                  wallets[3].privkey,
                                  safety_checks=False,
                                  tx_fee=10000 * 5)
    if 'error' in resp:
        print json.dumps(resp, indent=4)

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

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

    # warn the serialization checker that this changes behavior from 0.13
    print "BLOCKSTACK_SERIALIZATION_CHANGE_BEHAVIOR"
    sys.stdout.flush()
def scenario(wallets, **kw):

    global synchronized, value_hash

    import ysi_integration_tests.atlas_network as atlas_network

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

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

    # set up RPC daemon
    test_proxy = testlib.TestAPIProxy()
    ysi_client.set_default_proxy(test_proxy)
    wallet_keys = ysi_client.make_wallet_keys(
        owner_privkey=wallets[3].privkey,
        data_privkey=wallets[4].privkey,
        payment_privkey=wallets[5].privkey)
    testlib.ysi_client_set_wallet("0123456789abcdef",
                                  wallet_keys['payment_privkey'],
                                  wallet_keys['owner_privkey'],
                                  wallet_keys['data_privkey'])

    # register 10 names
    for i in xrange(0, 10):
        res = testlib.ysi_name_preorder("foo_{}.test".format(i),
                                        wallets[2].privkey, wallets[3].addr)
        if 'error' in res:
            print json.dumps(res)
            return False

    testlib.next_block(**kw)

    for i in xrange(0, 10):
        res = testlib.ysi_name_register("foo_{}.test".format(i),
                                        wallets[2].privkey, wallets[3].addr)
        if 'error' in res:
            print json.dumps(res)
            return False

    testlib.next_block(**kw)

    # start up an Atlas test network with 9 nodes: the main one doing the test, and 8 subordinate ones that treat it as a seed peer
    # organize nodes into a linear chain: node n is neighbor to n-1 and n+1, with the seed at one end.
    # nodes cannot talk to anyone else.
    atlas_nodes = [17000, 17001, 17002, 17003, 17004, 17005, 17006, 17007]
    atlas_topology = {}

    atlas_topology[17000] = [16264, 17001]
    atlas_topology[17007] = [17006]

    for i in xrange(1, len(atlas_nodes) - 1):
        atlas_topology[atlas_nodes[i]] = [
            atlas_nodes[i - 1], atlas_nodes[i + 1]
        ]

    def chain_drop(src_hostport, dest_hostport):
        if src_hostport is None:
            return 0.0

        src_host, src_port = ysi_client.utils.url_to_host_port(src_hostport)
        dest_host, dest_port = ysi_client.utils.url_to_host_port(dest_hostport)

        if (src_port == 16264
                and dest_port == 17000) or (src_port == 17000
                                            and dest_port == 16264):
            # seed end of the chain
            return 0.0

        if abs(src_port - dest_port) <= 1:
            # chain link
            return 0.0

        # drop otherwise
        return 1.0

    network_des = atlas_network.atlas_network_build(
        atlas_nodes, atlas_topology, {},
        os.path.join(testlib.working_dir(**kw), "atlas_network"))
    atlas_network.atlas_network_start(network_des, drop_probability=chain_drop)

    print "Waiting 25 seconds for the altas peers to catch up"
    time.sleep(25.0)

    # make 10 empty zonefiles and propagate them
    for i in xrange(0, 10):
        data_pubkey = virtualchain.BitcoinPrivateKey(
            wallet_keys['data_privkey']).public_key().to_hex()
        empty_zonefile = ysi_client.zonefile.make_empty_zonefile(
            "foo_{}.test".format(i),
            data_pubkey,
            urls=["file:///tmp/foo_{}.test".format(i)])
        empty_zonefile_str = ysi_zones.make_zone_file(empty_zonefile)
        value_hash = ysi_client.hash_zonefile(empty_zonefile)

        res = testlib.ysi_name_update("foo_{}.test".format(i), value_hash,
                                      wallets[3].privkey)
        if 'error' in res:
            print json.dumps(res)
            return False

        testlib.next_block(**kw)

        # propagate
        res = testlib.ysi_cli_sync_zonefile('foo_{}.test'.format(i),
                                            zonefile_string=empty_zonefile_str)
        if 'error' in res:
            print json.dumps(res)
            return False

    # wait at most 60 seconds for atlas network to converge
    synchronized = False
    for i in xrange(0, 60):
        atlas_network.atlas_print_network_state(network_des)
        if atlas_network.atlas_network_is_synchronized(
                network_des,
                testlib.last_block(**kw) - 1, 1):
            print "Synchronized!"
            sys.stdout.flush()
            synchronized = True
            break

        else:
            time.sleep(1.0)

    # shut down
    atlas_network.atlas_network_stop(network_des)
    if not synchronized:
        print "Not synchronized"
        sys.stdout.flush()

    return synchronized