|
| 1 | +# Fabtoken Testing Architecture |
| 2 | + |
| 3 | +This document explains the testing architecture for the Fabtoken implementation in the Fabric Token SDK. |
| 4 | + |
| 5 | +> **Related Documentation:** |
| 6 | +> - [Running Benchmarks](./fabtoken.md) - How to run performance benchmarks |
| 7 | +
|
| 8 | +## Overview |
| 9 | + |
| 10 | +The Fabtoken tests are organized in a **layered architecture** that mirrors the **code abstraction levels**. Each layer represents a different level of the software stack - from core operations to high-level service APIs. |
| 11 | + |
| 12 | +## Architecture Layers |
| 13 | + |
| 14 | +Each layer represents a different **code abstraction level**. |
| 15 | + |
| 16 | +``` |
| 17 | +┌─────────────────────────────────────────────────────────────────┐ |
| 18 | +│ Layer 3: Service Layer (Highest Abstraction) │ |
| 19 | +├─────────────────────────────────────────────────────────────────┤ |
| 20 | +│ Transfer Generation Service │ |
| 21 | +│ Location: token/core/fabtoken/v1/ │ |
| 22 | +│ Tests: - BenchmarkTransferServiceTransfer │ |
| 23 | +│ - TestParallelBenchmarkTransferServiceTransfer │ |
| 24 | +│ Purpose: End-to-end transfer operation generation with vault, │ |
| 25 | +│ audit, and metadata handling │ |
| 26 | +├─────────────────────────────────────────────────────────────────┤ |
| 27 | +│ Issue Generation Service │ |
| 28 | +│ Location: token/core/fabtoken/v1/ │ |
| 29 | +│ Tests: - BenchmarkIssueServiceIssue │ |
| 30 | +│ - TestParallelBenchmarkIssueServiceIssue │ |
| 31 | +│ Purpose: End-to-end issue operation generation through high-level│ |
| 32 | +│ service API │ |
| 33 | +├─────────────────────────────────────────────────────────────────┤ |
| 34 | +│ Auditor Check Service │ |
| 35 | +│ Location: token/core/fabtoken/v1/ │ |
| 36 | +│ Tests: - BenchmarkAuditorServiceCheck │ |
| 37 | +│ - TestParallelBenchmarkAuditorServiceCheck │ |
| 38 | +│ Purpose: End-to-end audit verification through high-level │ |
| 39 | +│ service API │ |
| 40 | +├─────────────────────────────────────────────────────────────────┤ |
| 41 | +│ Transfer/Issue Validator Service │ |
| 42 | +│ Location: token/core/fabtoken/v1/validator/ │ |
| 43 | +│ Tests: - BenchmarkValidatorTransfer │ |
| 44 | +│ - TestParallelBenchmarkValidatorTransfer │ |
| 45 | +│ - BenchmarkValidatorIssue │ |
| 46 | +│ - TestParallelBenchmarkValidatorIssue │ |
| 47 | +│ Purpose: Token request validation with signatures, business │ |
| 48 | +│ logic, and format verification │ |
| 49 | +└─────────────────────────────────────────────────────────────────┘ |
| 50 | +
|
| 51 | +┌─────────────────────────────────────────────────────────────────┐ |
| 52 | +│ Layer 2: Action Operations │ |
| 53 | +├─────────────────────────────────────────────────────────────────┤ |
| 54 | +│ Transfer Generation (token/core/fabtoken/v1/) │ |
| 55 | +│ Tests: - BenchmarkSender │ |
| 56 | +│ - BenchmarkParallelSender │ |
| 57 | +│ - TestParallelBenchmarkSender │ |
| 58 | +│ Purpose: Transfer action generation and serialization │ |
| 59 | +├─────────────────────────────────────────────────────────────────┤ |
| 60 | +│ Transfer Verification (token/core/fabtoken/v1/) │ |
| 61 | +│ Tests: - BenchmarkVerificationSenderProof │ |
| 62 | +│ - BenchmarkVerificationParallelSenderProof │ |
| 63 | +│ - TestParallelBenchmarkVerificationSenderProof │ |
| 64 | +│ Purpose: Deserialization and format validation of transfer │ |
| 65 | +│ actions │ |
| 66 | +├─────────────────────────────────────────────────────────────────┤ |
| 67 | +│ Issue Generation (token/core/fabtoken/v1/) │ |
| 68 | +│ Tests: - BenchmarkIssuer │ |
| 69 | +│ Purpose: Issue action generation and serialization │ |
| 70 | +├─────────────────────────────────────────────────────────────────┤ |
| 71 | +│ Issue Verification (token/core/fabtoken/v1/) │ |
| 72 | +│ Tests: - BenchmarkProofVerificationIssuer │ |
| 73 | +│ Purpose: Deserialization and verification of issue actions │ |
| 74 | +└─────────────────────────────────────────────────────────────────┘ |
| 75 | +
|
| 76 | +┌─────────────────────────────────────────────────────────────────┐ |
| 77 | +│ Layer 1: Core Operations (Lowest Abstraction) │ |
| 78 | +│ Location: token/core/fabtoken/v1/ │ |
| 79 | +│ Tests: - BenchmarkTransferProofGeneration │ |
| 80 | +│ - TestParallelBenchmarkTransferProofGeneration │ |
| 81 | +│ Purpose: Pure transfer action structure generation and │ |
| 82 | +│ serialization │ |
| 83 | +└─────────────────────────────────────────────────────────────────┘ |
| 84 | +``` |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## Layer 1: Core Operations |
| 89 | + |
| 90 | +**Location:** `token/core/fabtoken/v1/` |
| 91 | + |
| 92 | +### Tests |
| 93 | +- `BenchmarkTransferProofGeneration` |
| 94 | +- `TestParallelBenchmarkTransferProofGeneration` |
| 95 | + |
| 96 | +### Purpose |
| 97 | +Pure transfer action generation and serialization. In Fabtoken, since there are no complex zero-knowledge proofs, this layer focuses on the core action structure creation. |
| 98 | + |
| 99 | +### Example Commands |
| 100 | +```bash |
| 101 | +cd token/core/fabtoken/v1 |
| 102 | +go test -bench=BenchmarkTransferProofGeneration -benchtime=10s |
| 103 | +go test -run=TestParallelBenchmarkTransferProofGeneration -v |
| 104 | +``` |
| 105 | + |
| 106 | +--- |
| 107 | + |
| 108 | +## Layer 2: Action Operations |
| 109 | + |
| 110 | +### Transfer Action Generation |
| 111 | + |
| 112 | +**Location:** `token/core/fabtoken/v1/` |
| 113 | + |
| 114 | +#### Tests |
| 115 | +- `BenchmarkSender` |
| 116 | +- `BenchmarkParallelSender` |
| 117 | +- `TestParallelBenchmarkSender` |
| 118 | + |
| 119 | +#### Purpose |
| 120 | +Complete transfer action creation from inputs to serialized output. |
| 121 | + |
| 122 | +#### Example Commands |
| 123 | +```bash |
| 124 | +cd token/core/fabtoken/v1 |
| 125 | +go test -bench=BenchmarkSender -benchtime=10s |
| 126 | +go test -bench=BenchmarkParallelSender -benchtime=10s |
| 127 | +go test -run=TestParallelBenchmarkSender -v |
| 128 | +``` |
| 129 | + |
| 130 | +### Transfer Action Verification |
| 131 | + |
| 132 | +**Location:** `token/core/fabtoken/v1/` |
| 133 | + |
| 134 | +#### Tests |
| 135 | +- `BenchmarkVerificationSenderProof` |
| 136 | +- `BenchmarkVerificationParallelSenderProof` |
| 137 | +- `TestParallelBenchmarkVerificationSenderProof` |
| 138 | + |
| 139 | +#### Purpose |
| 140 | +Deserialization and verification of transfer actions. |
| 141 | + |
| 142 | +#### Example Commands |
| 143 | +```bash |
| 144 | +cd token/core/fabtoken/v1 |
| 145 | +go test -bench=BenchmarkVerificationSenderProof -benchtime=10s |
| 146 | +go test -bench=BenchmarkVerificationParallelSenderProof -benchtime=10s |
| 147 | +go test -run=TestParallelBenchmarkVerificationSenderProof -v |
| 148 | +``` |
| 149 | + |
| 150 | +### Issue Action Generation |
| 151 | + |
| 152 | +**Location:** `token/core/fabtoken/v1/` |
| 153 | + |
| 154 | +#### Tests |
| 155 | +- `BenchmarkIssuer` |
| 156 | + |
| 157 | +#### Purpose |
| 158 | +Complete issue action creation from inputs to serialized output. |
| 159 | + |
| 160 | +#### Example Commands |
| 161 | +```bash |
| 162 | +cd token/core/fabtoken/v1 |
| 163 | +go test -bench=BenchmarkIssuer -benchtime=10s |
| 164 | +``` |
| 165 | + |
| 166 | +### Issue Action Verification |
| 167 | + |
| 168 | +**Location:** `token/core/fabtoken/v1/` |
| 169 | + |
| 170 | +#### Tests |
| 171 | +- `BenchmarkProofVerificationIssuer` |
| 172 | + |
| 173 | +#### Purpose |
| 174 | +Deserialization and verification of issue actions. |
| 175 | + |
| 176 | +#### Example Commands |
| 177 | +```bash |
| 178 | +cd token/core/fabtoken/v1 |
| 179 | +go test -bench=BenchmarkProofVerificationIssuer -benchtime=10s |
| 180 | +``` |
| 181 | + |
| 182 | +--- |
| 183 | + |
| 184 | +## Layer 3: Service Layer |
| 185 | + |
| 186 | +The Service Layer provides the highest level of abstraction for complete end-to-end operations through the Service APIs. |
| 187 | + |
| 188 | +### Transfer Generation Service |
| 189 | + |
| 190 | +**Location:** `token/core/fabtoken/v1/` |
| 191 | + |
| 192 | +#### Tests |
| 193 | +- `BenchmarkTransferServiceTransfer` |
| 194 | +- `TestParallelBenchmarkTransferServiceTransfer` |
| 195 | + |
| 196 | +#### Purpose |
| 197 | +Complete end-to-end transfer operation generation through the high-level Transfer Service API. |
| 198 | + |
| 199 | +#### Includes |
| 200 | +- Token Loading from vault |
| 201 | +- Input Preparation |
| 202 | +- Sender Initialization |
| 203 | +- Output Processing |
| 204 | +- Action Generation and Serialization |
| 205 | +- Audit Information collection |
| 206 | + |
| 207 | +#### Example Commands |
| 208 | +```bash |
| 209 | +cd token/core/fabtoken/v1 |
| 210 | +go test -bench=BenchmarkTransferServiceTransfer -benchtime=10s |
| 211 | +go test -run=TestParallelBenchmarkTransferServiceTransfer -v |
| 212 | +``` |
| 213 | + |
| 214 | +### Issue Generation Service |
| 215 | + |
| 216 | +**Location:** `token/core/fabtoken/v1/` |
| 217 | + |
| 218 | +#### Tests |
| 219 | +- `BenchmarkIssueServiceIssue` |
| 220 | +- `TestParallelBenchmarkIssueServiceIssue` |
| 221 | + |
| 222 | +#### Purpose |
| 223 | +End-to-end issue operation generation through the high-level Issue Service API. |
| 224 | + |
| 225 | +#### Includes |
| 226 | +- Wallet lookup and signer resolution |
| 227 | +- Output token creation |
| 228 | +- Action and metadata serialization |
| 229 | + |
| 230 | +#### Example Commands |
| 231 | +```bash |
| 232 | +cd token/core/fabtoken/v1 |
| 233 | +go test -bench=BenchmarkIssueServiceIssue -benchtime=10s |
| 234 | +go test -run=TestParallelBenchmarkIssueServiceIssue -v |
| 235 | +``` |
| 236 | + |
| 237 | +### Auditor Check Service |
| 238 | + |
| 239 | +**Location:** `token/core/fabtoken/v1/` |
| 240 | + |
| 241 | +#### Tests |
| 242 | +- `BenchmarkAuditorServiceCheck` |
| 243 | +- `TestParallelBenchmarkAuditorServiceCheck` |
| 244 | + |
| 245 | +#### Purpose |
| 246 | +End-to-end audit verification through the high-level Auditor Service API. |
| 247 | + |
| 248 | +#### Includes |
| 249 | +- Action deserialization |
| 250 | +- Request verification |
| 251 | +- Identity matching via the driver deserializer |
| 252 | + |
| 253 | +#### Example Commands |
| 254 | +```bash |
| 255 | +cd token/core/fabtoken/v1 |
| 256 | +go test -bench=BenchmarkAuditorServiceCheck -benchtime=10s |
| 257 | +go test -run=TestParallelBenchmarkAuditorServiceCheck -v |
| 258 | +``` |
| 259 | + |
| 260 | +### Transfer/Issue Validator Service |
| 261 | + |
| 262 | +**Location:** `token/core/fabtoken/v1/validator/` |
| 263 | + |
| 264 | +#### Tests |
| 265 | +- `BenchmarkValidatorTransfer` |
| 266 | +- `TestParallelBenchmarkValidatorTransfer` |
| 267 | +- `BenchmarkValidatorIssue` |
| 268 | +- `TestParallelBenchmarkValidatorIssue` |
| 269 | + |
| 270 | +#### Purpose |
| 271 | +Complete validation pipeline performance, including all signature and business logic checks. |
| 272 | + |
| 273 | +#### Example Commands |
| 274 | +```bash |
| 275 | +cd token/core/fabtoken/v1/validator |
| 276 | +go test -bench=BenchmarkValidatorTransfer -benchtime=10s |
| 277 | +go test -run=TestParallelBenchmarkValidatorTransfer -v |
| 278 | +go test -bench=BenchmarkValidatorIssue -benchtime=10s |
| 279 | +go test -run=TestParallelBenchmarkValidatorIssue -v |
| 280 | +``` |
| 281 | + |
| 282 | +--- |
| 283 | + |
| 284 | +## Testing Strategy |
| 285 | + |
| 286 | +### Understanding the Layers |
| 287 | + |
| 288 | +Each layer tests a **different code abstraction level independently**: |
| 289 | + |
| 290 | +- **Layer 1** tests the core action structure generation. |
| 291 | +- **Layer 2** tests the action creation/verification code. |
| 292 | +- **Layer 3** tests the service layer code: |
| 293 | + - **Transfer Generation Service**: end-to-end transfer generation |
| 294 | + - **Issue Generation Service**: end-to-end issue generation |
| 295 | + - **Auditor Check Service**: audit verification |
| 296 | + - **Transfer Validator Service**: validation logic |
| 297 | + |
| 298 | +--- |
| 299 | + |
| 300 | +## Parallel Testing Variants |
| 301 | + |
| 302 | +Most layers include parallel test variants that run benchmarks concurrently: |
| 303 | +- **`Benchmark*Parallel`**: Go's built-in parallel benchmarking (`*testing.B`) |
| 304 | +- **`TestParallelBenchmark*`**: Custom parallel benchmarking framework (`*testing.T`) |
| 305 | + |
| 306 | +These help identify concurrency issues and measure performance under load. |
0 commit comments