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.
Description
TeachLinkBridge::mint_content_token(contracts/teachlink/src/tokenization.rs) validatescontent_hashwith:If
content_hashisn't exactly 32 bytes, this.unwrap()panics the whole contract invocation (HostError: Error(WasmVm, InvalidAction), "caught panic 'calledResult::unwrap()on anErrvalue: InvalidBytesLength'") instead of returning a properResult::Errwith a contract error the caller can handle.This was discovered because the
test_cross_contract_interactions.rstest fixture (content_params()) was passing a 6-byte placeholder (b"QmHash") ascontent_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.?returningTokenizationError::InvalidContentHashor similar) so callers get a normal contract error instead of the invocation panicking.Steps to reproduce
Call
mint_content_tokenwith acontent_hashthat isn't exactly 32 bytes.Suggested fix
Replace the
.unwrap()inmint_content_tokenwith?(or equivalent), propagating a properTokenizationErrorvariant instead of panicking.