htlcswitch: add basic table driven tests for ExpectedFee

This commit is contained in:
yohei okada 2018-05-29 21:52:07 +09:00
parent b5a228808b
commit 7b37cbd2d9
No known key found for this signature in database
GPG Key ID: D1EBC2E62F2011EE
2 changed files with 54 additions and 1 deletions

@ -94,7 +94,6 @@ type ForwardingPolicy struct {
func ExpectedFee(f ForwardingPolicy,
htlcAmt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
// TODO(roasbeef): write some basic table driven tests
return f.BaseFee + (htlcAmt*f.FeeRate)/1000000
}

@ -4473,3 +4473,57 @@ func TestChannelLinkFail(t *testing.T) {
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)
}
}
}