def test_validate_block_by_itself_invalid_coinbase_transaction(): coinstate = CoinState.empty() transactions = [ Transaction(inputs=[ Input( OutputReference(b'x' * 32, 1), SECP256k1Signature(b'y' * 64), ) ], outputs=[Output(1, example_public_key)]) ] summary = construct_minable_summary(coinstate, transactions, 1615209942, 39) evidence = construct_pow_evidence(coinstate, summary, 0, transactions) block = Block(BlockHeader(summary, evidence), transactions) with pytest.raises(ValidateTransactionError, match=".*thin air.*"): validate_block_by_itself(block, 1615209942)
def test_block_serialization(): block = Block( header=BlockHeader( summary=example_block_summary, pow_evidence=example_pow_evidence, ), transactions=[ Transaction( inputs=[ Input(output_reference=OutputReference(b"b" * 32, 1234), signature=SECP256k1Signature(b"b" * 64)) ], outputs=[ Output(value=1582, public_key=SECP256k1PublicKey(b"g" * 64)) ], ) ] * 2, ) serialize_and_deserialize(block)
def handle_scrypt_output_message(self, miner_id: int, data: bytes) -> None: summary_hash: bytes = data self.increment_hash_counter() summary, current_height, transactions = self.mining_args[miner_id] evidence = construct_pow_evidence_after_scrypt(summary_hash, self.coinstate, summary, current_height, transactions) block = Block(BlockHeader(summary, evidence), transactions) if block.hash() >= block.target: # we didn't mine the block return self.network_thread.local_peer.chain_manager.set_coinstate( self.coinstate) self.network_thread.local_peer.network_manager.broadcast_block(block) self.coinstate = self.coinstate.add_block(block, int(time())) # Originally there was a disk write in this spot. During testing of the chain.cache changes, # it was found there is a race condition between the mining thread and the networking thread. # Better to skip the write here and just let the networking thread do it. print(f"miner {miner_id} found block: {block_filename(block)}") # get new public key for miner self.public_key = self.wallet.get_annotated_public_key( "reserved for potentially mined block") save_wallet(self.wallet) self.balance = self.wallet.get_balance( self.coinstate) / Decimal(SASHIMI_PER_COIN)