@@ -201,17 +201,21 @@ fn test_invalid_muxed_ed25519() {
201201 r = "MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVAAAAAAAAAAAAAAV75I" . parse ( ) ;
202202 assert_eq ! ( r, Err ( DecodeError :: InvalidPayloadLength ) ) ;
203203
204- // TODO: This case is meant to exercise the "invalid algorithm (low 3 bits
205- // of version byte are 7)" rejection path, but the CRC bytes still match
206- // the original `M` version, so flipping to `M4` trips the checksum check
207- // before the version-byte match. The following input has version byte
208- // `(12 << 3) | 7 = 0x67` ("M4" prefix) with a CRC recomputed for that
209- // version byte, and a zeroed 40-byte payload, which would actually surface
210- // as `UnsupportedVersion`:
211- // "M4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC4ZS"
204+ // Invalid algorithm (low 3 bits of version byte are 7). This input was
205+ // produced by flipping the algorithm bits of an otherwise valid `M`
206+ // strkey without recomputing the CRC, so the checksum check fires before
207+ // the version-byte match — see the `M4…C4ZS` case below for an input
208+ // that reaches the `UnsupportedVersion` path.
212209 r = "M47QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAAAAAAAACJUQ" . parse ( ) ;
213210 assert_eq ! ( r, Err ( DecodeError :: ChecksumMismatch ) ) ;
214211
212+ // Invalid algorithm (low 3 bits of version byte are 7). Same ed25519 +
213+ // id payload as the valid `MA7QYNF7…CJUQ` strkey above, but the version
214+ // byte is `(12 << 3) | 7 = 0x67` with a CRC recomputed for that version
215+ // byte, so the checksum check passes and the version-byte match fails.
216+ r = "M47QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAAAAAAAABIFE" . parse ( ) ;
217+ assert_eq ! ( r, Err ( DecodeError :: UnsupportedVersion ) ) ;
218+
215219 // Padding bytes are not allowed
216220 r = "MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAAAAAAAACJUK===" . parse ( ) ;
217221 assert_eq ! ( r, Err ( DecodeError :: InvalidBase32 ) ) ;
@@ -716,16 +720,12 @@ fn test_valid_claimable_balance() {
716720
717721#[ test]
718722fn test_invalid_claimable_balances ( ) {
719- // TODO: This test input is prefixed with `L`, not `B`, so it actually
720- // routes through `LiquidityPool` decoding and fails with
721- // `InvalidPayloadLength`. It is not exercising the claimable-balance
722- // "too long" path the comment implies. A `B`-prefixed input that is
723- // genuinely too long for a claimable balance (34-byte payload, binary
724- // length 37, with a valid CRC) would also produce `InvalidPayloadLength`
725- // via the claimable-balance path:
726- // "BAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZMEQ"
723+ // Too long strkey input. `B`-prefixed with a 34-byte payload (one byte
724+ // longer than a claimable balance's 33-byte payload) and a valid CRC, so
725+ // decoding reaches `ClaimableBalance::from_payload` with a 34-byte
726+ // payload that fails its 33-byte length check.
727727 let mut r: Result < Strkey , _ > =
728- "LAAD6DBUX6J22DMZOHIEZTEQ64CVCHEDRKWZONFEUL5Q26QD7R76RGX7FIWQ " . parse ( ) ;
728+ "BAAD6DBUX6J22DMZOHIEZTEQ64CVCHEDRKWZONFEUL5Q26QD7R76RGX74RYA " . parse ( ) ;
729729 assert_eq ! ( r, Err ( DecodeError :: InvalidPayloadLength ) ) ;
730730
731731 // Invalid length (Claimable balance should be 1+32 bytes, not 6).
@@ -749,17 +749,20 @@ fn test_invalid_claimable_balances() {
749749 r = "BAADMPVKHBTYIH522D2O3CGHPHSP4ZXFNISHBXEYYDWJYBZ5AXD3CA3GDEAAAAAAA" . parse ( ) ;
750750 assert_eq ! ( r, Err ( DecodeError :: InvalidBase32 ) ) ;
751751
752- // TODO: The comment says "base-32 decoding should yield 35 bytes, not 36"
753- // but a claimable balance's binary length is 36 bytes (1 version + 1 sub +
754- // 32 hash + 2 CRC). This input decodes fine, but its sub-version byte
755- // isn't zero, so it fails with `UnsupportedClaimableBalanceVersion`
756- // rather than a length error. A `B`-prefixed input whose binary decodes
757- // to 35 bytes (one short of the expected 36) with a valid CRC would
758- // exercise the length path and produce `InvalidPayloadLength`:
759- // "BAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZBO"
752+ // Unsupported claimable-balance sub-version. The input is the right
753+ // length (decodes to 36 bytes: 1 version + 1 sub + 32 hash + 2 CRC) but
754+ // its sub-version byte is non-zero, so it fails the V0 check.
760755 r = "BA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUADTYY" . parse ( ) ;
761756 assert_eq ! ( r, Err ( DecodeError :: UnsupportedClaimableBalanceVersion ) ) ;
762757
758+ // Invalid length (base-32 decoding yields 35 bytes, not the expected 36).
759+ // Same V0 sub-version + 32-byte hash as the valid CB strkey, but with the
760+ // trailing hash byte dropped — giving a 32-byte payload (V0 + 31 of 32
761+ // hash bytes) that decoding routes to `ClaimableBalance::from_payload`
762+ // and fails its length check.
763+ r = "BAADMPVKHBTYIH522D2O3CGHPHSP4ZXFNISHBXEYYDWJYBZ5AXD3C3NP" . parse ( ) ;
764+ assert_eq ! ( r, Err ( DecodeError :: InvalidPayloadLength ) ) ;
765+
763766 // Invalid algorithm (low 3 bits of version byte are 7).
764767 r = "B47QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVA4D" . parse ( ) ;
765768 assert_eq ! ( r, Err ( DecodeError :: UnsupportedVersion ) ) ;
0 commit comments