lnwallet/test: move test cases out of function
This commit is contained in:
parent
3b7f084509
commit
98ec8bf502
@ -341,116 +341,13 @@ func (tc *testContext) extractFundingInput() (*Utxo, *wire.TxOut, error) {
|
||||
return &block1Utxo, txout, nil
|
||||
}
|
||||
|
||||
// TestCommitmentAndHTLCTransactions checks the test vectors specified in
|
||||
// BOLT 03, Appendix C. This deterministically generates commitment and second
|
||||
// level HTLC transactions and checks that they match the expected values.
|
||||
func TestCommitmentAndHTLCTransactions(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tc, err := newTestContext()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Generate random some keys that don't actually matter but need to be set.
|
||||
var (
|
||||
identityKey *btcec.PublicKey
|
||||
localDelayBasePoint *btcec.PublicKey
|
||||
)
|
||||
generateKeys := []**btcec.PublicKey{
|
||||
&identityKey,
|
||||
&localDelayBasePoint,
|
||||
}
|
||||
for _, keyRef := range generateKeys {
|
||||
privkey, err := btcec.NewPrivateKey(btcec.S256())
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to generate new key: %v", err)
|
||||
}
|
||||
*keyRef = privkey.PubKey()
|
||||
}
|
||||
|
||||
// Manually construct a new LightningChannel.
|
||||
channelState := channeldb.OpenChannel{
|
||||
ChanType: channeldb.SingleFunderTweaklessBit,
|
||||
ChainHash: *tc.netParams.GenesisHash,
|
||||
FundingOutpoint: tc.fundingOutpoint,
|
||||
ShortChannelID: tc.shortChanID,
|
||||
IsInitiator: true,
|
||||
IdentityPub: identityKey,
|
||||
LocalChanCfg: channeldb.ChannelConfig{
|
||||
ChannelConstraints: channeldb.ChannelConstraints{
|
||||
DustLimit: tc.dustLimit,
|
||||
MaxPendingAmount: lnwire.NewMSatFromSatoshis(tc.fundingAmount),
|
||||
MaxAcceptedHtlcs: input.MaxHTLCNumber,
|
||||
CsvDelay: tc.localCsvDelay,
|
||||
},
|
||||
MultiSigKey: keychain.KeyDescriptor{
|
||||
PubKey: tc.localFundingPubKey,
|
||||
},
|
||||
PaymentBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: tc.localPaymentBasePoint,
|
||||
},
|
||||
HtlcBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: tc.localPaymentBasePoint,
|
||||
},
|
||||
DelayBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: localDelayBasePoint,
|
||||
},
|
||||
},
|
||||
RemoteChanCfg: channeldb.ChannelConfig{
|
||||
MultiSigKey: keychain.KeyDescriptor{
|
||||
PubKey: tc.remoteFundingPubKey,
|
||||
},
|
||||
PaymentBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: tc.remotePaymentBasePoint,
|
||||
},
|
||||
HtlcBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: tc.remotePaymentBasePoint,
|
||||
},
|
||||
},
|
||||
Capacity: tc.fundingAmount,
|
||||
RevocationProducer: shachain.NewRevocationProducer(zeroHash),
|
||||
}
|
||||
signer := &input.MockSigner{
|
||||
Privkeys: []*btcec.PrivateKey{
|
||||
tc.localFundingPrivKey, tc.localPaymentPrivKey,
|
||||
},
|
||||
NetParams: tc.netParams,
|
||||
}
|
||||
|
||||
// Construct a LightningChannel manually because we don't have nor need all
|
||||
// of the dependencies.
|
||||
channel := LightningChannel{
|
||||
channelState: &channelState,
|
||||
Signer: signer,
|
||||
commitBuilder: NewCommitmentBuilder(&channelState),
|
||||
}
|
||||
err = channel.createSignDesc()
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to generate channel sign descriptor: %v", err)
|
||||
}
|
||||
|
||||
// The commitmentPoint is technically hidden in the spec, but we need it to
|
||||
// generate the correct tweak.
|
||||
tweak := input.SingleTweakBytes(tc.commitmentPoint, tc.localPaymentBasePoint)
|
||||
keys := &CommitmentKeyRing{
|
||||
CommitPoint: tc.commitmentPoint,
|
||||
LocalCommitKeyTweak: tweak,
|
||||
LocalHtlcKeyTweak: tweak,
|
||||
LocalHtlcKey: tc.localPaymentPubKey,
|
||||
RemoteHtlcKey: tc.remotePaymentPubKey,
|
||||
ToLocalKey: tc.localDelayPubKey,
|
||||
ToRemoteKey: tc.remotePaymentPubKey,
|
||||
RevocationKey: tc.localRevocationPubKey,
|
||||
}
|
||||
|
||||
// testCases encode the raw test vectors specified in Appendix C of BOLT 03.
|
||||
testCases := []struct {
|
||||
// testCases encode the raw test vectors specified in Appendix C of BOLT 03.
|
||||
var testCases = []struct {
|
||||
commitment channeldb.ChannelCommitment
|
||||
htlcDescs []htlcDesc
|
||||
expectedCommitmentTxHex string
|
||||
remoteSigHex string
|
||||
}{
|
||||
}{
|
||||
{
|
||||
commitment: channeldb.ChannelCommitment{
|
||||
CommitHeight: 42,
|
||||
@ -728,6 +625,109 @@ func TestCommitmentAndHTLCTransactions(t *testing.T) {
|
||||
expectedCommitmentTxHex: "02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8001c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de8431100400473044022031a82b51bd014915fe68928d1abf4b9885353fb896cac10c3fdd88d7f9c7f2e00220716bda819641d2c63e65d3549b6120112e1aeaf1742eed94a471488e79e206b101473044022064901950be922e62cbe3f2ab93de2b99f37cff9fc473e73e394b27f88ef0731d02206d1dfa227527b4df44a07599289e207d6fd9cca60c0365682dcd3deaf739567e01475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220",
|
||||
remoteSigHex: "3044022064901950be922e62cbe3f2ab93de2b99f37cff9fc473e73e394b27f88ef0731d02206d1dfa227527b4df44a07599289e207d6fd9cca60c0365682dcd3deaf739567e",
|
||||
},
|
||||
}
|
||||
|
||||
// TestCommitmentAndHTLCTransactions checks the test vectors specified in
|
||||
// BOLT 03, Appendix C. This deterministically generates commitment and second
|
||||
// level HTLC transactions and checks that they match the expected values.
|
||||
func TestCommitmentAndHTLCTransactions(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tc, err := newTestContext()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Generate random some keys that don't actually matter but need to be set.
|
||||
var (
|
||||
identityKey *btcec.PublicKey
|
||||
localDelayBasePoint *btcec.PublicKey
|
||||
)
|
||||
generateKeys := []**btcec.PublicKey{
|
||||
&identityKey,
|
||||
&localDelayBasePoint,
|
||||
}
|
||||
for _, keyRef := range generateKeys {
|
||||
privkey, err := btcec.NewPrivateKey(btcec.S256())
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to generate new key: %v", err)
|
||||
}
|
||||
*keyRef = privkey.PubKey()
|
||||
}
|
||||
|
||||
// Manually construct a new LightningChannel.
|
||||
channelState := channeldb.OpenChannel{
|
||||
ChanType: channeldb.SingleFunderTweaklessBit,
|
||||
ChainHash: *tc.netParams.GenesisHash,
|
||||
FundingOutpoint: tc.fundingOutpoint,
|
||||
ShortChannelID: tc.shortChanID,
|
||||
IsInitiator: true,
|
||||
IdentityPub: identityKey,
|
||||
LocalChanCfg: channeldb.ChannelConfig{
|
||||
ChannelConstraints: channeldb.ChannelConstraints{
|
||||
DustLimit: tc.dustLimit,
|
||||
MaxPendingAmount: lnwire.NewMSatFromSatoshis(tc.fundingAmount),
|
||||
MaxAcceptedHtlcs: input.MaxHTLCNumber,
|
||||
CsvDelay: tc.localCsvDelay,
|
||||
},
|
||||
MultiSigKey: keychain.KeyDescriptor{
|
||||
PubKey: tc.localFundingPubKey,
|
||||
},
|
||||
PaymentBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: tc.localPaymentBasePoint,
|
||||
},
|
||||
HtlcBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: tc.localPaymentBasePoint,
|
||||
},
|
||||
DelayBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: localDelayBasePoint,
|
||||
},
|
||||
},
|
||||
RemoteChanCfg: channeldb.ChannelConfig{
|
||||
MultiSigKey: keychain.KeyDescriptor{
|
||||
PubKey: tc.remoteFundingPubKey,
|
||||
},
|
||||
PaymentBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: tc.remotePaymentBasePoint,
|
||||
},
|
||||
HtlcBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: tc.remotePaymentBasePoint,
|
||||
},
|
||||
},
|
||||
Capacity: tc.fundingAmount,
|
||||
RevocationProducer: shachain.NewRevocationProducer(zeroHash),
|
||||
}
|
||||
signer := &input.MockSigner{
|
||||
Privkeys: []*btcec.PrivateKey{
|
||||
tc.localFundingPrivKey, tc.localPaymentPrivKey,
|
||||
},
|
||||
NetParams: tc.netParams,
|
||||
}
|
||||
|
||||
// Construct a LightningChannel manually because we don't have nor need all
|
||||
// of the dependencies.
|
||||
channel := LightningChannel{
|
||||
channelState: &channelState,
|
||||
Signer: signer,
|
||||
commitBuilder: NewCommitmentBuilder(&channelState),
|
||||
}
|
||||
err = channel.createSignDesc()
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to generate channel sign descriptor: %v", err)
|
||||
}
|
||||
|
||||
// The commitmentPoint is technically hidden in the spec, but we need it to
|
||||
// generate the correct tweak.
|
||||
tweak := input.SingleTweakBytes(tc.commitmentPoint, tc.localPaymentBasePoint)
|
||||
keys := &CommitmentKeyRing{
|
||||
CommitPoint: tc.commitmentPoint,
|
||||
LocalCommitKeyTweak: tweak,
|
||||
LocalHtlcKeyTweak: tweak,
|
||||
LocalHtlcKey: tc.localPaymentPubKey,
|
||||
RemoteHtlcKey: tc.remotePaymentPubKey,
|
||||
ToLocalKey: tc.localDelayPubKey,
|
||||
ToRemoteKey: tc.remotePaymentPubKey,
|
||||
RevocationKey: tc.localRevocationPubKey,
|
||||
}
|
||||
|
||||
for i, test := range testCases {
|
||||
|
Loading…
Reference in New Issue
Block a user