github.com/decred/dcrlnd@v0.7.6/channeldb/migration13/migration_test.go (about) 1 package migration13 2 3 import ( 4 "testing" 5 6 "github.com/decred/dcrlnd/channeldb/migtest" 7 "github.com/decred/dcrlnd/kvdb" 8 ) 9 10 var ( 11 hex = migtest.Hex 12 13 zeroTime = hex("0000000000000000") 14 noFailureMessage = hex("00") 15 failureReasonUnknown = hex("00") 16 zeroFailureSourceIdx = hex("00000000") 17 18 hash1 = hex("02acee76ebd53d00824410cf6adecad4f50334dac702bd5a2d3ba01b91709f0e") 19 creationInfoAmt1 = hex("00000000004c4b40") 20 creationInfoTime1 = hex("000000005e4fb7ab") // 1582282667 (decimal) 21 creationInfoTimeNano1 = hex("15f565b3cccaee00") // 1582282667000000000 (decimal) 22 creationInfoPayReq1 = hex("00000000") 23 attemptInfo1 = hex("2997a72e129fc9d638ef2fa4e233567d808d4f18a4f087637582427962eb3bf800005ce600000000004c4b402102ec12e83eafe27ce6d03bbe0c0de4b79fe2b9934615c8aa7693f73d2e41b089700000000121028c2dd128c7a6c1a0fceb3e3eb5ed55e0a0ae1a939eb786b097322d830d47db75005ca4000001000000005ce600000000004c4b400000000000") 24 attemptID1 = hex("0000000000000001") 25 paymentID1 = hex("0000000000000001") 26 27 hash2 = hex("62eb3f0a48f954e495d0c14ac63df04a67cefa59dafdbcd3d5046d1f5647840c") 28 preimage2 = hex("479593b7d3cbb45beb22d448451a2f3619b2095adfb38f4d92e9886e96534368") 29 attemptID2 = hex("00000000000003e8") 30 paymentID2 = hex("0000000000000002") 31 attemptInfo2 = hex("8de663f9bb4b8d1ebdb496d22dc1cb657a346215607308549f41b01e2adf2ce900005ce600000000005b8d802102ec12e83eafe27ce6d03bbe0c0de4b79fe2b9934615c8aa7693f73d2e41b089700000000121028c2dd128c7a6c1a0fceb3e3eb5ed55e0a0ae1a939eb786b097322d830d47db75005ca4000001000000005ce600000000005b8d8000000000010000000000000008233d281e2cbe01f0b82dd6750967c9233426b98ae6549c696365f57f86f942a3795b8d80") 32 creationInfoAmt2 = hex("00000000005b8d80") 33 creationInfoTime2 = hex("000000005e4fb97f") // 1582283135 (decimal) 34 creationInfoTimeNano2 = hex("15F56620C3C43600") // 1582283135000000000 (decimal) 35 creationInfoPayReq2 = hex("000000fc6c6e62637274363075317030796c7774367070357674346e377a6a676c39327766397773633939767630307366666e7561376a656d74376d6535373471336b3337346a387373787164717163717a70677370353835357075743937713863747374776b7735796b306a667278736e746e7a6878326a77786a636d3937346c636437327a3564757339717939717371653872336b3578733379367868667366366d6a6e706d717172306661797a677a63336a6b663571787a6c376866787a6666763578667a7679647564327275767974706571787072376868796830726a747574373033333274737774686661616e303773766b6667716b7174667275") 36 37 hash3 = hex("62eb3f0a48f954e495d0c14ac63df04a67cefa59dafdbcd3d5046d1f5647840d") 38 attemptInfo3 = hex("53ce0a4c1507cc5ea00ec88b76bd43a3978ac13605497030b821af6ce9c110f300005ce600000000006acfc02102ec12e83eafe27ce6d03bbe0c0de4b79fe2b9934615c8aa7693f73d2e41b089700000000121028c2dd128c7a6c1a0fceb3e3eb5ed55e0a0ae1a939eb786b097322d830d47db75005ca4000001000000005ce600000000006acfc000000000010000000000000008233044f235354472318b381fad3e21eb5a58f5099918868b0610e7b7bcb7a4adc96acfc0") 39 attemptID3 = hex("00000000000003e9") 40 paymentID3 = hex("0000000000000003") 41 creationInfoAmt3 = hex("00000000006acfc0") 42 creationInfoTime3 = hex("000000005e4fb98d") // 1582283149 43 creationInfoTimeNano3 = hex("15F56624063B4200") // 1582283149000000000 (decimal) 44 creationInfoPayReq3 = hex("000000fc6c6e62637274373075317030796c7776327070357674346e377a6a676c39327766397773633939767630307366666e7561376a656d74376d6535373471336b3337346a387373787364717163717a706773703578707a307964663467336572727a656372376b6e7567307474667630327a7665727a72676b70737375376d6d6564617934687973397179397173717774656479336e666c323534787a36787a75763974746767757a647473356e617a7461616a6735667772686438396b336d70753971726d7a6c3779637a306e30666e6e763077753032726632706e64636c393761646c667636376a7a6e7063677477356434366771323571326e32") 45 46 // pre is the data in the payments root bucket in database version 12 format. 47 pre = map[string]interface{}{ 48 // A failed payment. 49 hash1: map[string]interface{}{ 50 "payment-attempt-info": attemptID1 + attemptInfo1, 51 "payment-creation-info": hash1 + creationInfoAmt1 + creationInfoTime1 + creationInfoPayReq1, 52 "payment-fail-info": hex("03"), 53 "payment-sequence-key": paymentID1, 54 }, 55 56 // A settled payment. 57 hash2: map[string]interface{}{ 58 "payment-attempt-info": attemptID2 + attemptInfo2, 59 "payment-creation-info": hash2 + creationInfoAmt2 + creationInfoTime2 + creationInfoPayReq2, 60 "payment-sequence-key": paymentID2, 61 "payment-settle-info": preimage2, 62 }, 63 64 // An in-flight payment. 65 hash3: map[string]interface{}{ 66 "payment-attempt-info": attemptID3 + attemptInfo3, 67 "payment-creation-info": hash3 + creationInfoAmt3 + creationInfoTime3 + creationInfoPayReq3, 68 "payment-sequence-key": paymentID3, 69 }, 70 } 71 72 // post is the expected data after migration. 73 post = map[string]interface{}{ 74 hash1: map[string]interface{}{ 75 "payment-creation-info": hash1 + creationInfoAmt1 + creationInfoTimeNano1 + creationInfoPayReq1, 76 "payment-fail-info": hex("03"), 77 "payment-htlcs-bucket": map[string]interface{}{ 78 attemptID1: map[string]interface{}{ 79 "htlc-attempt-info": attemptInfo1 + zeroTime, 80 "htlc-fail-info": zeroTime + noFailureMessage + failureReasonUnknown + zeroFailureSourceIdx, 81 }, 82 }, 83 "payment-sequence-key": paymentID1, 84 }, 85 hash2: map[string]interface{}{ 86 "payment-creation-info": hash2 + creationInfoAmt2 + creationInfoTimeNano2 + creationInfoPayReq2, 87 "payment-htlcs-bucket": map[string]interface{}{ 88 attemptID2: map[string]interface{}{ 89 "htlc-attempt-info": attemptInfo2 + zeroTime, 90 "htlc-settle-info": preimage2 + zeroTime, 91 }, 92 }, 93 "payment-sequence-key": paymentID2, 94 }, 95 hash3: map[string]interface{}{ 96 "payment-creation-info": hash3 + creationInfoAmt3 + creationInfoTimeNano3 + creationInfoPayReq3, 97 "payment-htlcs-bucket": map[string]interface{}{ 98 attemptID3: map[string]interface{}{ 99 "htlc-attempt-info": attemptInfo3 + zeroTime, 100 }, 101 }, 102 "payment-sequence-key": paymentID3, 103 }, 104 } 105 ) 106 107 // TestMigrateMpp asserts that the database is properly migrated to the mpp 108 // payment structure. 109 func TestMigrateMpp(t *testing.T) { 110 var paymentsRootBucket = []byte("payments-root-bucket") 111 112 migtest.ApplyMigration( 113 t, 114 func(tx kvdb.RwTx) error { 115 return migtest.RestoreDB(tx, paymentsRootBucket, pre) 116 }, 117 func(tx kvdb.RwTx) error { 118 return migtest.VerifyDB(tx, paymentsRootBucket, post) 119 }, 120 MigrateMPP, 121 false, 122 ) 123 }