-
Notifications
You must be signed in to change notification settings - Fork 19
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
reporter: refactor reporter, datagen and fuzz tests on block handlers #95
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Some comments about testing more cases:
reporter/utils_test.go
Outdated
return mockBTCClient, mockBabylonClient, reporter | ||
} | ||
|
||
// FuzzProcessHeaders is a fuzz tests for ProcessHeaders() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// FuzzProcessHeaders is a fuzz tests for ProcessHeaders() | |
// FuzzProcessHeaders fuzz tests ProcessHeaders() |
} | ||
|
||
// FuzzProcessHeaders is a fuzz tests for ProcessHeaders() | ||
// - Data: a number of random blocks, with or without Babylon txs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case seems to test the submission of only one block. We should also test this with multiple blocks. To make this realistic, once a block does not exist then all of its descendants won't exist as well. So we can do:
- Randomly identify the total number of blocks and generate them.
- Randomly identify the number of those blocks that exist on Babylon. Can be [0, N], where N is the total number of blocks. The first set of headers up to this number exist on Babylon, the rest do not.
- Verify that only the required headers were submitted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, done
reporter/utils_test.go
Outdated
}) | ||
} | ||
|
||
// FuzzProcessCheckpoints is a fuzz tests for ProcessCheckpoints() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// FuzzProcessCheckpoints is a fuzz tests for ProcessCheckpoints() | |
// FuzzProcessCheckpoints fuzz tests ProcessCheckpoints() |
reporter/utils_test.go
Outdated
mockBabylonClient.EXPECT().MustInsertBTCSpvProof(gomock.Any()).Return(&sdk.TxResponse{Code: 0}).AnyTimes() | ||
|
||
containsCkpt := datagen.OneInN(2) | ||
containsCkpt = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is always true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, it was from a debugging attempt. Good catch!
} | ||
|
||
// FuzzProcessCheckpoints is a fuzz tests for ProcessCheckpoints() | ||
// - Data: a number of random blocks, with or without Babylon txs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests only a single block.
reporter/utils_test.go
Outdated
|
||
containsCkpt := datagen.OneInN(2) | ||
containsCkpt = true | ||
block, _ := vdatagen.GenRandomBlock(containsCkpt, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this only contains one half of the checkpoint? Maybe we should test for this case as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, done
@@ -68,6 +68,40 @@ func GenRandomTx() *wire.MsgTx { | |||
return tx | |||
} | |||
|
|||
func GenRandomBabylonTxPair() ([]*wire.MsgTx, *btctxformatter.RawBtcCheckpoint) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
ProcessHeaders
Partially fixes BM-156
This PR aims at implementing fuzz tests for reporter's
ProcessHeaders
function. Along the way, it does some refactoring for mocking the reporter. Specifically, this PRReporter
GenRandomBlockchainWithBabylonTx
that generates a blockchain in which blocks may contain some Babylon txsProcessHeaders
, where given a block that may or may not be duplicated on Babylon BTCLightclient, check whether the reporter does the deduplication correctly or not.ProcessCheckpoints
, where given a block that may or may not contain a pair of Babylon txs, check whether the reporter extracts correct checkpoint segments and matches checkpoint segments correctly.