Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final demo contract suggestions #102

Merged
merged 17 commits into from
May 17, 2024

Conversation

koxu1996
Copy link
Contributor

@koxu1996 koxu1996 commented May 17, 2024

Final suggestions before merging demo contract.

Refactor Cargo dependencies

  • b17471f - Remove unused base64 dependency.
  • 9ec324f - Remove unused test-support feature from contract dependency.
  • 8d648e4 - Remove unused bincode dependency and use no-std-helpers.
  • 0709c3e - Switch to Casper dependencies from crates.
  • 8cf3bc5 - Disable default features where possible.
  • 46b1fc4 - Unify format of Cargo.toml files.

Minor fixes/improvements

  • 8440fa4 - Remove outdated comment about security badges.
  • 757c612 - Fix misplaced args with contract package/uref.
  • 25a70d1 - Simplify comment about contract utilities.
  • 4bcb72e - Avoid using "deposit contract" name.
  • 8010d8e - Stored contract name is actually a contract hash.

Allow running WASM tests without extra setup

No longer need to set PATH_TO_WASM_BINARIES, install wasm-opt or use Nix 😮‍💨. Just compile contracts, and run integration tests with cargo test - it will take care of WASM optimization during runtime.

  • fe652c1 - Add wasm-opt dependency.
  • ce89f53 - Replace compile-time env with helper for WASM directory.
  • 6119d49 - Run WASM optimization in tests runtime.
  • 42fff34 - Refactor WASM helper for tests.

@koxu1996 koxu1996 self-assigned this May 17, 2024
@koxu1996
Copy link
Contributor Author

koxu1996 commented May 17, 2024

@marijanp It seems that reverting to stable toolchain for non-WASM targets breaks builds. Could you help with making this dual toolchain setup?

Update: I was informed that unstable toolchain will be used in a prover as well, and having 2 different toolchains will be too heavy for CI/CD. So I am reverting my change; will explore how to build contracts with stable toolchain later.

For now we can stick to unstable one, to avoid heavy CI/CD.
@koxu1996 koxu1996 requested a review from jonas089 May 17, 2024 14:08
@koxu1996 koxu1996 marked this pull request as ready for review May 17, 2024 14:10
@koxu1996
Copy link
Contributor Author

@jonas089 Ready for review, even some tests are failing 🤔

kairos-tarpaulin> running 6 tests
kairos-tarpaulin> test tests::should_install_contract ... ok
kairos-tarpaulin> test tests::test_deposit_succeeds ... ok
kairos-tarpaulin> test tests::test_transfer_from_contract_purse_by_uref_to_user_should_fails ... ok
kairos-tarpaulin> test tests::test_transfer_from_contract_purse_by_uref_to_admin_should_fails ... ok
kairos-tarpaulin> test tests::test_transfer_from_contract_purse_to_admin_fails ... ok
kairos-tarpaulin> test tests::test_transfer_from_contract_purse_to_user_fails ... ok
kairos-tarpaulin> test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.33s
kairos-tarpaulin> Error: "Test failed during run"
error: builder for '/nix/store/zpxg73h8aa75vbn5yr88n9ml0gg0hy1g-kairos-tarpaulin-0.1.0.drv' failed with exit code 1;

@marijanp It it nix/cachix issue?

Copy link

File Coverage
All files 58%
kairos-server/src/routes/deposit.rs 88%
kairos-server/src/routes/transfer.rs 90%
kairos-test-utils/src/cctl.rs 90%
kairos-crypto/src/implementations/casper.rs 6%
kairos-server/src/config.rs 0%
kairos-server/src/errors.rs 12%
kairos-server/src/lib.rs 95%
kairos-server/src/utils.rs 22%
kairos-server/src/state/transactions/batch_state.rs 36%
kairos-server/src/state/transactions.rs 66%
kairos-server/src/state/trie.rs 35%
kairos-test-utils/src/cctl/parsers.rs 66%
kairos-tx/src/asn.rs 51%
kairos-tx/src/error.rs 0%
kairos-server/tests/transactions.rs 85%
demo-contract-tests/tests/test_fixture/mod.rs 97%
demo-contract-tests/tests/test_fixture/wasm_helper.rs 68%

Minimum allowed coverage is 60%

Generated by 🐒 cobertura-action against 0c3ff1a

@marijanp
Copy link
Contributor

@jonas089 Ready for review, even some tests are failing 🤔

kairos-tarpaulin> running 6 tests
kairos-tarpaulin> test tests::should_install_contract ... ok
kairos-tarpaulin> test tests::test_deposit_succeeds ... ok
kairos-tarpaulin> test tests::test_transfer_from_contract_purse_by_uref_to_user_should_fails ... ok
kairos-tarpaulin> test tests::test_transfer_from_contract_purse_by_uref_to_admin_should_fails ... ok
kairos-tarpaulin> test tests::test_transfer_from_contract_purse_to_admin_fails ... ok
kairos-tarpaulin> test tests::test_transfer_from_contract_purse_to_user_fails ... ok
kairos-tarpaulin> test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.33s
kairos-tarpaulin> Error: "Test failed during run"
error: builder for '/nix/store/zpxg73h8aa75vbn5yr88n9ml0gg0hy1g-kairos-tarpaulin-0.1.0.drv' failed with exit code 1;

@marijanp It it nix/cachix issue?

You have to scroll up in the build log, it says that the port is already in use. Current state of investigation: calling bind with port 0 to get any available port by the OS as described here, does not release the port fast enough such that the server can bind to it. What the reason for that is, is unclear. The TcpListener should be dropped right after we access the bind_address's port.

Interestingly if you run it on more powerful machines, the issue does not apper. Thus I believe it has something to do with GHA runners just not having enought computational power.

Copy link
Contributor

@jonas089 jonas089 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm :)

@koxu1996 koxu1996 changed the base branch from main to feature/deposit-contract May 17, 2024 15:17
Copy link
Contributor

@marijanp marijanp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wasm_helper module basically allows running tests without nix by requiring to build the contracts manually first and then running the tests. PATH_TO_WASM_BINARIES is still being defaulted to if it is sourced (still compatible with nix develop).

I'm fine with the other changes, I also like the changes to use the casper deps from crates.io.

} else {
"release"
};
panic!("WASM directory does not exist: {}. Please build smart contracts at `./kairos-contracts` with `cargo build` for {}.", base_path.display(), build_type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not very nice imo, but if it allows you to run the tests without needing to be in a nix devShell it's fine to me.

@koxu1996 koxu1996 merged commit a5b73c6 into feature/deposit-contract May 17, 2024
7 checks passed
@marijanp marijanp deleted the deposit-contract-suggestions branch May 17, 2024 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants