templates.invalid_mutation_tests

  1# List of scenario that should not pass
  2
  3import smartpy as sp
  4
  5
  6# class InvertVerifyCondition(sp.Contract):
  7#     def __init__(self):
  8#         self.init(0)
  9
 10#     @sp.entrypoint
 11#     def fail_if_negative(self, params):
 12#         sp.verify(params >= 0)
 13#         self.data = params
 14
 15
 16# @sp.add_test(name="InvertVerifyCondition")
 17# def test():
 18#     c1 = InvertVerifyCondition()
 19#     sc = sp.test_scenario()
 20#     sc += c1
 21#     c1.fail_if_negative(5)
 22#     sc.verify(c1.data == 5)
 23#     # Expected:
 24#     # c1.fail_if_negative(-5, _valid=False)
 25
 26
 27# @sp.add_test(name="Mutation1")
 28# def test():
 29#     s = sp.test_scenario()
 30#     with s.mutation_test() as mt:
 31#         mt.add_scenario("InvertVerifyCondition")
 32
 33
 34################################################################################
 35
 36
 37# class ErrorMessage(sp.Contract):
 38#     def __init__(self):
 39#         self.init(0)
 40
 41#     @sp.entrypoint
 42#     def fail(self):
 43#         sp.failwith("FAILURE")
 44
 45
 46# @sp.add_test(name="ErrorMessage")
 47# def test():
 48#     c1 = ErrorMessage()
 49#     sc = sp.test_scenario()
 50#     sc += c1
 51#     c1.fail(_valid=False)
 52#     # Expected:
 53#     # c1.fail(_valid=False, _exception="FAILURE")
 54
 55
 56# @sp.add_test(name="Mutation2")
 57# def test():
 58#     s = sp.test_scenario()
 59#     with s.mutation_test() as mt:
 60#         mt.add_scenario("ErrorMessage")
 61
 62
 63################################################################################
 64
 65
 66# class OrVerifyCondition(sp.Contract):
 67#     def __init__(self):
 68#         self.init(0)
 69
 70#     @sp.entrypoint
 71#     def set_data(self, a, b):
 72#         with sp.if_(a | b):
 73#             self.data += 1
 74
 75
 76# @sp.add_test(name="OrVerifyCondition")
 77# def test():
 78#     c1 = OrVerifyCondition()
 79#     sc = sp.test_scenario()
 80#     sc += c1
 81#     sc.verify(c1.data == 0)
 82#     c1.set_data(a=True, b=False)
 83#     sc.verify(c1.data == 1)
 84#     c1.set_data(a=False, b=True)
 85#     sc.verify(c1.data == 2)
 86#     c1.set_data(a=False, b=False)
 87#     # Expected
 88#     # sc.verify(c1.data == 2)
 89
 90
 91# @sp.add_test(name="Mutation3")
 92# def test():
 93#     s = sp.test_scenario()
 94#     with s.mutation_test() as mt:
 95#         mt.add_scenario("OrVerifyCondition")
 96
 97
 98################################################################################
 99
100
101# class AndVerifyCondition(sp.Contract):
102#     def __init__(self):
103#         self.init(0)
104
105#     @sp.entrypoint
106#     def set_data(self, a, b):
107#         with sp.if_(a & b):
108#             self.data += 1
109
110
111# @sp.add_test(name="AndVerifyCondition")
112# def test():
113#     c1 = AndVerifyCondition()
114#     sc = sp.test_scenario()
115#     sc += c1
116#     sc.verify(c1.data == 0)
117#     c1.set_data(a=True, b=False)
118#     sc.verify(c1.data == 0)
119#     c1.set_data(a=False, b=True)
120#     sc.verify(c1.data == 0)
121#     c1.set_data(a=True, b=True)
122#     # Expected
123#     # sc.verify(c1.data == 1)
124
125
126# @sp.add_test(name="Mutation3Bis")
127# def test():
128#     s = sp.test_scenario()
129#     with s.mutation_test() as mt:
130#         mt.add_scenario("AndVerifyCondition")
131
132
133################################################################################
134
135
136# class EchoTez(sp.Contract):
137#     @sp.entrypoint
138#     def echoTez(self):
139#         sp.send(sp.sender, sp.amount)
140
141
142# @sp.add_test(name="EchoTez")
143# def test():
144#     c1 = EchoTez()
145#     sc = sp.test_scenario()
146#     sc += c1
147#     alice = sp.test_account("alice")
148#     c1.echoTez().run(sender=alice, amount=sp.tez(5))
149#     # Expected
150#     # A test of the consequence of the send operation.
151
152
153# @sp.add_test(name="Mutation4")
154# def test():
155#     s = sp.test_scenario()
156#     with s.mutation_test() as mt:
157#         mt.add_scenario("EchoTez")
158
159
160################################################################################
161
162
163# class NatIsNat(sp.Contract):
164#     def __init__(self):
165#         self.init(0)
166
167#     @sp.entrypoint
168#     def set_data(self, params):
169#         sp.set_type(params, sp.nat)
170#         # Expected: Remove the following line.
171#         sp.verify(params > 0)
172#         self.data = params
173
174
175# @sp.add_test(name="NatIsNat")
176# def test():
177#     c1 = NatIsNat()
178#     sc = sp.test_scenario()
179#     sc += c1
180#     c1.set_data(5)
181#     sc.verify(c1.data == 5)
182
183
184# @sp.add_test(name="Mutation5")
185# def test():
186#     s = sp.test_scenario()
187#     with s.mutation_test() as mt:
188#         mt.add_scenario("NatIsNat")
189
190
191################################################################################
192
193
194# class ElseDoesNothing(sp.Contract):
195#     def __init__(self):
196#         self.init(0)
197
198#     @sp.entrypoint
199#     def set_data(self, params):
200#         with sp.if_(params):
201#             self.data += 1
202
203
204# @sp.add_test(name="ElseDoesNothing")
205# def test():
206#     c1 = ElseDoesNothing()
207#     sc = sp.test_scenario()
208#     sc += c1
209#     sc.verify(c1.data == 0)
210#     c1.set_data(True)
211#     sc.verify(c1.data == 1)
212#     c1.set_data(False)
213#     # Expected
214#     # sc.verify(c1.data == 1)
215
216
217# @sp.add_test(name="Mutation6")
218# def test():
219#     s = sp.test_scenario()
220#     with s.mutation_test() as mt:
221#         mt.add_scenario("ElseDoesNothing")
222
223
224################################################################################
225
226
227# class OnchainView(sp.Contract):
228#     def __init__(self):
229#         self.init(sp.nat(0))
230
231#     @sp.onchain_view()
232#     def get_data(self):
233#         sp.result(self.data)
234
235
236# @sp.add_test(name="OnchainView")
237# def test():
238#     c1 = OnchainView()
239#     sc = sp.test_scenario()
240#     sc += c1
241#     # Expected
242#     # sc.verify(c1.get_data() == 0)
243
244
245# @sp.add_test(name="Mutation7")
246# def test():
247#     s = sp.test_scenario()
248#     with s.mutation_test() as mt:
249#         mt.add_scenario("OnchainView")