generated from bitcoin-sv/template
-
Notifications
You must be signed in to change notification settings - Fork 20
Conform this function to match SV Node calculation #268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d1a9849
add ArcBroadcast abstraction
shruggr a342376
add missing ARC status
shruggr 43ca85f
Conform this function to match SV Node calculation
sirdeggen 2ca2c8c
Refactor fee calculation and add unit tests for calculateFee function
shruggr 578fc89
Merge branch 'feat/arc-broadcast' into fix/feemodel
shruggr d3b8b77
update changelog for v1.2.12
shruggr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package feemodel | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestCalculateFee(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| txSize int | ||
| satoshisPerKB uint64 | ||
| expectedFee uint64 | ||
| description string | ||
| }{ | ||
| { | ||
| name: "240 bytes at 100 sats/KB", | ||
| txSize: 240, | ||
| satoshisPerKB: 100, | ||
| expectedFee: 24, | ||
| description: "240/1000 * 100 = 24 - tests the bug where casting happened before multiplication", | ||
| }, | ||
| { | ||
| name: "240 bytes at 1 sat/KB", | ||
| txSize: 240, | ||
| satoshisPerKB: 1, | ||
| expectedFee: 1, | ||
| description: "Edge case that would pass even with buggy implementation", | ||
| }, | ||
| { | ||
| name: "240 bytes at 10 sats/KB", | ||
| txSize: 240, | ||
| satoshisPerKB: 10, | ||
| expectedFee: 3, | ||
| description: "240/1000 * 10 = 2.4, ceil = 3", | ||
| }, | ||
| { | ||
| name: "250 bytes at 500 sats/KB", | ||
| txSize: 250, | ||
| satoshisPerKB: 500, | ||
| expectedFee: 125, | ||
| description: "250/1000 * 500 = 125", | ||
| }, | ||
| { | ||
| name: "1000 bytes at 100 sats/KB", | ||
| txSize: 1000, | ||
| satoshisPerKB: 100, | ||
| expectedFee: 100, | ||
| description: "1000/1000 * 100 = 100", | ||
| }, | ||
| { | ||
| name: "1500 bytes at 100 sats/KB", | ||
| txSize: 1500, | ||
| satoshisPerKB: 100, | ||
| expectedFee: 150, | ||
| description: "1500/1000 * 100 = 150", | ||
| }, | ||
| { | ||
| name: "1500 bytes at 500 sats/KB", | ||
| txSize: 1500, | ||
| satoshisPerKB: 500, | ||
| expectedFee: 750, | ||
| description: "1500/1000 * 500 = 750", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| fee := calculateFee(tt.txSize, tt.satoshisPerKB) | ||
| require.Equal(t, tt.expectedFee, fee, tt.description) | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the fee calculation. Assuming the fee rate is 100sat/KB, if the
math.Ceil()is over the entire equation, it allows for the fee to be lower than 100 sats for transactions of size lower than 1 KB. If themath.Ceil()is only over thetxSizeBytes / 1000, then the fee will never be lower than 100 sats