test_proto.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. from src.protocol import Protocol
  2. from src.mining import Miner
  3. from src.block import GENESIS_BLOCK
  4. from src.crypto import Signing
  5. from src.transaction import Transaction, TransactionInput, TransactionTarget
  6. from time import sleep
  7. reward_key = Signing.generatePrivateKey()
  8. proto1 = Protocol(("127.0.0.1", 1337), GENESIS_BLOCK, 1337)
  9. proto2 = Protocol(("127.0.0.1", 1337), GENESIS_BLOCK, 1338)
  10. miner1 = Miner(proto1, reward_key)
  11. miner2 = Miner(proto2, reward_key)
  12. miner2.chain_changed()
  13. miner1.chain_changed()
  14. sleep(5)
  15. #proto.fake_block_received(GENESIS_BLOCK)
  16. strans1 = miner2.chainbuilder.primary_block_chain.head.transactions[0]
  17. strans1 = TransactionInput(strans1.get_hash(), 0)
  18. strans2 = miner2.chainbuilder.primary_block_chain.head.transactions[0]
  19. strans2 = TransactionInput(strans2.get_hash(), 0)
  20. trans = Transaction([strans1, strans2], [])
  21. trans.sign([reward_key, reward_key])
  22. miner2.chainbuilder.new_transaction_received(trans)
  23. sleep(5)
  24. print(len(miner1.chainbuilder.primary_block_chain.blocks))
  25. print(len(miner2.chainbuilder.primary_block_chain.blocks))
  26. hashes1 = [b.hash for b in miner1.chainbuilder.primary_block_chain.blocks[:70]]
  27. hashes2 = [b.hash for b in miner2.chainbuilder.primary_block_chain.blocks[:70]]
  28. print(hashes1 == hashes2)