-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from LN-Zap/tests
Expand test coverage
- Loading branch information
Showing
4 changed files
with
93 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Dev | ||
name: Main | ||
|
||
on: | ||
push: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ name: Test | |
|
||
on: | ||
push: | ||
branches-ignore: | ||
- master | ||
|
||
jobs: | ||
publish: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,89 @@ | ||
import { expect, test } from "bun:test"; | ||
import { addFeeEstimates } from "../src/util"; | ||
import { | ||
addFeeEstimates, | ||
filterEstimates, | ||
extractMempoolFees, | ||
calculateFees, | ||
} from "../src/util"; | ||
|
||
// Define test data | ||
const mempoolFeeEstimates: MempoolFeeEstimates = { | ||
fastestFee: 500, | ||
halfHourFee: 400, | ||
hourFee: 300, | ||
economyFee: 200, | ||
minimumFee: 100, | ||
}; | ||
const bitcoindFeeEstimates: FeeByBlockTarget = { | ||
1: 300000, | ||
10: 250000, | ||
20: 200000, | ||
}; | ||
const esploraFeeEstimates: FeeByBlockTarget = { | ||
10: 400000, | ||
20: 300000, | ||
30: 150000, | ||
}; | ||
|
||
// Test addFeeEstimates function | ||
test("addFeeEstimates", () => { | ||
const feeByBlockTarget: FeeByBlockTarget = { 1: 100, 2: 200, 3: 300 }; | ||
const newEstimates: FeeByBlockTarget = { 4: 50, 5: 150, 6: 250 }; | ||
const feeByBlockTarget: FeeByBlockTarget = { 1: 500, 2: 400, 3: 300 }; | ||
const newEstimates: FeeByBlockTarget = { 4: 320, 5: 300, 6: 250 }; | ||
|
||
addFeeEstimates(feeByBlockTarget, newEstimates); | ||
|
||
expect(feeByBlockTarget[4]).toEqual(50); | ||
expect(feeByBlockTarget[1]).toEqual(500); | ||
expect(feeByBlockTarget[2]).toEqual(400); | ||
expect(feeByBlockTarget[3]).toEqual(300); | ||
expect(feeByBlockTarget[4]).toBeUndefined(); | ||
expect(feeByBlockTarget[5]).toBeUndefined(); | ||
expect(feeByBlockTarget[6]).toBeUndefined(); | ||
expect(feeByBlockTarget[6]).toEqual(250); | ||
expect(Object.keys(feeByBlockTarget).length).toEqual(4); | ||
}); | ||
|
||
// Test filterEstimates function | ||
test("filterEstimates", () => { | ||
const feeByBlockTarget: FeeByBlockTarget = { 1: 500, 2: 400, 3: 300 }; | ||
const feeMinimum = 350; | ||
|
||
const result = filterEstimates(feeByBlockTarget, feeMinimum); | ||
|
||
expect(result[1]).toEqual(500); | ||
expect(result[2]).toEqual(400); | ||
expect(result[3]).toBeUndefined(); | ||
expect(Object.keys(result).length).toEqual(2); | ||
}); | ||
|
||
// Test extractMempoolFees function | ||
test("extractMempoolFees", () => { | ||
const depth = 3; | ||
|
||
const result: FeeByBlockTarget = extractMempoolFees( | ||
mempoolFeeEstimates, | ||
depth, | ||
); | ||
|
||
expect(result[1]).toEqual(500); | ||
expect(result[3]).toEqual(400); | ||
expect(result[6]).toBeUndefined(); | ||
}); | ||
|
||
// Test calculateFees function | ||
test("calculateFees", () => { | ||
const result: FeeByBlockTarget = calculateFees( | ||
mempoolFeeEstimates, | ||
esploraFeeEstimates, | ||
bitcoindFeeEstimates, | ||
20000, | ||
); | ||
|
||
expect(result[1]).toEqual(500000); | ||
expect(result[2]).toBeUndefined(); | ||
expect(result[3]).toEqual(400000); | ||
expect(result[4]).toBeUndefined(); | ||
expect(result[6]).toEqual(300000); | ||
expect(result[10]).toEqual(250000); | ||
expect(result[20]).toEqual(200000); | ||
expect(result[30]).toBeUndefined(); | ||
expect(Object.keys(result).length).toEqual(5); | ||
}); |