templates.test_transfers_to_accounts

 1import smartpy as sp
 2
 3
 4@sp.module
 5def main():
 6    class TestContract(sp.Contract):
 7        @sp.entrypoint
 8        def deposit(self):
 9            pass
10
11        @sp.entrypoint
12        def withdraw(self, address, quantity):
13            sp.send(address, quantity)
14
15        @sp.entrypoint
16        def withdraw_all(self, address):
17            sp.send(address, sp.balance)
18
19
20@sp.add_test()
21def test():
22    sc = sp.test_scenario("Test", main)
23    account = sp.test_account("test")
24    c = main.TestContract()
25    c.set_initial_balance(sp.mutez(100))
26    sc += c
27    c.deposit(_amount=sp.mutez(1000))
28    sc.verify(c.balance == sp.mutez(1100))
29    c.withdraw(address=account.address, quantity=sp.mutez(200))
30    c.withdraw(
31        address=account.address,
32        quantity=sp.mutez(2000),
33        _valid=False,
34        _exception="Negative balance for KT1TezoooozzSmartPyzzSTATiCzzzwwBFA1",
35    )
36    sc.verify(c.balance == sp.mutez(900))
37    c.withdraw_all(account.address)
38    sc.verify(c.balance == sp.mutez(0))