upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-17 01:39:03 +0530
committerYour Name <you@example.com>2026-05-17 01:39:03 +0530
commit32844ac7c4a135659714aabf7d2414f156176d72 (patch)
tree414e6272a9a174bd50566c65e432ed62b29236b3 /tests/unit
parent60e0a1042e5c56fe7d4b46d760441391df4ff809 (diff)
test_cashu (10/10) + test_session (18/18): all 86 unit tests passing
- Expand esp_http_client.h stub: full config struct + method enum + init/perform/cleanup - Add portTICK_PERIOD_MS + esp_err_to_name to stubs - session.c: reject duplicate spent secrets in session_create (double-spend protection) - .gitignore: add test binaries
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/stubs/esp_err.h2
-rw-r--r--tests/unit/stubs/esp_http_client.h43
-rw-r--r--tests/unit/stubs/freertos/FreeRTOS.h1
3 files changed, 45 insertions, 1 deletions
diff --git a/tests/unit/stubs/esp_err.h b/tests/unit/stubs/esp_err.h
index 84c3734..9bedb72 100644
--- a/tests/unit/stubs/esp_err.h
+++ b/tests/unit/stubs/esp_err.h
@@ -13,6 +13,8 @@ typedef int esp_err_t;
13#define ESP_ERR_NO_MEM 0x101 13#define ESP_ERR_NO_MEM 0x101
14#define ESP_ERR_NOT_FOUND 0x104 14#define ESP_ERR_NOT_FOUND 0x104
15 15
16static inline const char *esp_err_to_name(esp_err_t err) { (void)err; return "ESP_OK"; }
17
16#define ESP_ERROR_CHECK(x) do { if ((x) != 0) { fprintf(stderr, "ESP_ERROR_CHECK failed: 0x%x\n", (int)(x)); abort(); } } while(0) 18#define ESP_ERROR_CHECK(x) do { if ((x) != 0) { fprintf(stderr, "ESP_ERROR_CHECK failed: 0x%x\n", (int)(x)); abort(); } } while(0)
17 19
18#endif 20#endif
diff --git a/tests/unit/stubs/esp_http_client.h b/tests/unit/stubs/esp_http_client.h
index 4169714..288ce3b 100644
--- a/tests/unit/stubs/esp_http_client.h
+++ b/tests/unit/stubs/esp_http_client.h
@@ -2,11 +2,52 @@
2#define STUBS_ESP_HTTP_CLIENT_H 2#define STUBS_ESP_HTTP_CLIENT_H
3 3
4#include "esp_err.h" 4#include "esp_err.h"
5#include <string.h>
6#include <stdlib.h>
5 7
6typedef void *esp_http_client_handle_t; 8typedef enum {
9 HTTP_METHOD_GET = 0,
10 HTTP_METHOD_POST,
11 HTTP_METHOD_PUT,
12 HTTP_METHOD_DELETE,
13} esp_http_client_method_t;
14
15typedef void *esp_crt_bundle_attach_fn_t(void *conf);
7 16
8typedef struct { 17typedef struct {
18 const char *url;
19 esp_http_client_method_t method;
20 int timeout_ms;
21 esp_crt_bundle_attach_fn_t *crt_bundle_attach;
9 int cert_pem; 22 int cert_pem;
10} esp_http_client_config_t; 23} esp_http_client_config_t;
11 24
25typedef void *esp_http_client_handle_t;
26
27static inline esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *cfg) {
28 (void)cfg;
29 return (void *)malloc(1);
30}
31static inline esp_err_t esp_http_client_set_header(esp_http_client_handle_t c, const char *k, const char *v) {
32 (void)c; (void)k; (void)v; return ESP_OK;
33}
34static inline esp_err_t esp_http_client_open(esp_http_client_handle_t c, int len) {
35 (void)c; (void)len; return ESP_OK;
36}
37static inline int esp_http_client_write(esp_http_client_handle_t c, const char *buf, int len) {
38 (void)c; (void)buf; return len;
39}
40static inline int esp_http_client_fetch_headers(esp_http_client_handle_t c) {
41 (void)c; return 0;
42}
43static inline int esp_http_client_get_status_code(esp_http_client_handle_t c) {
44 (void)c; return 200;
45}
46static inline int esp_http_client_read(esp_http_client_handle_t c, char *buf, int len) {
47 (void)c; (void)buf; (void)len; return 0;
48}
49static inline esp_err_t esp_http_client_cleanup(esp_http_client_handle_t c) {
50 free(c); return ESP_OK;
51}
52
12#endif 53#endif
diff --git a/tests/unit/stubs/freertos/FreeRTOS.h b/tests/unit/stubs/freertos/FreeRTOS.h
index 0fee758..696da87 100644
--- a/tests/unit/stubs/freertos/FreeRTOS.h
+++ b/tests/unit/stubs/freertos/FreeRTOS.h
@@ -6,6 +6,7 @@
6static inline uint32_t xTaskGetTickCount(void) { return 0; } 6static inline uint32_t xTaskGetTickCount(void) { return 0; }
7static inline void vTaskDelay(uint32_t ticks) { (void)ticks; } 7static inline void vTaskDelay(uint32_t ticks) { (void)ticks; }
8#define pdMS_TO_TICKS(ms) ((ms) / 10) 8#define pdMS_TO_TICKS(ms) ((ms) / 10)
9#define portTICK_PERIOD_MS 10
9#define portMAX_DELAY 0xFFFFFFFF 10#define portMAX_DELAY 0xFFFFFFFF
10 11
11#endif 12#endif