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
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,19 @@ jobs:
magic="$(xxd -p -l 4 "$wasm_path" 2>/dev/null || od -A n -N 4 -t x1 "$wasm_path" | tr -d ' ')"
test "$magic" = "0061736d"
working-directory: contract

- name: Build wasm release for myfans-lib
run: cargo build --release --target wasm32-unknown-unknown -p myfans-lib
working-directory: contract

- name: Verify myfans_lib.wasm artifact exists
run: test -f target/wasm32-unknown-unknown/release/myfans_lib.wasm
working-directory: contract

- name: Verify myfans_lib wasm
run: |
wasm_path="target/wasm32-unknown-unknown/release/myfans_lib.wasm"
test -s "$wasm_path"
magic="$(xxd -p -l 4 "$wasm_path" 2>/dev/null || od -A n -N 4 -t x1 "$wasm_path" | tr -d ' ')"
test "$magic" = "0061736d"
working-directory: contract
5 changes: 5 additions & 0 deletions contract/contracts/myfans-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum ContentType {
/// Shared error enum across all MyFans contracts.
/// Codes preserved exactly for test snapshot compatibility.
#[contracterror]
#[repr(u32)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MyfansError {
/// Common init/admin errors
Expand Down Expand Up @@ -52,6 +53,10 @@ pub enum MyfansError {
MinBalanceViolation = 106,
}

// Ensure numeric discriminants are represented as `u32` in the compiled ABI.
// This keeps the contracterror discriminants stable across builds and targets.


/// Stable numeric error codes for every MyFans contract, grouped by contract.
/// Clients can import these instead of hard-coding magic numbers.
///
Expand Down
23 changes: 16 additions & 7 deletions contract/contracts/test-consumer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
#![no_std]
use myfans_lib::{ContentType, MyfansError, SubscriptionStatus};
use soroban_sdk::{contract, contractimpl, Env};
use soroban_sdk::{contract, contractimpl, Env, Symbol};

#[contract]
pub struct TestConsumer;

#[contractimpl]
impl TestConsumer {
/// Returns true only when `status` is `Active`.
pub fn is_active(_env: Env, status: SubscriptionStatus) -> bool {
status == SubscriptionStatus::Active
pub fn is_active(env: Env, status: SubscriptionStatus) -> bool {
let active = status == SubscriptionStatus::Active;
env.events()
.publish((Symbol::new(&env, "test_consumer:is_active"),), active);
active
}

/// Returns the numeric discriminant of a `MyfansError` variant, confirming
/// the shared error type is importable and its codes are stable.
pub fn error_code(_env: Env, err: MyfansError) -> u32 {
err as u32
pub fn error_code(env: Env, err: MyfansError) -> u32 {
let code = err as u32;
env.events()
.publish((Symbol::new(&env, "test_consumer:error_code"),), code);
code
}

/// Returns the numeric discriminant of a `ContentType` variant.
pub fn content_code(_env: Env, ct: ContentType) -> u32 {
ct as u32
pub fn content_code(env: Env, ct: ContentType) -> u32 {
let code = ct as u32;
env.events()
.publish((Symbol::new(&env, "test_consumer:content_code"),), code);
code
}
}

Expand Down
Loading