channeldb: fail migration for accepted hodl invoices

This commit is contained in:
Joost Jager 2019-09-28 08:23:38 +02:00
parent 31f72f6c7d
commit ac7c93f544
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
2 changed files with 31 additions and 0 deletions

@ -69,6 +69,11 @@ func migrateInvoices(tx *bbolt.Tx) error {
return err
}
if invoice.Terms.State == ContractAccepted {
return fmt.Errorf("cannot upgrade with invoice(s) " +
"in accepted state, see release notes")
}
// Try to decode the payment request for every possible net to
// avoid passing a the active network to channeldb. This would
// be a layering violation, while this migration is only running

@ -127,6 +127,32 @@ func TestMigrateInvoices(t *testing.T) {
false)
}
// TestMigrateInvoicesHodl checks that a hodl invoice in the accepted state
// fails the migration.
func TestMigrateInvoicesHodl(t *testing.T) {
t.Parallel()
payReqBtc, err := getPayReq(&bitcoinCfg.MainNetParams)
if err != nil {
t.Fatal(err)
}
invoices := []Invoice{
{
PaymentRequest: []byte(payReqBtc),
Terms: ContractTerm{
State: ContractAccepted,
},
},
}
applyMigration(t,
func(d *DB) { beforeMigrationFuncV11(t, d, invoices) },
func(d *DB) {},
migrateInvoices,
true)
}
// signDigestCompact generates a test signature to be used in the generation of
// test payment requests.
func signDigestCompact(hash []byte) ([]byte, error) {