def ensure_rlp_objects_are_equal(obj_a, obj_b, obj_a_name, obj_b_name): if obj_a == obj_b: return diff = diff_rlp_object(obj_a, obj_b) longest_field_name = max(len(field_name) for field_name, _, _ in diff) error_message = ( "Mismatch between {obj_a_name} and {obj_b_name} on {0} fields:\n - {1}" .format( len(diff), "\n - ".join( tuple("{0}:\n (actual) : {1}\n (expected): {2}".format( pad_right(field_name, longest_field_name, ' '), actual, expected, ) for field_name, actual, expected in diff)), obj_a_name=obj_a_name, obj_b_name=obj_b_name, )) raise ValidationError(error_message)
def ensure_blocks_are_equal(self, block1, block2): if block1 == block2: return diff = diff_rlp_object(block1, block2) longest_field_name = max(len(field_name) for field_name, _, _ in diff) error_message = ( "Mismatch between block and imported block on {0} fields:\n - {1}".format( len(diff), "\n - ".join(tuple( "{0}:\n (actual) : {1}\n (expected): {2}".format( pad_right(field_name, longest_field_name, ' '), actual, expected, ) for field_name, actual, expected in diff )), ) ) raise ValidationError(error_message)
def import_block(self, block): self.configure_header( coinbase=block.header.coinbase, gas_limit=block.header.gas_limit, timestamp=block.header.timestamp, extra_data=block.header.extra_data, mix_hash=block.header.mix_hash, nonce=block.header.nonce, ) for transaction in block.transactions: self.apply_transaction(transaction) for uncle in block.uncles: self.block.add_uncle(uncle) mined_block = self.mine_block() if mined_block != block: diff = diff_rlp_object(mined_block, block) longest_field_name = max(len(field_name) for field_name, _, _ in diff) error_message = ( "Mismatch between block and imported block on {0} fields:\n - {1}".format( len(diff), "\n - ".join(tuple( "{0}:\n (actual) : {1}\n (expected): {2}".format( pad_right(field_name, longest_field_name, ' '), actual, expected, ) for field_name, actual, expected in diff )), ) ) raise ValidationError(error_message) return mined_block