Skip to content

Commit

Permalink
container: Test migration
Browse files Browse the repository at this point in the history
Signed-off-by: Leonard Lyubich <ctulhurider@gmail.com>
  • Loading branch information
cthulhu-rider committed Feb 22, 2023
1 parent 75edfcb commit 1cc44e9
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 6 deletions.
2 changes: 1 addition & 1 deletion alphabet/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestMigration_TestNet_0_16_0_to_0_17_0(t *testing.T) {
migration.AddedSingleItem("proxyScriptHash", proxyContract.BytesBE()),
),
SuperiorContracts: []migration.SuperiorContractConfig{
migration.DeployAndCatchSuperiorContract("netmap", deployCfg.SetArgI(0, false),
migration.DeployAndCatchSuperiorContract("netmap", deployCfg.ReplaceArgI(0, false),
func(cfg *migration.UpdateConfig, addr util.Uint160) {
cfg.SetArgI(1, addr)
},
Expand Down
74 changes: 73 additions & 1 deletion container/migration_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,73 @@
package container
package container_test

import (
"math/rand"
"testing"

"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-contract/tests/migration"
)

func randContractAddress() (res util.Uint160) {
rand.Read(res[:])
return
}

func TestMigration_TestNet_0_16_0_to_0_17_0(t *testing.T) {
const rootDomain = "neofs1" // must not equal to 'neofs'

deployCfg := migration.DeployWithArguments(
true, // Non-notary mode
util.Uint160{}, // Netmap contract
util.Uint160{}, // Balance contract
util.Uint160{}, // NeoFSID contract
util.Uint160{}, // NNS contract
rootDomain, // NNS root domain
)

netmapContract := randContractAddress()
balanceContract := randContractAddress()
neoFSIDContract := randContractAddress()
nnsContract := randContractAddress()

validUpdCfg := migration.UpdateWithArguments(
false,
netmapContract,
balanceContract,
neoFSIDContract,
nnsContract,
rootDomain,
)

migration.TestRemoteStorageMigration(t, "https://rpc1.morph.t5.fs.neo.org:51331", "container", migration.Options{
OnNNSDeploy: func(cfg *migration.DeployConfig, nnsContract util.Uint160) {
cfg.SetArgI(4, nnsContract)
},
DeployConfig: deployCfg,
UpdateFailures: []migration.UpdateFailScenario{
migration.InvalidConfigFailure("update to non-notary mode is not supported anymore",
validUpdCfg.ReplaceArgI(0, true),
),
},
ValidUpdateConfig: validUpdCfg,
UpdateModel: migration.MultiGroupUpdateModel(
migration.RemovedSingleItem("notary"),
migration.PersistedSingleItem("netmapScriptHash"),
migration.PersistedSingleItem("balanceScriptHash"),
migration.PersistedSingleItem("identityScriptHash"),
migration.PersistedSingleItem("nnsScriptHash"),
migration.PersistedSingleItem("nnsRoot"),
migration.PersistedItemsWithPrefix("o"),
migration.PersistedItemsWithPrefix("x"),
migration.PersistedItemsWithPrefix("cnr"),
migration.PersistedItemsWithPrefix("est"),
migration.PersistedItemsWithPrefix("nnsHasAlias"),
migration.ReplacedItemsWithKeyLength(32, func(prevKey []byte) []byte {
return append([]byte{'x'}, prevKey...)
}),
migration.ReplacedItemsWithKeyLength(25+32, func(prevKey []byte) []byte {
return append([]byte{'o'}, prevKey...)
}),
),
})
}
6 changes: 5 additions & 1 deletion tests/migration/blockchain_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type localBlockchain struct {
// testing.TB.
//
// See also nns.Register.
func newLocalBlockChain(tb testing.TB, nnsSourcesDir string) *localBlockchain {
func newLocalBlockChain(tb testing.TB, nnsSourcesDir string, onNNSDeploy func(util.Uint160)) *localBlockchain {
memStore := storage.NewMemoryStore()

useDefaultConfig := func(*config.Blockchain) {}
Expand All @@ -86,6 +86,10 @@ func newLocalBlockChain(tb testing.TB, nnsSourcesDir string) *localBlockchain {

nnsContract := res.deployContract(res.compileContractSourceCode(nnsSourcesDir), true, DeployConfig{})

if onNNSDeploy != nil {
onNNSDeploy(nnsContract)
}

nnsContractInvoker := res.contractInvoker(nnsContract)

nnsContractInvoker.InvokeAndCheck(tb, checkSingleTrueInStack, "register",
Expand Down
9 changes: 7 additions & 2 deletions tests/migration/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ func DeployWithArguments(args ...interface{}) DeployConfig {
}
}

// SetArgI returns copy of the DeployConfig with changed i-th argument.
func (x DeployConfig) SetArgI(i int, v interface{}) (res DeployConfig) {
// SetArgI overrides i-th argument with the given value.
func (x *DeployConfig) SetArgI(i int, v interface{}) {
x.args[i] = v
}

// ReplaceArgI returns copy of the DeployConfig with changed i-th argument.
func (x DeployConfig) ReplaceArgI(i int, v interface{}) (res DeployConfig) {
res.args = make([]interface{}, len(x.args))
copy(res.args, x.args)
res.args[i] = v
Expand Down
14 changes: 13 additions & 1 deletion tests/migration/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"testing"

"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/stretchr/testify/require"
)

Expand All @@ -13,6 +14,10 @@ type Options struct {
// overriding the default one in step 1.
NNSSourceCodeDir string

// OnNNSDeploy allows to modify DeployConfig dynamically after NeoFS NNS
// contract deployment.
OnNNSDeploy func(*DeployConfig, util.Uint160)

// Group of NeoFS contracts on which the tested one depends. If set, all
// superior contracts are pre-handled locally before step 3 in order.
SuperiorContracts []SuperiorContractConfig
Expand Down Expand Up @@ -72,7 +77,14 @@ func TestRemoteStorageMigration(tb testing.TB, blockChainRPCEndpoint, contractNa
opts.NNSSourceCodeDir = SameLevelFolder("nns")
}

bLocal := newLocalBlockChain(tb, opts.NNSSourceCodeDir)
var onNNSDeploy func(util.Uint160)
if opts.OnNNSDeploy != nil {
onNNSDeploy = func(addr util.Uint160) {
opts.OnNNSDeploy(&opts.DeployConfig, addr)
}
}

bLocal := newLocalBlockChain(tb, opts.NNSSourceCodeDir, onNNSDeploy)

// 2.
remoteTestContractState := bRemote.getNeoFSContractByName(contractName)
Expand Down

0 comments on commit 1cc44e9

Please sign in to comment.