[#139] container: Add SetAdmin
SetAdmin will allow to manage the root domain of the container. Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
parent
7e0f9b8b8e
commit
15b7b2ed40
4 changed files with 55 additions and 3 deletions
|
@ -18,6 +18,7 @@ permissions:
|
||||||
- "register"
|
- "register"
|
||||||
- "transferX"
|
- "transferX"
|
||||||
- "update"
|
- "update"
|
||||||
|
- "setAdmin"
|
||||||
|
|
||||||
events:
|
events:
|
||||||
- name: PutSuccess
|
- name: PutSuccess
|
||||||
|
|
|
@ -565,6 +565,21 @@ func NewEpoch(epochNum int) {
|
||||||
cleanupContainers(ctx, epochNum)
|
cleanupContainers(ctx, epochNum)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetAdmin sets admin for root container domain.
|
||||||
|
func SetAdmin(admin interop.Hash160) {
|
||||||
|
ctx := storage.GetReadOnlyContext()
|
||||||
|
|
||||||
|
if !runtime.CheckWitness(common.CommitteeAddress()) {
|
||||||
|
panic("only committee can set admin")
|
||||||
|
}
|
||||||
|
|
||||||
|
addrNNS := storage.Get(ctx, nnsContractKey).(interop.Hash160)
|
||||||
|
rootContainerDomain := storage.Get(ctx, nnsRootKey).(string)
|
||||||
|
|
||||||
|
contract.Call(addrNNS, "setAdmin", contract.All,
|
||||||
|
rootContainerDomain, admin)
|
||||||
|
}
|
||||||
|
|
||||||
// StartContainerEstimation method produces StartEstimation notification.
|
// StartContainerEstimation method produces StartEstimation notification.
|
||||||
// It can be invoked only by Alphabet nodes of the Inner Ring.
|
// It can be invoked only by Alphabet nodes of the Inner Ring.
|
||||||
func StartContainerEstimation(epoch int) {
|
func StartContainerEstimation(epoch int) {
|
||||||
|
|
|
@ -270,6 +270,28 @@ func (c *Contract) PutNamedUnsigned(container []byte, signature []byte, publicKe
|
||||||
return c.actor.MakeUnsignedCall(c.hash, "putNamed", nil, container, signature, publicKey, token, name, zone)
|
return c.actor.MakeUnsignedCall(c.hash, "putNamed", nil, container, signature, publicKey, token, name, zone)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetAdmin creates a transaction invoking `setAdmin` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) SetAdmin(admin util.Uint160) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "setAdmin", admin)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdminTransaction creates a transaction invoking `setAdmin` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) SetAdminTransaction(admin util.Uint160) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "setAdmin", admin)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdminUnsigned creates a transaction invoking `setAdmin` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) SetAdminUnsigned(admin util.Uint160) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "setAdmin", nil, admin)
|
||||||
|
}
|
||||||
|
|
||||||
// SetEACL creates a transaction invoking `setEACL` method of the contract.
|
// SetEACL creates a transaction invoking `setEACL` method of the contract.
|
||||||
// This transaction is signed and immediately sent to the network.
|
// This transaction is signed and immediately sent to the network.
|
||||||
// The values returned are its hash, ValidUntilBlock value and error if any.
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
|
|
@ -28,13 +28,17 @@ const (
|
||||||
containerAliasFee = 0o_0050_0000
|
containerAliasFee = 0o_0050_0000
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
containerRootDomain = "container"
|
||||||
|
)
|
||||||
|
|
||||||
func deployContainerContract(t *testing.T, e *neotest.Executor, addrNetmap, addrBalance, addrNNS util.Uint160) util.Uint160 {
|
func deployContainerContract(t *testing.T, e *neotest.Executor, addrNetmap, addrBalance, addrNNS util.Uint160) util.Uint160 {
|
||||||
args := make([]any, 5)
|
args := make([]any, 5)
|
||||||
args[0] = addrNetmap
|
args[0] = addrNetmap
|
||||||
args[1] = addrBalance
|
args[1] = addrBalance
|
||||||
args[2] = util.Uint160{} // not needed for now
|
args[2] = util.Uint160{} // not needed for now
|
||||||
args[3] = addrNNS
|
args[3] = addrNNS
|
||||||
args[4] = "frostfs"
|
args[4] = containerRootDomain
|
||||||
|
|
||||||
c := neotest.CompileFile(t, e.CommitteeHash, containerPath, path.Join(containerPath, "config.yml"))
|
c := neotest.CompileFile(t, e.CommitteeHash, containerPath, path.Join(containerPath, "config.yml"))
|
||||||
e.DeployContract(t, c, args)
|
e.DeployContract(t, c, args)
|
||||||
|
@ -207,14 +211,14 @@ func TestContainerPut(t *testing.T) {
|
||||||
stackitem.NewByteArray([]byte(base58.Encode(cnt.id[:]))),
|
stackitem.NewByteArray([]byte(base58.Encode(cnt.id[:]))),
|
||||||
})
|
})
|
||||||
cNNS := c.CommitteeInvoker(nnsHash)
|
cNNS := c.CommitteeInvoker(nnsHash)
|
||||||
cNNS.Invoke(t, expected, "resolve", "mycnt.frostfs", int64(nns.TXT))
|
cNNS.Invoke(t, expected, "resolve", "mycnt."+containerRootDomain, int64(nns.TXT))
|
||||||
|
|
||||||
t.Run("name is already taken", func(t *testing.T) {
|
t.Run("name is already taken", func(t *testing.T) {
|
||||||
c.InvokeFail(t, "name is already taken", "putNamed", putArgs...)
|
c.InvokeFail(t, "name is already taken", "putNamed", putArgs...)
|
||||||
})
|
})
|
||||||
|
|
||||||
c.Invoke(t, stackitem.Null{}, "delete", cnt.id[:], cnt.sig, cnt.pub, cnt.token)
|
c.Invoke(t, stackitem.Null{}, "delete", cnt.id[:], cnt.sig, cnt.pub, cnt.token)
|
||||||
cNNS.Invoke(t, stackitem.Null{}, "resolve", "mycnt.frostfs", int64(nns.TXT))
|
cNNS.Invoke(t, stackitem.Null{}, "resolve", "mycnt."+containerRootDomain, int64(nns.TXT))
|
||||||
|
|
||||||
t.Run("register in advance", func(t *testing.T) {
|
t.Run("register in advance", func(t *testing.T) {
|
||||||
cnt.value[len(cnt.value)-1] = 10
|
cnt.value[len(cnt.value)-1] = 10
|
||||||
|
@ -241,6 +245,16 @@ func TestContainerPut(t *testing.T) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("test setAdmin", func(t *testing.T) {
|
||||||
|
ctrNNS := neotest.CompileFile(t, c.CommitteeHash, nnsPath, path.Join(nnsPath, "config.yml"))
|
||||||
|
nnsInv := c.NewInvoker(ctrNNS.Hash, acc)
|
||||||
|
containerInv := c.WithSigners(c.Committee, acc)
|
||||||
|
|
||||||
|
nnsInv.InvokeFail(t, "not witnessed by admin", "addRecord", containerRootDomain, int64(nns.TXT), nns.Cnametgt+"=animals")
|
||||||
|
containerInv.Invoke(t, stackitem.Null{}, "setAdmin", acc.ScriptHash())
|
||||||
|
nnsInv.Invoke(t, stackitem.Null{}, "addRecord", containerRootDomain, int64(nns.TXT), nns.Cnametgt+"=animals")
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("create global domain", func(t *testing.T) {
|
t.Run("create global domain", func(t *testing.T) {
|
||||||
ctrNNS := neotest.CompileFile(t, c.CommitteeHash, nnsPath, path.Join(nnsPath, "config.yml"))
|
ctrNNS := neotest.CompileFile(t, c.CommitteeHash, nnsPath, path.Join(nnsPath, "config.yml"))
|
||||||
nnsHash := ctrNNS.Hash
|
nnsHash := ctrNNS.Hash
|
||||||
|
|
Loading…
Reference in a new issue