templates.send_twice

 1import smartpy as sp
 2
 3
 4@sp.module
 5def main():
 6    class Receiver(sp.Contract):
 7        @sp.entrypoint
 8        def receive_and_check(self, sender_balance, receiver_balance):
 9            assert (
10                sender_balance
11                == sp.view("get_balance", sp.sender, (), sp.mutez).unwrap_some()
12            )
13            assert receiver_balance == sp.balance
14
15    class Sender(sp.Contract):
16        @sp.entrypoint
17        def send(self, a):
18            c = sp.contract(
19                sp.record(sender_balance=sp.mutez, receiver_balance=sp.mutez),
20                a,
21                entrypoint="receive_and_check",
22            ).unwrap_some()
23            sp.transfer(
24                sp.record(sender_balance=sp.tez(110), receiver_balance=sp.tez(1)),
25                sp.tez(1),
26                c,
27            )
28            sp.transfer(
29                sp.record(sender_balance=sp.tez(100), receiver_balance=sp.tez(11)),
30                sp.tez(10),
31                c,
32            )
33
34        @sp.onchain_view()
35        def get_balance(self):
36            return sp.balance
37
38
39if "main" in __name__:
40
41    @sp.add_test()
42    def test():
43        sc = sp.test_scenario("Test", main)
44
45        sender = main.Sender()
46        sender.set_initial_balance(sp.tez(111))
47        sc += sender
48
49        receiver = main.Receiver()
50        sc += receiver
51
52        sender.send(receiver.address)