(t *testing.T)
| 5251 | } |
| 5252 | |
| 5253 | func TestInflightTransactionWithOverdraftOnCommit(t *testing.T) { |
| 5254 | // Test scenario: |
| 5255 | // 1. Create a source balance with 500 USD |
| 5256 | // 2. Create an inflight transaction for 1000 USD (exceeds balance) with AllowOverdraft: false |
| 5257 | // 3. The transaction should be QUEUED initially, then REJECTED due to insufficient funds |
| 5258 | // 4. Attempt to commit the rejected transaction |
| 5259 | // 5. Verify that balances remain unchanged since the transaction was rejected |
| 5260 | |
| 5261 | // Skip in short mode |
| 5262 | if testing.Short() { |
| 5263 | t.Skip("Skipping inflight overdraft test in short mode") |
| 5264 | } |
| 5265 | |
| 5266 | ctx := context.Background() |
| 5267 | cnf := &config.Configuration{ |
| 5268 | Redis: config.RedisConfig{ |
| 5269 | Dns: "localhost:6379", |
| 5270 | }, |
| 5271 | DataSource: config.DataSourceConfig{ |
| 5272 | Dns: "postgres://postgres:password@localhost:5432/ledgerforge?sslmode=disable", |
| 5273 | }, |
| 5274 | Queue: config.QueueConfig{ |
| 5275 | WebhookQueue: "webhook_queue_test_overdraft", |
| 5276 | IndexQueue: "index_queue_test_overdraft", |
| 5277 | TransactionQueue: "transaction_queue_test_overdraft", |
| 5278 | NumberOfQueues: 1, |
| 5279 | }, |
| 5280 | Server: config.ServerConfig{ |
| 5281 | SecretKey: "test-secret", |
| 5282 | }, |
| 5283 | Transaction: config.TransactionConfig{ |
| 5284 | BatchSize: 100, |
| 5285 | MaxQueueSize: 1000, |
| 5286 | LockDuration: time.Second * 30, |
| 5287 | IndexQueuePrefix: "test_index", |
| 5288 | }, |
| 5289 | } |
| 5290 | config.ConfigStore.Store(cnf) |
| 5291 | |
| 5292 | // Construct the specific transaction queue name |
| 5293 | transactionQueueName := fmt.Sprintf("%s_%d", cnf.Queue.TransactionQueue, 1) |
| 5294 | |
| 5295 | ds, err := database.NewDataSource(cnf) |
| 5296 | require.NoError(t, err, "Failed to create datasource") |
| 5297 | |
| 5298 | ledgerforge, err := NewLedgerForge(ds) |
| 5299 | require.NoError(t, err, "Failed to create LedgerForge instance") |
| 5300 | |
| 5301 | // Start the test Asynq worker to process queued transactions |
| 5302 | cleanupWorker := startTestAsynqWorker(t, cnf, ledgerforge, transactionQueueName) |
| 5303 | defer cleanupWorker() |
| 5304 | |
| 5305 | // Step 1: Create source and destination balances |
| 5306 | sourceBalance := &model.Balance{ |
| 5307 | Currency: "USD", |
| 5308 | LedgerID: "general_ledger_id", |
| 5309 | } |
| 5310 | destBalance := &model.Balance{ |
nothing calls this directly
no test coverage detected