forked from xplorfin/lndmock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bolt11.go
70 lines (59 loc) · 2.09 KB
/
bolt11.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package mock
import (
"encoding/hex"
"fmt"
"testing"
"time"
"github.com/brianvoe/gofakeit/v5"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/zpay32"
)
var params = chaincfg.MainNetParams
// MockLndInvoiceMainnet creates a mock lnd invoice on mainnet and returns the encoded
// and decoded *zpay32.Invoice object
func MockLndInvoiceMainnet(t *testing.T) (encoded string, decoded *zpay32.Invoice) { // nolint
// amounts from https://git.io/JttyN
var (
testPaymentHash [32]byte
testDescriptionHash [32]byte
)
testPrivKeyBytes, _ := hex.DecodeString("e126f68f7eafcc8b74f54d269fe206be715000f94dac067d1c04a8ca3b2db734")
testPrivKey, testPubKey := btcec.PrivKeyFromBytes(btcec.S256(), testPrivKeyBytes)
testMessageSigner := zpay32.MessageSigner{
SignCompact: func(hash []byte) ([]byte, error) {
sig, err := btcec.SignCompact(btcec.S256(),
testPrivKey, hash, true)
if err != nil {
return nil, fmt.Errorf("can't sign the "+
"message: %v", err)
}
return sig, nil
},
}
testDescription := gofakeit.Sentence(10)
testAmount := lnwire.MilliSatoshi(gofakeit.RandomUint([]uint{2400000000000, 250000000, 2000000000}))
testPaymentHashSlice, _ := hex.DecodeString("0001020304050607080900010203040506070809000102030405060708090102")
testDescriptionHashSlice := chainhash.HashB([]byte(gofakeit.Sentence(20)))
copy(testPaymentHash[:], testPaymentHashSlice[:])
copy(testDescriptionHash[:], testDescriptionHashSlice[:])
decoded = &zpay32.Invoice{
Net: ¶ms,
MilliSat: &testAmount,
Timestamp: gofakeit.DateRange(time.Now().AddDate(-1, 0, 0), time.Now()),
//DescriptionHash: &testDescriptionHash,
PaymentHash: &testPaymentHash,
Description: &testDescription,
Destination: testPubKey,
// If no features were set, we'll populate an empty feature vector.
Features: lnwire.NewFeatureVector(
nil, lnwire.Features),
}
encoded, err := decoded.Encode(testMessageSigner)
if err != nil {
t.Error(err)
}
return encoded, decoded
}