コード例 #1
0
ファイル: test_metadata.py プロジェクト: CityOfZion/neo3-boa
    def test_metadata_info_supported_standards(self):
        path = self.get_contract_path('MetadataInfoSupportedStandards.py')
        output, manifest = self.compile_and_save(path)

        self.assertIn('supportedstandards', manifest)
        self.assertIsInstance(manifest['supportedstandards'], list)
        self.assertGreater(len(manifest['supportedstandards']), 0)
        self.assertIn('NEP-17', manifest['supportedstandards'])

        from boa3_test.tests.test_classes.testengine import TestEngine
        engine = TestEngine()
        # verify using NeoManifestStruct
        nef, manifest = self.get_bytes_output(path)
        self.run_smart_contract(engine, path, 'Main')
        call_hash = engine.executed_script_hash.to_array()
        path = path.replace('.py', '.nef')

        get_contract_path = self.get_contract_path(
            'test_sc/native_test/contractmanagement', 'GetContract.py')
        engine = TestEngine()
        engine.add_contract(path)

        result = self.run_smart_contract(engine, get_contract_path, 'main',
                                         call_hash)
        from boa3_test.tests.test_classes.contract.neomanifeststruct import NeoManifestStruct
        manifest_struct = NeoManifestStruct.from_json(manifest)
        self.assertEqual(manifest_struct, result[4])
コード例 #2
0
ファイル: test_contract.py プロジェクト: CityOfZion/neo3-boa
    def test_create_contract_data_deploy(self):
        path = self.get_contract_path('CreateContract.py')
        call_contract_path = self.get_contract_path('NewContract.py')
        Boa3.compile_and_save(call_contract_path)

        nef_file, manifest = self.get_bytes_output(call_contract_path)
        arg_manifest = String(json.dumps(manifest,
                                         separators=(',', ':'))).to_bytes()

        engine = TestEngine()
        data = 'some sort of data'
        result = self.run_smart_contract(engine, path, 'Main', nef_file,
                                         arg_manifest, data)

        self.assertEqual(5, len(result))
        self.assertEqual(nef_file, result[3])
        manifest_struct = NeoManifestStruct.from_json(manifest)
        self.assertEqual(manifest_struct, result[4])

        notifies = engine.get_events('notify')
        self.assertEqual(2, len(notifies))
        self.assertEqual(False, notifies[0].arguments[0])  # not updated
        self.assertEqual(data, notifies[1].arguments[0])  # data
        result = self.run_smart_contract(engine, call_contract_path, 'main')
        self.assertEqual(data, result)
コード例 #3
0
    def test_deploy_contract(self):
        path = self.get_contract_path('DeployContract.py')
        call_contract_path = self.get_contract_path('test_sc/arithmetic_test', 'Addition.py')
        Boa3.compile_and_save(call_contract_path)

        nef_file, manifest = self.get_bytes_output(call_contract_path)
        arg_manifest = String(json.dumps(manifest, separators=(',', ':'))).to_bytes()

        engine = TestEngine()
        result = self.run_smart_contract(engine, path, 'Main', nef_file, arg_manifest, None)

        self.assertEqual(5, len(result))
        self.assertEqual(nef_file, result[3])
        manifest_struct = NeoManifestStruct.from_json(manifest)
        self.assertEqual(manifest_struct, result[4])
コード例 #4
0
    def test_get_contract(self):
        from boa3.neo3.contracts import CallFlags
        call_flag = Integer(CallFlags.ALL).to_byte_array(signed=True,
                                                         min_length=1)
        expected_output = (
            Opcode.INITSLOT + b'\x00\x01' + Opcode.LDARG0 + Opcode.PUSH1 +
            Opcode.PACK + Opcode.PUSHDATA1 +
            Integer(len(
                Interop.GetContract.method_name)).to_byte_array(min_length=1) +
            String(Interop.GetContract.method_name).to_bytes() +
            Opcode.PUSHDATA1 + Integer(len(
                constants.MANAGEMENT_SCRIPT)).to_byte_array(min_length=1) +
            constants.MANAGEMENT_SCRIPT + Opcode.PUSHDATA1 +
            Integer(len(call_flag)).to_byte_array(min_length=1) + call_flag +
            Opcode.ROT + Opcode.ROT + Opcode.SYSCALL +
            Interop.CallContract.interop_method_hash + Opcode.RET)
        path = self.get_contract_path('GetContract.py')
        output = Boa3.compile(path)
        self.assertEqual(expected_output, output)

        engine = TestEngine()
        result = self.run_smart_contract(engine, path, 'main', bytes(20))
        self.assertIsNone(result)

        call_contract_path = self.get_contract_path('test_sc/arithmetic_test',
                                                    'Addition.py')
        Boa3.compile_and_save(call_contract_path)

        script, manifest = self.get_output(call_contract_path)
        nef, manifest = self.get_bytes_output(call_contract_path)
        call_hash = hash160(script)
        call_contract_path = call_contract_path.replace('.py', '.nef')

        engine.add_contract(call_contract_path)

        result = self.run_smart_contract(engine, path, 'main', call_hash)
        self.assertEqual(5, len(result))
        self.assertEqual(call_hash, result[2])
        self.assertEqual(nef, result[3])
        manifest_struct = NeoManifestStruct.from_json(manifest)
        self.assertEqual(manifest_struct, result[4])
コード例 #5
0
    def test_get_contract(self):
        path = self.get_contract_path('GetContract.py')
        engine = TestEngine()
        result = self.run_smart_contract(engine, path, 'main', bytes(20))
        self.assertIsNone(result)

        call_contract_path = self.get_contract_path('test_sc/arithmetic_test', 'Addition.py')
        nef, manifest = self.get_bytes_output(call_contract_path)
        self.run_smart_contract(engine, call_contract_path, 'add', 1, 2)
        call_hash = engine.executed_script_hash.to_array()
        call_contract_path = call_contract_path.replace('.py', '.nef')

        engine = TestEngine()
        engine.add_contract(call_contract_path)

        result = self.run_smart_contract(engine, path, 'main', call_hash)
        self.assertEqual(5, len(result))
        self.assertEqual(call_hash, result[2])
        self.assertEqual(nef, result[3])
        manifest_struct = NeoManifestStruct.from_json(manifest)
        self.assertEqual(manifest_struct, result[4])
コード例 #6
0
    def test_get_contract(self):
        path = self.get_contract_path('GetContract.py')
        engine = TestEngine()
        result = self.run_smart_contract(engine, path, 'main', bytes(20))
        self.assertIsNone(result)

        call_contract_path = self.get_contract_path('test_sc/arithmetic_test',
                                                    'Addition.py')
        Boa3.compile_and_save(call_contract_path)

        script, manifest = self.get_output(call_contract_path)
        nef, manifest = self.get_bytes_output(call_contract_path)
        call_hash = hash160(script)
        call_contract_path = call_contract_path.replace('.py', '.nef')

        engine.add_contract(call_contract_path)

        result = self.run_smart_contract(engine, path, 'main', call_hash)
        self.assertEqual(5, len(result))
        self.assertEqual(call_hash, result[2])
        self.assertEqual(nef, result[3])
        manifest_struct = NeoManifestStruct.from_json(manifest)
        self.assertEqual(manifest_struct, result[4])
コード例 #7
0
    def test_create_contract(self):
        call_flag = Integer(CallFlags.ALL).to_byte_array(signed=True,
                                                         min_length=1)
        expected_output = (
            Opcode.INITSLOT + b'\x00' + b'\x02' + Opcode.LDARG1 +
            Opcode.LDARG0 + Opcode.PUSH2 + Opcode.PACK + Opcode.DUP +
            Opcode.PUSHNULL + Opcode.APPEND + Opcode.PUSHDATA1 +
            Integer(len(Interop.CreateContract.method_name)).to_byte_array(
                min_length=1) +
            String(Interop.CreateContract.method_name).to_bytes() +
            Opcode.PUSHDATA1 + Integer(len(
                constants.MANAGEMENT_SCRIPT)).to_byte_array(min_length=1) +
            constants.MANAGEMENT_SCRIPT + Opcode.PUSHDATA1 +
            Integer(len(call_flag)).to_byte_array(min_length=1) + call_flag +
            Opcode.ROT + Opcode.ROT + Opcode.SYSCALL +
            Interop.CallContract.interop_method_hash + Opcode.RET)

        path = self.get_contract_path('CreateContract.py')
        output = Boa3.compile(path)
        self.assertEqual(expected_output, output)

        call_contract_path = self.get_contract_path('test_sc/arithmetic_test',
                                                    'Addition.py')
        Boa3.compile_and_save(call_contract_path)

        nef_file, manifest = self.get_bytes_output(call_contract_path)
        arg_manifest = String(json.dumps(manifest,
                                         separators=(',', ':'))).to_bytes()

        engine = TestEngine()
        result = self.run_smart_contract(engine, path, 'Main', nef_file,
                                         arg_manifest)

        self.assertEqual(5, len(result))
        self.assertEqual(nef_file, result[3])
        manifest_struct = NeoManifestStruct.from_json(manifest)
        self.assertEqual(manifest_struct, result[4])