Module mutation_testing

Expand source code
import smartpy as sp

class MyContract(sp.Contract):
    def __init__(self):
        self.init(x = 42)

    @sp.entrypoint
    def entrypoint_1(self):
        self.data.x += 1

    @sp.entrypoint
    def entrypoint_2(self, params):
        sp.verify(params < 2)

@sp.add_test(name = "MyTest1")
def test():
    sc = sp.test_scenario()
    c1 = MyContract()
    sc += c1
    sc.verify(c1.data.x == 42)
    c1.entrypoint_1()
    sc.verify(c1.data.x == 43)

@sp.add_test(name = "MyTest2")
def test():
    sc = sp.test_scenario()
    c1 = MyContract()
    sc += c1
    c1.entrypoint_2(1)
    c1.entrypoint_2(4).run(valid = False)

@sp.add_test(name = "Mutation")
def test():
    scenario = sp.test_scenario()
    with scenario.mutation_test() as mt:
        # mt.show_paths(True)
        mt.add_scenario("MyTest1")
        mt.add_scenario("MyTest2")

Classes

class MyContract
Expand source code
class MyContract(sp.Contract):
    def __init__(self):
        self.init(x = 42)

    @sp.entrypoint
    def entrypoint_1(self):
        self.data.x += 1

    @sp.entrypoint
    def entrypoint_2(self, params):
        sp.verify(params < 2)

Ancestors

  • smartpy.Contract

Methods

def entrypoint_1(self)

Entrypoint.

Expand source code
@sp.entrypoint
def entrypoint_1(self):
    self.data.x += 1
def entrypoint_2(self, params)

Entrypoint.

Expand source code
@sp.entrypoint
def entrypoint_2(self, params):
    sp.verify(params < 2)