Пример #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)
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)
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)
Пример #5
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_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_transfer( "foo.test", wallets[0].addr, True, wallets[4].privkey )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )

    testlib.next_block( **kw )

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

    testlib.next_block( **kw )
Пример #6
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))
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, 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 * NAMESPACE_LIFETIME_MULTIPLIER - 4):
        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 )
    testlib.next_block( **kw )
    
    # transfer 
    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 )
    testlib.next_block( **kw )

    # update
    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 )
Пример #8
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)
Пример #9
0
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_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)

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

    testlib.next_block(**kw)
Пример #10
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)
Пример #11
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 )
Пример #12
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
Пример #13
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[3].privkey, wallets[4].addr )
    testlib.next_block( **kw )

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

    # should succeed 
    # in 0.13, this should go to a "None" address
    # in 0.14, this should go to the designated p2sh address
    testlib.ysi_name_transfer( "foo.test", wallets[2].addr, True, wallets[4].privkey )
    testlib.next_block( **kw )
   
    # should fail
    # in 0.13, this is because it's owned by the "None" address now 
    # in 0.14, this is because we're waiting until F-day 
    testlib.ysi_name_transfer( "foo.test", wallets[1].addr, True, wallets[2].privkey, safety_checks=False )
    testlib.next_block( **kw )

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

    # next epoch 

    # now, this should succeed
    testlib.ysi_name_transfer( "foo.test", wallets[0].addr, True, wallets[2].privkey )
    testlib.next_block( **kw )
Пример #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, 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)

    # renew

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

    testlib.next_block(**kw)

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

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

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

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

    testlib.next_block(**kw)

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

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

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

    # renew/update

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

    testlib.next_block(**kw)

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

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

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

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

    testlib.next_block(**kw)

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

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

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

    # renew/update/transfer

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

    testlib.next_block(**kw)

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

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

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

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

    testlib.next_block(**kw)

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

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

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

    # renew/transfer
    resp = testlib.ysi_name_renew("foo.test",
                                  wallets[2].privkey,
                                  recipient_addr=wallets[1].addr)
    if 'error' in resp:
        print json.dumps(resp, indent=4)
        return False

    testlib.next_block(**kw)

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

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

    if res['owner_address'] != wallets[1].addr:
        print res
        return False
Пример #15
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("foo1.test", wallets[2].privkey, wallets[3].addr)
    testlib.ysi_name_preorder("foo2.test", wallets[2].privkey, wallets[3].addr)
    testlib.ysi_name_preorder("foo3.test", wallets[2].privkey, wallets[3].addr)
    testlib.next_block(**kw)

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

    # whois
    for i in xrange(1, 4):
        name = 'foo{}.test'.format(i)

        res = testlib.ysi_cli_whois(name)
        if 'error' in res:
            print res
            return False

        if not res.has_key('zonefile_hash') or res[
                'zonefile_hash'] != '{}{}'.format(i, i) * 20:
            print res
            return False

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

    testlib.ysi_name_transfer('foo1.test', wallets[4].addr, True,
                              wallets[3].privkey)
    testlib.ysi_name_transfer('foo2.test', wallets[4].addr, True,
                              wallets[3].privkey)
    testlib.ysi_name_transfer('foo3.test', wallets[4].addr, True,
                              wallets[3].privkey)

    testlib.next_block(**kw)

    # whois
    for i in xrange(1, 4):
        name = 'foo{}.test'.format(i)

        res = testlib.ysi_cli_whois(name)
        if 'error' in res:
            print res
            return False

        if not res.has_key('zonefile_hash') or res[
                'zonefile_hash'] != '{}{}'.format(i, i) * 20:
            print res
            return False

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

    testlib.ysi_name_transfer('foo1.test', wallets[0].addr, False,
                              wallets[4].privkey)
    testlib.ysi_name_transfer('foo2.test', wallets[0].addr, False,
                              wallets[4].privkey)
    testlib.ysi_name_transfer('foo3.test', wallets[0].addr, False,
                              wallets[4].privkey)

    testlib.next_block(**kw)

    # whois
    for i in xrange(1, 4):
        name = 'foo{}.test'.format(i)

        res = testlib.ysi_cli_whois(name)
        if 'error' in res:
            print res
            return False

        if res.has_key('zoenfile_hash') and res['zonefile_hash']:
            print res
            return False

        if res['owner_address'] != wallets[0].addr:
            print res
            return False
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, 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)

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

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

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

    for did in [foo_did, bar_did, baz_did]:
        res = ysi_client.proxy.get_DID_blockchain_record(did)
        if 'error' in res:
            print res
            return False

        if res['address'] != wallets[3].addr:
            print 'wrong address; expected {}'.format(wallets[3].addr)
            print json.dumps(res, indent=4, sort_keys=True)
            return False

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

    # wait for them all to expire...
    for i in xrange(0, 3):
        testlib.next_block(**kw)

    # re-preorder/reregister to different addresses
    testlib.ysi_name_preorder("foo.test", wallets[4].privkey, wallets[0].addr)
    testlib.ysi_name_preorder("bar.test", wallets[4].privkey, wallets[1].addr)
    testlib.ysi_name_preorder("baz.test", wallets[4].privkey, wallets[2].addr)
    testlib.next_block(**kw)

    # re-register
    testlib.ysi_name_register("foo.test", wallets[4].privkey, wallets[0].addr)
    testlib.ysi_name_register("bar.test", wallets[4].privkey, wallets[1].addr)
    testlib.ysi_name_register("baz.test", wallets[4].privkey, wallets[2].addr)
    testlib.next_block(**kw)

    # foo's DID should no longer resolve, since foo was revoked
    res = ysi_client.proxy.get_DID_blockchain_record(foo_did)
    if 'error' not in res:
        print 'accidentally resolved {}'.format(foo_did)
        print res
        return False

    # non-revoked DIDs should resolve to the new addresses
    for did, addr in zip([bar_did, baz_did],
                         [wallets[1].addr, wallets[2].addr]):
        res = ysi_client.proxy.get_DID_blockchain_record(did)
        if 'error' in res:
            print res
            return False

        if res['address'] != addr:
            print 'wrong address post-reregister; expected {}'.format(addr)
            print json.dumps(res, indent=4, sort_keys=True)
            return False

    # dids for the new names
    foo2_did = 'did:stack:v0:{}-0'.format(wallets[0].addr)
    bar2_did = 'did:stack:v0:{}-0'.format(wallets[1].addr)
    baz2_did = 'did:stack:v0:{}-0'.format(wallets[2].addr)

    # new DIDs should all resolve to new addresses
    for did, addr in zip([foo2_did, bar2_did, baz2_did],
                         [wallets[0].addr, wallets[1].addr, wallets[2].addr]):
        res = ysi_client.proxy.get_DID_blockchain_record(did)
        if 'error' in res:
            print res
            return False

        if res['address'] != addr:
            print 'wrong address post-reregister: expected {}'.format(addr)
            print json.dumps(res, indent=4, sort_keys=True)
            return False

    # transfer all names back to wallets[3]
    testlib.ysi_name_transfer("foo.test", wallets[3].addr, True,
                              wallets[0].privkey)
    testlib.ysi_name_transfer("bar.test", wallets[3].addr, True,
                              wallets[1].privkey)
    testlib.ysi_name_transfer("baz.test", wallets[3].addr, True,
                              wallets[2].privkey)
    testlib.next_block(**kw)

    # all DIDs except for the original DID for foo.test should now resolve to wallets[3].addr
    for did in [bar_did, baz_did, foo2_did, bar2_did, baz2_did]:
        res = ysi_client.proxy.get_DID_blockchain_record(did)
        if 'error' in res:
            print res
            return False

        if res['address'] != wallets[3].addr:
            print 'wrong address post-reregister: expected {}'.format(
                wallets[3].addr)
            print json.dumps(res, indent=4, sort_keys=True)
            return False

    # foo's original DID should not resolve
    res = ysi_client.proxy.get_DID_blockchain_record(foo_did)
    if 'error' not in res:
        print 'accidentally resolved {}'.format(foo_did)
        print res
        return False
Пример #17
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)

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

    testlib.next_block(**kw)

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

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

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

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

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

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

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

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

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

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

    global debug

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

    global renew_block

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    testlib.next_block(**kw)
    renew_block = testlib.get_current_block(**kw)
Пример #21
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()
Пример #22
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):

    global first_name_block

    # 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)  # end of 689

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

    testlib.next_block(**kw)  # 690

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

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

    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)  # end of 692.  epoch 2 activates now

    whois = testlib.ysi_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.ysi_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.ysi_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.ysi_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.ysi_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.ysi_name_update('foo.test', '66' * 20, wallets[4].privkey)
    if 'error' not in resp:
        print resp
        return False

    # renew should work
    resp = testlib.ysi_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.ysi_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 snv_block_id_foo, snv_txid_bar, snv_txid_baz, last_consensus

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

    resp = testlib.ysi_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.ysi_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.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("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.ysi_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(**kw))
Пример #25
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)
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 ):

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

    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 debug, consensus, small_unspents

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

    expected_utxo_count = res['expected_utxo_count']

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

    testlib.next_block(**kw)

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

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

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

    # finish ordering the namespace
    resp = testlib.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 simplejson.dumps(resp, indent=4)

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

    testlib.next_block(**kw)

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

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

    testlib.next_block(**kw)

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

    expected_utxo_count = res['expected_utxo_count']

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

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

    testlib.next_block(**kw)

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

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

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

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

    testlib.next_block(**kw)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    testlib.next_block(**kw)

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

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

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

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

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

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

    testlib.next_block(**kw)

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

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

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

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

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

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

    testlib.next_block(**kw)
    '''