|
13 | 13 | PrivyDFlowPredictionTool, |
14 | 14 | PrivyDFlowPredictionPlugin, |
15 | 15 | ) |
| 16 | +from sakit.utils.wallet import sanitize_privy_user_id |
16 | 17 | from sakit.utils.dflow import ( |
17 | 18 | DFlowPredictionClient, |
18 | 19 | DFlowPredictionOrderResult, |
@@ -101,6 +102,83 @@ def sample_event(): |
101 | 102 | } |
102 | 103 |
|
103 | 104 |
|
| 105 | +# ============================================================================= |
| 106 | +# PRIVY USER ID SANITIZATION TESTS |
| 107 | +# ============================================================================= |
| 108 | + |
| 109 | + |
| 110 | +class TestPrivyUserIdSanitization: |
| 111 | + """Test privy_user_id sanitization to handle LLM formatting errors.""" |
| 112 | + |
| 113 | + def test_sanitize_none(self): |
| 114 | + """None should return None.""" |
| 115 | + assert sanitize_privy_user_id(None) is None |
| 116 | + |
| 117 | + def test_sanitize_empty_string(self): |
| 118 | + """Empty string should return None.""" |
| 119 | + assert sanitize_privy_user_id("") is None |
| 120 | + |
| 121 | + def test_sanitize_correct_format(self): |
| 122 | + """Correctly formatted ID should be returned as-is.""" |
| 123 | + user_id = "did:privy:cmiox5jks01fhk40d0feu1wt8" |
| 124 | + assert sanitize_privy_user_id(user_id) == user_id |
| 125 | + |
| 126 | + def test_sanitize_with_leading_quote(self): |
| 127 | + """Leading quote should be stripped.""" |
| 128 | + user_id = '"did:privy:cmiox5jks01fhk40d0feu1wt8' |
| 129 | + expected = "did:privy:cmiox5jks01fhk40d0feu1wt8" |
| 130 | + assert sanitize_privy_user_id(user_id) == expected |
| 131 | + |
| 132 | + def test_sanitize_with_capitalized_did(self): |
| 133 | + """Capitalized Did should be normalized.""" |
| 134 | + user_id = "Did:privy:cmiox5jks01fhk40d0feu1wt8" |
| 135 | + expected = "did:privy:cmiox5jks01fhk40d0feu1wt8" |
| 136 | + assert sanitize_privy_user_id(user_id) == expected |
| 137 | + |
| 138 | + def test_sanitize_with_all_caps(self): |
| 139 | + """All caps DID:PRIVY should be normalized.""" |
| 140 | + user_id = "DID:PRIVY:cmiox5jks01fhk40d0feu1wt8" |
| 141 | + expected = "did:privy:cmiox5jks01fhk40d0feu1wt8" |
| 142 | + assert sanitize_privy_user_id(user_id) == expected |
| 143 | + |
| 144 | + def test_sanitize_with_quotes_and_caps(self): |
| 145 | + """Leading quote and caps should both be fixed.""" |
| 146 | + user_id = '"Did:privy:cmiox5jks01fhk40d0feu1wt8' |
| 147 | + expected = "did:privy:cmiox5jks01fhk40d0feu1wt8" |
| 148 | + assert sanitize_privy_user_id(user_id) == expected |
| 149 | + |
| 150 | + def test_sanitize_with_single_quotes(self): |
| 151 | + """Single quotes should be stripped.""" |
| 152 | + user_id = "'did:privy:cmiox5jks01fhk40d0feu1wt8'" |
| 153 | + expected = "did:privy:cmiox5jks01fhk40d0feu1wt8" |
| 154 | + assert sanitize_privy_user_id(user_id) == expected |
| 155 | + |
| 156 | + def test_sanitize_with_whitespace(self): |
| 157 | + """Whitespace should be stripped.""" |
| 158 | + user_id = " did:privy:cmiox5jks01fhk40d0feu1wt8 " |
| 159 | + expected = "did:privy:cmiox5jks01fhk40d0feu1wt8" |
| 160 | + assert sanitize_privy_user_id(user_id) == expected |
| 161 | + |
| 162 | + def test_sanitize_preserves_unique_id_case(self): |
| 163 | + """Unique ID part should preserve its original case.""" |
| 164 | + user_id = "did:privy:CmIoX5jKs01fHk40D0fEu1wT8" |
| 165 | + expected = "did:privy:CmIoX5jKs01fHk40D0fEu1wT8" |
| 166 | + assert sanitize_privy_user_id(user_id) == expected |
| 167 | + |
| 168 | + def test_sanitize_non_privy_id(self): |
| 169 | + """Non-privy ID should be returned cleaned but not normalized.""" |
| 170 | + user_id = " some-other-id " |
| 171 | + expected = "some-other-id" |
| 172 | + assert sanitize_privy_user_id(user_id) == expected |
| 173 | + |
| 174 | + def test_sanitize_only_whitespace_and_quotes(self): |
| 175 | + """String with only whitespace and quotes should return None.""" |
| 176 | + assert sanitize_privy_user_id(" ") is None |
| 177 | + assert sanitize_privy_user_id('""') is None |
| 178 | + assert sanitize_privy_user_id("''") is None |
| 179 | + assert sanitize_privy_user_id('" "') is None |
| 180 | + |
| 181 | + |
104 | 182 | # ============================================================================= |
105 | 183 | # TOOL INITIALIZATION TESTS |
106 | 184 | # ============================================================================= |
|
0 commit comments