github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/validator/tests/test_duplicate_handler/mock.py (about) 1 # Copyright 2017 Intel Corporation 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # ------------------------------------------------------------------------------ 15 16 17 class MockCompleter: 18 def __init__(self): 19 self.blocks = {} 20 self.batches = {} 21 22 def get_block(self, block_id): 23 return self.blocks.get(block_id) 24 25 def get_batch(self, batch_id): 26 return self.batches.get(batch_id) 27 28 def add_block(self, block_id): 29 self.blocks[block_id] = 1 30 31 def add_batch(self, batch_id): 32 self.batches[batch_id] = 1 33 34 35 class MockChainController: 36 def __init__(self): 37 self.blocks = {} 38 39 def has_block(self, block_id): 40 if block_id in self.blocks: 41 return True 42 return False 43 44 def add_block(self, block_id): 45 self.blocks[block_id] = 1 46 47 48 class MockPublisher: 49 def __init__(self): 50 self.batches = [] 51 52 def has_batch(self, batch_id): 53 if batch_id in self.batches: 54 return True 55 return False 56 57 def add_batch(self, batch_id): 58 self.batches.append(batch_id)