From bda49a6ed9c436c3f0507c15d37d66409b53e059 Mon Sep 17 00:00:00 2001 From: enitrat Date: Tue, 17 Sep 2024 14:11:14 +0200 Subject: [PATCH] fix tests --- .../src/instructions/logging_operations.cairo | 131 ++++++++---------- 1 file changed, 55 insertions(+), 76 deletions(-) diff --git a/crates/evm/src/instructions/logging_operations.cairo b/crates/evm/src/instructions/logging_operations.cairo index 0165c7f69..2c83d14cd 100644 --- a/crates/evm/src/instructions/logging_operations.cairo +++ b/crates/evm/src/instructions/logging_operations.cairo @@ -107,18 +107,18 @@ mod tests { let result = vm.exec_log0(); // Then - assert(result.is_ok(), 'should have succeeded'); - assert(vm.stack.len() == 0, 'stack should be empty'); + assert!(result.is_ok()); + assert_eq!(vm.stack.len(), 0); let mut events = vm.env.state.events; - assert(events.len() == 1, 'context should have one event'); + assert_eq!(events.len(), 1); let event = events.pop_front().unwrap(); - assert(event.keys.len() == 0, 'event should not have keys'); + assert_eq!(event.keys.len(), 0); - assert(event.data.len() == 31, 'event should have 31 bytes'); + assert_eq!(event.data.len(), 31); let data_expected = u256_to_bytes_array(Bounded::::MAX).span().slice(0, 31); - assert(event.data.span() == data_expected, 'event data are incorrect'); + assert_eq!(event.data.span(), data_expected); } #[test] @@ -136,19 +136,19 @@ mod tests { let result = vm.exec_log1(); // Then - assert(result.is_ok(), 'should have succeeded'); - assert(vm.stack.len() == 0, 'stack should be empty'); + assert!(result.is_ok()); + assert_eq!(vm.stack.len(), 0); let mut events = vm.env.state.events; - assert(events.len() == 1, 'context should have one event'); + assert_eq!(events.len(), 1); let event = events.pop_front().unwrap(); - assert(event.keys.len() == 1, 'event should have one key'); - assert(*event.keys[0] == 0x0123456789ABCDEF, 'event key is not correct'); + assert_eq!(event.keys.len(), 1); + assert_eq!(event.keys[0], 0x0123456789ABCDEF); - assert(event.data.len() == 32, 'event should have 32 bytes'); + assert_eq!(event.data.len(), 32); let data_expected = u256_to_bytes_array(Bounded::::MAX).span().slice(0, 32); - assert(event.data.span() == data_expected, 'event data are incorrect'); + assert_eq!(event.data.span(), data_expected); } #[test] @@ -167,20 +167,20 @@ mod tests { let result = vm.exec_log2(); // Then - assert(result.is_ok(), 'should have succeeded'); - assert(vm.stack.len() == 0, 'stack should be empty'); + assert!(result.is_ok()); + assert_eq!(vm.stack.len(), 0); let mut events = vm.env.state.events; - assert(events.len() == 1, 'context should have one event'); + assert_eq!(events.len(), 1); let event = events.pop_front().unwrap(); - assert(event.keys.len() == 2, 'event should have two keys'); - assert(*event.keys[0] == 0x0123456789ABCDEF, 'event key is not correct'); - assert(*event.keys[1] == Bounded::::MAX, 'event key is not correct'); + assert_eq!(event.keys.len(), 2); + assert_eq!(event.keys[0], 0x0123456789ABCDEF); + assert_eq!(event.keys[1], Bounded::::MAX); - assert(event.data.len() == 5, 'event should have 5 bytes'); + assert_eq!(event.data.len(), 5); let data_expected = u256_to_bytes_array(Bounded::::MAX).span().slice(0, 5); - assert(event.data.span() == data_expected, 'event data are incorrect'); + assert_eq!(event.data.span(), data_expected); } #[test] @@ -205,23 +205,20 @@ mod tests { let result = vm.exec_log3(); // Then - assert(result.is_ok(), 'should have succeeded'); - assert(vm.stack.len() == 0, 'stack should be empty'); + assert!(result.is_ok()); + assert_eq!(vm.stack.len(), 0); let mut events = vm.env.state.events; - assert(events.len() == 1, 'context should have one event'); + assert_eq!(events.len(), 1); let event = events.pop_front().unwrap(); - assert(event.keys.len() == 3, 'event should have 3 keys'); - assert(*event.keys[0] == 0x0123456789ABCDEF, 'event key is not correct'); - assert(*event.keys[1] == Bounded::::MAX, 'event key is not correct'); - assert(*event.keys[2] == 0x00, 'event key is not correct'); + assert_eq!(event.keys.span(), [0x0123456789ABCDEF, Bounded::::MAX, 0x00].span()); - assert(event.data.len() == 40, 'event should have 40 bytes'); + assert_eq!(event.data.len(), 40); let data_expected = u256_to_bytes_array(Bounded::::MAX).span(); - assert(event.data.span().slice(0, 32) == data_expected, 'event data are incorrect'); + assert_eq!(event.data.span().slice(0, 32), data_expected); let data_expected = [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF].span(); - assert(event.data.span().slice(32, 8) == data_expected, 'event data are incorrect'); + assert_eq!(event.data.span().slice(32, 8), data_expected); } #[test] @@ -247,22 +244,18 @@ mod tests { let result = vm.exec_log4(); // Then - assert(result.is_ok(), 'should have succeeded'); - assert(vm.stack.len() == 0, 'stack should be empty'); + assert!(result.is_ok()); + assert_eq!(vm.stack.len(), 0); let mut events = vm.env.state.events; - assert(events.len() == 1, 'context should have one event'); + assert_eq!(events.len(), 1); let event = events.pop_front().unwrap(); - assert(event.keys.len() == 4, 'event should have 4 keys'); - assert(*event.keys[0] == 0x0123456789ABCDEF, 'event key is not correct'); - assert(*event.keys[1] == Bounded::::MAX, 'event key is not correct'); - assert(*event.keys[2] == 0x00, 'event key is not correct'); - assert(*event.keys[3] == Bounded::::MAX, 'event key is not correct'); + assert_eq!(event.keys.span(), [0x0123456789ABCDEF, Bounded::::MAX, 0x00, Bounded::::MAX].span()); - assert(event.data.len() == 10, 'event should have 10 bytes'); + assert_eq!(event.data.len(), 10); let data_expected = [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x00, 0x00].span(); - assert(event.data.span() == data_expected, 'event data are incorrect'); + assert_eq!(event.data.span(), data_expected); } #[test] @@ -280,9 +273,9 @@ mod tests { let result = vm.exec_log1(); // Then - assert(result.is_err(), 'should have returned an error'); - assert( - result.unwrap_err() == EVMError::WriteInStaticContext, 'err != WriteInStaticContext' + assert!(result.is_err()); + assert_eq!( + result.unwrap_err(), EVMError::WriteInStaticContext ); } @@ -301,17 +294,16 @@ mod tests { let result = vm.exec_log1(); // Then - assert(result.is_ok(), 'should have succeeded'); - assert(vm.stack.len() == 0, 'stack should be empty'); + assert!(result.is_ok()); + assert_eq!(vm.stack.len(), 0); let mut events = vm.env.state.events; - assert(events.len() == 1, 'context should have one event'); + assert_eq!(events.len(), 1); let event = events.pop_front().unwrap(); - assert(event.keys.len() == 1, 'event should have one key'); - assert(*event.keys[0] == 0x0123456789ABCDEF, 'event key is not correct'); + assert_eq!(event.keys.span(), [0x0123456789ABCDEF].span()); - assert(event.data.len() == 0, 'event data should be empty'); + assert_eq!(event.data.len(), 0); } #[test] @@ -329,11 +321,8 @@ mod tests { let result = vm.exec_log1(); // Then - assert(result.is_err(), 'should return an error'); - assert( - result.unwrap_err() == EVMError::TypeConversionError(TYPE_CONVERSION_ERROR), - 'err != TypeConversionError' - ); + assert!(result.is_err()); + assert_eq!(result.unwrap_err(), EVMError::TypeConversionError(TYPE_CONVERSION_ERROR)); } #[test] @@ -351,11 +340,8 @@ mod tests { let result = vm.exec_log1(); // Then - assert(result.is_err(), 'should return an error'); - assert( - result.unwrap_err() == EVMError::TypeConversionError(TYPE_CONVERSION_ERROR), - 'err != TypeConversionError' - ); + assert!(result.is_err()); + assert_eq!(result.unwrap_err(), EVMError::MemoryLimitOOG); } #[test] @@ -387,32 +373,25 @@ mod tests { vm.exec_log4().expect('exec_log4 failed'); // Then - assert(vm.stack.len() == 0, 'stack size should be 0'); + assert!(vm.stack.is_empty()); let mut events = vm.env.state.events; - assert(events.len() == 2, 'context should have 2 events'); + assert_eq!(events.len(), 2); let event1 = events.pop_front().unwrap(); - assert(event1.keys.len() == 3, 'event1 should have 3 keys'); - assert(*event1.keys[0] == 0x0123456789ABCDEF, 'event1 key is not correct'); - assert(*event1.keys[1] == Bounded::::MAX, 'event1 key is not correct'); - assert(*event1.keys[2] == 0x00, 'event1 key is not correct'); + assert_eq!(event1.keys.span(), [0x0123456789ABCDEF, Bounded::::MAX, 0x00].span()); - assert(event1.data.len() == 40, 'event1 should have 40 bytes'); + assert_eq!(event1.data.len(), 40); let data_expected = u256_to_bytes_array(Bounded::::MAX).span(); - assert(event1.data.span().slice(0, 32) == data_expected, 'event1 data are incorrect'); + assert_eq!(event1.data.span().slice(0, 32), data_expected); let data_expected = [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF].span(); - assert(event1.data.span().slice(32, 8) == data_expected, 'event1 data are incorrect'); + assert_eq!(event1.data.span().slice(32, 8), data_expected); let event2 = events.pop_front().unwrap(); - assert(event2.keys.len() == 4, 'event2 should have 4 keys'); - assert(*event2.keys[0] == 0x0123456789ABCDEF, 'event2 key is not correct'); - assert(*event2.keys[1] == Bounded::::MAX, 'event2 key is not correct'); - assert(*event2.keys[2] == 0x00, 'event2 key is not correct'); - assert(*event2.keys[3] == Bounded::::MAX, 'event2 key is not correct'); + assert_eq!(event2.keys.span(), [0x0123456789ABCDEF, Bounded::::MAX, 0x00, Bounded::::MAX].span()); - assert(event2.data.len() == 10, 'event2 should have 10 bytes'); + assert_eq!(event2.data.len(), 10); let data_expected = [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x00, 0x00].span(); - assert(event2.data.span() == data_expected, 'event2 data are incorrect'); + assert_eq!(event2.data.span(), data_expected); } }