[#151] netmap: allow to update config values in _deploy

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-10-19 13:04:10 +03:00 committed by Alex Vanin
parent c957b9ca69
commit c5e026c6e7
2 changed files with 31 additions and 18 deletions

View file

@ -61,10 +61,6 @@ var (
func _deploy(data interface{}, isUpdate bool) { func _deploy(data interface{}, isUpdate bool) {
ctx := storage.GetContext() ctx := storage.GetContext()
if isUpdate {
return
}
args := data.([]interface{}) args := data.([]interface{})
notaryDisabled := args[0].(bool) notaryDisabled := args[0].(bool)
addrBalance := args[1].(interop.Hash160) addrBalance := args[1].(interop.Hash160)
@ -72,6 +68,22 @@ func _deploy(data interface{}, isUpdate bool) {
keys := args[3].([]interop.PublicKey) keys := args[3].([]interop.PublicKey)
config := args[4].([][]byte) config := args[4].([][]byte)
ln := len(config)
if ln%2 != 0 {
panic("_deploy: bad configuration")
}
for i := 0; i < ln/2; i++ {
key := config[i*2]
val := config[i*2+1]
setConfig(ctx, key, val)
}
if isUpdate {
return
}
if len(addrBalance) != 20 || len(addrContainer) != 20 { if len(addrBalance) != 20 || len(addrContainer) != 20 {
panic("init: incorrect length of contract script hash") panic("init: incorrect length of contract script hash")
} }
@ -101,18 +113,6 @@ func _deploy(data interface{}, isUpdate bool) {
runtime.Log("netmap contract notary disabled") runtime.Log("netmap contract notary disabled")
} }
ln := len(config)
if ln%2 != 0 {
panic("init: bad configuration")
}
for i := 0; i < ln/2; i++ {
key := config[i*2]
val := config[i*2+1]
setConfig(ctx, key, val)
}
runtime.Log("netmap contract initialized") runtime.Log("netmap contract initialized")
} }

View file

@ -6,9 +6,11 @@ import (
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/core" "github.com/nspcc-dev/neo-go/pkg/core"
"github.com/nspcc-dev/neo-go/pkg/encoding/bigint"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"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/wallet" "github.com/nspcc-dev/neo-go/pkg/wallet"
"github.com/nspcc-dev/neofs-contract/container"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -24,7 +26,7 @@ func deployNetmapContract(t *testing.T, bc *core.Blockchain, addrBalance, addrCo
return DeployContract(t, bc, netmapPath, args) return DeployContract(t, bc, netmapPath, args)
} }
func prepareNetmapContract(t *testing.T, bc *core.Blockchain) util.Uint160 { func prepareNetmapContract(t *testing.T, bc *core.Blockchain, config ...interface{}) util.Uint160 {
addrNNS := DeployContract(t, bc, nnsPath, nil) addrNNS := DeployContract(t, bc, nnsPath, nil)
ctrNetmap, err := ContractInfo(CommitteeAcc.Contract.ScriptHash(), netmapPath) ctrNetmap, err := ContractInfo(CommitteeAcc.Contract.ScriptHash(), netmapPath)
@ -38,7 +40,18 @@ func prepareNetmapContract(t *testing.T, bc *core.Blockchain) util.Uint160 {
deployContainerContract(t, bc, ctrNetmap.Hash, ctrBalance.Hash, addrNNS) deployContainerContract(t, bc, ctrNetmap.Hash, ctrBalance.Hash, addrNNS)
deployBalanceContract(t, bc, ctrNetmap.Hash, ctrContainer.Hash) deployBalanceContract(t, bc, ctrNetmap.Hash, ctrContainer.Hash)
return deployNetmapContract(t, bc, ctrBalance.Hash, ctrContainer.Hash, "ContainerFee", []byte{}) return deployNetmapContract(t, bc, ctrBalance.Hash, ctrContainer.Hash, config...)
}
func TestDeploySetConfig(t *testing.T) {
bc := NewChain(t)
h := prepareNetmapContract(t, bc, "SomeKey", "TheValue", container.AliasFeeKey, int64(123))
tx := PrepareInvoke(t, bc, CommitteeAcc, h, "config", "SomeKey")
CheckTestInvoke(t, bc, tx, "TheValue")
tx = PrepareInvoke(t, bc, CommitteeAcc, h, "config", container.AliasFeeKey)
CheckTestInvoke(t, bc, tx, bigint.ToBytes(big.NewInt(123)))
} }
func dummyNodeInfo(acc *wallet.Account) []byte { func dummyNodeInfo(acc *wallet.Account) []byte {