def test_exchanger(self): ts4.reset_all() # reset all data ts4.init('./', verbose=True) key1 = ts4.make_keypair() self.public1 = key1[1] self.secret1 = key1[0] now = int(time.time()) ts4.core.set_now(now) test = ts4.BaseContract('test', dict(), pubkey=self.public, private_key=self.secret, balance=150_000_000_000, nickname="test") now += 5 ts4.core.set_now(now) main = ts4.BaseContract('main', dict(), pubkey=self.public, private_key=self.secret, balance=150_000_000_000, nickname="main") now += 5 ts4.core.set_now(now) test.call_method("change_address", dict(_adr=main.addr), private_key=self.secret) now += 5 ts4.core.set_now(now) test.call_method("createTimer", dict(_payload=1, _time=20), private_key=self.secret) while len(ts4.globals.QUEUE) > 0: now += 5 ts4.core.set_now(now) ts4.dispatch_one_message() print(test.call_getter("results"))
ts4.dispatch_one_message() # Сheck the current balance of the sender and recipient sender.ensure_balance(balance_sender - amount) recipient.ensure_balance(balance_recipient + amount) # Send remainig balance and self-destroy sender's contract params = dict(addr=addr_recipient, amount=0, flags=160) sender.call_method('send_grams_with_flags', params) ts4.dispatch_one_message() # Сheck the current balance of the recipient, it's should be increased by sender's balance recipient.ensure_balance(balance_recipient + balance_sender) # Balance of the sender should be None, because of the contract destroyed assert eq(None, ts4.get_balance(sender.address)) # Initialize TS4 by specifying where the artifacts of the used contracts are located # verbose: toggle to print additional execution info ts4.init('contracts/', verbose=True) test1() # Ensure we have no undispatched messages ts4.reset_all() test2() ts4.reset_all() test3()
''' This tutorial demonstrates how to work with getters to receive different types of data (number, address, bool, bytes, string, array and struct). ''' import tonos_ts4.ts4 as ts4 eq = ts4.eq # Initialize TS4 by specifying where the artifacts of the used contracts are located # verbose: toggle to print additional execution info ts4.init('contracts/', verbose = False) # Load a contract from .tvc-file and deploy it into a virtual blockchain. # Constructor is called automatically. # After deployment, "logstr: Constructor" will appear in the output to facilitate the debugging process. tut01 = ts4.BaseContract('tutorial01', {}) # Call an integer getter and ensure that we received correct value print("Fetching 'm_number'... ", end='') expected_value = 3735928559 assert eq(expected_value, tut01.call_getter('m_number')) print('ok') # Call the getter and ensure that we received correct address print("Fetching 'm_address'... ", end='') expected_address = ts4.Address('0:c4a31362f0dd98a8cc9282c2f19358c888dfce460d93adb395fa138d61ae5069')
import tonos_ts4.ts4 as ts4 ts4.init("../build/", verbose=False) def cb_false(_): return False def call_with_wallet(smc_wallet, dest, value, payload, flags=3, bounce=True): smc_wallet.call_method( "sendTransaction", { "dest": dest, "value": value, "bounce": bounce, "flags": flags, "payload": payload, }, keys_multisig[0], ) def init_smc_nft_root(owner, mintType=0, fee=0): smc = ts4.BaseContract( "NftRootCustomMint", { "mintType": mintType, "fee": fee, "name": "name", "descriprion": "descriprion",
'anonymous_id': 0xFCEFE3D2B1EEFC9A506B167151E81AE248F31DE896AD48DC6DCC5F4805373B5A }) == (True, 0) assert AnonymousVote.call_getter( 'get_vote', { 'anonymous_id': 0x03028200952785FA92B6925F22270C139E3BDD3CC0A9EACF39B5987AFB531039 }) == (True, 0) AnonymousVote.call_method('vote', { 'proof': proof, 'vote_choice': 0, 'signed_vote': 0xE7EA50574F6E21467915257BC3BFA4B1B7315BF2E29F9DD6F5E53C9B99595A51, 'anonymous_id': 0xFCEFE3D2B1EEFC9A506B167151E81AE248F31DE896AD48DC6DCC5F4805373B5A }, expect_ec=109) assert AnonymousVote.call_getter('get_results') == {0: 2} print('Ok') if __name__ == '__main__': # verbose: toggle to print additional execution info ts4.init('.') test()
''' import time import tonos_ts4.ts4 as ts4 eq = ts4.eq now = int(time.time()) # Initialize TS4: ts4.init(path, verbose = False, time = 0) # path: set a directory where the artifacts of the used contracts are located # verbose: toggle to print additional execution info # time: in seconds. TS4 uses either real-clock or virtual time. Once you set time you switch # to virtual time mode, where you can move time to future on your own ts4.init('contracts/', verbose = True, time = now) # Deploy a contract tut07 = ts4.BaseContract('tutorial07', {}) # Call the getter and ensure that the required time has not yet arrived assert eq(False, tut07.call_getter('isUnlocked')) DAY = 86400 # Fast forward 7 days ts4.core.set_now(now + 7 * DAY) # ... and ensure that the required time has come assert eq(True, tut07.call_getter('isUnlocked')) # P.S. Traveling into the future is easy. Isn't it?
import tonos_ts4.ts4 as ts4, json eq = ts4.eq bt = 1000000 ts4.init('../build/', verbose=True) ts4.G_WARN_ON_UNEXPECTED_ANSWERS = True assert eq('0.2.1', ts4.__version__) print("==================== Initialization ====================") # Load some ABI beforehand to dismiss 'Unknown message' warnings ts4.register_abi('Padawan') ts4.register_abi('TONTokenWallet') ts4.register_abi('RootTokenContract') # ts4.register_abi('Proposal') helper = ts4.BaseContract('Helper', {}, nickname='helper') smcTestRoot = ts4.BaseContract('TestRoot', {}, nickname='TestRoot') (private_key, public_key) = ts4.make_keypair() smcSafeMultisigWallet = ts4.BaseContract( 'SafeMultisigWallet', ctor_params=dict( reqConfirms=0, owners=[public_key], ), pubkey=public_key, private_key=private_key,