From 6250e5eaf79790a60694392aad2e5bb3a5370219 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 18 Nov 2021 14:31:58 +0300 Subject: [PATCH] [#122] subnet: add contract skeleton Signed-off-by: Evgenii Stratonikov --- Makefile | 2 +- subnet/config.yml | 4 ++++ subnet/subnet_contract.go | 44 +++++++++++++++++++++++++++++++++++++++ tests/subnet_test.go | 30 ++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 subnet/config.yml create mode 100644 subnet/subnet_contract.go create mode 100644 tests/subnet_test.go diff --git a/Makefile b/Makefile index 06652f2..e477afa 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ all: sidechain mainnet sidechain: alphabet morph nns alphabet_sc = alphabet -morph_sc = audit balance container neofsid netmap proxy reputation +morph_sc = audit balance container neofsid netmap proxy reputation subnet mainnet_sc = neofs processing nns_sc = nns diff --git a/subnet/config.yml b/subnet/config.yml new file mode 100644 index 0000000..5d978d1 --- /dev/null +++ b/subnet/config.yml @@ -0,0 +1,4 @@ +name: "NeoFS Subnet" +safemethods: ["version"] +permissions: + - methods: ["update"] \ No newline at end of file diff --git a/subnet/subnet_contract.go b/subnet/subnet_contract.go new file mode 100644 index 0000000..0cc9221 --- /dev/null +++ b/subnet/subnet_contract.go @@ -0,0 +1,44 @@ +package subnet + +import ( + "github.com/nspcc-dev/neo-go/pkg/interop" + "github.com/nspcc-dev/neo-go/pkg/interop/contract" + "github.com/nspcc-dev/neo-go/pkg/interop/native/management" + "github.com/nspcc-dev/neo-go/pkg/interop/runtime" + "github.com/nspcc-dev/neo-go/pkg/interop/storage" + "github.com/nspcc-dev/neofs-contract/common" +) + +const ( + notaryDisabledKey = 'z' +) + +// _deploy function sets up initial list of inner ring public keys. +func _deploy(data interface{}, isUpdate bool) { + if isUpdate { + return + } + + args := data.(struct { + notaryDisabled bool + }) + + ctx := storage.GetContext() + storage.Put(ctx, []byte{notaryDisabledKey}, args.notaryDisabled) +} + +// Update method updates contract source code and manifest. Can be invoked +// only by committee. +func Update(script []byte, manifest []byte, data interface{}) { + if !common.HasUpdateAccess() { + panic("only committee can update contract") + } + + contract.Call(interop.Hash160(management.Hash), "update", contract.All, script, manifest, data) + runtime.Log("subnet contract updated") +} + +// Version returns version of the contract. +func Version() int { + return common.Version +} diff --git a/tests/subnet_test.go b/tests/subnet_test.go new file mode 100644 index 0000000..b5ed73b --- /dev/null +++ b/tests/subnet_test.go @@ -0,0 +1,30 @@ +package tests + +import ( + "path" + "testing" + + "github.com/nspcc-dev/neo-go/pkg/neotest" + "github.com/nspcc-dev/neo-go/pkg/util" + "github.com/nspcc-dev/neofs-contract/common" +) + +const subnetPath = "../subnet" + +func deploySubnetContract(t *testing.T, e *neotest.Executor) util.Uint160 { + c := neotest.CompileFile(t, e.CommitteeHash, subnetPath, path.Join(subnetPath, "config.yml")) + args := []interface{}{true} + e.DeployContract(t, c, args) + return c.Hash +} + +func newSubnetInvoker(t *testing.T) *neotest.ContractInvoker { + e := newExecutor(t) + h := deploySubnetContract(t, e) + return e.CommitteeInvoker(h) +} + +func TestSubnet_Version(t *testing.T) { + e := newSubnetInvoker(t) + e.Invoke(t, common.Version, "version") +}