Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions contracts/prompt-hash/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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`.
Expand All @@ -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)]
Expand Down
34 changes: 34 additions & 0 deletions contracts/prompt-hash/src/mock_has_access.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
24 changes: 23 additions & 1 deletion contracts/prompt-hash/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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);
}
Expand Down