starknet-edu / counter-workshop

Code for Counter Workshop using latest Starknet syntax.
MIT License
41 stars 90 forks source link

Compilation Errors Due to Deprecated or Missing Functions and Traits ( step 6 ) #59

Closed ChapuKosi closed 2 months ago

ChapuKosi commented 3 months ago

Description:

When running the tests in the project, I encountered multiple compilation errors related to missing or deprecated functions and traits from the snforge_std library. This prevents the test code from compiling and running successfully.

Problematic Code:

The test code below fails to compile due to several missing identifiers and ambiguous method calls.

use super::utils::deploy_contract;
use counter::counter::{ICounterDispatcher, ICounterDispatcherTrait};
use snforge_std::{spy_events, EventSpy, EventFetcher, EventAssertions, Event, SpyOn};

#[test]
fn test_counter_event() {
    let initial_counter = 15;
    let contract_address = deploy_contract(initial_counter);
    let dispatcher = ICounterDispatcher { contract_address };

    let mut spy = spy_events(SpyOn::One(contract_address));
    dispatcher.increase_counter();

    spy.fetch_events();
    assert!(spy.events.len() == 1, "here should be one event");

    let (from, event) = spy.events.at(0);
    assert!(from == @contract_address, "Emitted from wrong address");
    assert!(event.keys.at(0) == @selector!("CounterIncreased"), "Wrong event name");
}

Errors Encountered:

  1. Identifier not found for EventSpy, EventFetcher, EventAssertions, and SpyOn.
    
    error: Identifier not found.
    --> /home/bhanu/cairo/counter-workshop/tests/test_step.cairo:3:41
    use snforge_std::{spy_events, EventSpy, EventFetcher, EventAssertions, Event, SpyOn};
                                        ^**********^

2. Wrong number of arguments for spy_events.

error: Wrong number of arguments. Expected 0, found: 1 --> /home/bhanu/cairo/counter-workshop/tests/test_step.cairo:11:19 let mut spy = spy_events(SpyOn::One(contract_address)); ^**^


3. Method not found for fetch_events.

error: Method fetch_events not found on type <missing>. Did you import the correct trait and impl? --> /home/bhanu/cairo/counter-workshop/tests/test_step.cairo:14:9 spy.fetch_events(); ^**^


4. Ambiguous method call for len and at.

error: Ambiguous method call. More than one applicable trait function with a suitable self type was found: ArrayTrait::len and SpanTrait::len. Consider adding type annotations or explicitly refer to the impl function. --> /home/bhanu/cairo/counter-workshop/tests/test_step.cairo:15:24 assert!(spy.events.len() == 1, "here should be one event"); ^*^

error: Ambiguous method call. More than one applicable trait function with a suitable self type was found: ArrayTrait::at and SpanTrait::at. Consider adding type annotations or explicitly refer to the impl function. --> /home/bhanu/cairo/counter-workshop/tests/test_step.cairo:17:36 let (from, event) = spy.events.at(0); ^^



## Environment:

-Library Version:  snforge_std v0.27.0
-Build Tool: Scarb
-Cairo Version: Latest

## Expected Behavior:
The test should compile and run successfully without any errors.

## Actual Behavior:
Compilation fails with multiple errors indicating missing or ambiguous identifiers and methods.
robertkodra commented 3 months ago

@ChapuKosi This occurs for Starknet Foundry 0.27.0 as this version brought some changes to the Event Cheat. The current workshop works for 0.25.0.

I will upgrade the workshop this month to the latests versions.

robertkodra commented 2 months ago

Workshop has been updated to 0.27.0 and this error doesn't occur anymore. Closing this issue.