Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test_events_decode/lib.rs: Fix punctuation.
  • Loading branch information
blairmunroakusa committed Apr 3, 2023
commit 796981a58689943a2cf000109cc4fe79534bc350
29 changes: 13 additions & 16 deletions integration-tests/test_events_decode/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ mod testing_event_decode {
let caller = self.env().caller();
let contract = self.env().account_id();

// emit FlipEvent
// Emit FlipEvent.
self.env().emit_event(FlipEvent {
flipper: caller,
value: true,
});

// emit FlopEvent
// Emit FlopEvent.
self.env().emit_event(FlopEvent {
flipper: caller,
flopper: contract,
Expand Down Expand Up @@ -79,20 +79,20 @@ mod testing_event_decode {
#[ink::test]
fn unittest_event_emission_capture_decode() {

// given
let accounts = ink::env::test::default_accounts::<ink::env::DefaultEnvironment>();
ink::env::test::set_caller::<ink::env::DefaultEnvironment>(accounts.bob);

let mut contract = TestingEventDecode::new();
contract.flipflop();

// decode event
// Decode event.
let emitted_events = ink::env::test::recorded_events().collect::<Vec<_>>();
let decoded_events = decode_events(emitted_events);

let mut gotflip = false;
let mut gotflop = false;
// check events were emitted by the `flipflop` function

// Check events were emitted by the `flipflop` function.
for event in &decoded_events {
match event {
Event::FlipEvent(FlipEvent { flipper, value }) => {
Expand Down Expand Up @@ -126,7 +126,6 @@ mod testing_event_decode {
#[ink_e2e::test]
async fn e2etest_event_emission_capture_decode(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> {

// Given
let bob_account = ink_e2e::account_id(ink_e2e::AccountKeyring::Bob);
let constructor = TestingEventDecodeRef::new();
let contract_account_id = client
Expand All @@ -141,7 +140,7 @@ mod testing_event_decode {
.expect("instantiate failed")
.account_id;

// Check that FlipEvent was successfully emitted
// Check that FlipEvent was successfully emitted.
let flipflop_msg =
build_message::<TestingEventDecodeRef>(contract_account_id.clone())
.call(|contract| contract.flipflop());
Expand All @@ -150,7 +149,7 @@ mod testing_event_decode {
.await
.expect("flipflop failed");

// Filter the events
// Filter the events.
let contract_emitted_event = flipflop_result
.events
.iter()
Expand All @@ -169,19 +168,18 @@ mod testing_event_decode {
.expect("Expected flip event")
.unwrap();

// Decode the expected event type
// Decode the expected event type.
let event = contract_emitted_event.field_bytes();
let decode_event = <FlipEvent as scale::Decode>::decode(&mut &event[34..])
.expect("invalid data");

// Destructor
let FlipEvent { flipper, value } = decode_event;

// Check that FlopEvent was successully emitted
// Check that FlopEvent was successully emitted.
assert_eq!(value, true, "unexpected FlipEvent.value");
assert_eq!(flipper, bob_account, "unexpected FlipEvent.flipper");

// When
// Build flipflop message.
let flipflop_msg =
build_message::<TestingEventDecodeRef>(contract_account_id.clone())
.call(|contract| contract.flipflop());
Expand All @@ -190,7 +188,7 @@ mod testing_event_decode {
.await
.expect("flipflop failed");

// Filter the events
// Filter the events.
let contract_emitted_event = flipflop_result
.events
.iter()
Expand All @@ -209,15 +207,14 @@ mod testing_event_decode {
.expect("Expected flop event")
.unwrap();

// Decode the expected event type
// Decode the expected event type.
let event = contract_emitted_event.field_bytes();
let decode_event = <FlopEvent as scale::Decode>::decode(&mut &event[35..])
.expect("invalid data");

// Destructor
let FlopEvent { flipper, flopper, value } = decode_event;

// check event emitted by the `flip` function
// Check event emitted by the `flip` function.
assert_eq!(value, false, "unexpected FlopEvent.value");
assert_eq!(flipper, bob_account, "unexpected FlopEvent.flipper");
assert_eq!(flopper, contract_account_id, "unexpected FlopEvent.flopper");
Expand Down