def test_bank_balances(): # Create bank and issue Alice some coins bank = Bank() coinbase = bank.issue(1000, alice_public_key) # Alice sends 10 coins to Bob tx_ins = [TxIn(tx_id=coinbase.id, index=0, signature=None)] tx_id = uuid.uuid4() tx_outs = [ TxOut(tx_id=tx_id, index=0, amount=10, public_key=bob_public_key), TxOut(tx_id=tx_id, index=1, amount=990, public_key=alice_public_key), ] alice_to_bob = Tx(id=tx_id, tx_ins=tx_ins, tx_outs=tx_outs) alice_to_bob.sign_input(0, alice_private_key) # After signing, Bob modifies transaction to get more $$$ alice_to_bob.tx_outs[0].amount = 990 alice_to_bob.tx_outs[1].amount = 10 with pytest.raises(BadSignatureError): bank.handle_tx(alice_to_bob)
def test_bank_balances(): # Create bank and issue Alice some coins bank = Bank() coinbase = bank.issue(1000, alice_public_key) # Alice sends 10 coins to Bob tx_ins = [ TxIn(tx_id=coinbase.id, index=0, signature=None), ] tx_id = uuid.uuid4() tx_outs = [ TxOut(tx_id=tx_id, index=0, amount=10, public_key=bob_public_key), TxOut(tx_id=tx_id, index=1, amount=990, public_key=alice_public_key), ] alice_to_bob = Tx(id=tx_id, tx_ins=tx_ins, tx_outs=tx_outs) alice_to_bob.sign_input(0, alice_private_key) bank.handle_tx(alice_to_bob) alice_balance = bank.fetch_balance(alice_public_key) assert alice_balance == 990 # Alice sends 10 coins to Bob tx_ins = [ TxIn(tx_id=tx_id, index=1, signature=None), ] tx_id = uuid.uuid4() tx_outs = [ TxOut(tx_id=tx_id, index=0, amount=10, public_key=bob_public_key), TxOut(tx_id=tx_id, index=1, amount=980, public_key=alice_public_key), ] alice_to_bob = Tx(id=tx_id, tx_ins=tx_ins, tx_outs=tx_outs) alice_to_bob.sign_input(0, alice_private_key) bank.handle_tx(alice_to_bob) alice_balance = bank.fetch_balance(alice_public_key) assert alice_balance == 980