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

    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 )

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

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

    testlib.next_block( **kw )

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

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

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

    testlib.next_block( **kw )

    
    testlib.ysi_namespace_ready( "test", wallets[1].privkey )
    testlib.next_block( **kw )
    
    testlib.expect_snv_fail( "foo.test" )
    testlib.expect_snv_fail( "bar.test" )
    testlib.expect_snv_fail( "baz.test" )
def scenario(wallets, **kw):

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

    # NOTE: names expire in 5 * NAMESPACE_LIFETIME_MULTIPLER blocks
    testlib.ysi_namespace_reveal(
        "test", wallets[1].addr, 5, 250, 4,
        [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10,
        wallets[0].privkey)
    testlib.next_block(**kw)

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

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

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

    # put this here to help with interactive testing
    testlib.ysi_client_initialize_wallet("0123456789abcdef",
                                         wallets[2].privkey,
                                         wallets[3].privkey,
                                         wallets[4].privkey)

    print ""
    print "         An empty namespace called 'test' has been created"
    print "         Feel free to experiment with other namespaces"
    print ""
    print "         Available keys with a balance:"
    for w in wallets:
        print "         *  {}".format(testlib.serialize_privkey_info(
            w.privkey))

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

    # wait for a bit...
    for i in xrange(0, 10):
        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)
def scenario( wallets, **kw ):

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

    testlib.ysi_namespace_reveal( "test", wallets[1].addr, 2, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey, version_bits=2)
    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 )
        return False

    testlib.next_block( **kw )

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

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

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

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

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

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

    testlib.next_block( **kw )

    res = testlib.ysi_name_register( "foo.test", wallets[2].privkey, wallets[4].addr, zonefile_hash='22' * 20 )    
    if 'error' in res:
        print res
        return False

    testlib.next_block( **kw )

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

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

    if name_rec['value_hash'] != '22' * 20:
        print 'wrong value hash'
        return False
Exemple #7
0
def scenario( wallets, **kw ):

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

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

    testlib.next_block( **kw )
    testlib.expect_snv_fail_at('test', testlib.get_current_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 )

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

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

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

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

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

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

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

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

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

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

    # only wallets[3] should get it
    testlib.ysi_name_register("foo.test",
                              wallets[4].privkey,
                              wallets[3].addr,
                              safety_checks=False)
    testlib.ysi_name_register("foo.test",
                              wallets[2].privkey,
                              wallets[3].addr,
                              safety_checks=False)
    testlib.next_block(**kw)
    testlib.expect_snv_fail_at("foo.test", testlib.get_current_block(**kw))
def scenario(wallets, **kw):

    global snv_block_id, last_consensus

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

    # NOTE: names expire in 5 * NAMESPACE_LIFETIME_MULTIPLIER blocks
    testlib.ysi_namespace_reveal(
        "test", wallets[1].addr, 5, 250, 4,
        [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10,
        wallets[0].privkey)
    testlib.next_block(**kw)

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

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

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

    snv_block_id = testlib.get_current_block()

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

    # this one expires the name
    testlib.next_block(**kw)

    last_consensus = testlib.get_consensus_at(testlib.get_current_block())
Exemple #10
0
def scenario(wallets, **kw):

    global snv_block_id, last_consensus

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

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

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

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

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

    snv_block_id = testlib.get_current_block()

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

    last_consensus = testlib.get_consensus_at(testlib.get_current_block())
Exemple #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, 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)
Exemple #12
0
def scenario( wallets, **kw ):

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

    # NOTE: names expire in 5 * NAMESPACE_LIFETIME_MULTIPLER blocks
    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.ysi_name_preorder( "foo.test", wallets[3].privkey, wallets[4].addr )

    testlib.next_block( **kw )

    first_preorder = testlib.get_current_block( **kw )

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

    for i in xrange(0, 2 * ysi_server.config.get_epoch_namespace_lifetime_multiplier( testlib.get_current_block(**kw), "test" ) + 1):
        testlib.next_block( **kw )

    testlib.next_block( **kw )

    # should fail
    testlib.ysi_name_register( "foo.test", wallets[3].privkey, wallets[4].addr )
    testlib.next_block( **kw )
    testlib.expect_snv_fail_at('foo.test', testlib.get_current_block(**kw))

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

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

    # pre-0.0.14 uses lifetime field literally; this should no longer work.
    for i in xrange(0, 5 * NAMESPACE_LIFETIME_MULTIPLIER):
        testlib.next_block(**kw)

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

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

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

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

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

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

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

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

    # has to be the same key that registered...
    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)

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

    # save the wallet
    wallet = testlib.ysi_client_initialize_wallet("0123456789abcdef",
                                                  wallets[2].privkey,
                                                  wallets[3].privkey,
                                                  wallets[4].privkey,
                                                  start_rpc=False)
    if 'error' in wallet:
        print 'failed to set wallet: {}'.format(wallet)
        return False

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

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

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

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

    testlib.ysi_name_register("demo.id", wallets[2].privkey, wallets[3].addr)
    testlib.next_block(**kw)
def scenario( wallets, **kw ):

    global wallet_keys, wallet_keys_2, error, index_file_data, resource_data

    empty_key = ECPrivateKey().to_hex()

    wallet_keys = testlib.ysi_client_initialize_wallet(
        "0123456789abcdef", wallets[1].privkey, wallets[2].privkey, wallets[0].privkey)
    test_proxy = testlib.TestAPIProxy()
    ysi_client.set_default_proxy( test_proxy )

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

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

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

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

    testlib.next_block( **kw )

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

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

    api_pass = conf['api_password']

    # let's do a withdraw of all
    res = testlib.ysi_REST_call('POST', '/v1/wallet/balance', None, api_pass=api_pass, data= {
        'address' : virtualchain.get_privkey_address(empty_key),
        })
    if 'error' in res['response']:
        res['test'] = 'Failed to perform withdraw'
        print json.dumps(res)
        error = True
        return False
    for i in xrange (0, 1):
        testlib.next_block( **kw )
    print 'Waiting for the withdraw to go through'
    res = testlib.ysi_REST_call('GET', '/v1/wallet/balance/0', None, api_pass=api_pass)
    if 'error' in res['response']:
        res['test'] = 'Failed to get wallet balance'
        print json.dumps(res)
        error = True
        return False

    res = testlib.ysi_REST_call('GET', '/v1/wallet/balance/0', None, api_pass=api_pass)
    if 'error' in res['response']:
        res['test'] = 'Failed to get wallet balance'
        print json.dumps(res)
        error = True
        return False
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)

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

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

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

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

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

    testlib.next_block(**kw)

    testlib.ysi_namespace_ready("test", wallets[1].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)
def scenario(wallets, **kw):

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

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

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

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

    # should fail (safety checks stop it)
    resp = testlib.ysi_name_register('foo.test',
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='22' * 20)
    if 'error' not in resp:
        print resp
        return False

    # should succeed in being sent, but will be rejected
    resp = testlib.ysi_name_register('foo.test',
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='22' * 20,
                                     safety_checks=False,
                                     tx_fee=300 * 5)
    if 'error' in resp:
        print resp
        return False

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

    # must NOT be registered
    resp = testlib.ysi_cli_whois('foo.test')
    if 'error' not in resp:
        print resp
        return False

    # epoch 3 now active.
    # try again, and it should succeed
    resp = testlib.ysi_name_register('foo.test',
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     zonefile_hash='22' * 20)
    if 'error' in resp:
        print resp
        return False

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

    global update_hashes, update_blocks

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

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

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

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

        testlib.next_block(**kw)

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

        testlib.next_block(**kw)

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

        testlib.next_block(**kw)

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

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

        if i == 10:
            break

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

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

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

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

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

        testlib.next_block(**kw)

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

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

        testlib.next_block(**kw)

        if i == 3:
            break

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

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

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

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

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

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

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

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

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

    snv_block_id_foo = testlib.get_current_block()

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

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

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

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

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

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

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

    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)
Exemple #26
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,
                              wallet=wallets[3])
    testlib.next_block(**kw)

    # should fail, since multisig isn't enabled yet
    testlib.ysi_name_register("foo.test",
                              wallets[2].privkey,
                              wallets[3].addr,
                              wallet=wallets[3])
    testlib.next_block(**kw)

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

    # foo.test should be preordered (in both 0.13 and 0.14)
    state_engine = testlib.get_state_engine()
    preorder = state_engine.get_name_preorder(
        "foo.test", virtualchain.make_payment_script(wallets[2].addr),
        wallets[3].addr)
    if preorder is None:
        print "foo.test not preordered"
        return False

    # epoch changes here

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

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

    testlib.ysi_name_register("bar.test", wallets[3].privkey, wallets[4].addr)
    testlib.next_block(**kw)
def scenario( wallets, **kw ):

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

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

    testlib.ysi_namespace_ready( "id", wallets[1].privkey )
    testlib.next_block( **kw )
    
    wallet = testlib.ysi_client_initialize_wallet( "0123456789abcdef", wallets[2].privkey, wallets[3].privkey, wallets[4].privkey )
    resp = testlib.ysi_cli_register( "foo.id", "0123456789abcdef", 
                                            recipient_address = 'mi8mUNSFC9EoGXmjPF8vKqCUSfGE2fbD4V')
    if 'error' in resp:
        print >> sys.stderr, json.dumps(resp, indent=4, sort_keys=True)
        return False
   
    # wait for the preorder to get confirmed
    for i in xrange(0, 10):
        testlib.next_block( **kw )

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

    r = ysi_client.actions.cli_get_registrar_info(None)
    assert 'errors' not in r['register'][0]

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

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

    # wait for the update to go off
    for i in xrange(0, 8):
        testlib.next_block( **kw )
    
    # drain the wallet
    print >> sys.stderr, "Lets drain the wallet."
    testlib.ysi_cli_withdraw( "0123456789abcdef", 'mi8mUNSFC9EoGXmjPF8vKqCUSfGE2fbD4V' )
    print >> sys.stderr, "Drained!"

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

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

    global final_consensus

    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_multi( ["foo.test", "bar.test", "baz.test"], wallets[2].privkey, [wallets[3].addr, wallets[4].addr, wallets[5].addr] )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        sys.exit(1)
       
    testlib.next_block( **kw )

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

    resp = testlib.ysi_name_preorder( "goo.test", wallets[2].privkey, wallets[3].addr )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        sys.exit(1)

    testlib.next_block( **kw )

    resp = testlib.ysi_name_register( "bar.test", wallets[2].privkey, wallets[4].addr )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        sys.exit(1)

    resp = testlib.ysi_name_register( "goo.test", wallets[2].privkey, wallets[3].addr )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        sys.exit(1)

    resp = testlib.ysi_name_register( "baz.test", wallets[2].privkey, wallets[5].addr )
    if 'error' in resp:
        print json.dumps( resp, indent=4 )
        sys.exit(1)

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

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

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

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

    print >> sys.stderr, "We're a go!  Start the Blockstack API server with `ysi api start`"