Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CU-86dt50abt - Error when compiling using union type notation with | (bitwise or) in Event argument type #1233

Merged
merged 1 commit into from
Apr 10, 2024

Conversation

meevee98
Copy link
Contributor

@meevee98 meevee98 commented Apr 9, 2024

Summary or solution description
Fixed the behavior of typeA | typeB to have the same behavior as Union[typeA, typeB] on Event definitions.

How to Reproduce

transfer = CreateNewEvent(
[
('from', UInt160 | None),
('to', UInt160 | None),
('amount', int)
],
'Transfer'
)

Tests

def test_event_nep17_transfer_built_compile(self):
event_id = 'Transfer'
event_name = String(event_id).to_bytes(min_length=1)
expected_output = (
Opcode.INITSLOT # Main()
+ b'\x00\x03'
+ Opcode.LDARG2 # event(from_addr, to_addr, amount)
+ Opcode.LDARG1
+ Opcode.LDARG0
+ Opcode.PUSH3
+ Opcode.PACK
+ Opcode.PUSHDATA1
+ Integer(len(event_name)).to_byte_array(min_length=1)
+ event_name
+ Opcode.SYSCALL
+ self.notify_syscall
+ Opcode.RET # return
)
output, _ = self.assertCompile('EventNep17TransferBuilt.py')
self.assertEqual(expected_output, output)
async def test_event_nep17_transfer_built_run(self):
await self.set_up_contract('EventNep17TransferBuilt.py')
transfer_args = b'1', b'2', 10
result, events = await self.call('Main', [*transfer_args], return_type=None)
self.assertIsNone(result)
self.assertEqual(1, len(events))
event = boatestcase.BoaTestEvent.from_notification(events[0], bytes, bytes, int)
self.assertEqual(transfer_args, event.state)
def test_event_nep11_transfer_compile(self):
event_id = 'Transfer'
event_name = String(event_id).to_bytes(min_length=1)
expected_output = (
Opcode.INITSLOT # Main()
+ b'\x00\x04'
+ Opcode.LDARG3 # event(from_addr, to_addr, amount, token_id)
+ Opcode.LDARG2
+ Opcode.LDARG1
+ Opcode.LDARG0
+ Opcode.PUSH4
+ Opcode.PACK
+ Opcode.PUSHDATA1
+ Integer(len(event_name)).to_byte_array(min_length=1)
+ event_name
+ Opcode.SYSCALL
+ self.notify_syscall
+ Opcode.RET # return
)
output, _ = self.assertCompile('EventNep11Transfer.py')
self.assertEqual(expected_output, output)
async def test_event_nep11_transfer_run(self):
await self.set_up_contract('EventNep11Transfer.py')
transfer_args = b'1', b'2', 10, b'someToken'
result, events = await self.call('Main', [*transfer_args], return_type=None)
self.assertIsNone(result)
self.assertEqual(1, len(events))
event = boatestcase.BoaTestEvent.from_notification(events[0], bytes, bytes, int, bytes)
self.assertEqual(transfer_args, event.state)
def test_event_without_types(self):
path = self.get_contract_path('EventWithoutTypes.py')
self.assertCompilerLogs(CompilerError.MismatchedTypes, path)
async def test_event_with_duplicated_name(self):
await self.set_up_contract('EventWithDuplicatedName.py')
arg = 10
event_id = 'example'
result, events = await self.call('example', [arg], return_type=None)
self.assertIsNone(result)
self.assertEqual(1, len(events))
event = boatestcase.BoaTestEvent.from_notification(events[0], int)
self.assertEqual((arg,), event.state)

@meevee98 meevee98 self-assigned this Apr 9, 2024
@melanke
Copy link
Contributor

melanke commented Apr 9, 2024

1 similar comment
@melanke
Copy link
Contributor

melanke commented Apr 9, 2024

@luc10921 luc10921 merged commit 01b259b into development Apr 10, 2024
4 checks passed
@luc10921 luc10921 deleted the CU-86dt50abt branch April 10, 2024 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants