-
Notifications
You must be signed in to change notification settings - Fork 170
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
feat: Create datagen testutil for common random generation functions #55
Conversation
func GenRandomBtcdHeader(version int32, bits uint32, nonce uint32, | ||
timeInt int64, prevBlockStr string, merkleRootStr string) *wire.BlockHeader { |
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.
One useful function would be to create a header that extends a parent.
In that case you already have a parent hash, but you can also reuse the same version, and make sure the time is incremented by a random amount, but isn't less.
That can be used to generate a full block tree, recursively.
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.
Yep that would be super useful and I intend to implement it when doing keeper tests. Let's implement it when it is needed.
x/btclightclient/types/msgs_test.go
Outdated
// If the header hex is the same as the default one, then this is the seed input | ||
headerBytes := bbl.NewBTCHeaderBytesFromBlockHeader(btcdHeader) | ||
headerHex := headerBytes.MarshalHex() | ||
seedInput := types.DefaultBaseHeaderHex == headerHex | ||
|
||
// Make the address have a proper size | ||
if len(addressBytes) == 0 || len(addressBytes) >= 256 { | ||
addressBytes = genRandomByteArray(1 + uint64(rand.Intn(257))) | ||
addressBytes = datagen.GenRandomByteArray(1 + uint64(rand.Intn(257))) |
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.
Why the 1 +
? It looks like this will go up to 257.
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 catch!
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 an useful, even though I don't fully understand the sizes in the tests.
Might be useful in #47 since it uses similar functions with the ones used on the
btclightclient
module.