Merge pull request #1296 from parakeety/add-tdt

htlcswitch: add basic table driven tests for ExpectedFee
This commit is contained in:
Olaoluwa Osuntokun 2018-06-15 16:36:40 -07:00 committed by GitHub
commit 2f6ff2666c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 1 deletions

View File

@ -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
} }

View File

@ -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)
}
}
}