Exemplo n.º 1
0
    def setUpClass(cls):
        super(TestNotifyDebugEvents, cls).setUpClass()
        output = Compiler.instance().load('%s/sc_debug_events.py' %
                                          os.path.dirname(__file__)).default
        cls.script = output.write()

        settings.set_log_smart_contract_events(False)
Exemplo n.º 2
0
    def test_ICOTemplate_4_attachments(self):

        output = Compiler.instance().load('%s/ico_template.py' % TestContract.dirname).default
        out = output.write()

        # test mint tokens without being kyc verified
        tx, results, total_ops, engine = TestBuild(out, ['get_attachments', '[]', '--attach-neo=10'], self.GetWallet3(), '0705', '05')
        self.assertEqual(len(results), 1)
        attachments = results[0].GetArray()
        self.assertEqual(len(attachments), 4)

        fn = FunctionCode(out, '0705', '05')

        self.assertEqual(attachments[0].GetByteArray(), fn.ScriptHash().Data)
        self.assertEqual(attachments[1].GetByteArray(), self.wallet_3_script_hash.Data)
        self.assertEqual(attachments[2].GetBigInteger(), Fixed8.FromDecimal(10).value)
        self.assertEqual(attachments[3].GetBigInteger(), 0)

        tx, results, total_ops, engine = TestBuild(out, ['get_attachments', '[]'], self.GetWallet3(), '0705', '05')
        self.assertEqual(len(results), 1)
        attachments = results[0].GetArray()
        self.assertEqual(len(attachments), 4)

        self.assertEqual(attachments[1].GetByteArray(), bytearray())
        self.assertEqual(attachments[2].GetBigInteger(), 0)
        self.assertEqual(attachments[3].GetBigInteger(), 0)

        tx, results, total_ops, engine = TestBuild(out, ['get_attachments', '[]', '--attach-neo=3', '--attach-gas=3.12'], self.GetWallet1(), '0705', '05')
        self.assertEqual(len(results), 1)
        attachments = results[0].GetArray()
        self.assertEqual(len(attachments), 4)
        self.assertEqual(attachments[1].GetByteArray(), self.wallet_1_script_hash.Data)
        self.assertEqual(attachments[2].GetBigInteger(), Fixed8.FromDecimal(3).value)
        self.assertEqual(attachments[3].GetBigInteger(), Fixed8.FromDecimal(3.12).value)
Exemplo n.º 3
0
    def test_AddTest(self):

        output = Compiler.instance().load(
            '%s/boa_test/example/AddTest.py' %
            TestContract.dirname).default.write()

        tx, results, total_ops, engine = TestBuild(output, [2],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 4)

        tx, results, total_ops, engine = TestBuild(output, [23234],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(results[0].GetBigInteger(), 23236)

        tx, results, total_ops, engine = TestBuild(output, [0],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(results[0].GetBigInteger(), 2)

        tx, results, total_ops, engine = TestBuild(output, [-112],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(results[0].GetBigInteger(), -110)
Exemplo n.º 4
0
    def test_CompareTest1(self):

        output = Compiler.instance().load('%s/boa_test/example/CompareTest1.py' % TestContract.dirname).default
        out = output.write()

        tx, results, total_ops, engine = TestBuild(out, [1, 2, 3, 4], self.GetWallet1(), '02020202', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 11)

        tx, results, total_ops, engine = TestBuild(out, [1, 2, 4, 3], self.GetWallet1(), '02020202', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 1)

        tx, results, total_ops, engine = TestBuild(out, [1, 4, 3, 5], self.GetWallet1(), '02020202', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 22)

        tx, results, total_ops, engine = TestBuild(out, [4, 1, 5, 3], self.GetWallet1(), '02020202', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 3)

        tx, results, total_ops, engine = TestBuild(out, [9, 1, 3, 5], self.GetWallet1(), '02020202', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 10)

        tx, results, total_ops, engine = TestBuild(out, [9, 5, 3, 5], self.GetWallet1(), '02020202', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 8)
Exemplo n.º 5
0
def BuildAndRun(arguments,
                wallet,
                verbose=True,
                min_fee=DEFAULT_MIN_FEE,
                invocation_test_mode=True):
    arguments, from_addr = get_from_addr(arguments)
    path = get_arg(arguments)

    contract_script = Compiler.instance().load_and_save(path)

    newpath = path.replace('.py', '.avm')
    logger.info("Saved output to %s " % newpath)

    debug_map_path = path.replace('.py', '.debug.json')
    debug_map = None
    if os.path.exists(debug_map_path):
        with open(debug_map_path, 'r') as dbg:
            debug_map = json.load(dbg)

    return DoRun(contract_script,
                 arguments,
                 wallet,
                 path,
                 verbose,
                 from_addr,
                 min_fee,
                 invocation_test_mode,
                 debug_map=debug_map)
Exemplo n.º 6
0
    def test_Storage2(self):
        output = Compiler.instance().load('%s/boa_test/example/blockchain/StorageTest.py' % TestContract.dirname).default
        out = output.write()

        snapshot = GetBlockchain()._db.createSnapshot()

        tx, results, total_ops, engine = TestBuild(out, ['sget', 100, 10000000000], self.GetWallet1(), '070505', '05', snapshot=snapshot)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'')

        tx, results, total_ops, engine = TestBuild(out, ['sput', 100, 10000000000], self.GetWallet1(), '070505', '05', snapshot=snapshot)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'\x01')

        tx, results, total_ops, engine = TestBuild(out, ['sget', 100, 10000000000], self.GetWallet1(), '070505', '05', snapshot=snapshot)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 10000000000)

        tx, results, total_ops, engine = TestBuild(out, ['sdel', 100, 10000000000], self.GetWallet1(), '070505', '05', snapshot=snapshot)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'\x01')

        tx, results, total_ops, engine = TestBuild(out, ['sget', 100, 10000000000], self.GetWallet1(), '070505', '05', snapshot=snapshot)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'')
Exemplo n.º 7
0
    def test_Storage(self):
        output = Compiler.instance().load(
            '%s/boa_test/example/blockchain/StorageTest.py' %
            TestContract.dirname).default
        out = output.write()

        tx, results, total_ops, engine = TestBuild(
            out, ['sget', 'something', 'blah'], self.GetWallet1(), '070505',
            '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'')

        tx, results, total_ops, engine = TestBuild(
            out, ['sput', 'something', 'blah'], self.GetWallet1(), '070505',
            '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'\x01')

        tx, results, total_ops, engine = TestBuild(
            out, ['sget', 'something', 'blah'], self.GetWallet1(), '070505',
            '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'blah')

        tx, results, total_ops, engine = TestBuild(
            out, ['sdel', 'something', 'blah'], self.GetWallet1(), '070505',
            '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'\x01')

        tx, results, total_ops, engine = TestBuild(
            out, ['sget', 'something', 'blah'], self.GetWallet1(), '070505',
            '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'')
Exemplo n.º 8
0
    def test_abi_methods_success(self):
        path = '%s/boa_test/example/AbiMethods1.py' % TestContract.dirname
        output = Compiler.load(path).default
        json_file = json.loads(
            output.generate_abi_json('AbiMethods1.avm', 'test'))

        entry_point = json_file['entrypoint']
        self.assertEqual(entry_point, 'main')
        functions = json_file['functions']
        self.assertEqual(len(functions), 2)

        main_function = functions[0]
        main_params = main_function['parameters']
        self.assertEqual(main_function['name'], 'main')
        self.assertEqual(main_function['returnType'], 'Any')
        self.assertEqual(len(main_params), 2)
        self.assertEqual(main_params[0]['name'], 'operation')
        self.assertEqual(main_params[0]['type'], 'String')
        self.assertEqual(main_params[1]['name'], 'args')
        self.assertEqual(main_params[1]['type'], 'Array')

        add_function = functions[1]
        add_params = add_function['parameters']
        self.assertEqual(add_function['name'], 'add')
        self.assertEqual(add_function['returnType'], 'Integer')
        self.assertEqual(len(add_params), 2)
        self.assertEqual(add_params[0]['name'], 'a')
        self.assertEqual(add_params[0]['type'], 'Integer')
        self.assertEqual(add_params[1]['name'], 'b')
        self.assertEqual(add_params[1]['type'], 'Integer')
Exemplo n.º 9
0
    def test_iterators(self):

        output = Compiler.instance().load('%s/boa_test/example/demo/IteratorTest.py' % TestContract.dirname).default
        out = output.write()

        tx, results, total_ops, engine = TestBuild(out, [1], self.GetWallet1(), '02', '01')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), True)

        tx, results, total_ops, engine = TestBuild(out, [2], self.GetWallet1(), '02', '01')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 3)

        tx, results, total_ops, engine = TestBuild(out, [3], self.GetWallet1(), '02', '01')
        self.assertEqual(len(results), 1)
        res = [i.GetString() for i in results[0].GetArray()]
        self.assertEqual(res, ['a', 'c', 'f'])

        tx, results, total_ops, engine = TestBuild(out, [4], self.GetWallet1(), '02', '01')
        self.assertEqual(len(results), 1)
        res = [i.GetBigInteger() for i in results[0].GetArray()]
        self.assertEqual(res, [1, 4, 13])

        tx, results, total_ops, engine = TestBuild(out, [5], self.GetWallet1(), '02', '01')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 3)

        tx, results, total_ops, engine = TestBuild(out, [6], self.GetWallet1(), '02', '01')
        self.assertEqual(len(results), 1)
        res = [i.GetBigInteger() for i in results[0].GetArray()]
        self.assertEqual(res, [1, 4, 13])
Exemplo n.º 10
0
    def test_MethodTest6(self):
        output = Compiler.instance().load('%s/boa_test/example/Fibonacci.py' %
                                          TestContract.dirname).default
        out = output.write()

        tx, results, total_ops, engine = TestBuild(out, [4], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 3)

        tx, results, total_ops, engine = TestBuild(out, [5], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 5)

        tx, results, total_ops, engine = TestBuild(out, [6], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 8)

        tx, results, total_ops, engine = TestBuild(out, [7], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 13)

        tx, results, total_ops, engine = TestBuild(out, [11],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 89)
Exemplo n.º 11
0
    def __init__(self, ctx, files):
        self.start = ctx['start']
        self.end = ctx['end']
        self.line = ctx['file_line_no']
        self.file_id = ctx['file']
        self.method_name = ctx['method']
        for file in files:
            if file['id'] == self.file_id:
                self.file_url = file['url']

        self.file_lines = []

        try:
            default_module = Compiler.load(
                self.file_url, use_nep8=settings.COMPILER_NEP_8).default
            self.method = default_module.method_by_name(self.method_name)
        except Exception as e:
            logger.error('Could not load module %s %s ' % (self.file_url, e))

        try:
            with open(self.file_url, 'r') as dbg_file:
                for ln in dbg_file:
                    self.file_lines.append(ln.replace('\n', ''))
        except Exception as e:
            logger.error("Could not open file %s : %s " % (self.file_url, e))
Exemplo n.º 12
0
    def test_Contract(self):
        output = Compiler.instance().load(
            '%s/boa_test/example/blockchain/ContractTest.py' %
            TestContract.dirname).default
        out = output.write()

        contract_hash = bytearray(
            b"\xccN\xe2\xf1\xc9\xf4\xe0x\'V\xda\xbf$m\nO\xe6\n\x03T")
        contract_script = '746b4c04000000004c04000000004c04000000006161681e416e745368617265732e426c6f636b636861696e2e47657448656967687461681d416e745368617265732e426c6f636b636861696e2e476574426c6f636b744c0400000000948c6c766b947275744c0400000000936c766b9479744c0400000000948c6c766b947961681d416e745368617265732e4865616465722e47657454696d657374616d70a0744c0401000000948c6c766b947275744c0401000000948c6c766b9479641b004c0400000000744c0402000000948c6c766b947275623200744c0401000000936c766b9479744c0402000000936c766b9479617cac744c0402000000948c6c766b947275620300744c0402000000948c6c766b947961748c6c766b946d748c6c766b946d748c6c766b946d746c768c6b946d746c768c6b946d746c768c6b946d6c7566'

        tx, results, total_ops, engine = TestBuild(
            out, ['get_contract', contract_hash], self.GetWallet1(), '070505',
            '05')
        self.assertEqual(len(results), 1)
        self.assertIsInstance(results[0].GetInterface(), ContractState)

        tx, results, total_ops, engine = TestBuild(
            out, ['get_script', contract_hash], self.GetWallet1(), '070505',
            '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray().hex(), contract_script)

        tx, results, total_ops, engine = TestBuild(
            out, ['get_storage_context', contract_hash], self.GetWallet1(),
            '070505', '05')
        self.assertEqual(len(results), 0)

        tx, results, total_ops, engine = TestBuild(out,
                                                   ['destroy', contract_hash],
                                                   self.GetWallet1(), '070505',
                                                   '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 1)
Exemplo n.º 13
0
    def test_Account(self):

        output = Compiler.instance().load('%s/boa_test/example/blockchain/AccountTest.py' % TestContract.dirname).default
        out = output.write()
        string_ouput = output.to_s()
        self.assertGreater(len(string_ouput), 0)

        account = self.wallet_1_script_hash.Data

        bad_account = bytearray(b'S\xefB\xc8\xdf!^\xbeZ|z\xe8\x01\xcb\xc3\xac/\xacE)')

        tx, results, total_ops, engine = TestBuild(out, ['get_hash', bad_account], self.GetWallet1(), '07', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), True)

        tx, results, total_ops, engine = TestBuild(out, ['get_hash', account], self.GetWallet1(), '07', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), account)

        tx, results, total_ops, engine = TestBuild(out, ['get_votes', account], self.GetWallet1(), '07', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetArray(), [])

        tx, results, total_ops, engine = TestBuild(out, ['get_balance_gas', account], self.GetWallet1(), '07', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 1399980000)

        tx, results, total_ops, engine = TestBuild(out, ['get_balance_neo', account], self.GetWallet1(), '07', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 5000000000)
Exemplo n.º 14
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--version",
                        action="version",
                        version=f"neo-boa v{__version__}")
    parser.add_argument("input", help=".py smart contract to compile")
    args = parser.parse_args()

    if not args.input.endswith(".py") or not os.path.isfile(args.input):
        print("Input file is not .py")
        sys.exit(1)

    Compiler.load_and_save(args.input)
    print(
        f"Wrote {args.input.replace('.py', '.avm')} to {os.path.abspath(os.curdir)}/"
    )
Exemplo n.º 15
0
 def test_Range3(self):
     output = Compiler.instance().load('%s/boa_test/example/IterTest7.py' %
                                       TestContract.dirname).default
     out = output.write()
     tx, results, total_ops, engine = TestBuild(out, [], self.GetWallet1(),
                                                '', '07')
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0].GetBigInteger(), 12)
Exemplo n.º 16
0
    def test_compile_1(self):

        sc = Compiler.load_and_save('%s/boa_test/example/AddTest1.py' %
                                    TestContract.dirname)

        expected_output = '%s/%s' % (TestContract.dirname, self.TEST_SC_OUTPUT)

        self.assertTrue(os.path.exists(expected_output))
Exemplo n.º 17
0
 def test_list2(self):
     output = Compiler.instance().load('%s/boa_test/example/ArrayTest2.py' %
                                       TestContract.dirname).default
     out = output.write()
     tx, results, total_ops, engine = TestBuild(out, [], self.GetWallet1(),
                                                '', '02')
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0].GetByteArray(), bytearray(b'\xa0'))
Exemplo n.º 18
0
    def test_Runtime(self):

        dispatched_events = []
        dispatched_logs = []

        def on_notif(evt):
            dispatched_events.append(evt)

        def on_log(evt):
            dispatched_logs.append(evt)

        events.on(SmartContractEvent.RUNTIME_NOTIFY, on_notif)
        events.on(SmartContractEvent.RUNTIME_LOG, on_log)

        output = Compiler.instance().load(
            '%s/boa_test/example/blockchain/RuntimeTest.py' %
            TestContract.dirname).default
        out = output.write()

        tx, results, total_ops, engine = TestBuild(out, ['get_time', 1],
                                                   self.GetWallet1(), '0202',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), bytearray(b'\x01r\x04Z'))

        tx, results, total_ops, engine = TestBuild(out, [
            'check_witness',
            bytearray(b'S\xefB\xc8\xdf!^\xbeZ|z\xe8\x01\xcb\xc3\xac/\xacI)')
        ], self.GetWallet1(), '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), True)

        tx, results, total_ops, engine = TestBuild(out, ['log', 'hello'],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), True)
        self.assertEqual(len(dispatched_logs), 1)
        self.assertEqual(dispatched_logs[0].event_payload.Value, 'hello')

        tx, results, total_ops, engine = TestBuild(out, ['notify', 1234],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), True)
        self.assertEqual(len(dispatched_events), 1)
        self.assertEqual(
            int.from_bytes(dispatched_events[0].event_payload.Value, 'little'),
            1234)

        tx, results, total_ops, engine = TestBuild(out, ['get_trigger', 1234],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 16)

        events.off(SmartContractEvent.RUNTIME_NOTIFY, on_notif)
        events.off(SmartContractEvent.RUNTIME_LOG, on_log)
Exemplo n.º 19
0
 def test_MethodTest5(self):
     output = Compiler.instance().load(
         '%s/boa_test/example/MethodTest5.py' % TestContract.dirname,
         use_nep8=False).default
     out = output.write()
     tx, results, total_ops, engine = TestBuild(out, [], self.GetWallet1(),
                                                '', '02')
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0].GetBigInteger(), 15)
Exemplo n.º 20
0
def BuildAndRun(arguments, wallet, verbose=True, min_fee=DEFAULT_MIN_FEE):
    path = get_arg(arguments)

    contract_script = Compiler.instance().load_and_save(path)

    newpath = path.replace('.py', '.avm')
    print("Saved output to %s " % newpath)

    return DoRun(contract_script, arguments, wallet, path, verbose, min_fee=min_fee)
Exemplo n.º 21
0
 def test_list6(self):
     output = Compiler.instance().load(
         '%s/boa_test/example/ArrayReverseTest.py' %
         TestContract.dirname).default
     out = output.write()
     tx, results, total_ops, engine = TestBuild(out, [], self.GetWallet1(),
                                                '', '02')
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0].GetString(), 'blah')
Exemplo n.º 22
0
 def test_Range1(self):
     output = Compiler.instance().load('%s/boa_test/example/RangeTest.py' %
                                       TestContract.dirname).default
     out = output.write()
     tx, results, total_ops, engine = TestBuild(out, [], self.GetWallet1(),
                                                '', '07')
     self.assertEqual(len(results), 1)
     res = results[0].GetArray()
     self.assertEqual(len(res), 20)
Exemplo n.º 23
0
 def test_dict_has_key(self):
     output = Compiler.instance().load(
         '%s/boa_test/example/DictTestHasKey.py' %
         TestContract.dirname).default
     out = output.write()
     tx, results, total_ops, engine = TestBuild(out, [], self.GetWallet1(),
                                                '', '02')
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0].GetBigInteger(), 22)
Exemplo n.º 24
0
    def test_Concat1(self):
        output = Compiler.instance().load('%s/boa_test/example/ConcatTest.py' %
                                          TestContract.dirname).default
        out = output.write()

        tx, results, total_ops, engine = TestBuild(out, [], self.GetWallet1(),
                                                   '', '07')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetString(), 'helloworld')
Exemplo n.º 25
0
 def test_dict_keys1(self):
     output = Compiler.instance().load(
         '%s/boa_test/example/DictTestKeys.py' %
         TestContract.dirname).default
     out = output.write()
     tx, results, total_ops, engine = TestBuild(out, [], self.GetWallet1(),
                                                '', '02')
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0].GetByteArray(),
                      bytearray(b'ab\x04mzmcallltrs'))
Exemplo n.º 26
0
 def test_list7(self):
     output = Compiler.instance().load('%s/boa_test/example/ArrayTest4.py' %
                                       TestContract.dirname).default
     out = output.write()
     tx, results, total_ops, engine = TestBuild(out, [], self.GetWallet1(),
                                                '', '02')
     self.assertEqual(len(results), 1)
     res = results[0].GetArray()
     self.assertEqual(len(res), 3)
     self.assertEqual(res[0].GetBigInteger(), 3)
Exemplo n.º 27
0
    def setUp(self):
        self.dropDebugStorage()

        contract_schema = Compiler.instance().load('%s/NEO/contracts/document.py' % TestContract.dirname).default
        self.contract = contract_schema.write()

        random_address = bytearray(os.urandom(LENGTH_ADDRESS))
        random_hash = bytearray(os.urandom(LENGTH_ADDRESS))

        self.data = self.ContractData(random_address, random_hash)
Exemplo n.º 28
0
    def test_Output(self):

        output = Compiler.instance().load('%s/boa_test/example/blockchain/OutputsTest.py' % TestContract.dirname).default
        out = output.write()

        txid = bytearray(b'&\xb4^\x06\xe6/\xbc\xe6|\x12\xacY![JJ\xeec\x14"\xe7\x8c*\xf3j\x85H_\x10\xc1\xe3\x96')

        tx, results, total_ops, engine = TestBuild(out, [txid], self.GetWallet1(), '07', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(len(results[0].GetArray()), 2)
Exemplo n.º 29
0
    def test_abi_method_without_decorator(self):
        path = '%s/boa_test/example/AbiMethods8.py' % TestContract.dirname
        output = Compiler.load(path).default
        json_file = json.loads(
            output.generate_abi_json('AbiMethods8.avm', 'test'))

        entry_point = json_file['entrypoint']
        self.assertEqual(entry_point, 'method')
        functions = json_file['functions']
        self.assertEqual(len(functions), 0)
Exemplo n.º 30
0
    def test_ICOTemplate_2(self):

        output = Compiler.instance().load('%s/ico_template.py' % TestContract.dirname).default
        out = output.write()

        # now transfer tokens to wallet 2

        TestContract.dispatched_events = []

        test_transfer_amount = 2400000001
        tx, results, total_ops, engine = TestBuild(out, ['transfer', parse_param([bytearray(TOKEN_OWNER), self.wallet_2_script_hash.Data, test_transfer_amount])], self.GetWallet1(), '0705', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), True)

        self.assertEqual(len(TestContract.dispatched_events), 1)
        evt = TestContract.dispatched_events[0]
        self.assertIsInstance(evt, NotifyEvent)
        self.assertEqual(evt.addr_from.Data, bytearray(TOKEN_OWNER))
        self.assertEqual(evt.addr_to, self.wallet_2_script_hash)
        self.assertEqual(evt.amount, test_transfer_amount)

        # now get balance of wallet 2
        tx, results, total_ops, engine = TestBuild(out, ['balanceOf', parse_param([self.wallet_2_script_hash.Data])], self.GetWallet1(), '0705', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), test_transfer_amount)

        # now the owner should have less
        tx, results, total_ops, engine = TestBuild(out, ['balanceOf', parse_param([bytearray(TOKEN_OWNER)])], self.GetWallet1(), '0705', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), TOKEN_INITIAL_AMOUNT - test_transfer_amount)

        # now this transfer should fail
        tx, results, total_ops, engine = TestBuild(out, ['transfer', parse_param([bytearray(TOKEN_OWNER), self.wallet_2_script_hash.Data, TOKEN_INITIAL_AMOUNT])], self.GetWallet1(), '0705', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), False)

        # this transfer should fail because it is not signed by the 'from' address
        tx, results, total_ops, engine = TestBuild(out, ['transfer', parse_param([bytearray(TOKEN_OWNER), self.wallet_2_script_hash.Data, 10000])], self.GetWallet3(), '0705', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), False)

        # now this transfer should fail, this is from address with no tokens
        tx, results, total_ops, engine = TestBuild(out, ['transfer', parse_param([self.wallet_3_script_hash.Data, self.wallet_2_script_hash.Data, 1000])], self.GetWallet3(), '0705', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), False)

        # get balance of bad data
        tx, results, total_ops, engine = TestBuild(out, ['balanceOf', parse_param(['abc'])], self.GetWallet1(), '0705', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 0)

        # get balance no params
        tx, results, total_ops, engine = TestBuild(out, ['balanceOf', parse_param([])], self.GetWallet1(), '0705', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), False)
Exemplo n.º 31
0
def BuildAndRun(arguments, wallet, verbose=True, min_fee=DEFAULT_MIN_FEE, invocation_test_mode=True):
    arguments, from_addr = get_from_addr(arguments)
    path = get_arg(arguments)

    contract_script = Compiler.instance().load_and_save(path)

    newpath = path.replace('.py', '.avm')
    logger.info("Saved output to %s " % newpath)

    debug_map_path = path.replace('.py', '.debug.json')
    debug_map = None
    if os.path.exists(debug_map_path):
        with open(debug_map_path, 'r') as dbg:
            debug_map = json.load(dbg)

    return DoRun(contract_script, arguments, wallet, path, verbose, from_addr, min_fee, invocation_test_mode, debug_map=debug_map)
Exemplo n.º 32
0
    def setUpClass(cls):
        super(TestNotifyDebugEvents, cls).setUpClass()
        output = Compiler.instance().load('%s/sc_debug_events.py' % os.path.dirname(__file__)).default
        cls.script = output.write()

        settings.set_log_smart_contract_events(False)
Exemplo n.º 33
0
from boa.compiler import Compiler

Compiler.load_and_save('ico_template.py')
Exemplo n.º 34
0
 def setUpClass(cls):
     super(TestVMErrors, cls).setUpClass()
     output = Compiler.instance().load('%s/sc_vm_errors.py' % os.path.dirname(__file__)).default
     cls.script = output.write()
     settings.set_loglevel(DEBUG)