Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wire: Correct fuzz test for MsgCommitSig. #293

Merged
merged 1 commit into from Aug 31, 2017
Merged

wire: Correct fuzz test for MsgCommitSig. #293

merged 1 commit into from Aug 31, 2017

Conversation

davecgh
Copy link
Contributor

@davecgh davecgh commented Aug 29, 2017

This corrects the fuzz test in TestLightningWireProtocol for MsgCommitSig to avoid creating an empty slice since the decoded message only creates a slice when there are greater than zero signatures and an empty slice is not considered equal to a nil slice under reflection.

This can be tested by running the TestLightningWireProtocol 100 times in a loop with and without this change.

For example, here is the redacted output prior to this PR:

$ for i in $(seq 0 1 100); do go test -run TestLightningWireProtocol; done
...
        lnwire_test.go:127: messages don't match after re-encoding: (*lnwire.CommitSig)(0xc04204a900)({
                 ChanID: (lnwire.ChannelID) (len=32 cap=32) 19fda145e1053c5d36890e5169101beeb80875fea036c0b8de1c7bc66c427739,
                 CommitSig: (*btcec.Signature)(0x8bcac0)({
                  R: (*big.Int)(0xc042003260)(63724406601629180062774974542967536251589935445068131219452686511677818569431),
                  S: (*big.Int)(0xc042003280)(18801056069249825825291287104931333862866033135609736119018462340006816851118)
                 }),
                 HtlcSigs: ([]*btcec.Signature) {
                 }
                })
                 vs (*lnwire.CommitSig)(0xc04204a940)({
                 ChanID: (lnwire.ChannelID) (len=32 cap=32) 19fda145e1053c5d36890e5169101beeb80875fea036c0b8de1c7bc66c427739,
                 CommitSig: (*btcec.Signature)(0xc0424fd340)({
                  R: (*big.Int)(0xc042196e60)(63724406601629180062774974542967536251589935445068131219452686511677818569431),
                  S: (*big.Int)(0xc042196e80)(18801056069249825825291287104931333862866033135609736119018462340006816851118)
                 }),
                 HtlcSigs: ([]*btcec.Signature) <nil>
                })
...

With this PR, it successfully ran 100 iterations without fail.

This corrects the fuzz test in TestLightningWireProtocol for
MsgCommitSig to avoid creating an empty slice since the decoded message
only creates a slice when there are greater than zero signatures and an
empty slice is not considered equal to a nil slice under reflection.

This can be tested by running the TestLightningWireProtocol 1000 times
in a loop with and without this change.
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🕺🏾

Once I get your final PR merged in, we'll be able to switch over to using go1.9 in Travis!

@Roasbeef Roasbeef merged commit 42a263b into lightningnetwork:master Aug 31, 2017
@davecgh davecgh deleted the wire_correct_commitsig_test branch August 31, 2017 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants