summary refs log tree commit diff stats
path: root/contract
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-09-25 17:36:31 +0530
committerAndinus <andinus@nand.sh>2021-09-25 17:38:04 +0530
commit8e321251e28d8a88d133eab55dc2d69b258f5789 (patch)
treecf0bff4d09f5478e2adf984995adf055fc6d36cf /contract
parent7b1334ade193f4ffabfb235f99329f2f70e7bb7c (diff)
downloadMyMedMemoir-8e321251e28d8a88d133eab55dc2d69b258f5789.tar.gz
Verify if the ID exists
Diffstat (limited to 'contract')
-rw-r--r--contract/memoir.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/contract/memoir.py b/contract/memoir.py
index c33c155..a9f3cc6 100644
--- a/contract/memoir.py
+++ b/contract/memoir.py
@@ -12,10 +12,19 @@ class Memoir(sp.Contract):
     @sp.entry_point
     def add_record(self, params):
         self.data.records[params.id] = params.record
+        # Verify that the ID doesn't exist.
+        # sp.verify(
+        #     self.data.records.contains(params.id) == False,
+        #     message = "Record exists"
+        # )
 
     @sp.entry_point
     def update_record(self, params):
-        self.data.records = sp.update_map(self.data.records, params.id, sp.some(params.record))
+        self.data.records = sp.update_map(
+            self.data.records,
+            params.id,
+            sp.some(params.record)
+        )
 
     @sp.entry_point
     def delete_record(self, params):
@@ -28,8 +37,19 @@ def test():
 
     c1 = Memoir()
     scenario += c1
+
+    # Try adding records.
     scenario += c1.add_record(id = 0, record = '{record #0}')
     scenario += c1.add_record(id = 1, record = '{record #1}')
     scenario += c1.add_record(id = 2, record = '{record #2}')
+
+    # Updating records.
     scenario += c1.update_record(id = 1, record = '{record #1 - updated}')
+
+    # Deleting records.
     scenario += c1.delete_record(id = 2)
+
+    # Trying to add over existing record. Should Fail.
+    # scenario += c1.add_record(
+    #     id = 2, record = '{record #2 - fail}'
+    # ).run(valid = False)