hicommonwealth / edgeware-contracts-tutorials

Collected tutorials for building EVM and WASM smart contracts on Edgeware
https://contracts.edgewa.re
MIT License
5 stars 5 forks source link

Ballot Contract Tutorial #22

Closed YameenMalik closed 3 years ago

YameenMalik commented 3 years ago
dillchen commented 3 years ago

@yangwao if you can run through the tutorial itself and make sure everything is all good, then I think you can merge. I've finished with light copy edits. Great work @YameenMalik!

yangwao commented 3 years ago

The tests has failed to me trying 5.2-solution.rs && 5.3-solution.rs.

❯ cargo +nightly test
   Compiling ballot v0.1.0 (/Users/wao/Projects/edg/contracts/ballot)
error[E0433]: failed to resolve: use of undeclared crate or module `ink_prelude`
 --> lib.rs:9:9
  |
9 |     use ink_prelude::vec::Vec;
  |         ^^^^^^^^^^^ use of undeclared crate or module `ink_prelude`

error: aborting due to previous error

Of course, build as well.

   Compiling ink_lang_macro v3.0.0-rc2
   Compiling ink_env v3.0.0-rc2
   Compiling ink_storage v3.0.0-rc2
   Compiling ink_lang v3.0.0-rc2
   Compiling ballot v0.1.0 (/Users/wao/Projects/edg/contracts/ballot)
error[E0433]: failed to resolve: use of undeclared crate or module `ink_prelude`
 --> lib.rs:9:9
  |
9 |     use ink_prelude::vec::Vec;
  |         ^^^^^^^^^^^ use of undeclared crate or module `ink_prelude`

error: aborting due to previous error
YameenMalik commented 3 years ago

@yangwao seems you had not updated your cargo.toml file with ink_prelude dependency. You can do this by including the following line under your dependencies list in cargo.toml ink_prelude = { version = "3.0.0-rc2", default-features = false }. I have updated the contract template section to include this dependency.

yangwao commented 3 years ago

Seems now tests have passed and it builds

~/Projects/edg/contracts/ballot
❯ cargo +nightly test
   Compiling ballot v0.1.0 (/Users/wao/Projects/edg/contracts/ballot)
    Finished test [unoptimized + debuginfo] target(s) in 4.09s
     Running target/debug/deps/ballot-35ac2c17b7faccaa

running 3 tests
test ballot::tests::adding_voters_work ... ok
test ballot::tests::adding_proposals_works ... ok
test ballot::tests::new_works ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

~/Projects/edg/contracts/ballot
❯ cargo +nightly build
   Compiling ballot v0.1.0 (/Users/wao/Projects/edg/contracts/ballot)
    Finished dev [unoptimized + debuginfo] target(s) in 1.66s
~/Projects/edg/contracts/ballot
~/Projects/edg/contracts/ballot
❯ cargo +nightly test
   Compiling ballot v0.1.0 (/Users/wao/Projects/edg/contracts/ballot)
    Finished test [unoptimized + debuginfo] target(s) in 1.62s
     Running target/debug/deps/ballot-35ac2c17b7faccaa

running 8 tests
test ballot::tests::adding_voters_work ... ok
test ballot::tests::default_works ... ok
test ballot::tests::adding_proposals_works ... ok
test ballot::tests::voting_works ... ok
test ballot::tests::give_voting_rights_work ... ok
test ballot::tests::delegation_works ... ok
test ballot::tests::new_works ... ok
test ballot::tests::get_winning_proposal_name_working ... ok

test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

~/Projects/edg/contracts/ballot
❯ cargo +nightly build
   Compiling ballot v0.1.0 (/Users/wao/Projects/edg/contracts/ballot)
    Finished dev [unoptimized + debuginfo] target(s) in 4.13s