mint_content_token panics instead of returning an error for invalid content_hash length #485
Description
Description
TeachLinkBridge::mint_content_token (contracts/teachlink/src/tokenization.rs) validates content_hash with:
crate::validation::BytesValidator::validate_length(&content_hash, 32, 32).unwrap();If content_hash isn't exactly 32 bytes, this .unwrap() panics the whole contract invocation (HostError: Error(WasmVm, InvalidAction), "caught panic 'called Result::unwrap() on an Err value: InvalidBytesLength'") instead of returning a proper Result::Err with a contract error the caller can handle.
This was discovered because the test_cross_contract_interactions.rs test fixture (content_params()) was passing a 6-byte placeholder (b"QmHash") as content_hash, which panicked 6 different tests once CI was fixed to actually run them (see #484). The test fixture itself has been corrected to use a valid 32-byte hash, but the production .unwrap() should probably be replaced with proper error propagation (e.g. ? returning TokenizationError::InvalidContentHash or similar) so callers get a normal contract error instead of the invocation panicking.
Steps to reproduce
Call mint_content_token with a content_hash that isn't exactly 32 bytes.
Suggested fix
Replace the .unwrap() in mint_content_token with ? (or equivalent), propagating a proper TokenizationError variant instead of panicking.
Activity
RUKAYAT-CODER commentedon Jul 1, 2026
Same pattern found a second time in the same function:
mint_content_tokenalso hasif royalty_percentage > 100 { panic!("Royalty percentage cannot exceed 100"); }- a directpanic!, not even aResult::Err. This should probably also be converted to a properTokenizationErrorreturn alongside thecontent_hashlength-validation fix already described above.