Skip to content

Commit a4bbe0f

Browse files
committed
refactor(verification): implement verify_minted_tokens
1 parent 5693c13 commit a4bbe0f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

hathor/verification/token_creation_transaction_verifier.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from hathor.transaction import Transaction
1615
from hathor.transaction.exceptions import InvalidToken, TransactionDataError
1716
from hathor.transaction.token_creation_tx import TokenCreationTransaction
1817
from hathor.transaction.util import clean_token_string
@@ -29,26 +28,24 @@ def verify(self, tx: TokenCreationTransaction, *, reject_locked_reward: bool = T
2928
We also overload verify_sum to make some different checks
3029
"""
3130
super().verify(tx, reject_locked_reward=reject_locked_reward)
31+
self.verify_minted_tokens(tx)
3232
self.verify_token_info(tx)
3333

34-
def verify_sum(self, tx: Transaction) -> None:
34+
def verify_minted_tokens(self, tx: TokenCreationTransaction) -> None:
3535
""" Besides all checks made on regular transactions, a few extra ones are made:
3636
- only HTR tokens on the inputs;
3737
- new tokens are actually being minted;
3838
3939
:raises InvalidToken: when there's an error in token operations
4040
:raises InputOutputMismatch: if sum of inputs is not equal to outputs and there's no mint/melt
4141
"""
42-
assert isinstance(tx, TokenCreationTransaction)
4342
token_dict = tx.get_complete_token_info()
4443

4544
# make sure tokens are being minted
4645
token_info = token_dict[not_none(tx.hash)]
4746
if token_info.amount <= 0:
4847
raise InvalidToken('Token creation transaction must mint new tokens')
4948

50-
super().verify_sum(tx)
51-
5249
def verify_token_info(self, tx: TokenCreationTransaction) -> None:
5350
""" Validates token info
5451
"""

tests/tx/test_verification.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ def test_token_creation_transaction_verify(self) -> None:
780780
verify_reward_locked_wrapped = Mock(wraps=self.verifiers.token_creation_tx.verify_reward_locked)
781781

782782
verify_token_info_wrapped = Mock(wraps=self.verifiers.token_creation_tx.verify_token_info)
783+
verify_minted_tokens_wrapped = Mock(wraps=self.verifiers.token_creation_tx.verify_minted_tokens)
783784

784785
with (
785786
patch.object(TokenCreationTransactionVerifier, 'verify_pow', verify_pow_wrapped),
@@ -795,6 +796,7 @@ def test_token_creation_transaction_verify(self) -> None:
795796
patch.object(TokenCreationTransactionVerifier, 'verify_sum', verify_sum_wrapped),
796797
patch.object(TokenCreationTransactionVerifier, 'verify_reward_locked', verify_reward_locked_wrapped),
797798
patch.object(TokenCreationTransactionVerifier, 'verify_token_info', verify_token_info_wrapped),
799+
patch.object(TokenCreationTransactionVerifier, 'verify_minted_tokens', verify_minted_tokens_wrapped),
798800
):
799801
self.manager.verification_service.verify(tx)
800802

@@ -813,6 +815,7 @@ def test_token_creation_transaction_verify(self) -> None:
813815

814816
# TokenCreationTransaction methods
815817
verify_token_info_wrapped.assert_called_once()
818+
verify_minted_tokens_wrapped.assert_called_once()
816819

817820
def test_token_creation_transaction_validate_basic(self) -> None:
818821
tx = self._get_valid_token_creation_tx()
@@ -907,6 +910,7 @@ def test_token_creation_transaction_validate_full(self) -> None:
907910
verify_reward_locked_wrapped = Mock(wraps=self.verifiers.token_creation_tx.verify_reward_locked)
908911

909912
verify_token_info_wrapped = Mock(wraps=self.verifiers.token_creation_tx.verify_token_info)
913+
verify_minted_tokens_wrapped = Mock(wraps=self.verifiers.token_creation_tx.verify_minted_tokens)
910914

911915
with (
912916
patch.object(TokenCreationTransactionVerifier, 'verify_parents_basic', verify_parents_basic_wrapped),
@@ -924,6 +928,7 @@ def test_token_creation_transaction_validate_full(self) -> None:
924928
patch.object(TokenCreationTransactionVerifier, 'verify_sum', verify_sum_wrapped),
925929
patch.object(TokenCreationTransactionVerifier, 'verify_reward_locked', verify_reward_locked_wrapped),
926930
patch.object(TokenCreationTransactionVerifier, 'verify_token_info', verify_token_info_wrapped),
931+
patch.object(TokenCreationTransactionVerifier, 'verify_minted_tokens', verify_minted_tokens_wrapped),
927932
):
928933
self.manager.verification_service.validate_full(tx)
929934

@@ -944,6 +949,7 @@ def test_token_creation_transaction_validate_full(self) -> None:
944949

945950
# TokenCreationTransaction methods
946951
verify_token_info_wrapped.assert_called_once()
952+
verify_minted_tokens_wrapped.assert_called_once()
947953

948954

949955
class SyncV1VerificationTest(unittest.SyncV1Params, BaseVerificationTest):

0 commit comments

Comments
 (0)