forked from TrueCloudLab/frostfs-node
[#932] adm: Move const
to package constants
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
814c411f4a
commit
e2cee4cf09
29 changed files with 140 additions and 114 deletions
|
@ -3,6 +3,7 @@ package initialize
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||
morphUtil "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
@ -28,7 +29,7 @@ func initializeSideChainCmd(cmd *cobra.Command, _ []string) error {
|
|||
|
||||
// 3. Deploy NNS contract.
|
||||
cmd.Println("Stage 3: deploy NNS contract.")
|
||||
if err := morphUtil.DeployNNS(initCtx, morphUtil.DeployMethodName); err != nil {
|
||||
if err := morphUtil.DeployNNS(initCtx, constants.DeployMethodName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package initialize
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||
morphUtil "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
||||
|
@ -10,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func deployContracts(c *morphUtil.InitializeContext) error {
|
||||
alphaCs := c.GetContract(morphUtil.AlphabetContract)
|
||||
alphaCs := c.GetContract(constants.AlphabetContract)
|
||||
|
||||
var keysParam []any
|
||||
|
||||
|
@ -38,7 +39,7 @@ func deployContracts(c *morphUtil.InitializeContext) error {
|
|||
return fmt.Errorf("could not create actor: %w", err)
|
||||
}
|
||||
|
||||
txHash, vub, err := act.SendCall(management.Hash, morphUtil.DeployMethodName, params...)
|
||||
txHash, vub, err := act.SendCall(management.Hash, constants.DeployMethodName, params...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("can't deploy alphabet #%d contract: %w", i, err)
|
||||
}
|
||||
|
@ -46,7 +47,7 @@ func deployContracts(c *morphUtil.InitializeContext) error {
|
|||
c.SentTxs = append(c.SentTxs, morphUtil.HashVUBPair{Hash: txHash, Vub: vub})
|
||||
}
|
||||
|
||||
for _, ctrName := range morphUtil.ContractList {
|
||||
for _, ctrName := range constants.ContractList {
|
||||
cs := c.GetContract(ctrName)
|
||||
|
||||
ctrHash := cs.Hash
|
||||
|
@ -60,12 +61,12 @@ func deployContracts(c *morphUtil.InitializeContext) error {
|
|||
return fmt.Errorf("can't sign manifest group: %v", err)
|
||||
}
|
||||
|
||||
args, err := morphUtil.GetContractDeployData(c, ctrName, keysParam, morphUtil.DeployMethodName)
|
||||
args, err := morphUtil.GetContractDeployData(c, ctrName, keysParam, constants.DeployMethodName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: getting deploy params: %v", ctrName, err)
|
||||
}
|
||||
params := morphUtil.GetContractDeployParameters(cs, args)
|
||||
res, err := c.CommitteeAct.MakeCall(management.Hash, morphUtil.DeployMethodName, params...)
|
||||
res, err := c.CommitteeAct.MakeCall(management.Hash, constants.DeployMethodName, params...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("can't deploy %s contract: %w", ctrName, err)
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-contract/nns"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||
morphUtil "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util"
|
||||
morphClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
|
@ -32,7 +33,7 @@ func setNNS(c *morphUtil.InitializeContext) error {
|
|||
bw := io.NewBufBinWriter()
|
||||
emit.AppCall(bw.BinWriter, nnsCs.Hash, "register", callflag.All,
|
||||
"frostfs", c.CommitteeAcc.Contract.ScriptHash(),
|
||||
morphUtil.FrostfsOpsEmail, int64(3600), int64(600), int64(morphUtil.DefaultExpirationTime), int64(3600))
|
||||
constants.FrostfsOpsEmail, int64(3600), int64(600), int64(constants.DefaultExpirationTime), int64(3600))
|
||||
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
||||
if err := c.SendCommitteeTx(bw.Bytes(), true); err != nil {
|
||||
return fmt.Errorf("can't add domain root to NNS: %w", err)
|
||||
|
@ -42,7 +43,7 @@ func setNNS(c *morphUtil.InitializeContext) error {
|
|||
}
|
||||
}
|
||||
|
||||
alphaCs := c.GetContract(morphUtil.AlphabetContract)
|
||||
alphaCs := c.GetContract(constants.AlphabetContract)
|
||||
for i, acc := range c.Accounts {
|
||||
alphaCs.Hash = state.CreateContractHash(acc.Contract.ScriptHash(), alphaCs.NEF.Checksum, alphaCs.Manifest.Name)
|
||||
|
||||
|
@ -53,7 +54,7 @@ func setNNS(c *morphUtil.InitializeContext) error {
|
|||
c.Command.Printf("NNS: Set %s -> %s\n", domain, alphaCs.Hash.StringLE())
|
||||
}
|
||||
|
||||
for _, ctrName := range morphUtil.ContractList {
|
||||
for _, ctrName := range constants.ContractList {
|
||||
cs := c.GetContract(ctrName)
|
||||
|
||||
domain := ctrName + ".frostfs"
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||
morphUtil "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
|
@ -68,7 +69,7 @@ func registerCandidateRange(c *morphUtil.InitializeContext, start, end int) erro
|
|||
if err != nil {
|
||||
return fmt.Errorf("can't create tx: %w", err)
|
||||
}
|
||||
if err := c.MultiSign(tx, morphUtil.CommitteeAccountName); err != nil {
|
||||
if err := c.MultiSign(tx, constants.CommitteeAccountName); err != nil {
|
||||
return fmt.Errorf("can't sign a transaction: %w", err)
|
||||
}
|
||||
|
||||
|
@ -123,7 +124,7 @@ func transferNEOToAlphabetContracts(c *morphUtil.InitializeContext) error {
|
|||
return err
|
||||
}
|
||||
|
||||
cs := c.GetContract(morphUtil.AlphabetContract)
|
||||
cs := c.GetContract(constants.AlphabetContract)
|
||||
amount := initialAlphabetNEOAmount / len(c.Wallets)
|
||||
|
||||
bw := io.NewBufBinWriter()
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||
cmdConfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/config"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/generate"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/netmap"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/node"
|
||||
|
@ -49,10 +50,10 @@ func TestInitialize(t *testing.T) {
|
|||
testInitialize(t, 16)
|
||||
})
|
||||
t.Run("max nodes", func(t *testing.T) {
|
||||
testInitialize(t, util.MaxAlphabetNodes)
|
||||
testInitialize(t, constants.MaxAlphabetNodes)
|
||||
})
|
||||
t.Run("too many nodes", func(t *testing.T) {
|
||||
require.ErrorIs(t, generateTestData(t, t.TempDir(), util.MaxAlphabetNodes+1), util.ErrTooManyAlphabetNodes)
|
||||
require.ErrorIs(t, generateTestData(t, t.TempDir(), constants.MaxAlphabetNodes+1), util.ErrTooManyAlphabetNodes)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -61,7 +62,7 @@ func testInitialize(t *testing.T, committeeSize int) {
|
|||
v := viper.GetViper()
|
||||
|
||||
require.NoError(t, generateTestData(t, testdataDir, committeeSize))
|
||||
v.Set(util.ProtoConfigPath, filepath.Join(testdataDir, protoFileName))
|
||||
v.Set(constants.ProtoConfigPath, filepath.Join(testdataDir, protoFileName))
|
||||
|
||||
// Set to the path or remove the next statement to download from the network.
|
||||
require.NoError(t, Cmd.Flags().Set(commonflags.ContractsInitFlag, contractsPath))
|
||||
|
@ -119,7 +120,7 @@ func generateTestData(t *testing.T, dir string, size int) error {
|
|||
return fmt.Errorf("wallet doesn't exist: %w", err)
|
||||
}
|
||||
for _, acc := range w.Accounts {
|
||||
if acc.Label == util.SingleAccountName {
|
||||
if acc.Label == constants.SingleAccountName {
|
||||
pub, ok := vm.ParseSignatureContract(acc.Contract.Script)
|
||||
if !ok {
|
||||
return fmt.Errorf("could not parse signature script for %s", acc.Address)
|
||||
|
@ -150,7 +151,7 @@ func setTestCredentials(v *viper.Viper, size int) {
|
|||
for i := 0; i < size; i++ {
|
||||
v.Set("credentials."+innerring.GlagoliticLetter(i).String(), strconv.FormatUint(uint64(i), 10))
|
||||
}
|
||||
v.Set("credentials.contract", util.TestContractPassword)
|
||||
v.Set("credentials.contract", constants.TestContractPassword)
|
||||
}
|
||||
|
||||
func TestNextPollInterval(t *testing.T) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||
morphUtil "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
|
@ -67,7 +68,7 @@ func transferFunds(c *morphUtil.InitializeContext) error {
|
|||
return fmt.Errorf("can't create transfer transaction: %w", err)
|
||||
}
|
||||
|
||||
if err := c.MultiSignAndSend(tx, morphUtil.ConsensusAccountName); err != nil {
|
||||
if err := c.MultiSignAndSend(tx, constants.ConsensusAccountName); err != nil {
|
||||
return fmt.Errorf("can't send transfer transaction: %w", err)
|
||||
}
|
||||
|
||||
|
@ -83,7 +84,7 @@ func transferFundsFinished(c *morphUtil.InitializeContext) (bool, error) {
|
|||
}
|
||||
|
||||
func transferGASToProxy(c *morphUtil.InitializeContext) error {
|
||||
proxyCs := c.GetContract(morphUtil.ProxyContract)
|
||||
proxyCs := c.GetContract(constants.ProxyContract)
|
||||
|
||||
r := nep17.NewReader(c.ReadOnlyInvoker, gas.Hash)
|
||||
bal, err := r.BalanceOf(proxyCs.Hash)
|
||||
|
@ -100,7 +101,7 @@ func transferGASToProxy(c *morphUtil.InitializeContext) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := c.MultiSignAndSend(tx, morphUtil.CommitteeAccountName); err != nil {
|
||||
if err := c.MultiSignAndSend(tx, constants.CommitteeAccountName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package initialize
|
|||
|
||||
import (
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
@ -30,7 +30,7 @@ var Cmd = &cobra.Command{
|
|||
_ = viper.BindPFlag(commonflags.ContainerFeeInitFlag, cmd.Flags().Lookup(containerFeeCLIFlag))
|
||||
_ = viper.BindPFlag(commonflags.ContainerAliasFeeInitFlag, cmd.Flags().Lookup(containerAliasFeeCLIFlag))
|
||||
_ = viper.BindPFlag(commonflags.WithdrawFeeInitFlag, cmd.Flags().Lookup(withdrawFeeCLIFlag))
|
||||
_ = viper.BindPFlag(util.ProtoConfigPath, cmd.Flags().Lookup(util.ProtoConfigPath))
|
||||
_ = viper.BindPFlag(constants.ProtoConfigPath, cmd.Flags().Lookup(constants.ProtoConfigPath))
|
||||
},
|
||||
RunE: initializeSideChainCmd,
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ func initInitCmd() {
|
|||
// Defaults are taken from neo-preodolenie.
|
||||
Cmd.Flags().Uint64(containerFeeCLIFlag, 1000, "Container registration fee")
|
||||
Cmd.Flags().Uint64(containerAliasFeeCLIFlag, 500, "Container alias fee")
|
||||
Cmd.Flags().String(util.ProtoConfigPath, "", "Path to the consensus node configuration")
|
||||
Cmd.Flags().String(constants.ProtoConfigPath, "", "Path to the consensus node configuration")
|
||||
Cmd.Flags().String(commonflags.LocalDumpFlag, "", "Path to the blocks dump file")
|
||||
Cmd.MarkFlagsMutuallyExclusive(commonflags.ContractsInitFlag, commonflags.ContractsURLFlag)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue