(t *testing.T)
| 86 | } |
| 87 | |
| 88 | func TestCanProcessTransaction(t *testing.T) { |
| 89 | t.Run("Sufficient funds", func(t *testing.T) { |
| 90 | sourceBalance := &Balance{ |
| 91 | Balance: big.NewInt(500), |
| 92 | } |
| 93 | txn := &Transaction{ |
| 94 | PreciseAmount: Int64ToBigInt(400), |
| 95 | } |
| 96 | err := canProcessTransaction(txn, sourceBalance) |
| 97 | assert.NoError(t, err) |
| 98 | }) |
| 99 | |
| 100 | t.Run("Insufficient funds, no overdraft", func(t *testing.T) { |
| 101 | sourceBalance := &Balance{ |
| 102 | Balance: big.NewInt(500), |
| 103 | } |
| 104 | txn := &Transaction{ |
| 105 | PreciseAmount: Int64ToBigInt(600), |
| 106 | } |
| 107 | err := canProcessTransaction(txn, sourceBalance) |
| 108 | assert.Error(t, err) |
| 109 | assert.EqualError(t, err, "insufficient funds in source balance") |
| 110 | }) |
| 111 | |
| 112 | t.Run("Unconditional overdraft", func(t *testing.T) { |
| 113 | sourceBalance := &Balance{ |
| 114 | Balance: big.NewInt(200), |
| 115 | } |
| 116 | txn := &Transaction{ |
| 117 | PreciseAmount: Int64ToBigInt(1000), |
| 118 | AllowOverdraft: true, |
| 119 | OverdraftLimit: 0, |
| 120 | } |
| 121 | err := canProcessTransaction(txn, sourceBalance) |
| 122 | assert.NoError(t, err) |
| 123 | }) |
| 124 | |
| 125 | t.Run("Overdraft within limit", func(t *testing.T) { |
| 126 | sourceBalance := &Balance{ |
| 127 | Balance: big.NewInt(500), |
| 128 | } |
| 129 | txn := &Transaction{ |
| 130 | PreciseAmount: Int64ToBigInt(1000), // This would result in -500 balance |
| 131 | Precision: 1, |
| 132 | OverdraftLimit: 600, // Limit allows up to -600 |
| 133 | } |
| 134 | err := canProcessTransaction(txn, sourceBalance) |
| 135 | assert.NoError(t, err) |
| 136 | }) |
| 137 | |
| 138 | t.Run("Overdraft exceeding limit", func(t *testing.T) { |
| 139 | sourceBalance := &Balance{ |
| 140 | Balance: big.NewInt(500), |
| 141 | } |
| 142 | txn := &Transaction{ |
| 143 | PreciseAmount: Int64ToBigInt(1200), // This would result in -700 balance |
| 144 | Precision: 1, |
| 145 | OverdraftLimit: 600, // Limit only allows up to -600 |
nothing calls this directly
no test coverage detected