templates.test_build_lambda
1import smartpy as sp 2 3 4@sp.module 5def main(): 6 class MyContract2(sp.Contract): 7 def __init__(self): 8 self.data.result = sp.cast( 9 None, sp.option[sp.lambda_(sp.unit, sp.unit, with_operations=True)] 10 ) 11 12 @sp.entrypoint 13 def exec_lambda(self, params): 14 self.data.result = sp.Some(params) 15 16 class MyContract3(sp.Contract): 17 def __init__(self): 18 self.data.result = sp.cast( 19 None, sp.option[sp.lambda_(sp.unit, sp.unit, with_operations=True)] 20 ) 21 22 @sp.entrypoint 23 def exec_lambda(self, params): 24 self.data.result = sp.Some(params) 25 26 @sp.entrypoint 27 def nothing(self): 28 pass 29 30 31def dummy_lambda_function(params): 32 sp.set_type(params, sp.unit) 33 dummyContractHandle = sp.contract(sp.unit, sp.self_address).unwrap_some() 34 sp.transfer(sp.unit, sp.mutez(0), dummyContractHandle) 35 36 37@sp.add_test() 38def test(): 39 scenario = sp.test_scenario("Lambdas", main) 40 scenario.h1("Lambdas") 41 c2 = main.MyContract2() 42 scenario += c2 43 c2.exec_lambda(sp.build_lambda(dummy_lambda_function, with_operations=True)) 44 c3 = main.MyContract3() 45 scenario += c3 46 c3.exec_lambda(sp.build_lambda(dummy_lambda_function, with_operations=True))
def
dummy_lambda_function(params):