Problem with tests: test from documentation doesn't work

Hey guys! Sorry for the possibly stupid question

Trying to implement smart contract and decided to make some tests integration to start smart and fast development of the dapp.

Used this tutorial moving step by step I ran into a problem: my test fails because the counter is not incrementing (I left log there)

I’m changed the contract a bit: added init func, return changed value from increment func and added logs after each call and this test

Here is my repo GitHub - chlenc/fuel-project

This is main.sw file fuel-project/main.sw at master · chlenc/fuel-project · GitHub

This is my test file fuel-project/harness.rs at master · chlenc/fuel-project · GitHub

Thanks!

The test

let (instance, _id) = get_contract_instance().await;
let init_result = instance.methods().init(1).call().await.unwrap();
println!("0️⃣ Init result: {}",init_result.value);
let increment_result = instance.methods().increment(1).call().await.unwrap();
println!("1️⃣ Increment result: {}",increment_result.value);
let result = instance.methods().count().call().await.unwrap();
println!("✅ Count: {}",result.value);
assert_eq!(result.value, 2);

make output like that

0️⃣ Init result: 1
1️⃣ Increment result: 1
✅ Count: 0
6 Likes

Hey! Thanks for pointing this out. Your tests are correct, and it looks like you’re on the wrong version of forc. Run these and then try to rebuild and run the tests again:

fuelup self update

fuelup toolchain install beta-2

fuelup default beta-2

This should work :slight_smile:

3 Likes

I have no problem using it. It’s very easy to use

@camiinthisthang.sway 's answer helps me to fix it, thanks

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.