def scenario( wallets, **kw ):

    blockstack.lib.config.set_genesis_block_patches(genesis_patches)
    testlib.set_account_audits(False)

    # in block 689, so the patch hasn't taken place yet
    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 100 + 600000
    assert balances[wallets[1].addr][STACKS] == 123 + 1000
    assert balances[wallets[2].addr][STACKS] == 0

    # send some tokens to a brand-new address
    testlib.blockstack_send_tokens(new_addr, "STACKS", 600000, wallets[0].privkey)
    testlib.blockstack_send_tokens(new_unlocked_addr, "STACKS", 100, wallets[0].privkey)
    testlib.next_block(**kw) # end of 689, triggers vesting of block 690
    
    assert virtualchain.lib.indexer.StateEngine.get_block_statistics(testlib.get_current_block(**kw))['num_processed_ops'] == 2

    # new balances should reflect patch
    balances = testlib.get_addr_balances([w.addr for w in wallets] + [new_addr_b58, new_grant_addr_b58, new_unlocked_addr_b58])
    print balances

    assert balances[wallets[0].addr][STACKS] == 100 + 200 + 600000 + 600001 + 10000 + 10001 + 10002 + 10003 + 10004 + 10005 - 600000 - 100         # += new value + retroactive vesting
    assert balances[wallets[1].addr][STACKS] == 123 + 1000 + (10000000 * 10)
    assert balances[wallets[2].addr][STACKS] == 123456
    assert balances[new_addr_b58][STACKS] == 600000 + 222222 + 66
    assert balances[new_grant_addr_b58][STACKS] == 567 + (10000000 * 10)
    assert balances[new_unlocked_addr_b58][STACKS] == 100 + 123456 + 22000 + 22001 + 22002 + 22003 + 22004 + 22005

    # send some tokens to a brand-new address
    # should be transfer-locked
    testlib.blockstack_send_tokens(new_addr_b58, "STACKS", 600000, wallets[0].privkey, safety_checks=False, expect_fail=True)
    testlib.blockstack_send_tokens(new_grant_addr_b58, "STACKS", 1, new_wallet, safety_checks=False, expect_fail=True)
    testlib.blockstack_send_tokens(new_grant_addr_b58, "STACKS", 10000000, wallets[1].privkey, safety_checks=False)
    testlib.blockstack_send_tokens(new_addr_b58, "STACKS", 10000000, wallets[1].privkey, safety_checks=False)
    testlib.blockstack_send_tokens(new_grant_addr_b58, "STACKS", 3, new_unlocked_wallet, safety_checks=False)
    testlib.next_block(**kw)

    assert virtualchain.lib.indexer.StateEngine.get_block_statistics(testlib.get_current_block(**kw))['num_processed_ops'] == 3
    
    balances = testlib.get_addr_balances([w.addr for w in wallets] + [new_addr_b58, new_grant_addr_b58, new_unlocked_addr_b58])
    print balances

    assert balances[wallets[0].addr][STACKS] == 100 + 200 + 600000 + 600001 + 600010 + 10000 + 10001 + 10002 + 10003 + 10004 + 10005 + 10006 - 600000 - 100         # += new value + retroactive vesting
    assert balances[wallets[1].addr][STACKS] == 123 + 1000 + (10000000 * 10) - 10000000 - 10000000
    assert balances[wallets[2].addr][STACKS] == 123456
    assert balances[new_addr_b58][STACKS] == 600000 + 222222 + 66 + 10000000
    assert balances[new_grant_addr_b58][STACKS] == 567 + (10000000 * 10) + 10000000 + 3
    assert balances[new_unlocked_addr_b58][STACKS] == 100 + 123456 + 22000 + 22001 + 22002 + 22003 + 22004 + 22005 + 22006 - 3

    # TODO history of each address should be changed to reflect vesting
    # TODO try different lock heights -- can we retroactively grant tokens to an address that has received or spent tokens already?
    # TODO: make sure we re-lock an account if it received tokens prior to the patch, and is granted new tokens with a time-lock

    """
Пример #2
0
def scenario(wallets, **kw):

    testlib.set_account_audits(False)

    times = []

    for i in range(690, 726):
        t1 = time.time()

        # vest accounts
        testlib.next_block(**kw)

        t2 = time.time()
        times.append(t2 - t1)

    balances = {}
    for wallet in wallets:
        info = requests.get(
            'http://localhost:16268/v1/accounts/{}/STACKS/balance'.format(
                wallet.addr)).json()
        balances[wallet.addr] = {STACKS: int(info['balance'])}

    for i in range(0, len(wallets)):
        assert balances[wallets[i].addr][STACKS] == 3600000

    avg = sum(times) / len(times)
    times.sort()
    med = times[len(times) / 2]
    _90th = times[(len(times) * 9) / 10]
    _95th = times[(len(times) * 95) / 100]
    _99th = times[(len(times) * 99) / 100]

    print ''
    print 'avg time to vest: {}'.format(avg)
    print 'med time to vest: {}'.format(med)
    print '90% time to vest: {}'.format(_90th)
    print '95% time to vest: {}'.format(_95th)
    print '99% time to vest: {}'.format(_99th)
    print ''

    sys.stdout.flush()

    time.sleep(60)
Пример #3
0
def scenario( wallets, **kw ):
    global TRANSACTION_BROADCASTER_URL


    # fill in URL
    tb_conf_path = os.path.join(os.environ['BLOCKSTACK_WORKING_DIR'], 'transaction-broadcaster.conf')
    with open(tb_conf_path, 'r') as f:
        tb_conf = json.loads(f.read().strip())

    TRANSACTION_BROADCASTER_URL = 'http://{}:{}'.format(TESTNET_PUBLIC_HOST, tb_conf['port'])

    PORTNUM = int(os.environ.get('TESTNET_PORTNUM', '30001'))
    start_test_server(PORTNUM)

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

    # same price curve as public .id namespace
    testlib.blockstack_namespace_reveal( "id2", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey, version_bits=3)
    testlib.blockstack_namespace_reveal( "test", wallets[1].addr, -1, 250, 4, [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey, version_bits=3)
    testlib.blockstack_namespace_reveal( "sandbox", wallets[1].addr, -1, 250, 4, [6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey, version_bits=3)
    testlib.next_block( **kw )

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

    testlib.set_account_audits(False)

    print 'Testnet initialized'

    # do 1-minute block times forever
    while True:
        time.sleep(60)
        testlib.next_block(**kw)
Пример #4
0
def scenario(wallets, **kw):
    patch_addrs_path = blockstack.lib.config.get_genesis_bulk_address_path(
        "blockchain-airdrop-2020.csv")
    patch_file_contents = open(patch_addrs_path).read().strip()
    patch_file_addrs = map(
        lambda a: str(a.strip()),
        filter(lambda a: len(a.strip()) > 0, patch_file_contents.split('\n')))
    assert len(patch_file_addrs) == 322146

    for a in patch_file_addrs:
        try:
            virtualchain.address_reencode(a)
        except Exception as e:
            print "not a valid address: {}".format(a)
            traceback.print_exc()
            raise e

    blockstack.lib.config.set_genesis_block_patches_files(
        genesis_patches_files)
    testlib.set_account_audits(False)

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

    for i in range(0, len(patch_file_addrs) / 10000):
        assert genesis_patches_files.get(str(i + 691)) is not None
        assert genesis_patches_files[str(
            i + 691)]['metadata'] == 'batch-{}'.format(i + 1)

    testlib.next_block(**kw)

    times = []

    for i in range(0, (len(patch_file_addrs) / 10000) + 1):
        t1 = time.time()
        testlib.next_block(
            **kw)  # make the balances real (end of 691 + i, start of 692 + i)
        t2 = time.time()

        db_path = os.path.join(os.environ['BLOCKSTACK_WORKING_DIR'],
                               'blockstack-server.db')
        db = namedb.namedb_open(db_path)
        cur = db.cursor()
        cur.execute('BEGIN')
        for j in range(i * 10000, min(len(patch_file_addrs), (i + 1) * 10000)):
            addr = virtualchain.address_reencode(patch_file_addrs[j].strip())
            acct = namedb.namedb_get_account(cur, addr, 'STACKS')
            assert acct is not None, "no account {} (the {}'th one)".format(
                addr, j)
            assert namedb.namedb_get_account_balance(acct) == 100 * 10**6
        cur.execute('END')

        print "Processing time: {}".format(t2 - t1)
        times.append(t2 - t1)
        db.close()

    print "Total processing times"
    for t in times:
        print "{}".format(t)

    db_path = os.path.join(os.environ['BLOCKSTACK_WORKING_DIR'],
                           'blockstack-server.db')
    db = namedb.namedb_open(db_path)
    cur = db.cursor()
    cur.execute('BEGIN')
    for i in range(0, len(patch_file_addrs)):
        if i % 1000 == 0:
            print "Tested {} addresses".format(i)

        addr = virtualchain.address_reencode(patch_file_addrs[i].strip())
        acct = namedb.namedb_get_account(cur, addr, 'STACKS')
        assert acct is not None, "no account {} (the {}'th one)".format(
            addr, i)
        assert namedb.namedb_get_account_balance(acct) == 100 * 10**6
    cur.execute('END')
Пример #5
0
def scenario(wallets, **kw):
    global GAIA_READ_URL
    global GAIA_READ_PORT
    global GAIA_WRITE_PORT
    global GAIA_WRITE_URL

    # get gaia hub info
    with open(os.path.join(os.environ['BLOCKSTACK_WORKING_DIR'], 'gaia.conf'),
              'r') as f:
        GAIA_CONF = json.loads(f.read().strip())

    try:
        GAIA_READ_PORT = urlparse.urlparse(
            GAIA_CONF['readURL']).netloc.split(':')[-1]
        GAIA_READ_PORT = int(GAIA_READ_PORT)
    except:
        GAIA_READ_PORT = 80

    if os.environ.get('BLOCKSTACK_PUBLIC_TESTNET_GAIA_READ_PORT'):
        GAIA_READ_PORT = int(
            os.environ['BLOCKSTACK_PUBLIC_TESTNET_GAIA_READ_PORT'])

    read_urlinfo = urlparse.urlparse(GAIA_CONF['readURL'])

    GAIA_READ_URL = 'http://{}:{}'.format(
        read_urlinfo.netloc.split(':')[0], GAIA_READ_PORT)

    GAIA_WRITE_PORT = GAIA_CONF['port']
    if os.environ.get('BLOCKSTACK_PUBLIC_TESTNET_GAIA_WRITE_PORT'):
        GAIA_WRITE_PORT = int(
            os.environ['BLOCKSTACK_PUBLIC_TESTNET_GAIA_WRITE_PORT'])

    GAIA_WRITE_URL = 'http://{}:{}'.format(GAIA_CONF['servername'],
                                           GAIA_WRITE_PORT)

    # fill in URL
    tb_conf_path = os.path.join(os.environ['BLOCKSTACK_WORKING_DIR'],
                                'transaction-broadcaster.conf')
    with open(tb_conf_path, 'r') as f:
        tb_conf = json.loads(f.read().strip())

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

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

    # import a name with the CLI
    res = testlib.nodejs_cli('name_import', 'hello_imports.test',
                             'ID-{}'.format(wallets[3].addr),
                             'http://*****:*****@Person',
            'account': []
        }, wallets[3].privkey)
    testlib.blockstack_put_profile('hello_imports.test', profile_data,
                                   wallets[3].privkey, 'http://*****:*****@Person',
            'account': []
        }, wallets[3].privkey)
    testlib.blockstack_put_profile('hello2.test', profile_data,
                                   wallets[3].privkey, 'http://localhost:4001')

    stop_subdomain_registrar()
def scenario( wallets, **kw ):
    patch_file_contents = '\n'.join(patch_file_addrs)
    
    h = hashlib.new('sha256')
    h.update(patch_file_contents)
    patch_file_hash = h.hexdigest()

    with open(patch_addrs_path, 'w') as f:
        f.write(patch_file_contents)

    for k in genesis_patches_files:
        genesis_patches_files[k]['sha256'] = patch_file_hash

    blockstack.lib.config.set_genesis_block_patches(genesis_patches)
    blockstack.lib.config.set_genesis_block_patches_files(genesis_patches_files)
    testlib.set_account_audits(False)

    # in block 689, so the patch hasn't taken place yet
    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 100 + 600000
    assert balances[wallets[1].addr][STACKS] == 123 + 1000
    assert balances[wallets[2].addr][STACKS] == 0

    # send some tokens to a brand-new address
    testlib.blockstack_send_tokens(new_addr, "STACKS", 600000, wallets[0].privkey)
    testlib.blockstack_send_tokens(new_unlocked_addr, "STACKS", 100, wallets[0].privkey)
    testlib.next_block(**kw) # end of 689, triggers vesting of block 690
    
    assert virtualchain.lib.indexer.StateEngine.get_block_statistics(testlib.get_current_block(**kw))['num_processed_ops'] == 2

    # new balances should reflect patch
    balances = testlib.get_addr_balances([w.addr for w in wallets] + [new_addr_b58, new_grant_addr_b58, new_unlocked_addr_b58])
    print balances

    assert balances[wallets[0].addr][STACKS] == 100 + 200 + 600000 + 600001 + 10000 + 10001 + 10002 + 10003 + 10004 + 10005 - 600000 - 100         # += new value + retroactive vesting
    assert balances[wallets[1].addr][STACKS] == 123 + 1000 + (10000000 * 10)
    assert balances[wallets[2].addr][STACKS] == 123456
    assert balances[new_addr_b58][STACKS] == 600000 + 222222 + 66
    assert balances[new_grant_addr_b58][STACKS] == 567 + (10000000 * 10)
    assert balances[new_unlocked_addr_b58][STACKS] == 100 + 123456 + 22000 + 22001 + 22002 + 22003 + 22004 + 22005

    # send some tokens to a brand-new address
    # should be transfer-locked
    testlib.blockstack_send_tokens(new_addr_b58, "STACKS", 600000, wallets[0].privkey, safety_checks=False, expect_fail=True)
    testlib.blockstack_send_tokens(new_grant_addr_b58, "STACKS", 1, new_wallet, safety_checks=False, expect_fail=True)
    testlib.blockstack_send_tokens(new_grant_addr_b58, "STACKS", 10000000, wallets[1].privkey, safety_checks=False)
    testlib.blockstack_send_tokens(new_addr_b58, "STACKS", 10000000, wallets[1].privkey, safety_checks=False)
    testlib.blockstack_send_tokens(new_grant_addr_b58, "STACKS", 3, new_unlocked_wallet, safety_checks=False)
    testlib.next_block(**kw)  # 690

    assert virtualchain.lib.indexer.StateEngine.get_block_statistics(testlib.get_current_block(**kw))['num_processed_ops'] == 3
    
    balances = testlib.get_addr_balances([w.addr for w in wallets] + [new_addr_b58, new_grant_addr_b58, new_unlocked_addr_b58])
    print balances

    assert balances[wallets[0].addr][STACKS] == 100 + 200 + 600000 + 600001 + 600010 + 10000 + 10001 + 10002 + 10003 + 10004 + 10005 + 10006 - 600000 - 100         # += new value + retroactive vesting
    assert balances[wallets[1].addr][STACKS] == 123 + 1000 + (10000000 * 10) - 10000000 - 10000000
    assert balances[wallets[2].addr][STACKS] == 123456
    assert balances[new_addr_b58][STACKS] == 600000 + 222222 + 66 + 10000000
    assert balances[new_grant_addr_b58][STACKS] == 567 + (10000000 * 10) + 10000000 + 3
    assert balances[new_unlocked_addr_b58][STACKS] == 100 + 123456 + 22000 + 22001 + 22002 + 22003 + 22004 + 22005 + 22006 - 3

    # apply patches from files
    balances = testlib.get_addr_balances(patch_file_addrs[0:5])
    print balances

    for addr in patch_file_addrs[0:5]:
        assert balances[addr].get(STACKS, 0) == 0

    testlib.next_block(**kw)    # make the balances real (end of 691)

    balances = testlib.get_addr_balances(patch_file_addrs[0:5])
    for addr in patch_file_addrs[0:5]:
        assert balances[addr][STACKS] == 12345
    
    # apply patches from files
    balances_before_patch = testlib.get_addr_balances(patch_file_addrs[5:8])
    print balances_before_patch

    assert balances_before_patch[new_addr_b58][STACKS] == 600000 + 222222 + 66 + 10000000
    assert balances_before_patch[new_grant_addr_b58][STACKS] == 567 + (10000000 * 10) + 10000000 + 3
    assert balances_before_patch[new_unlocked_addr_b58][STACKS] == 100 + 123456 + 22000 + 22001 + 22002 + 22003 + 22004 + 22005 + 22006 + 22007 - 3

    testlib.next_block(**kw)    # make the balances real (end of 692)

    balances_after_patch = testlib.get_addr_balances(patch_file_addrs[5:8])

    assert balances_after_patch[new_addr_b58][STACKS] == 600000 + 222222 + 66 + 10000000 + 23456
    assert balances_after_patch[new_grant_addr_b58][STACKS] == 567 + (10000000 * 10) + 10000000 + 3 + 23456
    assert balances_after_patch[new_unlocked_addr_b58][STACKS] == 100 + 123456 + 22000 + 22001 + 22002 + 22003 + 22004 + 22005 + 22006 + 22007 + 22008 - 3 + 23456

    # drain-transfer from newly-granted
    for (addr, privkey) in zip(patch_file_addrs[0:5], patch_file_privkeys):
        testlib.send_funds(wallets[0].privkey, 388500, virtualchain.address_reencode(addr))
        testlib.blockstack_send_tokens(new_addr_b58, "STACKS", 12345, privkey)

    testlib.next_block(**kw)
    
    balances_after_xfer = testlib.get_addr_balances(patch_file_addrs)
    print balances_after_xfer

    for addr in patch_file_addrs[0:5]:
        assert balances_after_xfer[addr].get(STACKS, 0) == 0

    assert balances_after_xfer[new_addr_b58][STACKS] == 600000 + 222222 + 66 + 10000000 + 23456 + 12345*5
    assert balances_after_xfer[new_grant_addr_b58][STACKS] == 567 + (10000000 * 10) + 10000000 + 3 + 23456
    assert balances_after_xfer[new_unlocked_addr_b58][STACKS] == 100 + 123456 + 22000 + 22001 + 22002 + 22003 + 22004 + 22005 + 22006 + 22007 + 22008 + 22009 - 3 + 23456
Пример #7
0
def scenario( wallets, **kw ):
    global TRANSACTION_BROADCASTER_URL
    
    global GAIA_READ_URL
    global GAIA_READ_PORT
    global GAIA_WRITE_PORT
    global GAIA_WRITE_URL

    # get gaia hub info 
    with open(os.path.join(os.environ['BLOCKSTACK_WORKING_DIR'], 'gaia.conf'), 'r') as f:
        GAIA_CONF = json.loads(f.read().strip())

    try:
        GAIA_READ_PORT = urlparse.urlparse(GAIA_CONF['readURL']).netloc.split(':')[-1]
        GAIA_READ_PORT = int(GAIA_READ_PORT)
    except:
        GAIA_READ_PORT = 80

    if os.environ.get('BLOCKSTACK_PUBLIC_TESTNET_GAIA_READ_PORT'):
        GAIA_READ_PORT = int(os.environ['BLOCKSTACK_PUBLIC_TESTNET_GAIA_READ_PORT'])

    read_urlinfo = urlparse.urlparse(GAIA_CONF['readURL'])

    GAIA_READ_URL = 'http://{}:{}'.format(read_urlinfo.netloc.split(':')[0], GAIA_READ_PORT)

    GAIA_WRITE_PORT = GAIA_CONF['port']
    if os.environ.get('BLOCKSTACK_PUBLIC_TESTNET_GAIA_WRITE_PORT'):
        GAIA_WRITE_PORT = int(os.environ['BLOCKSTACK_PUBLIC_TESTNET_GAIA_WRITE_PORT'])

    GAIA_WRITE_URL = 'http://{}:{}'.format(GAIA_CONF['servername'], GAIA_WRITE_PORT)

    # fill in URL 
    tb_conf_path = os.path.join(os.environ['BLOCKSTACK_WORKING_DIR'], 'transaction-broadcaster.conf')
    with open(tb_conf_path, 'r') as f:
        tb_conf = json.loads(f.read().strip())

    TRANSACTION_BROADCASTER_URL = 'http://{}:{}'.format(TESTNET_PUBLIC_HOST, tb_conf['port'])

    PORTNUM = int(os.environ.get('TESTNET_PORTNUM', '30001'))
    start_test_server(PORTNUM)

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

    # same price curve as public .id namespace
    testlib.blockstack_namespace_reveal( "id2", wallets[1].addr, 52595, 250, 4, [6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey, version_bits=3)
    testlib.blockstack_namespace_reveal( "test", wallets[1].addr, -1, 250, 4, [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey, version_bits=3)
    testlib.blockstack_namespace_reveal( "sandbox", wallets[1].addr, -1, 250, 4, [6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], 10, 10, wallets[0].privkey, version_bits=3)
    testlib.next_block( **kw )

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

    testlib.blockstack_register_user(SUBDOMAIN_DOMAIN, SUBDOMAIN_PAYMENT_KEY, SUBDOMAIN_OWNER_KEY, gaia_host='{}:{}'.format(TESTNET_PUBLIC_HOST, GAIA_READ_PORT), **kw)

    start_subdomain_registrar()

    testlib.set_account_audits(False)

    print 'Testnet initialized'

    # do 1-minute block times forever
    while True:
        time.sleep(60)
        testlib.next_block(**kw)