def test_raise_exception_if_block_is_already_signed(self): # Arrange block = Block() tx = Transaction(VERSION, Transaction.GUZI_CREATE, EMPTY_HASH, 0) random_sign(block, REF_PUB_KEY, REF_PRIV_KEY) # Act with pytest.raises(FullBlockError): block.add_transaction(tx)
def test_increase_transaction_count(self): # Arrange block = Block() tx = Transaction(VERSION, Transaction.GUZI_CREATE, EMPTY_HASH, 0) # Act block.add_transaction(tx) # Assert assert len(block.transactions) == 1
def test_raise_exception_if_too_much_transactions_in_last_block(self): # Arrange block = Block() tx = Transaction(VERSION, Transaction.PAYMENT, NEW_USER_PUB_KEY, 0) for i in range(MAX_TX_IN_BLOCK): block.add_transaction( Transaction(VERSION, Transaction.PAYMENT, NEW_USER_PUB_KEY, i)) # Act with pytest.raises(FullBlockError): block.add_transaction(tx)
def test_shouldnt_add_existing_transaction_twice(self): # Arrange block = Block() tx = Transaction(VERSION, Transaction.GUZI_CREATE, EMPTY_HASH, 0) # Act block.add_transaction(tx) block.add_transaction(tx) block.add_transaction(tx) # Assert assert len(block.transactions) == 1
def test_compute_merkle_root_1_tx(self): """ If there is only 1 transaction, merkle root should be : hash(hash0 + hash0) """ # Arrange tx = Transaction(VERSION, Transaction.GUZI_CREATE, NEW_USER_PUB_KEY, 0) block = Block() block.add_transaction(tx) expected_merkle_root = guzi_hash(tx.to_hash() + tx.to_hash()) # Act result = block.compute_merkle_root() # Assert assert result == expected_merkle_root