[#1959] neofs-adm: Allow to test all commands with a local dump
Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
parent
8648b102db
commit
02bea52f40
3 changed files with 26 additions and 6 deletions
|
@ -126,13 +126,10 @@ func newInitializeContext(cmd *cobra.Command, v *viper.Viper) (*initializeContex
|
||||||
|
|
||||||
var c Client
|
var c Client
|
||||||
if v.GetString(localDumpFlag) != "" {
|
if v.GetString(localDumpFlag) != "" {
|
||||||
if cmd.Name() != "init" {
|
|
||||||
return nil, errors.New("dump creation is only supported for `init` command")
|
|
||||||
}
|
|
||||||
if v.GetString(endpointFlag) != "" {
|
if v.GetString(endpointFlag) != "" {
|
||||||
return nil, fmt.Errorf("`%s` and `%s` flags are mutually exclusive", endpointFlag, localDumpFlag)
|
return nil, fmt.Errorf("`%s` and `%s` flags are mutually exclusive", endpointFlag, localDumpFlag)
|
||||||
}
|
}
|
||||||
c, err = newLocalClient(v, wallets)
|
c, err = newLocalClient(cmd, v, wallets)
|
||||||
} else {
|
} else {
|
||||||
c, err = getN3Client(v)
|
c, err = getN3Client(v)
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,4 +70,5 @@ func TestInitialize(t *testing.T) {
|
||||||
v.Set(epochDurationInitFlag, 1)
|
v.Set(epochDurationInitFlag, 1)
|
||||||
v.Set(maxObjectSizeInitFlag, 1024)
|
v.Set(maxObjectSizeInitFlag, 1024)
|
||||||
require.NoError(t, initializeSideChainCmd(initCmd, nil))
|
require.NoError(t, initializeSideChainCmd(initCmd, nil))
|
||||||
|
require.NoError(t, forceNewEpochCmd(forceNewEpoch, nil))
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -50,7 +51,7 @@ type localClient struct {
|
||||||
maxGasInvoke int64
|
maxGasInvoke int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func newLocalClient(v *viper.Viper, wallets []*wallet.Wallet) (*localClient, error) {
|
func newLocalClient(cmd *cobra.Command, v *viper.Viper, wallets []*wallet.Wallet) (*localClient, error) {
|
||||||
cfg, err := config.LoadFile(v.GetString(protoConfigPath))
|
cfg, err := config.LoadFile(v.GetString(protoConfigPath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -88,9 +89,30 @@ func newLocalClient(v *viper.Viper, wallets []*wallet.Wallet) (*localClient, err
|
||||||
|
|
||||||
go bc.Run()
|
go bc.Run()
|
||||||
|
|
||||||
|
dumpPath := v.GetString(localDumpFlag)
|
||||||
|
if cmd.Name() != "init" {
|
||||||
|
f, err := os.OpenFile(dumpPath, os.O_RDONLY, 0600)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't open local dump: %w", err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
r := io.NewBinReaderFromIO(f)
|
||||||
|
|
||||||
|
var skip uint32
|
||||||
|
if bc.BlockHeight() != 0 {
|
||||||
|
skip = bc.BlockHeight() + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
count := r.ReadU32LE() - skip
|
||||||
|
if err := chaindump.Restore(bc, r, skip, count, nil); err != nil {
|
||||||
|
return nil, fmt.Errorf("can't restore local dump: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &localClient{
|
return &localClient{
|
||||||
bc: bc,
|
bc: bc,
|
||||||
dumpPath: v.GetString(localDumpFlag),
|
dumpPath: dumpPath,
|
||||||
accounts: accounts[:m],
|
accounts: accounts[:m],
|
||||||
maxGasInvoke: 15_0000_0000,
|
maxGasInvoke: 15_0000_0000,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
Loading…
Reference in a new issue