frostfs-node/cmd/neofs-adm/internal/modules/morph/initialize_test.go

87 lines
2.7 KiB
Go
Raw Normal View History

package morph
import (
"encoding/hex"
"os"
"path/filepath"
"strconv"
"testing"
"github.com/nspcc-dev/neo-go/pkg/config"
"github.com/nspcc-dev/neo-go/pkg/vm"
"github.com/nspcc-dev/neo-go/pkg/wallet"
"github.com/nspcc-dev/neofs-node/pkg/innerring"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)
const contractsPath = "../../../../../../neofs-contract/neofs-contract-v0.16.0.tar.gz"
func TestInitialize(t *testing.T) {
// This test needs neofs-contract tarball, so it is skipped by default.
// It is here for performing local testing after the changes.
t.Skip()
t.Run("4 nodes", func(t *testing.T) {
testInitialize(t, 4)
})
t.Run("7 nodes", func(t *testing.T) {
testInitialize(t, 7)
})
}
func testInitialize(t *testing.T, committeeSize int) {
validatorCount := committeeSize
walletDir := newTempDir(t)
v := viper.GetViper()
v.Set(alphabetWalletsFlag, walletDir)
sizeStr := strconv.FormatUint(uint64(committeeSize), 10)
require.NoError(t, generateAlphabetCmd.Flags().Set(alphabetSizeFlag, sizeStr))
for i := 0; i < committeeSize; i++ {
v.Set("credentials."+innerring.GlagoliticLetter(i).String(), strconv.FormatUint(uint64(i), 10))
}
v.Set("credentials.contract", testContractPassword)
require.NoError(t, generateAlphabetCreds(generateAlphabetCmd, nil))
var pubs []string
for i := 0; i < committeeSize; i++ {
p := filepath.Join(walletDir, innerring.GlagoliticLetter(i).String()+".json")
w, err := wallet.NewWalletFromFile(p)
require.NoError(t, err, "wallet doesn't exist")
for _, acc := range w.Accounts {
if acc.Label == singleAccountName {
pub, ok := vm.ParseSignatureContract(acc.Contract.Script)
require.True(t, ok)
pubs = append(pubs, hex.EncodeToString(pub))
continue
}
}
}
cfg := config.Config{}
cfg.ProtocolConfiguration.ValidatorsCount = validatorCount
cfg.ProtocolConfiguration.SecondsPerBlock = 1
cfg.ProtocolConfiguration.StandbyCommittee = pubs // sorted by glagolic letters
cfg.ProtocolConfiguration.P2PSigExtensions = true
cfg.ProtocolConfiguration.VerifyTransactions = true
data, err := yaml.Marshal(cfg)
require.NoError(t, err)
protoPath := filepath.Join(walletDir, "proto.yml")
require.NoError(t, os.WriteFile(protoPath, data, os.ModePerm))
v.Set(protoConfigPath, protoPath)
// Set to the path or remove the next statement to download from the network.
require.NoError(t, initCmd.Flags().Set(contractsInitFlag, contractsPath))
v.Set(localDumpFlag, filepath.Join(walletDir, "out"))
v.Set(alphabetWalletsFlag, walletDir)
v.Set(epochDurationInitFlag, 1)
v.Set(maxObjectSizeInitFlag, 1024)
require.NoError(t, initializeSideChainCmd(initCmd, nil))
require.NoError(t, forceNewEpochCmd(forceNewEpoch, nil))
}