Exemple #1
0
    def test_methods_for_contract_single_function(self):
        code = '''
@export
def test_func(arg: str, arg2: int):
    return arg, arg2
        '''

        compiled = self.compiler.parse_to_code(code)

        expected = [{
            'name': 'test_func',
            'arguments': [
                {
                    'name': 'arg',
                    'type': 'str'
                },
                {
                    'name': 'arg2',
                    'type': 'int'
                }
            ]
        }]

        got = parser.methods_for_contract(compiled)

        self.assertListEqual(expected, got)
Exemple #2
0
    async def get_methods(self, request, contract):
        contract_code = self.client.raw_driver.get_contract(contract)

        if contract_code is None:
            return response.json(
                {'error': '{} does not exist'.format(contract)},
                status=404,
                headers={'Access-Control-Allow-Origin': '*'})

        funcs = parser.methods_for_contract(contract_code)

        return response.json({'methods': funcs},
                             status=200,
                             headers={'Access-Control-Allow-Origin': '*'})
Exemple #3
0
    def test_methods_for_contract_multiple_functions_and_privates(self):
        code = '''
@export
def test_func(arg: str, arg2: int):
    return arg, arg2
    
@export
def another_one(something: Any, something_else: dict):
    a = 123
    b = 456
    return add(a, b)
    
def add(a, b):
    return a + b
'''
        compiled = self.compiler.parse_to_code(code)

        expected = [{
            'name': 'test_func',
            'arguments': [
                {
                    'name': 'arg',
                    'type': 'str'
                },
                {
                    'name': 'arg2',
                    'type': 'int'
                }
            ],
        },
        {
            'name': 'another_one',
            'arguments': [
                {
                    'name': 'something',
                    'type': 'Any'
                },
                {
                    'name': 'something_else',
                    'type': 'dict'
                }
            ]
        }]

        got = parser.methods_for_contract(compiled)

        self.assertListEqual(expected, got)
Exemple #4
0
    def test_methods_for_contract_datetime(self):
        code = '''
@export
def thing(arg: datetime.datetime, arg2: datetime.timedelta):
    return 123        
'''
        compiled = self.compiler.parse_to_code(code)
        got = parser.methods_for_contract(compiled)

        expected = [{
            'name':
            'thing',
            'arguments': [{
                'name': 'arg',
                'type': 'datetime.datetime'
            }, {
                'name': 'arg2',
                'type': 'datetime.timedelta'
            }]
        }]

        self.assertEqual(expected, got)