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

Add unit tests + Update doc #24

Merged
merged 14 commits into from
Nov 21, 2023
Merged

Add unit tests + Update doc #24

merged 14 commits into from
Nov 21, 2023

Conversation

gRoussac
Copy link
Collaborator

This PR intends to

  • Introduce unit tests below the sdk methods (rpcs/deploy/deploy_utlis/contract/helpers)
  • Update doc after some code changes (please do not review the docs folder and all the html files)

Multi threading the tests (like the integration tests) does not work correctly so using one thread.

$ make test 
cargo test -- --test-threads=1 --nocapture
running 142 tests
test helpers::tests::test_cl_value_to_json ... ok
test helpers::tests::test_get_blake2b_hash ... ok
test helpers::tests::test_get_current_timestamp ... ok
test helpers::tests::test_get_gas_price_or_default ... ok
test helpers::tests::test_get_str_or_default ... ok
test helpers::tests::test_get_ttl_or_default ... ok
test helpers::tests::test_hex_to_string ... ok
test helpers::tests::test_hex_to_uint8_vec ... ok
test helpers::tests::test_insert_arg_json ... ok
test helpers::tests::test_insert_arg_simple ... ok
test helpers::tests::test_json_pretty_print ... ok
test helpers::tests::test_motes_to_cspr ... ok
test helpers::tests::test_parse_timestamp ... ok
test helpers::tests::test_parse_ttl ... ok
test helpers::tests::test_public_key_from_private_key ... error wasm Error in public_key_from_private_key: FromDer(UnexpectedEnd)
ok
test helpers::tests::test_secret_key_from_pem ... ok
test sdk::contract::call_entrypoint::tests::test_call_entrypoint_with_error ... ok
test sdk::contract::call_entrypoint::tests::test_call_entrypoint_with_invalid_input ... error wasm Error during install: invalid argument 'parse_payment_info': Missing a required arg - exactly one of the following must be provided: ["payment_amount", "payment_hash", "payment_name", "payment_package_hash", "payment_package_name", "payment_path"]
ok
test sdk::contract::call_entrypoint::tests::test_call_entrypoint_with_none_values ... error wasm Error during install: invalid argument 'is_session_transfer': requires --session-arg to be present
ok
test sdk::contract::call_entrypoint::tests::test_call_entrypoint_with_valid_input ... ok
test sdk::contract::call_entrypoint::tests::test_call_entrypoint_without_private_key ... ok
test sdk::contract::install::tests::test_install_with_error ... ok
test sdk::contract::install::tests::test_install_with_invalid_input ... error wasm Error during install: invalid argument 'parse_payment_info': Missing a required arg - exactly one of the following must be provided: ["payment_amount", "payment_hash", "payment_name", "payment_package_hash", "payment_package_name", "payment_path"]
ok
test sdk::contract::install::tests::test_install_with_none_values ... error wasm Error during install: invalid argument 'is_session_transfer': requires --session-arg to be present
ok
test sdk::contract::install::tests::test_install_with_valid_input ... ok
test sdk::contract::install::tests::test_install_without_private_key ... ok
test sdk::contract::query_contract_dict::tests::test_query_contract_dict_with_empty_state_root_hash ... ok
test sdk::contract::query_contract_dict::tests::test_query_contract_dict_with_error ... ok
test sdk::contract::query_contract_dict::tests::test_query_contract_dict_with_invalid_params_input ... error wasm Error converting dictionary_item_params
ok
test sdk::contract::query_contract_dict::tests::test_query_contract_dict_with_none_values ... ok
test sdk::contract::query_contract_dict::tests::test_query_contract_dict_with_state_root_hash ... ok
test sdk::contract::query_contract_dict::tests::test_query_contract_dict_with_valid_identifier_input ... ok
test sdk::contract::query_contract_dict::tests::test_query_contract_dict_with_valid_params_input ... ok
test sdk::contract::query_contract_key::tests::test_query_contract_key_with_block_id ... ok
test sdk::contract::query_contract_key::tests::test_query_contract_key_with_error ... ok
test sdk::contract::query_contract_key::tests::test_query_contract_key_with_global_state_identifier ... ok
test sdk::contract::query_contract_key::tests::test_query_contract_key_with_missing_key ... error wasm Error: Missing key from formatted string
ok
test sdk::contract::query_contract_key::tests::test_query_contract_key_with_none_values ... ok
test sdk::contract::query_contract_key::tests::test_query_contract_key_with_state_root_hash ... ok
test sdk::deploy::deploy::tests::test_deploy_with_invalid_deploy_params ... error wasm Error during deploy: invalid argument 'parse_payment_info': Missing a required arg - exactly one of the following must be provided: ["payment_amount", "payment_hash", "payment_name", "payment_package_hash", "payment_package_name", "payment_path"]
ok
test sdk::deploy::deploy::tests::test_deploy_with_valid_deploy_params ... ok
test sdk::deploy::deploy::tests::test_deploy_with_valid_deploy_params_without_private_key ... ok
test sdk::deploy::speculative_deploy::tests::test_speculative_deploy_with_invalid_params ... error wasm Error during speculative_deploy: invalid argument 'parse_payment_info': Missing a required arg - exactly one of the following must be provided: ["payment_amount", "payment_hash", "payment_name", "payment_package_hash", "payment_package_name", "payment_path"]
ok
test sdk::deploy::speculative_deploy::tests::test_speculative_deploy_with_valid_params_without_private_key ... error wasm Error during speculative_deploy: deploy requires session account - use `with_account` or `with_secret_key`
ok
test sdk::deploy::speculative_transfer::tests::test_speculative_transfer_with_invalid_params ... error wasm Error during speculative_transfer: invalid argument 'parse_payment_info': Missing a required arg - exactly one of the following must be provided: ["payment_amount", "payment_hash", "payment_name", "payment_package_hash", "payment_package_name", "payment_path"]
ok
test sdk::deploy::speculative_transfer::tests::test_speculative_transfer_with_valid_params_without_private_key ... ok
test sdk::deploy::transfer::tests::test_transfer_with_invalid_transfer_params ... error wasm Error during transfer: invalid argument 'parse_payment_info': Missing a required arg - exactly one of the following must be provided: ["payment_amount", "payment_hash", "payment_name", "payment_package_hash", "payment_package_name", "payment_path"]
ok
test sdk::deploy::transfer::tests::test_transfer_with_valid_transfer_params ... ok
test sdk::deploy::transfer::tests::test_transfer_with_valid_transfer_params_without_private_key ... ok
test sdk::deploy_utils::make_deploy::tests::test_make_deploy_with_invalid_params ... ok
test sdk::deploy_utils::make_deploy::tests::test_make_deploy_with_valid_params ... ok
test sdk::deploy_utils::make_deploy::tests::test_make_deploy_with_valid_params_without_private_key ... ok
test sdk::deploy_utils::make_transfer::tests::test_make_transfer_with_invalid_transfer_params ... ok
test sdk::deploy_utils::make_transfer::tests::test_make_transfer_with_valid_transfer_params ... ok
test sdk::deploy_utils::make_transfer::tests::test_make_transfer_with_valid_transfer_params_without_private_key ... ok
test sdk::deploy_utils::sign_deploy::tests::test_sign_deploy_with_invalid_signature ... error wasm Error loading secret key: FromPem("malformedframing")
ok
test sdk::deploy_utils::sign_deploy::tests::test_sign_deploy_with_valid_params ... ok
test sdk::rpcs::get_account::tests::test_get_account_with_account_identifier ... ok
test sdk::rpcs::get_account::tests::test_get_account_with_account_identifier_as_string ... ok
test sdk::rpcs::get_account::tests::test_get_account_with_block_identifier ... ok
test sdk::rpcs::get_account::tests::test_get_account_with_error ... ok
test sdk::rpcs::get_account::tests::test_get_account_with_missing_account ... error wasm Error: Missing account identifier
ok
test sdk::rpcs::get_account::tests::test_get_account_with_none_values ... ok
test sdk::rpcs::get_auction_info::tests::test_get_auction_info_with_block_id_string ... ok
test sdk::rpcs::get_auction_info::tests::test_get_auction_info_with_block_identifier ... ok
test sdk::rpcs::get_auction_info::tests::test_get_auction_info_with_error ... ok
test sdk::rpcs::get_auction_info::tests::test_get_auction_info_with_none_values ... ok
test sdk::rpcs::get_balance::tests::test_get_balance_with_error ... ok
test sdk::rpcs::get_balance::tests::test_get_balance_with_none_values ... ok
test sdk::rpcs::get_balance::tests::test_get_balance_with_purse_uref ... ok
test sdk::rpcs::get_balance::tests::test_get_balance_with_purse_uref_as_string ... ok
test sdk::rpcs::get_balance::tests::test_get_balance_with_state_root_hash ... ok
test sdk::rpcs::get_block::tests::test_get_block_with_block_id_string ... ok
test sdk::rpcs::get_block::tests::test_get_block_with_block_identifier ... ok
test sdk::rpcs::get_block::tests::test_get_block_with_error ... ok
test sdk::rpcs::get_block::tests::test_get_block_with_none_values ... ok
test sdk::rpcs::get_block_transfers::tests::test_get_block_transfers_with_block_id_string ... ok
test sdk::rpcs::get_block_transfers::tests::test_get_block_transfers_with_block_identifier ... ok
test sdk::rpcs::get_block_transfers::tests::test_get_block_transfers_with_error ... ok
test sdk::rpcs::get_block_transfers::tests::test_get_block_transfers_with_none_values ... ok
test sdk::rpcs::get_chainspec::tests::test_get_chainspec_with_error ... ok
test sdk::rpcs::get_chainspec::tests::test_get_chainspec_with_none_values ... ok
test sdk::rpcs::get_chainspec::tests::test_get_chainspec_with_specific_arguments ... ok
test sdk::rpcs::get_deploy::tests::test_get_deploy_with_error ... ok
test sdk::rpcs::get_deploy::tests::test_get_deploy_with_finalized_approvals ... ok
test sdk::rpcs::get_deploy::tests::test_get_deploy_with_invalid_deploy_hash ... ok
test sdk::rpcs::get_deploy::tests::test_get_deploy_with_none_values ... ok
test sdk::rpcs::get_deploy::tests::test_get_deploy_with_valid_deploy_hash ... ok
test sdk::rpcs::get_dictionary_item::tests::test_get_dictionary_item_with_empty_state_root_hash ... ok
test sdk::rpcs::get_dictionary_item::tests::test_get_dictionary_item_with_error ... ok
test sdk::rpcs::get_dictionary_item::tests::test_get_dictionary_item_with_invalid_params_input ... error wasm Error converting dictionary_item_params
ok
test sdk::rpcs::get_dictionary_item::tests::test_get_dictionary_item_with_none_values ... ok
test sdk::rpcs::get_dictionary_item::tests::test_get_dictionary_item_with_state_root_hash ... ok
test sdk::rpcs::get_dictionary_item::tests::test_get_dictionary_item_with_valid_identifier_input ... ok
test sdk::rpcs::get_dictionary_item::tests::test_get_dictionary_item_with_valid_params_input ... ok
test sdk::rpcs::get_era_info::tests::test_get_era_info_with_block_id_string ... ok
test sdk::rpcs::get_era_info::tests::test_get_era_info_with_block_identifier ... ok
test sdk::rpcs::get_era_info::tests::test_get_era_info_with_error ... ok
test sdk::rpcs::get_era_info::tests::test_get_era_info_with_none_values ... ok
test sdk::rpcs::get_era_summary::tests::test_get_era_summary_with_block_id_string ... ok
test sdk::rpcs::get_era_summary::tests::test_get_era_summary_with_block_identifier ... ok
test sdk::rpcs::get_era_summary::tests::test_get_era_summary_with_error ... ok
test sdk::rpcs::get_era_summary::tests::test_get_era_summary_with_none_values ... ok
test sdk::rpcs::get_node_status::tests::test_get_node_status_with_error ... ok
test sdk::rpcs::get_node_status::tests::test_get_node_status_with_none_values ... ok
test sdk::rpcs::get_node_status::tests::test_get_node_status_with_specific_arguments ... ok
test sdk::rpcs::get_peers::tests::test_get_peers_with_error ... ok
test sdk::rpcs::get_peers::tests::test_get_peers_with_none_values ... ok
test sdk::rpcs::get_peers::tests::test_get_peers_with_specific_arguments ... ok
test sdk::rpcs::get_state_root_hash::tests::test_get_state_root_hash_with_block_id_string ... ok
test sdk::rpcs::get_state_root_hash::tests::test_get_state_root_hash_with_block_identifier ... ok
test sdk::rpcs::get_state_root_hash::tests::test_get_state_root_hash_with_error ... ok
test sdk::rpcs::get_state_root_hash::tests::test_get_state_root_hash_with_none_values ... ok
test sdk::rpcs::get_validator_changes::tests::test_get_validator_changes_with_error ... ok
test sdk::rpcs::get_validator_changes::tests::test_get_validator_changes_with_none_values ... ok
test sdk::rpcs::get_validator_changes::tests::test_get_validator_changes_with_specific_arguments ... ok
test sdk::rpcs::list_rpcs::tests::test_list_rpcs_with_error ... ok
test sdk::rpcs::list_rpcs::tests::test_list_rpcs_with_none_values ... ok
test sdk::rpcs::list_rpcs::tests::test_list_rpcs_with_specific_arguments ... ok
test sdk::rpcs::put_deploy::tests::test_put_deploy ... ok
test sdk::rpcs::put_deploy::tests::test_put_deploy_with_error ... ok
test sdk::rpcs::put_deploy::tests::test_put_deploy_with_none_values ... ok
test sdk::rpcs::query_balance::tests::test_query_balance_with_block_id ... ok
test sdk::rpcs::query_balance::tests::test_query_balance_with_error ... ok
test sdk::rpcs::query_balance::tests::test_query_balance_with_global_state_identifier ... ok
test sdk::rpcs::query_balance::tests::test_query_balance_with_missing_purse ... error wasm Error: Missing purse identifier
ok
test sdk::rpcs::query_balance::tests::test_query_balance_with_none_values ... ok
test sdk::rpcs::query_balance::tests::test_query_balance_with_purse_identifier ... ok
test sdk::rpcs::query_balance::tests::test_query_balance_with_purse_identifier_as_string ... ok
test sdk::rpcs::query_balance::tests::test_query_balance_with_state_root_hash ... ok
test sdk::rpcs::query_global_state::tests::test_query_global_state_with_block_id ... ok
test sdk::rpcs::query_global_state::tests::test_query_global_state_with_error ... ok
test sdk::rpcs::query_global_state::tests::test_query_global_state_with_global_state_identifier ... ok
test sdk::rpcs::query_global_state::tests::test_query_global_state_with_missing_key ... error wasm Error: Missing key from formatted string
ok
test sdk::rpcs::query_global_state::tests::test_query_global_state_with_none_values ... ok
test sdk::rpcs::query_global_state::tests::test_query_global_state_with_state_root_hash ... ok
test sdk::rpcs::speculative_exec::tests::test_speculative_exec_with_error ... ok
test sdk::rpcs::speculative_exec::tests::test_speculative_exec_with_none_values ... ok
test types::deploy_params::deploy_str_params::tests::test_deploy_str_params_to_casper_client ... ok
test types::deploy_params::dictionary_item_str_params::tests::test_dictionary_item_str_params_to_casper_client ... error wasm Error converting dictionary_item_params
ok
test types::deploy_params::payment_str_params::tests::test_payment_str_params_to_casper_client ... ok
test types::deploy_params::session_str_params::tests::test_session_str_params_to_casper_client ... ok

test result: ok. 142 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 94.78s

     Running unittests src/main.rs (target/debug/deps/casper_rust_wasm_sdk-a3ce00cbf39b43d4)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests casper_rust_wasm_sdk

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

@gRoussac gRoussac linked an issue Nov 15, 2023 that may be closed by this pull request
@gRoussac gRoussac marked this pull request as ready for review November 15, 2023 13:08
@gRoussac gRoussac self-assigned this Nov 15, 2023
@gRoussac gRoussac added the documentation Improvements or additions to documentation label Nov 15, 2023
Copy link

@ACStone-MTS ACStone-MTS left a comment

Choose a reason for hiding this comment

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

One small fix, leaving approval to tech reviewers.

docs/README.md Outdated Show resolved Hide resolved
Co-authored-by: Adam Stone <[email protected]>
Copy link

@zacshowa zacshowa left a comment

Choose a reason for hiding this comment

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

One tiny nit. Otherwise LGTM

Comment on lines 234 to 235
let err = "Error: Missing purse identifier".to_string();
error(&err);

Choose a reason for hiding this comment

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

From my understanding of Rust, I believe this just convert the &str literal into a String and then back into an &str correct? If that is the case we can probably just revert these lines.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, that is correct I changed that a lot and added an Err using the string as String just below.
I moved the to_string below thus.

           let err = "Error: Missing key from formatted string";
            error(err);
            return Err(SdkError::InvalidArgument {
                context: "query_global_state",
                error: err.to_string(),
            });

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

also fixed the context

@gRoussac gRoussac merged commit 3d77826 into main Nov 21, 2023
This was linked to issues Jan 9, 2024
@gRoussac gRoussac linked an issue Jan 9, 2024 that may be closed by this pull request
@gRoussac gRoussac linked an issue Jan 9, 2024 that may be closed by this pull request
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
3 participants