3434 TransactionHash ,
3535 Tuple ,
3636 TypeVar ,
37+ typecheck ,
3738)
3839
3940# Quick overview
@@ -159,8 +160,7 @@ class ContractSendEvent(Event):
159160 triggered_by_block_hash : BlockHash
160161
161162 def __post_init__ (self ) -> None :
162- if not isinstance (self .triggered_by_block_hash , T_BlockHash ):
163- raise ValueError ("triggered_by_block_hash must be of type block_hash" )
163+ typecheck (self .triggered_by_block_hash , T_BlockHash )
164164
165165
166166@dataclass
@@ -181,10 +181,8 @@ class ContractReceiveStateChange(StateChange):
181181 block_hash : BlockHash
182182
183183 def __post_init__ (self ) -> None :
184- if not isinstance (self .block_number , T_BlockNumber ):
185- raise ValueError ("block_number must be of type block_number" )
186- if not isinstance (self .block_hash , T_BlockHash ):
187- raise ValueError ("block_hash must be of type block_hash" )
184+ typecheck (self .block_number , T_BlockNumber )
185+ typecheck (self .block_hash , T_BlockHash )
188186
189187
190188ST = TypeVar ("ST" , bound = State )
@@ -208,7 +206,7 @@ def __init__(
208206 state_transition: function that can apply a StateChange message.
209207 current_state: current application state.
210208 """
211- if not callable (state_transition ):
209+ if not callable (state_transition ): # pragma: no unittest
212210 raise ValueError ("state_transition must be a callable" )
213211
214212 self .state_transition = state_transition
@@ -291,17 +289,10 @@ class BalanceProofUnsignedState(State):
291289 balance_hash : BalanceHash = field (default = EMPTY_BALANCE_HASH )
292290
293291 def __post_init__ (self ) -> None :
294- if not isinstance (self .nonce , int ):
295- raise ValueError ("nonce must be int" )
296-
297- if not isinstance (self .transferred_amount , T_TokenAmount ):
298- raise ValueError ("transferred_amount must be a token_amount instance" )
299-
300- if not isinstance (self .locked_amount , T_TokenAmount ):
301- raise ValueError ("locked_amount must be a token_amount instance" )
302-
303- if not isinstance (self .locksroot , T_Keccak256 ):
304- raise ValueError ("locksroot must be a keccak256 instance" )
292+ typecheck (self .nonce , int )
293+ typecheck (self .transferred_amount , T_TokenAmount )
294+ typecheck (self .locked_amount , T_TokenAmount )
295+ typecheck (self .locksroot , T_Keccak256 )
305296
306297 if self .nonce <= 0 :
307298 raise ValueError ("nonce cannot be zero or negative" )
@@ -356,26 +347,13 @@ class BalanceProofSignedState(State):
356347 balance_hash : BalanceHash = field (default = EMPTY_BALANCE_HASH )
357348
358349 def __post_init__ (self ) -> None :
359- if not isinstance (self .nonce , int ):
360- raise ValueError ("nonce must be int" )
361-
362- if not isinstance (self .transferred_amount , T_TokenAmount ):
363- raise ValueError ("transferred_amount must be a token_amount instance" )
364-
365- if not isinstance (self .locked_amount , T_TokenAmount ):
366- raise ValueError ("locked_amount must be a token_amount instance" )
367-
368- if not isinstance (self .locksroot , T_Keccak256 ):
369- raise ValueError ("locksroot must be a keccak256 instance" )
370-
371- if not isinstance (self .message_hash , T_Keccak256 ):
372- raise ValueError ("message_hash must be a keccak256 instance" )
373-
374- if not isinstance (self .signature , T_Signature ):
375- raise ValueError ("signature must be a signature instance" )
376-
377- if not isinstance (self .sender , T_Address ):
378- raise ValueError ("sender must be an address instance" )
350+ typecheck (self .nonce , int )
351+ typecheck (self .transferred_amount , T_TokenAmount )
352+ typecheck (self .locked_amount , T_TokenAmount )
353+ typecheck (self .locksroot , T_Keccak256 )
354+ typecheck (self .message_hash , T_Keccak256 )
355+ typecheck (self .signature , T_Signature )
356+ typecheck (self .sender , T_Address )
379357
380358 if self .nonce <= 0 :
381359 raise ValueError ("nonce cannot be zero or negative" )
0 commit comments