lnwallet/test: make use of test htlcs explicit

Previously whether or not to add test htlcs was implictly controlled by
a nil value of the HtlcDescs test parameter. With the conversion to
json, that nil value got lost.

The reason that the test still passed is because with the fee rate of
the no-htlc test case, the htlcs were trimmed. Also because in the test
json, balances are specified after applying htlcs, the test didn't fail
with a mismatching balance.
This commit is contained in:
Joost Jager 2020-07-13 09:32:19 +02:00
parent fc12656a1a
commit 793b21b79e
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
3 changed files with 35 additions and 6 deletions

@ -4,6 +4,7 @@
"LocalBalance": 7000000000,
"RemoteBalance": 3000000000,
"FeePerKw": 15000,
"UseTestHtlcs": false,
"HtlcDescs": [],
"ExpectedCommitmentTxHex": "02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b80044a010000000000002200202b1b5854183c12d3316565972c4668929d314d81c5dcdbb21cb45fe8a9a8114f4a01000000000000220020e9e86e4823faa62e222ebc858a226636856158f07e69898da3b0d1af0ddb3994c0c62d0000000000220020f3394e1e619b0eca1f91be2fb5ab4dfc59ba5b84ebe014ad1d43a564d012994a508b6a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e04004830450221008266ac6db5ea71aac3c95d97b0e172ff596844851a3216eb88382a8dddfd33d2022050e240974cfd5d708708b4365574517c18e7ae535ef732a3484d43d0d82be9f701483045022100f89034eba16b2be0e5581f750a0a6309192b75cce0f202f0ee2b4ec0cc394850022076c65dc507fe42276152b7a3d90e961e678adbe966e916ecfe85e64d430e75f301475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220",
"RemoteSigHex": "3045022100f89034eba16b2be0e5581f750a0a6309192b75cce0f202f0ee2b4ec0cc394850022076c65dc507fe42276152b7a3d90e961e678adbe966e916ecfe85e64d430e75f3"
@ -13,6 +14,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 644,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "304402205912d91c58016f593d9e46fefcdb6f4125055c41a17b03101eaaa034b9028ab60220520d4d239c85c66e4c75c5b413620b62736e227659d7821b308e2b8ced3e728e",
@ -43,6 +45,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 645,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "30440220446f9e5c375db6a61d6eeee8b59219a30a4a37372afc2670a1a2889c78e9b943022061895f6088fb48b490ab2140a4842c277b64bf25ff591625dd0356e0c96ab7a8",
@ -69,6 +72,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 2060,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "30440220011f999016570bbab9f3125377d0f35096b4dbe155f97c20f71829ead2817d1602201f23f7e17f6928734601c5d8613431eed5c90aa41c3106e8c1cb02ce32aacb5d",
@ -95,6 +99,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 2061,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "3045022100e10744f572a2cd1d787c969e894b792afaed21217ee0480df0112d2fa3ef96ea02202af4f66eb6beebc36d8e98719ed6b4be1b181659fcb561fc491d8cfebff3aa85",
@ -117,6 +122,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 2184,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "304402202e03ba1390998b3487e9a7fefcb66814c09abea0ef1bcc915dbaefbcf310569a02206bd10493a105ac69048e9bcedcb8e3301ef81b55018d911a4afd297297f98d30",
@ -139,6 +145,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 2185,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "304502210094480e38afb41d10fae299224872f19c53abe23c7033a1c0642c48713e7863a10220726dd9456407682667dc4bd9c66975acb3744961770b5002f7eb9c0df9ef2f3e",
@ -157,6 +164,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 3686,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "304402202cfe6618926ca9f1574f8c4659b425e9790b4677ba2248d77901290806130ffe02204ab37bb0287abcdb8b750b018d41a09effe37cb65ff801fa70d3f1a416599841",
@ -175,6 +183,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 3687,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "3045022100b287bb8e079a62dcb3aaa8b6c67c0f434a87ebf64ab0bcfb2fc14b55576b859f02206d37c2eb5fd04cfc9eb0534c76a28a98da251b84a931377cce307af39dfaed74",
@ -189,6 +198,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 4893,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "30450221008db80f8531104820b3e894492b4463f074f965b542e1b5c153ddfb108a5ea642022030b203d857a2b3581c2087a7bf17c95d04fadc1c6cdae88c620477f2dccb1ee4",
@ -203,6 +213,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 4894,
"UseTestHtlcs": true,
"HtlcDescs": [],
"ExpectedCommitmentTxHex": "02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b80044a010000000000002200202b1b5854183c12d3316565972c4668929d314d81c5dcdbb21cb45fe8a9a8114f4a01000000000000220020e9e86e4823faa62e222ebc858a226636856158f07e69898da3b0d1af0ddb3994c0c62d0000000000220020f3394e1e619b0eca1f91be2fb5ab4dfc59ba5b84ebe014ad1d43a564d012994ad0886a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e04004830450221009f16ac85d232e4eddb3fcd750a68ebf0b58e3356eaada45d3513ede7e817bf4c02207c2b043b4e5f971261975406cb955219fa56bffe5d834a833694b5abc1ce4cfd01483045022100e784a66b1588575801e237d35e510fd92a81ae3a4a2a1b90c031ad803d07b3f3022021bc5f16501f167607d63b681442da193eb0a76b4b7fd25c2ed4f8b28fd35b9501475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220",
"RemoteSigHex": "3045022100e784a66b1588575801e237d35e510fd92a81ae3a4a2a1b90c031ad803d07b3f3022021bc5f16501f167607d63b681442da193eb0a76b4b7fd25c2ed4f8b28fd35b95"

@ -4,6 +4,7 @@
"LocalBalance": 7000000000,
"RemoteBalance": 3000000000,
"FeePerKw": 15000,
"UseTestHtlcs": false,
"HtlcDescs": [],
"ExpectedCommitmentTxHex": "02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8002c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de84311054a56a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0400473044022051b75c73198c6deee1a875871c3961832909acd297c6b908d59e3319e5185a46022055c419379c5051a78d00dbbce11b5b664a0c22815fbcc6fcef6b1937c383693901483045022100f51d2e566a70ba740fc5d8c0f07b9b93d2ed741c3c0860c613173de7d39e7968022041376d520e9c0e1ad52248ddf4b22e12be8763007df977253ef45a4ca3bdb7c001475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220",
"RemoteSigHex": "3045022100f51d2e566a70ba740fc5d8c0f07b9b93d2ed741c3c0860c613173de7d39e7968022041376d520e9c0e1ad52248ddf4b22e12be8763007df977253ef45a4ca3bdb7c0"
@ -13,6 +14,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 647,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "30440220385a5afe75632f50128cbb029ee95c80156b5b4744beddc729ad339c9ca432c802202ba5f48550cad3379ac75b9b4fedb86a35baa6947f16ba5037fb8b11ab343740",
@ -43,6 +45,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 648,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "3044022062ef2e77591409d60d7817d9bb1e71d3c4a2931d1a6c7c8307422c84f001a251022022dad9726b0ae3fe92bda745a06f2c00f92342a186d84518588cf65f4dfaada8",
@ -69,6 +72,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 2069,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "3045022100d1cf354de41c1369336cf85b225ed033f1f8982a01be503668df756a7e668b66022001254144fb4d0eecc61908fccc3388891ba17c5d7a1a8c62bdd307e5a513f992",
@ -95,6 +99,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 2070,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "3045022100eed143b1ee4bed5dc3cde40afa5db3e7354cbf9c44054b5f713f729356f08cf7022077161d171c2bbd9badf3c9934de65a4918de03bbac1450f715275f75b103f891",
@ -117,6 +122,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 2194,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "30450221009ed2f0a67f99e29c3c8cf45c08207b765980697781bb727fe0b1416de0e7622902206052684229bc171419ed290f4b615c943f819c0262414e43c5b91dcf72ddcf44",
@ -139,6 +145,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 2195,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "3045022100a8a78fa1016a5c5c3704f2e8908715a3cef66723fb95f3132ec4d2d05cd84fb4022025ac49287b0861ec21932405f5600cbce94313dbde0e6c5d5af1b3366d8afbfc",
@ -157,6 +164,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 3702,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "3045022100dfb73b4fe961b31a859b2bb1f4f15cabab9265016dd0272323dc6a9e85885c54022059a7b87c02861ee70662907f25ce11597d7b68d3399443a831ae40e777b76bdb",
@ -175,6 +183,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 3703,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "3044022044f65cf833afdcb9d18795ca93f7230005777662539815b8a601eeb3e57129a902206a4bf3e53392affbba52640627defa8dc8af61c958c9e827b2798ab45828abdd",
@ -189,6 +198,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 4914,
"UseTestHtlcs": true,
"HtlcDescs": [
{
"RemoteSigHex": "3045022100fcb38506bfa11c02874092a843d0cc0a8613c23b639832564a5f69020cb0f6ba02206508b9e91eaa001425c190c68ee5f887e1ad5b1b314002e74db9dbd9e42dbecf",
@ -203,6 +213,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 4915,
"UseTestHtlcs": true,
"HtlcDescs": [],
"ExpectedCommitmentTxHex": "02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8002c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de843110fa926a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0400483045022100a012691ba6cea2f73fa8bac37750477e66363c6d28813b0bb6da77c8eb3fb0270220365e99c51304b0b1a6ab9ea1c8500db186693e39ec1ad5743ee231b0138384b90147304402200769ba89c7330dfa4feba447b6e322305f12ac7dac70ec6ba997ed7c1b598d0802204fe8d337e7fee781f9b7b1a06e580b22f4f79d740059560191d7db53f876555201475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220",
"RemoteSigHex": "304402200769ba89c7330dfa4feba447b6e322305f12ac7dac70ec6ba997ed7c1b598d0802204fe8d337e7fee781f9b7b1a06e580b22f4f79d740059560191d7db53f8765552"
@ -212,6 +223,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 9651180,
"UseTestHtlcs": true,
"HtlcDescs": [],
"ExpectedCommitmentTxHex": "02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b800222020000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80ec0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de84311004004730440220514f977bf7edc442de8ce43ace9686e5ebdc0f893033f13e40fb46c8b8c6e1f90220188006227d175f5c35da0b092c57bea82537aed89f7778204dc5bacf4f29f2b901473044022037f83ff00c8e5fb18ae1f918ffc24e54581775a20ff1ae719297ef066c71caa9022039c529cccd89ff6c5ed1db799614533844bd6d101da503761c45c713996e3bbd01475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220",
"RemoteSigHex": "3044022037f83ff00c8e5fb18ae1f918ffc24e54581775a20ff1ae719297ef066c71caa9022039c529cccd89ff6c5ed1db799614533844bd6d101da503761c45c713996e3bbd"
@ -221,6 +233,7 @@
"LocalBalance": 6988000000,
"RemoteBalance": 3000000000,
"FeePerKw": 9651181,
"UseTestHtlcs": true,
"HtlcDescs": [],
"ExpectedCommitmentTxHex": "02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8001c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de8431100400473044022031a82b51bd014915fe68928d1abf4b9885353fb896cac10c3fdd88d7f9c7f2e00220716bda819641d2c63e65d3549b6120112e1aeaf1742eed94a471488e79e206b101473044022064901950be922e62cbe3f2ab93de2b99f37cff9fc473e73e394b27f88ef0731d02206d1dfa227527b4df44a07599289e207d6fd9cca60c0365682dcd3deaf739567e01475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220",
"RemoteSigHex": "3044022064901950be922e62cbe3f2ab93de2b99f37cff9fc473e73e394b27f88ef0731d02206d1dfa227527b4df44a07599289e207d6fd9cca60c0365682dcd3deaf739567e"

@ -139,10 +139,15 @@ type htlcDesc struct {
}
type testCase struct {
Name string
LocalBalance lnwire.MilliSatoshi
RemoteBalance lnwire.MilliSatoshi
FeePerKw btcutil.Amount
Name string
LocalBalance lnwire.MilliSatoshi
RemoteBalance lnwire.MilliSatoshi
FeePerKw btcutil.Amount
// UseTestHtlcs defined whether the fixed set of test htlc should be
// added to the channel before checking the commitment assertions.
UseTestHtlcs bool
HtlcDescs []htlcDesc
ExpectedCommitmentTxHex string
RemoteSigHex string
@ -252,7 +257,7 @@ func testVectors(t *testing.T, chanType channeldb.ChannelType, test testCase) {
remoteBalance := test.RemoteBalance
localBalance := test.LocalBalance
if test.HtlcDescs != nil {
if test.UseTestHtlcs {
for _, htlc := range testHtlcs {
if htlc.incoming {
remoteBalance += htlc.amount
@ -276,7 +281,7 @@ func testVectors(t *testing.T, chanType channeldb.ChannelType, test testCase) {
// map that allows us to identify the htlcs in the scripts later on and
// retrieve the corresponding preimage.
var hash160map map[[20]byte]lntypes.Preimage
if test.HtlcDescs != nil {
if test.UseTestHtlcs {
hash160map = addTestHtlcs(t, remoteChannel, localChannel)
}