-
Notifications
You must be signed in to change notification settings - Fork 293
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
main: add address encoding magic constants test #1458
Conversation
Ensures address encoding magics and NetworkAddressPrefix are consistent with each other. This test will light red when a new network is started with incorrect values.
Good catch for the non-pointer |
This test ensures address encoding magics and For example: the test will fail when someone changed Let's say a new network is started and the |
networkparams_test.go
Outdated
@@ -70,13 +72,79 @@ func checkGenesisBlockRespectsNetworkPowLimit( | |||
} | |||
} | |||
|
|||
func checkPrefix(t *testing.T, prefix string, encoded, networkName string) { |
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.
Missing function comment.
networkparams_test.go
Outdated
@@ -49,7 +51,7 @@ func checkPowLimitsAreConsistent(t *testing.T, params chaincfg.Params) { | |||
// | |||
// This test ensures these blocks will respect the network PoW limit. | |||
func checkGenesisBlockRespectsNetworkPowLimit( | |||
t *testing.T, params chaincfg.Params) { | |||
t *testing.T, params *chaincfg.Params) { |
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.
Please put this on the same line as the function def so it is consistent with the rest. Function definitions split on multiple lines causes some undesirable behavior with various tooling.
networkparams_test.go
Outdated
// The interval is mapped to corresponding interval in base 58. | ||
// Then prefixes are checked for mismatch. | ||
func checkInterval(t *testing.T, | ||
desiredPrefix string, keySize int, networkName string, magic [2]byte) { |
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.
Again, same line for func defs.
networkparams_test.go
Outdated
func checkInterval(t *testing.T, | ||
desiredPrefix string, keySize int, networkName string, magic [2]byte) { | ||
// min and max possible keys | ||
minKey := preFillArray(keySize, 0x00) // all zeroes |
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.
Please don't use postfix comments. I know there are a couple of instances of it, but almost nothing in the codebase does and consistency is more important.
networkparams_test.go
Outdated
func checkPrefix(t *testing.T, prefix string, encoded, networkName string) { | ||
if strings.Index(encoded, prefix) != 0 { | ||
t.Logf( | ||
"Address prefix mismatch for <%s>: expected <%s> received <%s>", |
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.
Don't put single params per line like this. It is not consistent with the rest of the code base.
networkparams_test.go
Outdated
} | ||
} | ||
|
||
func preFillArray(size int, value byte) []byte { |
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 function is unnecessary. Use bytes.Repeat
instead.
networkparams_test.go
Outdated
func checkPrefix(t *testing.T, prefix string, targetString, networkName string) { | ||
if strings.Index(targetString, prefix) != 0 { | ||
t.Logf("Address prefix mismatch for <%s>: expected <%s> received <%s>", | ||
networkName, prefix, targetString, |
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.
Closing paren here.
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.
Right.
@JFixby I fixed it for you, but please note the code contribution guidelines for commits in the future. Your commit message was not adhering to them in terms of max width. |
Thank you @davecgh. I may also suggest making a pre-push checklist similar to preflight checklist.
and so on. |
@JFixby There is a Contribution Checklist in the code contribution guidelines. I believe all of this information is in that document. If there is anything missing, I have no objections to PRs which add additional detail. |
Ensures address encoding magics and
params.NetworkAddressPrefix
are consistent with each other. This test will light red when a new network is started with incorrect values.Also there is a minor fix of *pointers for two other tests in this file.