Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
eae4c87
add availability endpoint
ss-es Apr 23, 2026
b5c2851
update proto definitions with more detail
ss-es Apr 24, 2026
9f26eab
remove types defined in axum.rs
ss-es Apr 24, 2026
4bf2129
remove unhelpful comments
ss-es Apr 24, 2026
e1a08f0
cleanup
ss-es Apr 24, 2026
1192448
collapse swagger by default
ss-es Apr 24, 2026
be65c6f
add example values
ss-es Apr 24, 2026
d94ea9e
cleanup
ss-es Apr 24, 2026
592fea6
cleanup examples
ss-es Apr 27, 2026
3fc97f3
update readme
ss-es Apr 27, 2026
318ebee
Merge branch 'main' into ss/axum-2
ss-es Apr 27, 2026
e4ec214
fix formatting
ss-es Apr 27, 2026
33e6ca2
update with serialization fixes/cleanup
ss-es Apr 27, 2026
a6d2f64
fix inconsistency
ss-es Apr 27, 2026
846fe8d
move descriptions into routes
ss-es Apr 27, 2026
bdbb33d
clippy
ss-es Apr 27, 2026
67c708c
cargo sort
ss-es Apr 27, 2026
178357d
update
ss-es Apr 27, 2026
408e4dc
add new v1 API tests
ss-es May 1, 2026
06c508a
fix reward merkle tree
ss-es May 1, 2026
f94e2a4
fix reward balance endpoint
ss-es May 1, 2026
ab8103e
refactor test
ss-es May 1, 2026
96ac79a
fix latest reward balance
ss-es May 1, 2026
7d86f58
fix routes
ss-es May 1, 2026
dafaccd
fix test
ss-es May 1, 2026
d6f02f5
rustfmt
ss-es May 1, 2026
f28b106
fix reward-amounts
ss-es May 1, 2026
5a678c8
Merge branch 'ss/axum-tests-1' into ss/axum-2
ss-es May 4, 2026
9d917b1
add parity tests
ss-es May 4, 2026
9864160
update incorrect_encoding_proof
ss-es May 6, 2026
6ad876c
u32 -> u64
ss-es May 6, 2026
c030d35
fix examples
ss-es May 6, 2026
3a35fa3
Merge branch 'main' into ss/axum-2
ss-es May 6, 2026
3b7072f
Merge branch 'main' into ss/axum-2
ss-es May 7, 2026
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
172 changes: 172 additions & 0 deletions crates/espresso/api/examples/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,66 @@ impl v1::RewardApi for TestApi {
}
}

// Implement v1::AvailabilityApi with test data
#[async_trait]
impl v1::AvailabilityApi for TestApi {
type NamespaceProofQueryData = (Vec<u8>, Option<Vec<u8>>); // (transactions, proof)
type IncorrectEncodingProof = Vec<u8>;
type StateCertQueryDataV1 = Vec<u8>;
type StateCertQueryDataV2 = Vec<u8>;

async fn get_namespace_proof(
&self,
block_id: v1::availability::BlockId,
namespace: u32,
) -> Result<Option<Self::NamespaceProofQueryData>> {
tracing::info!(
"v1: get_namespace_proof(block_id={:?}, namespace={})",
block_id,
namespace
);
Ok(Some((vec![0xaa, 0xbb, 0xcc], Some(vec![0x11, 0x22, 0x33]))))
}

async fn get_namespace_proof_range(
&self,
from: u64,
until: u64,
namespace: u32,
) -> Result<Vec<Self::NamespaceProofQueryData>> {
tracing::info!(
"v1: get_namespace_proof_range(from={}, until={}, namespace={})",
from,
until,
namespace
);
Ok(vec![(vec![0xaa, 0xbb], Some(vec![0x11, 0x22]))])
}

async fn get_incorrect_encoding_proof(
&self,
block_id: v1::availability::BlockId,
namespace: u32,
) -> Result<Self::IncorrectEncodingProof> {
tracing::info!(
"v1: get_incorrect_encoding_proof(block_id={:?}, namespace={})",
block_id,
namespace
);
Ok(vec![0xde, 0xad, 0xbe, 0xef])
}

async fn get_state_cert(&self, epoch: u64) -> Result<Self::StateCertQueryDataV1> {
tracing::info!("v1: get_state_cert(epoch={})", epoch);
Ok(vec![0x01, 0x02, 0x03])
}

async fn get_state_cert_v2(&self, epoch: u64) -> Result<Self::StateCertQueryDataV2> {
tracing::info!("v1: get_state_cert_v2(epoch={})", epoch);
Ok(vec![0x04, 0x05, 0x06])
}
}

// Implement v2::RewardApi (simplified API - latest-only for claim/balance/proof)
#[async_trait]
impl v2::RewardApi for TestApi {
Expand Down Expand Up @@ -158,6 +218,68 @@ impl v2::RewardApi for TestApi {
}
}

// Implement v2::DataApi with test data
#[async_trait]
impl v2::DataApi for TestApi {
async fn get_namespace_proof(
&self,
namespace_id: u32,
block_height: u64,
) -> Result<Self::NamespaceProof> {
tracing::info!(
"v2: get_namespace_proof(namespace_id={}, block_height={})",
namespace_id,
block_height
);
Ok((vec![0xaa, 0xbb, 0xcc], vec![0x11, 0x22, 0x33]))
}

async fn get_namespace_proof_range(
&self,
namespace_id: u32,
from: u64,
until: u64,
) -> Result<Vec<Self::NamespaceProof>> {
tracing::info!(
"v2: get_namespace_proof_range(namespace_id={}, from={}, until={})",
namespace_id,
from,
until
);
Ok(vec![
(vec![0xaa, 0xbb], vec![0x11, 0x22]),
(vec![0xcc, 0xdd], vec![0x33, 0x44]),
])
}

async fn get_incorrect_encoding_proof(
&self,
namespace_id: u32,
block_height: u64,
) -> Result<Self::IncorrectEncodingProof> {
tracing::info!(
"v2: get_incorrect_encoding_proof(namespace_id={}, block_height={})",
namespace_id,
block_height
);
Ok(vec![0xde, 0xad, 0xbe, 0xef])
}
}

// Implement v2::ConsensusApi with test data
#[async_trait]
impl v2::ConsensusApi for TestApi {
async fn get_state_certificate(&self, epoch: u64) -> Result<Self::StateCertificate> {
tracing::info!("v2: get_state_certificate(epoch={})", epoch);
Ok(vec![0x01, 0x02, 0x03, 0x04])
}

async fn get_stake_table(&self, epoch: u64) -> Result<Self::StakeTable> {
tracing::info!("v2: get_stake_table(epoch={})", epoch);
Ok(vec![0x05, 0x06, 0x07, 0x08])
}
}

// Implement ApiSerializations for v2 proto type conversions
impl ApiSerializations for TestApi {
type Address = String;
Expand All @@ -167,6 +289,14 @@ impl ApiSerializations for TestApi {
type RewardBalances = (Vec<(u128, u128)>, u64);
type RewardMerkleTreeData = Vec<u8>;

// Data API types
type NamespaceProof = (Vec<u8>, Vec<u8>); // (transactions, proof)
type IncorrectEncodingProof = Vec<u8>;

// Consensus API types
type StateCertificate = Vec<u8>;
type StakeTable = Vec<u8>;

fn deserialize_address(&self, s: &str) -> Result<Self::Address> {
// Simple validation: must start with 0x and be hex
if s.starts_with("0x") && s.len() == 42 {
Expand Down Expand Up @@ -252,6 +382,48 @@ impl ApiSerializations for TestApi {
data: value.clone(),
})
}

// Data API serialization methods

fn serialize_namespace_proof(
&self,
value: &Self::NamespaceProof,
) -> Result<serialization_api::v2::NamespaceProofResponse> {
let (transactions, proof) = value;
Ok(serialization_api::v2::NamespaceProofResponse {
transactions: transactions.clone(),
proof: proof.clone(),
})
}

fn serialize_incorrect_encoding_proof(
&self,
value: &Self::IncorrectEncodingProof,
) -> Result<serialization_api::v2::IncorrectEncodingProofResponse> {
Ok(serialization_api::v2::IncorrectEncodingProofResponse {
proof: value.clone(),
})
}

// Consensus API serialization methods

fn serialize_state_certificate(
&self,
value: &Self::StateCertificate,
) -> Result<serialization_api::v2::StateCertificateResponse> {
Ok(serialization_api::v2::StateCertificateResponse {
certificate: value.clone(),
})
}

fn serialize_stake_table(
&self,
value: &Self::StakeTable,
) -> Result<serialization_api::v2::StakeTableResponse> {
Ok(serialization_api::v2::StakeTableResponse {
stake_table: value.clone(),
})
}
}

#[tokio::main]
Expand Down
Loading
Loading