From 2eb3fb7075d181dabbfdcbeb6d6753cdf14ac805 Mon Sep 17 00:00:00 2001 From: luc10921 Date: Tue, 28 May 2024 15:40:52 -0300 Subject: [PATCH] CU-86dtn3pzu - Refactor remaining tests that uses TestRunner --- .../compiler_tests/test_builtin_method.py | 3 -- .../compiler_tests/test_file_generation.py | 14 ++--- boa3_test/tests/compiler_tests/test_list.py | 53 ++++++------------- boa3_test/tests/compiler_tests/test_string.py | 15 ++---- 4 files changed, 24 insertions(+), 61 deletions(-) diff --git a/boa3_test/tests/compiler_tests/test_builtin_method.py b/boa3_test/tests/compiler_tests/test_builtin_method.py index b6c3b0399..717b79738 100644 --- a/boa3_test/tests/compiler_tests/test_builtin_method.py +++ b/boa3_test/tests/compiler_tests/test_builtin_method.py @@ -883,7 +883,6 @@ async def test_max_int(self): async def test_max_int_more_arguments(self): await self.set_up_contract('MaxIntMoreArguments.py') - runner = BoaTestRunner(runner_id=self.method_name()) numbers = 4, 1, 16, 8, 2 result, _ = await self.call('main', [], return_type=int) @@ -1416,7 +1415,6 @@ def test_super_with_args(self): async def test_super_call_method(self): await self.set_up_contract('SuperCallMethod.py') - runner = BoaTestRunner(runner_id=self.method_name()) super_method_expected_result = -20 arg = 20 @@ -1531,7 +1529,6 @@ async def test_int_str(self): async def test_int_bytes(self): await self.set_up_contract('IntBytes.py') - runner = BoaTestRunner(runner_id=self.method_name()) value = b'0b101' base = 0 diff --git a/boa3_test/tests/compiler_tests/test_file_generation.py b/boa3_test/tests/compiler_tests/test_file_generation.py index 05ec83b3c..348727448 100644 --- a/boa3_test/tests/compiler_tests/test_file_generation.py +++ b/boa3_test/tests/compiler_tests/test_file_generation.py @@ -769,18 +769,12 @@ def test_compiler_error(self): with self.assertRaises(NotLoadedException): self.compile_and_save(path) - def test_generation_with_recursive_function(self): - path, _ = self.get_deploy_file_paths('test_sc/function_test', 'RecursiveFunction.py') - - from boa3.internal.neo3.vm import VMState - from boa3_test.tests.test_drive.testrunner.boa_test_runner import BoaTestRunner - runner = BoaTestRunner(runner_id=self.method_name()) + async def test_generation_with_recursive_function(self): + await self.set_up_contract('test_sc/function_test', 'RecursiveFunction.py') expected = self.fact(57) - invoke = runner.call_contract(path, 'main') - runner.execute() - self.assertEqual(VMState.HALT, runner.vm_state, msg=runner.cli_log) - self.assertEqual(expected, invoke.result) + result, _ = await self.call('main', return_type=int) + self.assertEqual(expected, result) def fact(self, f: int) -> int: if f <= 1: diff --git a/boa3_test/tests/compiler_tests/test_list.py b/boa3_test/tests/compiler_tests/test_list.py index f146b463e..3c171f04f 100644 --- a/boa3_test/tests/compiler_tests/test_list.py +++ b/boa3_test/tests/compiler_tests/test_list.py @@ -3,9 +3,7 @@ from boa3.internal.neo.vm.opcode.Opcode import Opcode from boa3.internal.neo.vm.type.Integer import Integer from boa3.internal.neo.vm.type.String import String -from boa3.internal.neo3.vm import VMState from boa3_test.tests import boatestcase -from boa3_test.tests.test_drive.testrunner.boa_test_runner import BoaTestRunner class TestList(boatestcase.BoaTestCase): @@ -1100,16 +1098,11 @@ def test_list_pop_compile(self): output, _ = self.assertCompile('PopList.py') self.assertEqual(expected_output, output) - def test_list_pop(self): - path, _ = self.get_deploy_file_paths('PopList.py') - runner = BoaTestRunner(runner_id=self.method_name()) + async def test_list_pop(self): + await self.set_up_contract('PopList.py') - invoke = (runner.call_contract(path, 'pop_test')) - - runner.execute() - self.assertEqual(VMState.HALT, runner.vm_state, msg=runner.error) - - self.assertEqual([1, 2, 3, 4, 5].pop(), invoke.result) + result, _ = await self.call('pop_test', [], return_type=int) + self.assertEqual([1, 2, 3, 4, 5].pop(), result) def test_list_pop_without_assignment_compile(self): expected_output = ( @@ -1147,18 +1140,13 @@ def test_list_pop_without_assignment_compile(self): output, _ = self.assertCompile('PopListWithoutAssignment.py') self.assertEqual(expected_output, output) - def test_list_pop_without_assignment(self): - path, _ = self.get_deploy_file_paths('PopListWithoutAssignment.py') - runner = BoaTestRunner(runner_id=self.method_name()) - - invoke = (runner.call_contract(path, 'pop_test')) - - runner.execute() - self.assertEqual(VMState.HALT, runner.vm_state, msg=runner.error) + async def test_list_pop_without_assignment(self): + await self.set_up_contract('PopListWithoutAssignment.py') list_ = [1, 2, 3, 4, 5] list_.pop() - self.assertEqual(list_, invoke.result) + result, _ = await self.call('pop_test', [], return_type=list[int]) + self.assertEqual(list_, result) def test_list_pop_literal_argument_compile(self): expected_output = ( @@ -1196,16 +1184,12 @@ def test_list_pop_literal_argument_compile(self): output, _ = self.assertCompile('PopListLiteralArgument.py') self.assertEqual(expected_output, output) - def test_list_pop_literal_argument(self): - path, _ = self.get_deploy_file_paths('PopListLiteralArgument.py') - runner = BoaTestRunner(runner_id=self.method_name()) + async def test_list_pop_literal_argument(self): + await self.set_up_contract('PopListLiteralArgument.py') - invoke = (runner.call_contract(path, 'pop_test')) - runner.execute() - self.assertEqual(VMState.HALT, runner.vm_state, msg=runner.error) - - self.assertEqual([1, 2, 3, 4, 5].pop(2), invoke.result) + result, _ = await self.call('pop_test', [], return_type=int) + self.assertEqual([1, 2, 3, 4, 5].pop(2), result) def test_list_pop_literal_negative_argument_compile(self): expected_output = ( @@ -1244,16 +1228,11 @@ def test_list_pop_literal_negative_argument_compile(self): output, _ = self.assertCompile('PopListLiteralNegativeArgument.py') self.assertEqual(expected_output, output) - def test_list_pop_literal_negative_argument(self): - path, _ = self.get_deploy_file_paths('PopListLiteralNegativeArgument.py') - runner = BoaTestRunner(runner_id=self.method_name()) - - invoke = (runner.call_contract(path, 'pop_test')) + async def test_list_pop_literal_negative_argument(self): + await self.set_up_contract('PopListLiteralNegativeArgument.py') - runner.execute() - self.assertEqual(VMState.HALT, runner.vm_state, msg=runner.error) - - self.assertEqual([1, 2, 3, 4, 5].pop(-2), invoke.result) + result, _ = await self.call('pop_test', [], return_type=int) + self.assertEqual([1, 2, 3, 4, 5].pop(-2), result) def test_list_pop_literal_variable_argument_compile(self): expected_output = ( diff --git a/boa3_test/tests/compiler_tests/test_string.py b/boa3_test/tests/compiler_tests/test_string.py index c237755f7..bac424ae0 100644 --- a/boa3_test/tests/compiler_tests/test_string.py +++ b/boa3_test/tests/compiler_tests/test_string.py @@ -3,9 +3,7 @@ from boa3.internal.neo.vm.type.Integer import Integer from boa3.internal.neo.vm.type.StackItem import StackItemType from boa3.internal.neo.vm.type.String import String -from boa3.internal.neo3.vm import VMState from boa3_test.tests import boatestcase -from boa3_test.tests.test_drive.testrunner.boa_test_runner import BoaTestRunner class TestString(boatestcase.BoaTestCase): @@ -1105,17 +1103,12 @@ async def test_string_class_variable_slicing(self): result, _ = await self.call('main', [start, end], return_type=str) self.assertEqual(string[start:end], result) - def test_f_string_literal(self): - path, _ = self.get_deploy_file_paths('FStringLiteral.py') - runner = BoaTestRunner(runner_id=self.method_name()) + async def test_f_string_literal(self): + await self.set_up_contract('FStringLiteral.py') - invoke = runner.call_contract(path, 'main') expected_result = "unit test" - - runner.execute() - self.assertEqual(VMState.HALT, runner.vm_state, msg=runner.error) - - self.assertEqual(expected_result, invoke.result) + result, _ = await self.call('main', [], return_type=str) + self.assertEqual(expected_result, result) async def test_f_string_string_var(self): await self.set_up_contract('FStringStringVar.py')