Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
fix payment threshold bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Nigel Christian committed Apr 8, 2021
1 parent 36c3ea7 commit b438f12
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gitpayd",
"version": "0.1.8",
"version": "0.1.9",
"description": "Github Workflows + BTC / LND, gitpayd watches your repo for new commits and sends payments to contributors",
"scripts": {
"clean": "rm -rf dist/",
Expand Down
3 changes: 1 addition & 2 deletions src/noops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const isValidPayment = (issueAmount: string, balance: number): boolean => {
return (
NUM_AMT > 0 &&
NUM_AMT < MAX_PAYMENT &&
balance >= NUM_AMT &&
NUM_AMT < PAYMENT_THRESHOLD
(balance - PAYMENT_THRESHOLD) > NUM_AMT
);
};

Expand Down
17 changes: 16 additions & 1 deletion test/test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AuthorizedRoles, splitter, validateCollaborators } from './util/test-util';
import { AuthorizedRoles, isValidPayment, splitter, validateCollaborators } from './util/test-util';
import { strict as assert } from 'assert';

const BODY: string = "Bounty: 100000";
Expand Down Expand Up @@ -26,4 +26,19 @@ describe('Test helper function for author validation', () => {
const check = validateCollaborators(AuthorizedRoles.COLLABORATOR);
assert.strictEqual(check, true);
});
});

describe('Test helper function for payment validation', () => {
it('should return true valid payment', () => {
const check = isValidPayment("10000", 400000);
assert.strictEqual(check, true);
});
it('should return false if above maximum allowable payment', () => {
const check = isValidPayment("100001", 400000);
assert.strictEqual(check, false);
});
it('should return false if it breaks threshold', () => {
const check = isValidPayment("10000", 209000);
assert.strictEqual(check, false);
});
});
18 changes: 18 additions & 0 deletions test/util/test-util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// TODO: fix yargs breaking test.
// This is duplicated form ../util/util.ts

const TEST_MAX_PAYMENT = 100000;
const TEST_PAYMENT_THRESHOLD = 200000;

/**
* Authorized roles
*/
Expand Down Expand Up @@ -29,4 +32,19 @@ export const validateCollaborators = (role: AuthorizedRoles): boolean => {
return (
role === AuthorizedRoles.COLLABORATOR || role === AuthorizedRoles.OWNER
);
};

/**
* Run payment validity logic
* @param issueAmount - issue bounty
* @param balance - balance of the lightning node gitpayd connects to
* @returns
*/
export const isValidPayment = (issueAmount: string, balance: number): boolean => {
const NUM_AMT = parseInt(issueAmount, 10);
return (
NUM_AMT > 0 &&
NUM_AMT < TEST_MAX_PAYMENT &&
(balance - TEST_PAYMENT_THRESHOLD) > NUM_AMT
);
};

0 comments on commit b438f12

Please sign in to comment.