@export def add(a: int, b: int): return private_add(a, b) def private_add(a, b): return a + b from contracting.client import ContractingClient # Client to interact with local contracts client = ContractingClient() # Submit contract locally client.submit(greeting) # List all locally available contracts print("contracts", client.get_contracts()) # Retrieve local contract greeting = client.get_contract("greeting") # Execute contract method 'hello()' print("greeting - hello()", greeting.hello()) # Execute contract method 'add()' print("greeting - add()", greeting.add(a=1, b=3)) # Output # contracts ['submission', 'greeting'] # greeting - hello() Hello World! # greeting - add() 4
import unittest from contracting.client import ContractingClient from exercises.lamdem_blog_sample import my_token client = ContractingClient() # SC's get added to DB with each call # You should either verify before submitting, or wrapping in a try/catch block running_contracts = client.get_contracts() if 'my_token' not in running_contracts: client.submit(my_token) # Running into errors when loading it like this. # I think it might be because of extra headers, and imports # with open('../exercises/lamdem_blog_sample.py') as f: # code = f.read() # client.submit(code, name='my_token') class MyTestCase(unittest.TestCase): def test_supply(self): my_token = client.get_contract('my_token') self.assertEqual(my_token.quick_read('S', 'me'), 50) def test_transfer(self): # set transaction sender client.signer = 'me' # get contract reference my_token = client.get_contract('my_token')