Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
fix(storage): hasSufficientFunds check funds for at least one period
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau committed Aug 3, 2020
1 parent 4cefd59 commit 8d245c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/services/storage/models/agreement.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ export default class Agreement extends Model {
return price <= this.availableFunds ? price : this.availableFunds
}

/**
* Helper which specifies if the Agreement has at the moment of the call
* sufficient funds for at least one more period.
*/
@Column(DataType.VIRTUAL)
get hasSufficientFunds () {
return this.toBePayedOut !== this.availableFunds
return this.availableFunds - this.toBePayedOut >= this.size * this.billingPrice
}
}
12 changes: 11 additions & 1 deletion test/services/storage/models.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const AGREEMENT_TEST_SCHEMA = [
billingPeriod: toSecond(hour),
lastPayout: new Date(Date.now() - day)
},
true
false
],
[
{
Expand All @@ -165,6 +165,16 @@ const AGREEMENT_TEST_SCHEMA = [
},
false
],
[
{
availableFunds: 120,
size: 10,
billingPrice: 10,
billingPeriod: toSecond(hour),
lastPayout: new Date(Date.now() - day)
},
false
],
[
{
availableFunds: 2400,
Expand Down

0 comments on commit 8d245c6

Please sign in to comment.