forked from TrueCloudLab/frostfs-contract
[#122] subnet: add contract skeleton
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
75bb382f7b
commit
6250e5eaf7
4 changed files with 79 additions and 1 deletions
2
Makefile
2
Makefile
|
@ -11,7 +11,7 @@ all: sidechain mainnet
|
||||||
sidechain: alphabet morph nns
|
sidechain: alphabet morph nns
|
||||||
|
|
||||||
alphabet_sc = alphabet
|
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
|
mainnet_sc = neofs processing
|
||||||
nns_sc = nns
|
nns_sc = nns
|
||||||
|
|
||||||
|
|
4
subnet/config.yml
Normal file
4
subnet/config.yml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
name: "NeoFS Subnet"
|
||||||
|
safemethods: ["version"]
|
||||||
|
permissions:
|
||||||
|
- methods: ["update"]
|
44
subnet/subnet_contract.go
Normal file
44
subnet/subnet_contract.go
Normal file
|
@ -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
|
||||||
|
}
|
30
tests/subnet_test.go
Normal file
30
tests/subnet_test.go
Normal file
|
@ -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")
|
||||||
|
}
|
Loading…
Reference in a new issue