def post(self): if (request.data.__len__() == 0): if (request.args.get('password', '') == None): key = Key.generate() else: key = Key.generate(request.args.get('password', '')) else: password = json.loads(request.data).get("password") if (password != ""): key = Key.generate(password) else: key = Key.generate() file_name = './{}.json'.format(key.public_key_hash()) with open(file_name) as json_file: data = json.load(json_file) os.remove(file_name) #activate / reveal data['secret_key'] = key.secret_key() return data
def setUp(self): self.util = PtzUtils(flextesa_sandbox) # self.util = PtzUtils(pytezos) self.admin_key = self.util.client.key self.orig_contracts() self.mike_key = Key.generate(export=False) self.kyle_key = Key.generate(export=False) # self.transfer_init_funds() print("basic test setup completed")
def test_should_set_new_admin(self): new_admin = Key.generate(export=False).public_key_hash() res = self.contract.set_admin(new_admin).interpret(storage=storage(), sender=first_signer_key.public_key_hash()) self.assertEqual(first_signer_key.public_key_hash(), res.storage["admin"]) self.assertEqual(new_admin, res.storage["pending_admin"])
def test_should_only_be_called_by_quorum_contract(self): with self.assertRaises(MichelsonRuntimeError) as context: payment_address = Key.generate(export=False).public_key_hash() self.bender_contract.signer_ops(signer_1_key, payment_address) \ .interpret(storage=(valid_storage()), sender=other_party) self.assertEqual("'NOT_SIGNER'", context.exception.args[-1])
def test_set_signer_payment_address(self): payment_address = Key.generate(export=False).public_key_hash() storage = valid_storage() res = self.bender_contract.signer_ops(signer_1_key, payment_address) \ .interpret(storage=storage, sender=super_admin) self.assertEqual(payment_address, res.storage["fees"]["signers"][signer_1_key])
def test_only_pending_admin_can_confirm(self): with self.assertRaises(MichelsonRuntimeError) as context: new_admin = Key.generate(export=False).public_key_hash() valid_storage = storage() valid_storage["pending_admin"] = new_admin self.contract.confirm_admin().interpret(storage=valid_storage, sender=first_signer_key.public_key_hash()) self.assertEqual("'NOT_A_PENDING_ADMIN'", context.exception.args[-1])
def test_should_confirm_new_admin(self): new_admin = Key.generate(export=False).public_key_hash() valid_storage = storage() valid_storage["pending_admin"] = new_admin res = self.contract.confirm_admin().interpret(storage=valid_storage, sender=new_admin) self.assertEqual(new_admin, res.storage["admin"]) self.assertEqual(None, res.storage["pending_admin"])
def test_distribute_xtz_to_signer_registered_payment_address(self): signer_1_payment_address = Key.generate(export=False).public_key_hash() initial_storage = valid_storage() with_xtz_to_distribute(100, initial_storage) initial_storage["fees"]["signers"][signer_1_key] = signer_1_payment_address res = self.bender_contract.distribute_xtz([signer_1_key]).interpret(storage=initial_storage, sender=super_admin, self_address=self_address) self.assertEqual(50, self._xtz_of(signer_1_payment_address, res.storage))
def test_should_fail_on_bad_signature(self): with self.assertRaises(MichelsonRuntimeError) as context: payment_address = Key.generate(export=False).public_key_hash() signature = first_signer_key.sign(self._pack_set_payment_address(0, payment_address)) current_storage = storage() current_storage["counters"][first_signer_id] = 1 self.contract.set_signer_payment_address(minter_contract=minter_contract, signer_id=first_signer_id, signature=signature).interpret( storage=current_storage, sender=payment_address, self_address=self_address, chain_id=chain_id) self.assertEqual("'BAD_SIGNATURE'", context.exception.args[-1])
def test_should_reject_other_transfers(self): with self.assertRaises(MichelsonRuntimeError) as context: storage = with_token_balance(initial_storage(), user, 100) destination = Key.generate(export=False).public_key_hash() self.contract.transfer([{ "from_": user, "txs": [{ "to_": destination, "token_id": 2, "amount": 10 }] }]).interpret(storage=storage, sender=user) self.assertEqual("'FA2_TOKEN_UNDEFINED'", context.exception.args[-1])
def test_operator_should_transfer_tokens(self): storage = with_token_balance(initial_storage(), user, 100) destination = Key.generate(export=False).public_key_hash() storage['assets']['operators'][(user, super_admin)] = None result = self.contract.transfer([{ "from_": user, "txs": [{ "to_": destination, "token_id": 0, "amount": 10 }] }]).interpret(storage=storage, sender=super_admin) self.assertEqual(10, balance_of(result.storage, destination)) self.assertEqual(90, balance_of(result.storage, user))
def test_should_set_signer_payment_address(self): payment_address = Key.generate(export=False).public_key_hash() signature = first_signer_key.sign(self._pack_set_payment_address(0, payment_address)) res = self.contract.set_signer_payment_address(minter_contract=minter_contract, signer_id=first_signer_id, signature=signature).interpret( storage=storage(), sender=payment_address, self_address=self_address, chain_id=chain_id) self.assertEqual(1, len(res.operations)) op = res.operations[0] self.assertEqual(minter_contract, op["destination"]) self.assertEqual('signer_ops', op["parameters"]["entrypoint"]) self.assertEqual(michelson_to_micheline( f'(Pair "{first_signer_key.public_key_hash()}" "{payment_address}")'), op['parameters']['value']) self.assertEqual(1, res.storage["counters"][first_signer_id])
def test_should_transfer_unfrozen(self): storage1 = initial_storage() storage = with_token_balance(storage1, user, 100) destination = Key.generate(export=False).public_key_hash() result = self.contract.transfer([{ "from_": user, "txs": [{ "to_": destination, "token_id": 0, "amount": 10 }] }]).interpret(storage=storage, sender=user) self.assertEqual(10, balance_of(result.storage, destination)) self.assertEqual(90, balance_of(result.storage, user))
import unittest from pathlib import Path from pytezos import Key, MichelsonRuntimeError from src.ligo import LigoContract from unittest_data_provider import data_provider reward_token = ("KT1VUNmGa1JYJuNxNS4XDzwpsc9N1gpcCBN2", 1) stake_token = ("KT1LRboPna9yQY9BrjtQYDS1DVxhKESK4VVd", 0) self_address = "KT1BEqzn5Wx8uJrZNvuS9DVHmLvG9td3fDLi" reserve_contract = "KT1K7L5bQzqmVRYyrgLTHWNHQ6C5vFpYGQRk" admin = Key.generate(export=False).public_key_hash() burn_address = Key.generate(export=False).public_key_hash() scale = 10 ** 16 class StackingContractTest(unittest.TestCase): @classmethod def setUpClass(cls) -> None: root_dir = Path(__file__).parent.parent / "ligo" cls.contract = LigoContract( root_dir / "stacking" / "stacking_main.mligo", "main" ).get_contract() class DepositTest(StackingContractTest): def test_should_increase_balance_on_staking(self): user = a_user() storage = with_balance(user, 150, valid_storage(total_supply=10))
minter_contract = "KT1VUNmGa1JYJuNxNS4XDzwpsc9N1gpcCBN2" chain_id = "NetXm8tYqnMWky1" minter_ep = """(or (or (pair %add_fungible_token (bytes %eth_contract) (pair %token_address address nat)) (pair %add_nft (bytes %eth_contract) (address %token_contract))) (or (pair %mint_fungible_token (bytes %erc_20) (pair (pair %event_id (bytes %block_hash) (nat %log_index)) (pair (address %owner) (nat %amount)))) (pair %mint_nft (bytes %erc_721) (pair (pair %event_id (bytes %block_hash) (nat %log_index)) (pair (address %owner) (nat %token_id))))))""" first_signer_id = "k51qzi5uqu5dilfdi6xt8tfbw4zmghwewcvvktm7z9fk4ktsx4z7wn0mz2glje" second_signer_id = "k51qzi5uqu5dhuc1pto6x98woksrqgwhq6d1lff2hfymxmlk4qd7vqgtf980yl" first_signer_key = Key.generate(curve=b'sp', export=False) second_signer_key = Key.generate(curve=b'sp', export=False) payload_type = michelson_to_micheline(f"(pair (pair chain_id address) (pair {minter_ep} address))") self_address = "KT1BEqzn5Wx8uJrZNvuS9DVHmLvG9td3fDLi" class QuorumContractTest(unittest.TestCase): @classmethod def setUpClass(cls) -> None: root_dir = Path(__file__).parent.parent / "ligo" cls.contract = LigoContract(root_dir / "quorum" / "multisig.mligo", "main").get_contract() class SignerTest(QuorumContractTest): def test_accepts_valid_signature(self):
from pathlib import Path from unittest import TestCase from pytezos import Key, MichelsonRuntimeError from src.ligo import LigoContract super_admin = Key.generate(export=False).public_key_hash() user = Key.generate(export=False).public_key_hash() second_user = Key.generate(export=False).public_key_hash() oracle_address = Key.generate(export=False).public_key_hash() contract_address = 'KT1RXpLtz22YgX24QQhxKVyKvtKZFaAVtTB9' dao_address = 'KT1Hd1hiG1PhZ7xRi1HUVoAXM7i7Pzta8EHW' class GovernanceTokenTest(TestCase): @classmethod def compile_contract(cls): root_dir = Path(__file__).parent.parent / "ligo" cls.contract = LigoContract( root_dir / "fa2" / "governance" / "main.mligo", "main").compile_contract() @classmethod def setUpClass(cls): cls.compile_contract() cls.maxDiff = None class Fa2Test(GovernanceTokenTest): def test_should_transfer_unfrozen(self):
from pathlib import Path from unittest import TestCase from pytezos import michelson_to_micheline, MichelsonRuntimeError, Key from src.ligo import LigoContract super_admin = 'tz1irF8HUsQp2dLhKNMhteG1qALNU9g3pfdN' user = '******' fees_contract = 'tz1et19hnF9qKv6yCbbxjS1QDXB5HVx6PCVk' token_contract = 'KT1LEzyhXGKfFsczmLJdfW1p8B1XESZjMCvw' nft_contract = 'KT1X82SpRG97yUYpyiYSWN4oPFYSq46BthCi' other_party = 'tz3SYyWM9sq9eWTxiA8KHb36SAieVYQPeZZm' self_address = 'KT1RXpLtz22YgX24QQhxKVyKvtKZFaAVtTB9' dev_pool = Key.generate(export=False).public_key_hash() staking_pool = Key.generate(export=False).public_key_hash() signer_1_key = Key.generate(export=False).public_key_hash() signer_2_key = Key.generate(export=False).public_key_hash() signer_3_key = Key.generate(export=False).public_key_hash() class MinterTest(TestCase): @classmethod def compile_contract(cls): root_dir = Path(__file__).parent.parent / "ligo" cls.bender_contract = LigoContract(root_dir / "minter" / "main.mligo", "main").compile_contract() @classmethod def setUpClass(cls): cls.compile_contract() cls.maxDiff = None
def a_user(): return Key.generate(export=False).public_key_hash()
import unittest from pathlib import Path from pytezos import Key, MichelsonRuntimeError from src.ligo import LigoContract from unittest_data_provider import data_provider reward_token = ("KT1VUNmGa1JYJuNxNS4XDzwpsc9N1gpcCBN2", 1) stake_token = ("KT1LRboPna9yQY9BrjtQYDS1DVxhKESK4VVd", 0) self_address = "KT1BEqzn5Wx8uJrZNvuS9DVHmLvG9td3fDLi" reserve_contract = "KT1K7L5bQzqmVRYyrgLTHWNHQ6C5vFpYGQRk" admin = Key.generate(export=False).public_key_hash() scale = 10**16 class StakingContractTest(unittest.TestCase): @classmethod def setUpClass(cls) -> None: root_dir = Path(__file__).parent.parent / "ligo" cls.contract = LigoContract( root_dir / "staking" / "staking_main.mligo", "main").get_contract() class DepositTest(StakingContractTest): def test_should_increase_balance_on_staking(self): user = a_user() storage = with_balance(user, 150, valid_storage(total_supply=10)) res = self.contract.stake(100).interpret(storage=storage, sender=user)