(t *testing.T)
| 223 | } |
| 224 | |
| 225 | func TestSequentialAllocation_FIFO(t *testing.T) { |
| 226 | datasource, _, err := newTestDataSource() |
| 227 | if err != nil { |
| 228 | t.Fatalf("Error creating test data source: %s", err) |
| 229 | } |
| 230 | |
| 231 | ledgerforge, err := NewLedgerForge(datasource) |
| 232 | if err != nil { |
| 233 | t.Fatalf("Error creating LedgerForge instance: %s", err) |
| 234 | } |
| 235 | |
| 236 | now := time.Now() |
| 237 | |
| 238 | tests := []struct { |
| 239 | name string |
| 240 | sources []LineageSource |
| 241 | amount *big.Int |
| 242 | expected []Allocation |
| 243 | }{ |
| 244 | { |
| 245 | name: "Single source covers amount", |
| 246 | sources: []LineageSource{ |
| 247 | {BalanceID: "shadow_1", Balance: big.NewInt(10000), CreatedAt: now}, |
| 248 | }, |
| 249 | amount: big.NewInt(5000), |
| 250 | expected: []Allocation{ |
| 251 | {BalanceID: "shadow_1", Amount: big.NewInt(5000)}, |
| 252 | }, |
| 253 | }, |
| 254 | { |
| 255 | name: "Multiple sources needed", |
| 256 | sources: []LineageSource{ |
| 257 | {BalanceID: "shadow_1", Balance: big.NewInt(3000), CreatedAt: now}, |
| 258 | {BalanceID: "shadow_2", Balance: big.NewInt(5000), CreatedAt: now.Add(time.Hour)}, |
| 259 | }, |
| 260 | amount: big.NewInt(6000), |
| 261 | expected: []Allocation{ |
| 262 | {BalanceID: "shadow_1", Amount: big.NewInt(3000)}, |
| 263 | {BalanceID: "shadow_2", Amount: big.NewInt(3000)}, |
| 264 | }, |
| 265 | }, |
| 266 | { |
| 267 | name: "Exhaust first source completely", |
| 268 | sources: []LineageSource{ |
| 269 | {BalanceID: "shadow_1", Balance: big.NewInt(5000), CreatedAt: now}, |
| 270 | {BalanceID: "shadow_2", Balance: big.NewInt(3000), CreatedAt: now.Add(time.Hour)}, |
| 271 | }, |
| 272 | amount: big.NewInt(6000), |
| 273 | expected: []Allocation{ |
| 274 | {BalanceID: "shadow_1", Amount: big.NewInt(5000)}, |
| 275 | {BalanceID: "shadow_2", Amount: big.NewInt(1000)}, |
| 276 | }, |
| 277 | }, |
| 278 | { |
| 279 | name: "Empty sources", |
| 280 | sources: []LineageSource{}, |
| 281 | amount: big.NewInt(1000), |
| 282 | expected: nil, |
nothing calls this directly
no test coverage detected