def get_contract(path): if path is None: files = glob('*.tz') assert len(files) == 1 contract = ContractInterface.from_file(abspath(files[0])) elif exists(path): contract = ContractInterface.from_file(path) else: network, address = path.split(':') contract = pytezos.using(shell=network).contract(address) return contract
def get_contract(path): if path is None: files = glob('*.tz') if len(files) != 1: raise Exception('No contracts found in working directory, specify --path implicitly') contract = ContractInterface.from_file(abspath(files[0])) elif exists(path): contract = ContractInterface.from_file(path) else: network, address = path.split(':') contract = pytezos.using(shell=network).contract(address) return contract
def __init__(self, client: PyTezosClient): self.client = client root_dir = Path(__file__).parent.parent / "michelson" self.minter_contract = ContractInterface.from_file(root_dir / "minter.tz") self.quorum_contract = ContractInterface.from_file(root_dir / "quorum.tz") self.fa2_contract = ContractInterface.from_file(root_dir / "multi_asset.tz") self.nft_contract = ContractInterface.from_file(root_dir / "nft.tz") self.governance_contract = ContractInterface.from_file( root_dir / "governance_token.tz")
def test_increment_decrement(self): counter = ContractInterface.from_file(join(dirname(__file__), 'contracts', 'macro_counter.tz')) res = counter.increaseCounterBy(5).interpret(storage=0) self.assertEqual(res.storage, 5) res = counter.decreaseCounterBy(5).interpret(storage=0) self.assertEqual(res.storage, -5)
def doubler(request): """Return configured instance of Doubler smart contract""" contract_path = compile('doubler', DoublerContract, __file__, request.config.cache) instance = ContractInterface.create_from(contract_path) instance.maxDiff = None return instance
def get_contract(path): path = get_local_contract_path(path) if path: contract = ContractInterface.from_file(path) else: network, address = path.split(':') contract = pytezos.using(shell=network).contract(address) return contract
def test_none_vs_unit(self): ci = ContractInterface.from_file(join(dirname(__file__), 'contracts', 'none_vs_unit.tz')) res = ci.callAnotherContract().interpret(storage=None) self.assertEqual(0, len(res.operations)) res = ci.callAnotherContract('KT1VG2WtYdSWz5E7chTeAdDPZNy2MpP8pTfL').interpret(storage=None) self.assertEqual(1, len(res.operations)) res = ci.doNothing().interpret(storage=None) self.assertEqual(Unit, res.storage)
def compile_contract(self): """ Force compilation of LIGO contract from source file and loads it into pytezos. :return: pytezos.ContractInterface """ command = f"{ligo_cmd} compile-contract {self.ligo_file} {self.main_func}" michelson = execute_command(command) self.contract_interface = ContractInterface.from_michelson(michelson) return self.contract_interface
def compile_contract(self): """ Force compilation of LIGO contract from source file and loads it into pytezos. :return: pytezos.ContractInterface """ command = f"{ligo_cmd} compile-contract {self.ligo_file} {self.main_func}" michelson = self._ligo_to_michelson(command) self.tz_file.write_text(michelson) self.contract_interface = ContractInterface.create_from(michelson) return self.contract_interface
def test_bmd_path(self): ci = ContractInterface.create_from(code) ci.contract.storage.big_map_init(michelson_to_micheline(storage)) query = ci.contract.storage.big_map_query( 'big_map_0/tz1bHzftcTKZMTZgLLtnrXydCm6UEqf4ivca') self.assertEqual( { 'big_map_id': 17, 'script_expr': 'expruGu4fvT7wyJYm2Rdz7jssqBZyoSmi3kub6Us3guARnzR9HBQCe' }, query)
def test_mint(self): token_v3 = ContractInterface.from_file(join(dirname(__file__), 'contracts', 'token.tz')) alice = "tz1ibMpWS6n6MJn73nQHtK5f4ogyYC1z9T9z" res = token_v3 \ .mint(mintOwner=alice, mintValue=3) \ .interpret( storage={ "admin": alice, "balances": {}, "paused": False, "shareType": "APPLE", "totalSupply": 0 }, source=alice) self.assertEqual(3, res.storage['balances'][alice])
def test_decode_from_michelson(self, file_name): """ Ensure that a valid Michelson contract with valid storage can be instantiated in Python """ storage_path = asset_directory.joinpath(file_name) with io.open(storage_path, 'r') as contract_data_input: michelson_storage = contract_data_input.read() contract_interface = ContractInterface.from_michelson( self.michelson_contract) python_storage = contract_interface.contract.storage.decode( michelson_storage) self.assertIsNotNone( python_storage, msg="Why couldn't the valid storage be decoded from Michelson?") contract_interface.contract.storage_from_michelson(michelson_storage) micheline_storage = contract_interface.contract.storage.encode( python_storage) self.assertIsNotNone( micheline_storage, msg= "Why couldn't python_storage (the result of decoding) be submitted " "for encoding?")
def participator(): """Return configured instance of Participator smart contract""" contract_path = 'src/contracts/participator/participator.tz' instance = ContractInterface.create_from(contract_path) instance.maxDiff = None return instance
def setUpClass(cls): cls.nft = ContractInterface.create_from(join(dirname(__file__), '../build/nft.tz'), shell='sandboxnet') cls.maxDiff = None
def setUpClass(cls): cls.nft = ContractInterface.create_from(join(dirname(__file__), 'nft.tz'), factory=NonFungibleTokenImpl)
def setUpClass(cls): cls.contract = ContractInterface.create_from(code)
def test_transfer_tokens(self): ci = ContractInterface.create_from(code) res = ci.call(0, 'KT1SmF5SCC5DrzkSm28HP9ovWVqcA5cmqZ1q').interpret( storage={"haha": "nice"}) self.assertEqual(1, len(res.operations))
def setUpClass(cls): cls.atomex = ContractInterface.create_from( join(dirname(__file__), 'atomex.tz')) cls.maxDiff = None
def test_docstring(self): ci = ContractInterface.from_file( join(dirname(__file__), 'contracts', 'macro_counter.tz')) print(ci.increaseCounterBy) self.assertFalse(is_interactive())
def test_now(self, network): contract = ContractInterface.from_michelson(code).using(network) now = pytezos.using(network).now() res = contract.default().run_code() self.assertEqual(now, res.storage)
if args.shell: pytezos = pytezos.using(shell=args.shell) print("Connecting to edo2net via: " + args.shell) cust_json = args.cust merch_json = args.merch # Set customer and merch pytezos interfaces cust_py = pytezos.using(key=cust_json) cust_addr = read_json_file(cust_json)['pkh'] merch_py = pytezos.using(key=merch_json) merch_addr = read_json_file(merch_json)['pkh'] # load cust_close json from libzkchannels cust_close_json = read_json_file('sample_cust_close.json') # load zchannel contracts main_code = ContractInterface.from_file('zkchannel_contract.tz') # Activate cust and merch testnet accounts try: print("Activating cust account") cust_py.activate_account().fill().sign().inject() except: print("Cust account already activated") try: print("Revealing cust pubkey") out = cust_py.reveal().autofill().sign().inject() except: pass cust_pubkey = cust_py.key.public_key()
def setUpClass(cls): cls.fa12 = ContractInterface.create_from( join(project_dir, 'samples/fa1.2.tz')) cls.viewer = pytezos.contract(viewer_address) cls.maxDiff = None
def setUpClass(cls): project_dir = dirname(dirname(__file__)) print("projectdir", project_dir) cls.voteContract = ContractInterface.create_from( join(project_dir, 'bin/vote.tz'))
def setUpClass(cls): project_dir = dirname(dirname(__file__)) print("projectdir", project_dir) cls.nftContract = ContractInterface.create_from( join(project_dir, 'src/land.tz'))
def setUpClass(cls): cls.ci = ContractInterface.from_michelson(code).using('mainnet')
def setUpClass(cls): cls.nftContract = ContractInterface.create_from(join(dirname(dirname(__file__)), 'test/helpers.tz')) cls.nftContract.address = contract_address
def test_increment(self): counter = ContractInterface.from_file( join(dirname(__file__), 'contracts', 'counter.tz')) res = counter.default('deadbeef').interpret(storage=[{}, 0]) self.assertEqual(1, res.storage[1]) self.assertIn(bytes.fromhex('deadbeef'), res.storage[0])
def setUpClass(cls): cls.atomex = ContractInterface.create_from( join(project_dir, 'src/atomex.tz')) cls.maxDiff = None
def test_concat(self): concat = ContractInterface.from_file( join(dirname(__file__), 'contracts', 'default_entrypoint.tz')) res = concat.default('bar').interpret(storage='foo') self.assertEqual('foobar', res.storage)
def setUpClass(cls): project_dir = dirname(dirname(__file__)) cls.nftContract = ContractInterface.create_from( path_to_michelson_contract) cls.nftContract.address = contract_address