Skip to content

Commit

Permalink
address requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JFixby committed Sep 26, 2018
1 parent 5fa3b74 commit 14130e7
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions networkparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package main

import (
"bytes"
"strings"
"testing"

Expand Down Expand Up @@ -50,8 +51,7 @@ func checkPowLimitsAreConsistent(t *testing.T, params *chaincfg.Params) {
// Solved block shouldn't be rejected due to the PoW limit check.
//
// This test ensures these blocks will respect the network PoW limit.
func checkGenesisBlockRespectsNetworkPowLimit(
t *testing.T, params *chaincfg.Params) {
func checkGenesisBlockRespectsNetworkPowLimit(t *testing.T, params *chaincfg.Params) {
genesis := params.GenesisBlock
bits := genesis.Header.Bits

Expand All @@ -72,36 +72,27 @@ func checkGenesisBlockRespectsNetworkPowLimit(
}
}

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>",
networkName,
prefix,
encoded,
// checkPrefix checks if targetString starts with the given prefix
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,
)
t.FailNow()
}
}

func preFillArray(size int, value byte) []byte {
b := make([]byte, size)
for i := 0; i < size; i++ {
b[i] = value
}
return b
}

// checkInterval creates two corner cases defining interval
// of all key values: [ xxxx000000000...0cccc , xxxx111111111...1cccc ],
// where xxxx - is the encoding magic, and cccc is a checksum.
// 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) {
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
maxKey := preFillArray(keySize, 0xff) // all ones
// all zeroes
minKey := bytes.Repeat([]byte{0x00}, keySize)
// all ones
maxKey := bytes.Repeat([]byte{0xff}, keySize)

base58interval := [2]string{
base58.CheckEncode(minKey, magic),
Expand All @@ -114,8 +105,7 @@ func checkInterval(t *testing.T,
// checkAddressPrefixesAreConsistent 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.
func checkAddressPrefixesAreConsistent(t *testing.T,
privateKeyPrefix string, params *chaincfg.Params) {
func checkAddressPrefixesAreConsistent(t *testing.T, privateKeyPrefix string, params *chaincfg.Params) {
P := params.NetworkAddressPrefix

// Desired prefixes
Expand Down

0 comments on commit 14130e7

Please sign in to comment.