Skip to content

Commit

Permalink
Merge pull request #1260 from CityOfZion/CU-86dtn3pzu
Browse files Browse the repository at this point in the history
CU-86dtn3pzu - Refactor remaining tests that uses TestRunner
  • Loading branch information
meevee98 authored May 29, 2024
2 parents b2fe543 + 2eb3fb7 commit 1d7fb79
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 61 deletions.
3 changes: 0 additions & 3 deletions boa3_test/tests/compiler_tests/test_builtin_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 4 additions & 10 deletions boa3_test/tests/compiler_tests/test_file_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
53 changes: 16 additions & 37 deletions boa3_test/tests/compiler_tests/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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 = (
Expand Down
15 changes: 4 additions & 11 deletions boa3_test/tests/compiler_tests/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 1d7fb79

Please sign in to comment.