Skip to content

Commit d3cfe70

Browse files
authored
fix paych vouchers make check (#538)
Signed-off-by: turuslan <[email protected]>
1 parent 132cdf0 commit d3cfe70

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

core/paych/vouchers.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,11 @@ namespace fc::paych_vouchers {
174174
std::unique_lock lock{mutex};
175175
OUTCOME_TRY(ctx, loadCtx(paych));
176176
OUTCOME_TRY(laneStates(ctx));
177-
if (amount <= laneRedeem(ctx, lane)) {
177+
const TokenAmount delta{amount - laneRedeem(ctx, lane)};
178+
if (delta <= 0) {
178179
return ERROR_TEXT("PaychVouchers::make voucher adds no value");
179180
}
180-
if (*ctx.total + amount > ctx.balance) {
181+
if (*ctx.total + delta > ctx.balance) {
181182
return ERROR_TEXT("PaychVouchers::make insufficient balance");
182183
}
183184
SignedVoucher voucher;

test/core/paych/vouchers_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,7 @@ namespace fc::paych_vouchers {
124124
checkFails(voucher);
125125
EXPECT_EQ(addOk(voucher, voucher.amount), 0);
126126
makeFails(1, balance - voucher.amount + 1);
127+
makeFails(0, voucher.amount);
128+
makeOk(0, voucher.amount + 1);
127129
}
128130
} // namespace fc::paych_vouchers

0 commit comments

Comments
 (0)