diff --git a/contracts/prompt-hash/src/lib.rs b/contracts/prompt-hash/src/lib.rs index 6194090f..c9ef27d8 100644 --- a/contracts/prompt-hash/src/lib.rs +++ b/contracts/prompt-hash/src/lib.rs @@ -1,6 +1,8 @@ -#![no_std] -#![allow(dead_code)] -#![allow(clippy::too_many_arguments)] +#clo_std] + +#[allow(dead_code)] + +#[allow(clippy::too_many_arguments)] // Test builds get `std` (and therefore `alloc`) back so dev-dependencies like // `proptest` work normally; the deployed wasm contract stays strictly `no_std`. @@ -15,10 +17,13 @@ mod types; #[cfg(test)] mod mock_asset; -#[cfg(all(test, not(feature = "isolate-gas-bench")))] +#[cfg(test)] +mod mock_has_access; + +#[cfg(all(test, not(feature = "isolate-gas-bench"))] mod test; -#[cfg(all(test, not(feature = "isolate-gas-bench")))] +#[cfg(all(test, not(feature = "isolate-gas-bench"))] mod fuzz; #[cfg(test)] diff --git a/contracts/prompt-hash/src/mock_has_access.rs b/contracts/prompt-hash/src/mock_has_access.rs new file mode 100644 index 00000000..37325e20 --- /dev/null +++ b/contracts/prompt-hash/src/mock_has_access.rs @@ -0,0 +1,34 @@ +use soroban_sdk:{contract, contractimpl, Address, Env}; +#[contract] +pub struct MockHasAccess; + +#[contractimpl] +impl MockHasAccess { + pub fn has_access(_env: Env, _user: Address) -> bool { + // Happy path mock always grants access. + true + } +} + +#[cfg(test)] +mod test { + use super::*; + use crate::contract::PromptHashContract; + use soroban_sdk::testutils::Address as _; + + #[test] + fn unlock_happy_path() { + let env = Env::default(); + env.mock_all_auths(); + + let user = Address::generate(&env); + let has_access_id = env.register_contract(None, MockHasAccess); + let contract_id = env.register_contract(None, PromptHashContract); + + let challenge = PromptHashContract::challenge(&env, &contract_id, &user); + let signature = PromptHashContract::sign(&env, &contract_id, &user, &challenge); + let unlocked = PromptHashContract::unlock(&env, &contract_id, &user, &signature, &has_access_id); + + assert(unlocked); + } +} \ No newline at end of file diff --git a/contracts/prompt-hash/src/test.rs b/contracts/prompt-hash/src/test.rs index 72bcbf26..2ad29d14 100644 --- a/contracts/prompt-hash/src/test.rs +++ b/contracts/prompt-hash/src/test.rs @@ -4,7 +4,7 @@ use crate::storage::Storage; use crate::types::{Error, ListingConfig, Split}; extern crate std; use soroban_sdk::{ - testutils::{Address as _, Events as _, Ledger}, + testutils::{ed25519::Sign, Address as _, Events as _, Ledger}, token, Address, Bytes, BytesN, Env, String, Vec, }; @@ -47,6 +47,28 @@ fn setup(env: &Env) -> PromptHashContext { } } +#[test] +fn test_unlock_happy_path() { + let env: Env = Default::default(); + let context = setup(&env); + let client = PromptHashContractClient::new(&env, &context.contract); + + let creator = Address::generate(&env); + let prompt_id = create_prompt( + &env, + &client, + &creator, + "Unlock Prompt", + 10_000, + &context.xlm, + ); + assert!(client.has_access(&creator, &prompt_id)); + + let challenge = client.challenge(&creator, &prompt_id); + let signature = creator.sign(&env, &challenge); + assert!(client.unlock(&creator, &prompt_id, &signature)); +} + fn set_pause(client: &PromptHashContractClient<'_>, context: &PromptHashContext, paused: bool) { client.set_pause_status(&paused, &context.admin, &context.admin_two); }