Esempio n. 1
0
 def test_generate_invoke_config(self):
     abi_path = os.path.join(os.getcwd(), 'test_file', 'test_compile',
                             'oep4_token_abi.json')
     invoke_config_path = os.path.join(os.getcwd(), 'test_file',
                                       'test_compile', 'invoke_config.json')
     PunicaCompiler.generate_invoke_config(abi_path, invoke_config_path)
     os.remove(invoke_config_path)
Esempio n. 2
0
 def test_compile_contract(self):
     contract_path = os.path.join(os.getcwd(), 'test_file', 'test_compile',
                                  'contracts', 'oep4.py')
     PunicaCompiler.compile_contract(contract_path)
     split_path = os.path.split(contract_path)
     save_path = os.path.join(os.getcwd(), 'build', split_path[1])
     avm_save_path = save_path.replace('.py', '.avm')
     abi_save_path = save_path.replace('.py', '.json')
     with open(
             os.path.join(os.getcwd(), 'test_file', 'test_compile',
                          'oep4.avm'), 'r') as f:
         target_avm = f.read()
     with open(
             os.path.join(os.getcwd(), 'test_file', 'test_compile',
                          'oep4.json'), 'r') as f:
         target_abi = f.read()
     with open(avm_save_path, 'r') as f:
         hex_avm_code = f.read()
         self.assertEqual(target_avm, hex_avm_code)
     with open(abi_save_path, 'r') as f:
         abi = f.read()
         self.assertEqual(target_abi, abi)
     os.remove(avm_save_path)
     os.remove(abi_save_path)
     os.removedirs('build')
Esempio n. 3
0
 def test_generate_avm_code(self):
     path = os.path.join(os.getcwd(), 'test_file', 'test_compile',
                         'oep4.py')
     hex_avm = PunicaCompiler.generate_avm_code(path)
     with open(
             os.path.join(os.getcwd(), 'test_file', 'test_compile',
                          'oep4.avm'), 'r') as f:
         self.assertEqual(f.read(), hex_avm)
Esempio n. 4
0
 def test_compile_contract_remote(self):
     contract_path = os.path.join(os.getcwd(), 'test_file',
                                  'test_compile_remote', 'oep4.py')
     PunicaCompiler.compile_contract(contract_path)
     avm_save_path = os.path.join(os.getcwd(), 'test_file',
                                  'test_compile_remote', 'build',
                                  'oep4.avm')
     abi_save_path = os.path.join(os.getcwd(), 'test_file',
                                  'test_compile_remote', 'build',
                                  'oep4_abi.json')
     with open(avm_save_path, 'r') as f:
         avm_save = f.read()
         self.assertIsNotNone(avm_save)
     with open(abi_save_path, 'r') as f3:
         abi_save = f3.read()
         self.assertIsNotNone(abi_save)
     os.remove(avm_save_path)
     os.remove(abi_save_path)
Esempio n. 5
0
def compile_contract(contract_dir, contract_name, avm, abi, local):
    contract_path = os.path.join(contract_dir, contract_name)
    print('Compile', contract_name)
    if avm:
        PunicaCompiler.generate_avm_file(contract_path)
        print('\tGenerate avm file successful...')
    if abi:
        PunicaCompiler.generate_abi_file(contract_path)
        print('\tGenerate abi file successful...')
    if not avm and not abi:
        PunicaCompiler.compile_contract(contract_path, local)
Esempio n. 6
0
def compile_contract(contract_dir, contract_name, avm, abi, local):
    contract_path = os.path.join(contract_dir, contract_name)
    print('\tCompile {}...'.format(contract_name))
    if avm:
        PunicaCompiler.generate_avm_file(contract_path)
        print('\tGenerate avm file successful...')
    if abi:
        PunicaCompiler.generate_abi_file(contract_path)
        print('\tGenerate abi file successful...')
    if not avm and not abi:
        PunicaCompiler.compile_contract(contract_path, local)
        print('\tGenerate abi file and avm file successful...')
    print('\tEnjoy your contracts:)')
def compile_contract(contract_dir, contract_name, avm, abi, local):
    contract_path = os.path.join(contract_dir, contract_name)
    print('Compile', contract_name)
    if avm:
        try:
            PunicaCompiler.generate_avm_file(contract_path)
            print('\tGenerate avm file successful...')
        except PunicaException as e:
            print(e.args[1])
    if abi:
        try:
            PunicaCompiler.generate_abi_file(contract_path)
            print('\tGenerate abi file successful...')
        except PunicaException as e:
            print(e.args[1])
    if not avm and not abi:
        try:
            PunicaCompiler.compile_contract(contract_path, local)
        except PunicaException as e:
            print(e.args[1])