Skip to content

Commit 2d637ff

Browse files
committed
add validation checks on asset-id
1 parent 1e6088e commit 2d637ff

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tests/intergration/test_provenance_contract.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@
2323
'(do
2424
(def provenance [])
2525
(defn version [] "{CONTRACT_VERSION}")
26+
(defn assert-asset-id [value]
27+
(when-not (and (blob? value) (== 32 (count (blob value)))) (fail "INVALID" "invalid asset-id"))
28+
)
2629
(defn register [asset-id]
30+
(assert-asset-id asset-id)
2731
(let [record {{:owner *caller* :timestamp *timestamp* :asset-id (blob asset-id)}}]
2832
(def provenance (conj provenance record))
2933
record
3034
)
3135
)
3236
(defn event-list [asset-id]
37+
(assert-asset-id asset-id)
3338
(mapcat (fn [record] (when (= (blob asset-id) (record :asset-id)) [record])) provenance)
3439
)
3540
(export event-list register version)
@@ -67,3 +72,6 @@ def test_provenance_contract(convex, test_account):
6772
assert(event_item['asset-id'] == asset_id)
6873

6974

75+
bad_asset_id = '0x' + secrets.token_hex(20)
76+
with pytest.raises(ConvexAPIError, match='INVALID'):
77+
result = convex.send(f'(call {contract_address} (register {bad_asset_id}))', test_account)

0 commit comments

Comments
 (0)