def setUpClass(cls): """ 블럭체인 생성 및 DB입력 """ cls.__peer_auth = test_util.create_default_peer_auth() cls.__peer_auth = test_util.create_default_peer_auth() set_mock(cls) # BlockChain 을 만듬 test_db = leveldb.LevelDB('./' + cls.test_block_db, create_if_missing=True) cls.assertIsNotNone(test_db, "DB생성 불가") cls.chain = BlockChain(test_db) cls.score = cls.SampleScore()
def set_mock(test): peer_auth = test_util.create_default_peer_auth() test.peer_auth = peer_auth peer_service_mock = PeerServiceMock() peer_service_mock.peer_manager = PeerManagerMock(peer_auth) peer_service_mock.channel_service = ChannelServiceMock(conf.LOOPCHAIN_DEFAULT_CHANNEL) ObjectManager().peer_service = peer_service_mock ObjectManager().channel_service = peer_service_mock.channel_service
def setUp(self): test_util.print_testname(self._testMethodName) self.peer_auth = test_util.create_default_peer_auth() set_mock(self) # BlockChain 을 만듬 test_db = test_util.make_level_db(self.db_name) self.assertIsNotNone(test_db, "DB생성 불가") self.chain = BlockChain(test_db)
def setUp(self): test_util.print_testname(self._testMethodName) self.peer_auth = test_util.create_default_peer_auth() set_mock(self)
def setUp(self): conf.ENABLE_USER_CONFIG = False conf.Configure().init_configure() test_util.print_testname(self._testMethodName) self.peer_auth = test_util.create_default_peer_auth() set_mock(self)
def test_block_v0_3(self): private_auth = test_util.create_default_peer_auth() tx_versioner = TransactionVersioner() dummy_receipts = {} block_builder = BlockBuilder.new("0.3", tx_versioner) for i in range(1000): tx_builder = TransactionBuilder.new("0x3", tx_versioner) tx_builder.private_key = private_auth.private_key tx_builder.to_address = ExternalAddress.new() tx_builder.step_limit = random.randint(0, 10000) tx_builder.value = random.randint(0, 10000) tx_builder.nid = 2 tx = tx_builder.build() tx_serializer = TransactionSerializer.new(tx.version, tx_versioner) block_builder.transactions[tx.hash] = tx dummy_receipts[tx.hash.hex()] = { "dummy_receipt": "dummy", "tx_dumped": tx_serializer.to_full_data(tx) } block_builder.peer_private_key = private_auth.private_key block_builder.height = 0 block_builder.state_hash = Hash32(bytes(Hash32.size)) block_builder.receipts = dummy_receipts block_builder.reps = [ ExternalAddress.fromhex_address(private_auth.address) ] block_builder.next_leader = ExternalAddress.fromhex( "hx00112233445566778899aabbccddeeff00112233") block = block_builder.build() block_verifier = BlockVerifier.new("0.3", tx_versioner) block_verifier.invoke_func = lambda b: (block, dummy_receipts) block_verifier.verify(block, None, None, block.header.peer_id, reps=block_builder.reps) block_serializer = BlockSerializer.new("0.3", tx_versioner) block_serialized = block_serializer.serialize(block) block_deserialized = block_serializer.deserialize(block_serialized) assert block.header == block_deserialized.header # FIXME : confirm_prev_block not serialized # assert block.body == block_deserialized.body tx_hashes = list(block.body.transactions) tx_index = random.randrange(0, len(tx_hashes)) block_prover = BlockProver.new(block.header.version, tx_hashes, BlockProverType.Transaction) tx_proof = block_prover.get_proof(tx_index) assert block_prover.prove(tx_hashes[tx_index], block.header.transaction_hash, tx_proof) block_prover = BlockProver.new(block.header.version, block_builder.receipts, BlockProverType.Receipt) receipt_proof = block_prover.get_proof(tx_index) receipt_hash = block_prover.to_hash32(block_builder.receipts[tx_index]) assert block_prover.prove(receipt_hash, block.header.receipt_hash, receipt_proof)