freeCodeCamp / solana-curriculum

freeCodeCamp Solana Curriculum
BSD 3-Clause "New" or "Revised" License
130 stars 50 forks source link

[BUG]: Tic-Tac-Toe part 1 - Lesson 8 - `anchor test` #208

Open gikf opened 1 year ago

gikf commented 1 year ago

Issue/Experience

I've encountered couple troubles with using anchor test during lesson 8.

1. error[E0658]: let...else statements are unstable

Starting from a freshly rebuild container, compilation was ending up with error

$ anchor test ```bash $ anchor test Warning: cargo-build-bpf is deprecated. Please, use cargo-build-sbf cargo-build-bpf child: /workspace/.local/share/solana/install/active_release/bin/cargo-build-sbf --arch bpf Compiling serde v1.0.164 Compiling thiserror v1.0.40 Compiling bytemuck v1.13.1 Compiling blake3 v1.4.0 Compiling solana-frozen-abi-macro v1.16.1 error[E0658]: `let...else` statements are unstable --> /workspace/.cargo/registry/src/github.com-1ecc6299db9ec823/solana-frozen-abi-macro-1.16.1/src/lib.rs:422:5 | 422 | / let Some(expected_digest) = expected_digest else { 423 | | return Error::new_spanned( 424 | | TokenStream2::from(item), 425 | | "the required \"digest\" = ... attribute is missing.", ... | 428 | | .into() 429 | | }; | |______^ | = note: see issue #87335 for more information = help: add `#![feature(let_else)]` to the crate attributes to enable For more information about this error, try `rustc --explain E0658`. error: could not compile `solana-frozen-abi-macro` due to previous error warning: build failed, waiting for other jobs to finish... ```

Following found suggestion I've checked solana version (it was 1.14.something) and updated it with solana-install init v1.16.0. This allowed to finish compilation.

2. missing keys in ~/.config/solana/id.json

Once compiling was done, next issue appeared to be missing solana keys (I haven't noted the specific error). I've assumed main issue here was using clean container, so I've used solana-keygen new which created new keys.

This allowed for running actual test.

3. anchor test test is passing (but lesson expects it to not pass)

At this point test is running. Lesson is expecting test to fail with the failed to send transaction error. However, the test is not failing for me, but happily passes.

$ anchor test ```bash root ~/solana-curriculum/learn-anchor-by-building-tic-tac-toe-part-1/tic-tac-toe (main) $ anchor test warning: unused variable: `ctx` --> programs/tic-tac-toe/src/lib.rs:9:23 | 9 | pub fn initialize(ctx: Context) -> Result<()> { | ^^^ help: if this is intentional, prefix it with an underscore: `_ctx` | = note: `#[warn(unused_variables)]` on by default warning: `tic-tac-toe` (lib) generated 1 warning (run `cargo fix --lib -p tic-tac-toe` to apply 1 suggestion) Finished release [optimized] target(s) in 0.20s Found a 'test' script in the Anchor.toml. Running it as a test suite! Running test suite: "/workspace/solana-curriculum/learn-anchor-by-building-tic-tac-toe-part-1/tic-tac-toe/Anchor.toml" yarn run v1.22.19 warning package.json: No license field $ /workspace/solana-curriculum/learn-anchor-by-building-tic-tac-toe-part-1/tic-tac-toe/node_modules/.bin/ts-mocha -p ./tsconfig.json -t 1000000 'tests/**/*.ts' tic-tac-toe Your transaction signature {--snip--} ✔ Is initialized! (610ms) 1 passing (615ms) Done in 3.22s. ```

It's very possible steps taken here by me were not the ones that should be taken, to fix the original issue, while keeping the output of the lesson as expected.

Output of running node tooling/camper-info.js from the workspace root

🔵 INFO:   Project:  learn-anchor-by-building-tic-tac-toe-part-1
🔵 INFO:   Lesson Number:  1
🔵 INFO:   Curriculum Version:  0.3.0
🔵 INFO:   freeCodeCamp - Courses:  undefined
🔵 INFO:   Commit:  1e5da88 chore(deps): update react monorepo

🔵 INFO:   OS Info: 
    Architecture: x64
    Platform: linux
    Release: 5.15.0-75-generic
    Type: Linux
kamalbuilds commented 1 year ago

yes, I can confirm. I have faced a similar experience as mentioned in this issue.