def scenario(wallets, **kw):

    # try to spend tokens with an invalid consensus hash (note that this is epoch 4)
    testlib.blockstack_send_tokens(wallets[1].addr,
                                   "STACKS",
                                   600000,
                                   wallets[0].privkey,
                                   consensus_hash='00' * 16,
                                   safety_checks=False,
                                   expect_fail=True)
    testlib.next_block(**kw)  # end of 689

    assert virtualchain.lib.indexer.StateEngine.get_block_statistics(
        testlib.get_current_block(**kw))['num_processed_ops'] == 0

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 600000
    assert balances[wallets[1].addr][STACKS] == 0
    assert balances[wallets[2].addr][STACKS] == 0

    # try to spend tokens with an empty consensus hash (note that this is epoch 5)
    testlib.blockstack_send_tokens(wallets[1].addr,
                                   "STACKS",
                                   600000,
                                   wallets[0].privkey,
                                   consensus_hash='00' * 16)
    testlib.next_block(**kw)

    assert virtualchain.lib.indexer.StateEngine.get_block_statistics(
        testlib.get_current_block(**kw))['num_processed_ops'] > 0

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 0
    assert balances[wallets[1].addr][STACKS] == 600000
    assert balances[wallets[2].addr][STACKS] == 0
def scenario(wallets, **kw):

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

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

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

    balances = testlib.get_wallet_balances(wallets[2])
    assert balances[wallets[2].addr][STACKS] == 0

    # should fail--not enough stacks
    testlib.blockstack_name_preorder("foo.test",
                                     wallets[2].privkey,
                                     wallets[3].addr,
                                     safety_checks=False,
                                     expect_fail=True)
    testlib.next_block(**kw)

    name_cost = testlib.blockstack_get_name_token_cost('foo.test')
    assert name_cost['units'] == STACKS
    assert name_cost['amount'] > 0

    # send tokens and preorder multiple times in the block
    # should all succeed, BUT: force them to go in order through UTXO chaining
    for i in range(0, 5):
        name_recipient_privkey = wallets[-(i + 1)].privkey
        name_recipient_addr = virtualchain.address_reencode(
            virtualchain.get_privkey_address(name_recipient_privkey))

        testlib.blockstack_send_tokens(name_recipient_addr, "STACKS",
                                       name_cost['amount'], wallets[0].privkey)
        testlib.send_funds(wallets[0].privkey, 1000000, name_recipient_addr)
        testlib.blockstack_name_preorder("foo_{}.test".format(i),
                                         name_recipient_privkey,
                                         wallets[3].addr,
                                         safety_checks=False)
        testlib.blockstack_name_register("foo_{}.test".format(i),
                                         name_recipient_privkey,
                                         wallets[3].addr,
                                         safety_checks=False)

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

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

    # will be rejected, since locked
    testlib.blockstack_send_tokens(wallets[1].addr,
                                   "STACKS",
                                   100000,
                                   wallets[0].privkey,
                                   safety_checks=False,
                                   expect_fail=True)
    testlib.next_block(**kw)  # end of 689

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 600000
    assert balances[wallets[1].addr][STACKS] == 0

    # will be rejected, since locked
    testlib.blockstack_send_tokens(wallets[1].addr,
                                   "STACKS",
                                   200000,
                                   wallets[0].privkey,
                                   safety_checks=False,
                                   expect_fail=True)
    testlib.next_block(**kw)  # end of 690

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 600000
    assert balances[wallets[1].addr][STACKS] == 0

    testlib.blockstack_send_tokens(wallets[1].addr,
                                   "STACKS",
                                   300000,
                                   wallets[0].privkey,
                                   safety_checks=False,
                                   expect_fail=True)
    testlib.next_block(**kw)  # end of 691

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 600000
    assert balances[wallets[1].addr][STACKS] == 0

    testlib.blockstack_send_tokens(wallets[1].addr,
                                   "STACKS",
                                   400000,
                                   wallets[0].privkey,
                                   safety_checks=False,
                                   expect_fail=True)
    testlib.next_block(**kw)  # end of 692

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 600000
    assert balances[wallets[1].addr][STACKS] == 0

    testlib.blockstack_send_tokens(wallets[1].addr,
                                   "STACKS",
                                   500000,
                                   wallets[0].privkey,
                                   safety_checks=False,
                                   expect_fail=True)
    testlib.next_block(**kw)  # end of 693

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 600000
    assert balances[wallets[1].addr][STACKS] == 0

    # will succeed
    testlib.blockstack_send_tokens(wallets[1].addr,
                                   "STACKS",
                                   600000,
                                   wallets[0].privkey,
                                   safety_checks=False)
    testlib.next_block(**kw)  # end of 694

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 0
    assert balances[wallets[1].addr][STACKS] == 600000
Пример #5
0
def scenario(wallets, **kw):

    # will be rejected, since locked
    testlib.blockstack_send_tokens(wallets[1].addr,
                                   "STACKS",
                                   100000,
                                   wallets[0].privkey,
                                   safety_checks=False,
                                   expect_fail=True)
    testlib.next_block(**kw)  # end of 689

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 600000
    assert balances[wallets[1].addr][STACKS] == 0
    assert balances[wallets[2].addr][STACKS] == 0

    # will succeed, since whitelisted
    testlib.blockstack_send_tokens(
        wallets[1].addr,
        "STACKS",
        100000,
        wallets[0].privkey,
        safety_checks=False
    )  # need to disable safety checks since it's "currently" block 690
    testlib.next_block(**kw)  # end of 690

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 500000
    assert balances[wallets[1].addr][STACKS] == 100000
    assert balances[wallets[2].addr][STACKS] == 0

    # try to send back (will fail since its locked)
    testlib.blockstack_send_tokens(wallets[0].addr,
                                   "STACKS",
                                   100000,
                                   wallets[1].privkey,
                                   safety_checks=False,
                                   expect_fail=True)
    testlib.next_block(**kw)  # end of 691

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 500000
    assert balances[wallets[1].addr][STACKS] == 100000
    assert balances[wallets[2].addr][STACKS] == 0

    # try to send back (will fail since the address is not whitelisted)
    testlib.blockstack_send_tokens(wallets[0].addr,
                                   "STACKS",
                                   100000,
                                   wallets[1].privkey,
                                   safety_checks=False,
                                   expect_fail=True)
    testlib.next_block(**kw)  # end of 692

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 500000
    assert balances[wallets[1].addr][STACKS] == 100000
    assert balances[wallets[2].addr][STACKS] == 0

    # send to wallets[2] (should succeed)
    testlib.blockstack_send_tokens(
        wallets[2].addr,
        "STACKS",
        50000,
        wallets[1].privkey,
        safety_checks=False
    )  # need to disable safety checks since it's "currently" block 692
    testlib.next_block(**kw)  # end of 693

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 500000
    assert balances[wallets[1].addr][STACKS] == 50000
    assert balances[wallets[2].addr][STACKS] == 50000

    # send to wallets[1] (should fail since locked)
    testlib.blockstack_send_tokens(wallets[1].addr,
                                   "STACKS",
                                   50000,
                                   wallets[2].privkey,
                                   safety_checks=False,
                                   expect_fail=True)
    testlib.next_block(**kw)  # end of 694

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 500000
    assert balances[wallets[1].addr][STACKS] == 50000
    assert balances[wallets[2].addr][STACKS] == 50000

    # send to wallets[1] (should succeed now)
    testlib.blockstack_send_tokens(wallets[1].addr,
                                   "STACKS",
                                   50000,
                                   wallets[2].privkey,
                                   safety_checks=False)
    testlib.next_block(**kw)  # end of 695

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 500000
    assert balances[wallets[1].addr][STACKS] == 100000
    assert balances[wallets[2].addr][STACKS] == 0

    # send to a new address
    new_addr = 'n17Wp3qk9WNGESLHHey18dcgQAn5aDDPuE'
    testlib.blockstack_send_tokens(new_addr,
                                   'STACKS',
                                   123456,
                                   wallets[0].privkey,
                                   safety_checks=False)
    testlib.next_block(**kw)  # end of 696

    balance_info = json.loads(testlib.nodejs_cli('balance', new_addr))
    assert int(balance_info['STACKS']) == 123456

    balance_info = json.loads(testlib.nodejs_cli('balance', wallets[0].addr))
    assert int(balance_info['STACKS']) == 500000 - 123456
def scenario( wallets, **kw ):

    # will be rejected, since locked
    testlib.blockstack_send_tokens(wallets[1].addr, "STACKS", 100000, wallets[0].privkey, safety_checks=False, expect_fail=True)
    testlib.next_block(**kw) # end of 689
    
    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 600000
    assert balances[wallets[1].addr][STACKS] == 0
    assert balances[wallets[2].addr][STACKS] == 0

    # will succeed, since whitelisted
    testlib.blockstack_send_tokens(wallets[1].addr, "STACKS", 100000, wallets[0].privkey, safety_checks=False)  # need to disable safety checks since it's "currently" block 690
    testlib.next_block(**kw) # end of 690

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 500000
    assert balances[wallets[1].addr][STACKS] == 100000
    assert balances[wallets[2].addr][STACKS] == 0

    # try to send back (will fail since its locked)
    testlib.blockstack_send_tokens(wallets[0].addr, "STACKS", 100000, wallets[1].privkey, safety_checks=False, expect_fail=True)
    testlib.next_block(**kw) # end of 691

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 500000
    assert balances[wallets[1].addr][STACKS] == 100000
    assert balances[wallets[2].addr][STACKS] == 0

    # try to send back (will fail since the address is not whitelisted)
    testlib.blockstack_send_tokens(wallets[0].addr, "STACKS", 100000, wallets[1].privkey, safety_checks=False, expect_fail=True)
    testlib.next_block(**kw) # end of 692

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 500000
    assert balances[wallets[1].addr][STACKS] == 100000
    assert balances[wallets[2].addr][STACKS] == 0

    # send to wallets[2] (should succeed)
    testlib.blockstack_send_tokens(wallets[2].addr, "STACKS", 50000, wallets[1].privkey, safety_checks=False)   # need to disable safety checks since it's "currently" block 692
    testlib.next_block(**kw) # end of 693

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 500000
    assert balances[wallets[1].addr][STACKS] == 50000
    assert balances[wallets[2].addr][STACKS] == 50000

    # send to wallets[1] (should fail since locked)
    testlib.blockstack_send_tokens(wallets[1].addr, "STACKS", 50000, wallets[2].privkey, safety_checks=False, expect_fail=True)
    testlib.next_block(**kw) # end of 694

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 500000
    assert balances[wallets[1].addr][STACKS] == 50000
    assert balances[wallets[2].addr][STACKS] == 50000

    # send to wallets[1] (should succeed now)
    testlib.blockstack_send_tokens(wallets[1].addr, "STACKS", 50000, wallets[2].privkey, safety_checks=False)
    testlib.next_block(**kw) # end of 695

    balances = testlib.get_wallet_balances(wallets)
    assert balances[wallets[0].addr][STACKS] == 500000
    assert balances[wallets[1].addr][STACKS] == 100000
    assert balances[wallets[2].addr][STACKS] == 0
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