pollForTransactionFundAllocation polls until the transaction has fund allocation metadata populated
(ctx context.Context, ledgerforge *LedgerForge, transactionID string, expectedCount int, pollInterval, timeout time.Duration)
| 126 | |
| 127 | // pollForTransactionFundAllocation polls until the transaction has fund allocation metadata populated |
| 128 | func pollForTransactionFundAllocation(ctx context.Context, ledgerforge *LedgerForge, transactionID string, expectedCount int, pollInterval, timeout time.Duration) (*TransactionLineage, error) { |
| 129 | timeoutCtx, cancel := context.WithTimeout(ctx, timeout) |
| 130 | defer cancel() |
| 131 | |
| 132 | ticker := time.NewTicker(pollInterval) |
| 133 | defer ticker.Stop() |
| 134 | |
| 135 | for { |
| 136 | select { |
| 137 | case <-timeoutCtx.Done(): |
| 138 | return nil, fmt.Errorf("timed out waiting for transaction %s to have %d fund allocations: %w", |
| 139 | transactionID, expectedCount, timeoutCtx.Err()) |
| 140 | case <-ticker.C: |
| 141 | lineage, err := ledgerforge.GetTransactionLineage(ctx, transactionID) |
| 142 | if err != nil { |
| 143 | continue |
| 144 | } |
| 145 | if len(lineage.FundAllocation) >= expectedCount { |
| 146 | return lineage, nil |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | func TestLineageFullFlow(t *testing.T) { |
| 153 | if testing.Short() { |
no test coverage detected