mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-20 02:27:21 +01:00
Merge pull request #1296 from parakeety/add-tdt
htlcswitch: add basic table driven tests for ExpectedFee
This commit is contained in:
commit
2f6ff2666c
@ -94,7 +94,6 @@ type ForwardingPolicy struct {
|
|||||||
func ExpectedFee(f ForwardingPolicy,
|
func ExpectedFee(f ForwardingPolicy,
|
||||||
htlcAmt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
htlcAmt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
||||||
|
|
||||||
// TODO(roasbeef): write some basic table driven tests
|
|
||||||
return f.BaseFee + (htlcAmt*f.FeeRate)/1000000
|
return f.BaseFee + (htlcAmt*f.FeeRate)/1000000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4473,3 +4473,57 @@ func TestChannelLinkFail(t *testing.T) {
|
|||||||
cleanUp()
|
cleanUp()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestExpectedFee tests calculation of ExpectedFee returns expected fee, given
|
||||||
|
// a baseFee, a feeRate, and an htlc amount.
|
||||||
|
func TestExpectedFee(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
baseFee lnwire.MilliSatoshi
|
||||||
|
feeRate lnwire.MilliSatoshi
|
||||||
|
htlcAmt lnwire.MilliSatoshi
|
||||||
|
expected lnwire.MilliSatoshi
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
lnwire.MilliSatoshi(0),
|
||||||
|
lnwire.MilliSatoshi(0),
|
||||||
|
lnwire.MilliSatoshi(0),
|
||||||
|
lnwire.MilliSatoshi(0),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
lnwire.MilliSatoshi(0),
|
||||||
|
lnwire.MilliSatoshi(1),
|
||||||
|
lnwire.MilliSatoshi(999999),
|
||||||
|
lnwire.MilliSatoshi(0),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
lnwire.MilliSatoshi(0),
|
||||||
|
lnwire.MilliSatoshi(1),
|
||||||
|
lnwire.MilliSatoshi(1000000),
|
||||||
|
lnwire.MilliSatoshi(1),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
lnwire.MilliSatoshi(0),
|
||||||
|
lnwire.MilliSatoshi(1),
|
||||||
|
lnwire.MilliSatoshi(1000001),
|
||||||
|
lnwire.MilliSatoshi(1),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
lnwire.MilliSatoshi(1),
|
||||||
|
lnwire.MilliSatoshi(1),
|
||||||
|
lnwire.MilliSatoshi(1000000),
|
||||||
|
lnwire.MilliSatoshi(2),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
f := ForwardingPolicy{
|
||||||
|
BaseFee: test.baseFee,
|
||||||
|
FeeRate: test.feeRate,
|
||||||
|
}
|
||||||
|
fee := ExpectedFee(f, test.htlcAmt)
|
||||||
|
if fee != test.expected {
|
||||||
|
t.Errorf("expected fee to be (%v), instead got (%v)", test.expected,
|
||||||
|
fee)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user