예제 #1
0
def test_spend_failure():
    remote = make_client_server()
    run = asyncio.get_event_loop().run_until_complete
    wallet_a = Wallet()
    wallet_b = Wallet()
    wallets = [wallet_a, wallet_b]
    amount = 5000
    # wallet a send to wallet b
    program = wallet_b.get_new_puzzle()
    puzzlehash = ProgramHash(program)
    spend_bundle = wallet_a.generate_signed_transaction(amount, puzzlehash)
    assert spend_bundle is None

    commit_and_notify(remote, wallets, wallet_a)
    amount = 50000000000000
    puzzlehash = wallet_b.get_new_puzzlehash()
    spend_bundle = wallet_a.generate_signed_transaction(amount, puzzlehash)
    assert spend_bundle is None
    amount = 999995000
    puzzlehash = wallet_b.get_new_puzzlehash()
    spend_bundle = wallet_a.generate_signed_transaction(amount, puzzlehash)
    _ = run(remote.push_tx(tx=spend_bundle))
    assert wallet_a.temp_balance == 5000

    amount = 6000
    puzzlehash = wallet_b.get_new_puzzlehash()
    spend_bundle = wallet_a.generate_signed_transaction(amount, puzzlehash)
    assert spend_bundle is None

    amount = 4000
    puzzlehash = wallet_b.get_new_puzzlehash()
    spend_bundle = wallet_a.generate_signed_transaction(amount, puzzlehash)
    _ = run(remote.push_tx(tx=spend_bundle))
    assert wallet_a.temp_balance == 1000
    commit_and_notify(remote, wallets, Wallet())
    assert wallet_a.current_balance == 1000
    assert wallet_a.temp_balance == 1000
예제 #2
0
def test_standard_spend():
    remote = make_client_server()
    run = asyncio.get_event_loop().run_until_complete
    wallet_a = Wallet()
    wallet_b = Wallet()
    wallets = [wallet_a, wallet_b]
    commit_and_notify(remote, wallets, wallet_a)

    assert wallet_a.current_balance == 1000000000
    assert len(wallet_a.my_utxos) == 2
    assert wallet_b.current_balance == 0
    assert len(wallet_b.my_utxos) == 0
    # wallet a send to wallet b
    program = wallet_b.get_new_puzzle()
    puzzlehash = ProgramHash(program)

    amount = 5000
    spend_bundle = wallet_a.generate_signed_transaction(amount, puzzlehash)
    _ = run(remote.push_tx(tx=spend_bundle))
    # give new wallet the reward to not complicate the one's we're tracking
    commit_and_notify(remote, wallets, Wallet())

    assert wallet_a.current_balance == 999995000
    assert wallet_b.current_balance == 5000
    assert len(wallet_b.my_utxos) == 1

    # wallet b sends back to wallet a
    puzzlehash = wallet_a.get_new_puzzlehash()

    amount = 5000
    spend_bundle = wallet_b.generate_signed_transaction(amount, puzzlehash)
    _ = run(remote.push_tx(tx=spend_bundle))
    # give new wallet the reward to not complicate the one's we're tracking
    commit_and_notify(remote, wallets, Wallet())
    assert wallet_a.current_balance == 1000000000
    assert wallet_b.current_balance == 0