diff options
| author | Your Name <you@example.com> | 2026-05-23 05:32:22 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-23 05:32:22 +0530 |
| commit | 5140a30be35aaf3574efce9193549f18524ce46e (patch) | |
| tree | c1146fc161fe787ccabd04558219b7591e207b61 /tests/unit/test_mining_payment.c | |
| parent | fb8558cbf964fae5a840f8f948b89a0d42045802 (diff) | |
Phase 7: eliminate shims - consumer files use component headers directly
- Deleted standalone shims: session.c/h, cashu.c/h, mining_payment.c/h, firewall.c/h
- Updated captive_portal.c, tollgate_api.c, tollgate_main.c, mcp_handler.c,
cvm_server.c, sw_miner.c, stratum_client.c to include component headers
- Moved tollgate_ip4_canforward_filter() lwIP hook into tollgate_main.c
- Fixed all unit tests to use component API (test_cashu, test_session,
test_mining_payment, test_stratum_proxy, test_session_payment_method,
test_firewall_sandbox, test_mcp_handler)
- Removed deleted source files from Makefile targets
- All 21 unit tests pass, ESP-IDF build passes
Diffstat (limited to 'tests/unit/test_mining_payment.c')
| -rw-r--r-- | tests/unit/test_mining_payment.c | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/tests/unit/test_mining_payment.c b/tests/unit/test_mining_payment.c index c3834fd..25932e5 100644 --- a/tests/unit/test_mining_payment.c +++ b/tests/unit/test_mining_payment.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | #include "test_framework.h" | 1 | #include "test_framework.h" |
| 2 | #include "../../main/mining_payment.h" | 2 | #include "tollgate_core_mining.h" |
| 3 | #include <stdio.h> | 3 | #include <stdio.h> |
| 4 | #include <string.h> | 4 | #include <string.h> |
| 5 | #include <math.h> | 5 | #include <math.h> |
| @@ -8,84 +8,84 @@ int main(void) | |||
| 8 | { | 8 | { |
| 9 | printf("=== test_mining_payment ===\n"); | 9 | printf("=== test_mining_payment ===\n"); |
| 10 | 10 | ||
| 11 | mining_payment_init(); | 11 | tollgate_core_mining_init(); |
| 12 | 12 | ||
| 13 | printf("\n--- mining_nbits_to_difficulty ---\n"); | 13 | printf("\n--- tollgate_core_mining_nbits_to_difficulty ---\n"); |
| 14 | uint64_t d1 = mining_nbits_to_difficulty(0); | 14 | uint64_t d1 = tollgate_core_mining_nbits_to_difficulty(0); |
| 15 | ASSERT(d1 == UINT64_MAX, "nbits=0 returns max"); | 15 | ASSERT(d1 == UINT64_MAX, "nbits=0 returns max"); |
| 16 | 16 | ||
| 17 | uint64_t d2 = mining_nbits_to_difficulty(0x170309E2); | 17 | uint64_t d2 = tollgate_core_mining_nbits_to_difficulty(0x170309E2); |
| 18 | ASSERT(d2 > 0, "mainnet nbits gives positive difficulty"); | 18 | ASSERT(d2 > 0, "mainnet nbits gives positive difficulty"); |
| 19 | printf(" INFO: difficulty for 0x170309E2 = %llu\n", (unsigned long long)d2); | 19 | printf(" INFO: difficulty for 0x170309E2 = %llu\n", (unsigned long long)d2); |
| 20 | 20 | ||
| 21 | uint64_t d3 = mining_nbits_to_difficulty(0x1d00ffff); | 21 | uint64_t d3 = tollgate_core_mining_nbits_to_difficulty(0x1d00ffff); |
| 22 | ASSERT(d3 == 1, "pseudotransaction nbits = difficulty 1"); | 22 | ASSERT(d3 == 1, "pseudotransaction nbits = difficulty 1"); |
| 23 | 23 | ||
| 24 | printf("\n--- mining_calculate_hashprice ---\n"); | 24 | printf("\n--- tollgate_core_mining_calc_hashprice ---\n"); |
| 25 | double hp1 = mining_calculate_hashprice(0); | 25 | double hp1 = tollgate_core_mining_calc_hashprice(0); |
| 26 | ASSERT(hp1 == 0.0, "nbits=0 gives hashprice 0"); | 26 | ASSERT(hp1 == 0.0, "nbits=0 gives hashprice 0"); |
| 27 | 27 | ||
| 28 | double hp2 = mining_calculate_hashprice(0x170309E2); | 28 | double hp2 = tollgate_core_mining_calc_hashprice(0x170309E2); |
| 29 | ASSERT(hp2 > 0.0, "mainnet nbits gives positive hashprice"); | 29 | ASSERT(hp2 > 0.0, "mainnet nbits gives positive hashprice"); |
| 30 | printf(" INFO: hashprice for 0x170309E2 = %.6f sat/GH/s/day\n", hp2); | 30 | printf(" INFO: hashprice for 0x170309E2 = %.6f sat/GH/s/day\n", hp2); |
| 31 | 31 | ||
| 32 | printf("\n--- mining_calculate_hashprice_override ---\n"); | 32 | printf("\n--- tollgate_core_mining_calc_hashprice_override ---\n"); |
| 33 | double hp3 = mining_calculate_hashprice_override(1000); | 33 | double hp3 = tollgate_core_mining_calc_hashprice_override(1000); |
| 34 | ASSERT(fabs(hp3 - 1000.0) < 0.001, "override returns exact value"); | 34 | ASSERT(fabs(hp3 - 1000.0) < 0.001, "override returns exact value"); |
| 35 | 35 | ||
| 36 | printf("\n--- mining_set_current_nbits ---\n"); | 36 | printf("\n--- tollgate_core_mining_set_current_nbits ---\n"); |
| 37 | mining_set_current_nbits(0x170309E2); | 37 | tollgate_core_mining_set_current_nbits(0x170309E2); |
| 38 | double hp4 = mining_get_current_hashprice(); | 38 | double hp4 = tollgate_core_mining_get_current_hashprice(); |
| 39 | ASSERT(fabs(hp4 - hp2) < 0.0001, "stored hashprice matches calculated"); | 39 | ASSERT(fabs(hp4 - hp2) < 0.0001, "stored hashprice matches calculated"); |
| 40 | 40 | ||
| 41 | printf("\n--- mining_get_or_create_client ---\n"); | 41 | printf("\n--- tollgate_core_mining_get_or_create_client ---\n"); |
| 42 | mining_client_stats_t *c1 = mining_get_or_create_client(0x0A010203); | 42 | tollgate_mining_client_stats_t *c1 = tollgate_core_mining_get_or_create_client(0x0A010203); |
| 43 | ASSERT(c1 != NULL, "created client 1"); | 43 | ASSERT(c1 != NULL, "created client 1"); |
| 44 | ASSERT(c1->ip == 0x0A010203, "client 1 IP matches"); | 44 | ASSERT(c1->ip == 0x0A010203, "client 1 IP matches"); |
| 45 | ASSERT(c1->shares_accepted == 0, "client 1 starts with 0 shares"); | 45 | ASSERT(c1->shares_accepted == 0, "client 1 starts with 0 shares"); |
| 46 | 46 | ||
| 47 | mining_client_stats_t *c2 = mining_get_or_create_client(0x0A010204); | 47 | tollgate_mining_client_stats_t *c2 = tollgate_core_mining_get_or_create_client(0x0A010204); |
| 48 | ASSERT(c2 != NULL, "created client 2"); | 48 | ASSERT(c2 != NULL, "created client 2"); |
| 49 | ASSERT(c2->ip == 0x0A010204, "client 2 IP matches"); | 49 | ASSERT(c2->ip == 0x0A010204, "client 2 IP matches"); |
| 50 | 50 | ||
| 51 | mining_client_stats_t *c1_again = mining_get_or_create_client(0x0A010203); | 51 | tollgate_mining_client_stats_t *c1_again = tollgate_core_mining_get_or_create_client(0x0A010203); |
| 52 | ASSERT(c1_again == c1, "same IP returns same client"); | 52 | ASSERT(c1_again == c1, "same IP returns same client"); |
| 53 | 53 | ||
| 54 | printf("\n--- mining_update_hashrate ---\n"); | 54 | printf("\n--- tollgate_core_mining_update_hashrate ---\n"); |
| 55 | mining_update_hashrate(0x0A010203, true); | 55 | tollgate_core_mining_update_hashrate(0x0A010203, true); |
| 56 | mining_update_hashrate(0x0A010203, true); | 56 | tollgate_core_mining_update_hashrate(0x0A010203, true); |
| 57 | mining_update_hashrate(0x0A010203, false); | 57 | tollgate_core_mining_update_hashrate(0x0A010203, false); |
| 58 | 58 | ||
| 59 | const mining_client_stats_t *c1_stats = mining_get_client_stats(0x0A010203); | 59 | const tollgate_mining_client_stats_t *c1_stats = tollgate_core_mining_get_client_stats(0x0A010203); |
| 60 | ASSERT(c1_stats != NULL, "client 1 stats found"); | 60 | ASSERT(c1_stats != NULL, "client 1 stats found"); |
| 61 | ASSERT(c1_stats->shares_accepted == 2, "client 1 has 2 accepted"); | 61 | ASSERT(c1_stats->shares_accepted == 2, "client 1 has 2 accepted"); |
| 62 | ASSERT(c1_stats->shares_rejected == 1, "client 1 has 1 rejected"); | 62 | ASSERT(c1_stats->shares_rejected == 1, "client 1 has 1 rejected"); |
| 63 | 63 | ||
| 64 | printf("\n--- mining_get_client_stats ---\n"); | 64 | printf("\n--- tollgate_core_mining_get_client_stats ---\n"); |
| 65 | const mining_client_stats_t *notfound = mining_get_client_stats(0xFFFFFFFF); | 65 | const tollgate_mining_client_stats_t *notfound = tollgate_core_mining_get_client_stats(0xFFFFFFFF); |
| 66 | ASSERT(notfound == NULL, "nonexistent client returns NULL"); | 66 | ASSERT(notfound == NULL, "nonexistent client returns NULL"); |
| 67 | 67 | ||
| 68 | printf("\n--- mining_shares_to_allotment_ms ---\n"); | 68 | printf("\n--- tollgate_core_mining_shares_to_allotment_ms ---\n"); |
| 69 | uint64_t allot1 = mining_shares_to_allotment_ms(0.0, 100.0, 21, 60000); | 69 | uint64_t allot1 = tollgate_core_mining_shares_to_allotment_ms(0.0, 100.0, 21, 60000); |
| 70 | ASSERT(allot1 == 0, "zero hashrate = zero allotment"); | 70 | ASSERT(allot1 == 0, "zero hashrate = zero allotment"); |
| 71 | 71 | ||
| 72 | uint64_t allot2 = mining_shares_to_allotment_ms(1.0, 100.0, 21, 60000); | 72 | uint64_t allot2 = tollgate_core_mining_shares_to_allotment_ms(1.0, 100.0, 21, 60000); |
| 73 | ASSERT(allot2 > 0, "positive hashrate gives positive allotment"); | 73 | ASSERT(allot2 > 0, "positive hashrate gives positive allotment"); |
| 74 | printf(" INFO: 1 GH/s at 100 sat/GH/s/day, 21 sats/60s => %llu ms\n", (unsigned long long)allot2); | 74 | printf(" INFO: 1 GH/s at 100 sat/GH/s/day, 21 sats/60s => %llu ms\n", (unsigned long long)allot2); |
| 75 | 75 | ||
| 76 | uint64_t allot3 = mining_shares_to_allotment_ms(10.0, 50.0, 10, 30000); | 76 | uint64_t allot3 = tollgate_core_mining_shares_to_allotment_ms(10.0, 50.0, 10, 30000); |
| 77 | ASSERT(allot3 > 0, "10 GH/s at 50 sat gives positive allotment"); | 77 | ASSERT(allot3 > 0, "10 GH/s at 50 sat gives positive allotment"); |
| 78 | printf(" INFO: 10 GH/s at 50 sat/GH/s/day, 10 sats/30s => %llu ms\n", (unsigned long long)allot3); | 78 | printf(" INFO: 10 GH/s at 50 sat/GH/s/day, 10 sats/30s => %llu ms\n", (unsigned long long)allot3); |
| 79 | 79 | ||
| 80 | printf("\n--- mining_shares_to_allotment_bytes ---\n"); | 80 | printf("\n--- tollgate_core_mining_shares_to_allotment_bytes ---\n"); |
| 81 | uint64_t ab1 = mining_shares_to_allotment_bytes(0.0, 100.0, 21, 1048576); | 81 | uint64_t ab1 = tollgate_core_mining_shares_to_allotment_bytes(0.0, 100.0, 21, 1048576); |
| 82 | ASSERT(ab1 == 0, "zero hashrate = zero bytes"); | 82 | ASSERT(ab1 == 0, "zero hashrate = zero bytes"); |
| 83 | 83 | ||
| 84 | uint64_t ab2 = mining_shares_to_allotment_bytes(1.0, 100.0, 21, 1048576); | 84 | uint64_t ab2 = tollgate_core_mining_shares_to_allotment_bytes(1.0, 100.0, 21, 1048576); |
| 85 | ASSERT(ab2 > 0, "positive hashrate gives positive bytes"); | 85 | ASSERT(ab2 > 0, "positive hashrate gives positive bytes"); |
| 86 | 86 | ||
| 87 | printf("\n--- mining_validate_share (stub) ---\n"); | 87 | printf("\n--- tollgate_core_mining_validate_share (stub) ---\n"); |
| 88 | esp_err_t vr = mining_validate_share(NULL, 0, NULL, 0); | 88 | esp_err_t vr = tollgate_core_mining_validate_share(NULL, 0, NULL, 0); |
| 89 | ASSERT(vr == ESP_OK, "validate share stub returns OK"); | 89 | ASSERT(vr == ESP_OK, "validate share stub returns OK"); |
| 90 | 90 | ||
| 91 | TEST_SUMMARY(); | 91 | TEST_SUMMARY(); |