mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-20 08:31:11 +00:00
118 lines
4.5 KiB
Go
118 lines
4.5 KiB
Go
|
package params
|
||
|
|
||
|
import (
|
||
|
"path"
|
||
|
"strings"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
||
|
)
|
||
|
|
||
|
func TestLoadConfigFile(t *testing.T) {
|
||
|
mainnetConfigFile := ConfigFilePath(t, "mainnet")
|
||
|
LoadChainConfigFile(mainnetConfigFile)
|
||
|
if BeaconConfig().MaxCommitteesPerSlot != MainnetConfig().MaxCommitteesPerSlot {
|
||
|
t.Errorf("Expected MaxCommitteesPerSlot to be set to mainnet value: %d found: %d",
|
||
|
MainnetConfig().MaxCommitteesPerSlot,
|
||
|
BeaconConfig().MaxCommitteesPerSlot)
|
||
|
}
|
||
|
if BeaconConfig().SecondsPerSlot != MainnetConfig().SecondsPerSlot {
|
||
|
t.Errorf("Expected SecondsPerSlot to be set to mainnet value: %d found: %d",
|
||
|
MainnetConfig().SecondsPerSlot,
|
||
|
BeaconConfig().SecondsPerSlot)
|
||
|
}
|
||
|
minimalConfigFile := ConfigFilePath(t, "minimal")
|
||
|
LoadChainConfigFile(minimalConfigFile)
|
||
|
if BeaconConfig().MaxCommitteesPerSlot != MinimalSpecConfig().MaxCommitteesPerSlot {
|
||
|
t.Errorf("Expected MaxCommitteesPerSlot to be set to minimal value: %d found: %d",
|
||
|
MinimalSpecConfig().MaxCommitteesPerSlot,
|
||
|
BeaconConfig().MaxCommitteesPerSlot)
|
||
|
}
|
||
|
if BeaconConfig().SecondsPerSlot != MinimalSpecConfig().SecondsPerSlot {
|
||
|
t.Errorf("Expected SecondsPerSlot to be set to minimal value: %d found: %d",
|
||
|
MinimalSpecConfig().SecondsPerSlot,
|
||
|
BeaconConfig().SecondsPerSlot)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func Test_replaceHexStringWithYAMLFormat(t *testing.T) {
|
||
|
|
||
|
testLines := []struct {
|
||
|
line string
|
||
|
wanted string
|
||
|
}{
|
||
|
{
|
||
|
line: "ONE_BYTE: 0x41",
|
||
|
wanted: "ONE_BYTE: 65\n",
|
||
|
},
|
||
|
{
|
||
|
line: "FOUR_BYTES: 0x41414141",
|
||
|
wanted: "FOUR_BYTES: \n- 65\n- 65\n- 65\n- 65\n",
|
||
|
},
|
||
|
{
|
||
|
line: "THREE_BYTES: 0x414141",
|
||
|
wanted: "THREE_BYTES: \n- 65\n- 65\n- 65\n- 0\n",
|
||
|
},
|
||
|
{
|
||
|
line: "EIGHT_BYTES: 0x4141414141414141",
|
||
|
wanted: "EIGHT_BYTES: \n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n",
|
||
|
},
|
||
|
{
|
||
|
line: "SIXTEEN_BYTES: 0x41414141414141414141414141414141",
|
||
|
wanted: "SIXTEEN_BYTES: \n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
||
|
"- 65\n- 65\n- 65\n- 65\n",
|
||
|
},
|
||
|
{
|
||
|
line: "TWENTY_BYTES: 0x4141414141414141414141414141414141414141",
|
||
|
wanted: "TWENTY_BYTES: \n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
||
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n",
|
||
|
},
|
||
|
{
|
||
|
line: "THIRTY_TWO_BYTES: 0x4141414141414141414141414141414141414141414141414141414141414141",
|
||
|
wanted: "THIRTY_TWO_BYTES: \n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
||
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
||
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n",
|
||
|
},
|
||
|
{
|
||
|
line: "FORTY_EIGHT_BYTES: 0x41414141414141414141414141414141414141414141414141414141414141414141" +
|
||
|
"4141414141414141414141414141",
|
||
|
wanted: "FORTY_EIGHT_BYTES: \n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
||
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
||
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
||
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n",
|
||
|
},
|
||
|
{
|
||
|
line: "NINETY_SIX_BYTES: 0x414141414141414141414141414141414141414141414141414141414141414141414141" +
|
||
|
"4141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141" +
|
||
|
"41414141414141414141414141",
|
||
|
wanted: "NINETY_SIX_BYTES: \n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
||
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
||
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
||
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
||
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
||
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
||
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n",
|
||
|
},
|
||
|
}
|
||
|
for _, line := range testLines {
|
||
|
parts := replaceHexStringWithYAMLFormat(line.line)
|
||
|
res := strings.Join(parts, "\n")
|
||
|
|
||
|
if res != line.wanted {
|
||
|
t.Errorf("expected conversion to be: %v got: %v", line.wanted, res)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ConfigFilePath sets the proper config and returns the relevant
|
||
|
// config file path from eth2-spec-tests directory.
|
||
|
func ConfigFilePath(t *testing.T, config string) string {
|
||
|
configFolderPath := path.Join("tests", config)
|
||
|
filepath, err := bazel.Runfile(configFolderPath)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
configFilePath := path.Join(filepath, "config.yaml")
|
||
|
return configFilePath
|
||
|
}
|