Allow proxy to own domains #74

Merged
fyrchik merged 3 commits from fyrchik/frostfs-contract:allow-proxy-toown into master 2024-09-04 19:51:17 +00:00
4 changed files with 48 additions and 14 deletions

View file

@ -19,6 +19,15 @@ func OnNEP17Payment(from interop.Hash160, amount int, data any) {
}
}
// OnNEP11Payment is a callback for NEP-11 compatible NNS contract.
func OnNEP11Payment(from interop.Hash160, amount int, token []byte, data any) {
caller := runtime.GetCallingScriptHash()
nnsHash := management.GetContractByID(1).Hash
if !common.BytesEqual(caller, []byte(nnsHash)) {
common.AbortWithMessage("proxy contract accepts NNS tokens only")
}
}
func _deploy(data any, isUpdate bool) {
if isUpdate {
args := data.([]any)

View file

@ -47,7 +47,7 @@ func newAlphabetInvoker(t *testing.T) (*neotest.Executor, *neotest.ContractInvok
container.AliasFeeKey, int64(containerAliasFee))
deployBalanceContract(t, e, ctrNetmap.Hash, ctrContainer.Hash)
deployContainerContract(t, e, ctrNetmap.Hash, ctrBalance.Hash, ctrNNS.Hash)
deployProxyContract(t, e, ctrNetmap.Hash)
deployProxyContract(t, e)
hash := deployAlphabetContract(t, e, ctrNetmap.Hash, ctrProxy.Hash, "Az", 0, 1)
alphabet := getAlphabetAcc(t, e)

View file

@ -10,7 +10,10 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-contract/nns"
"github.com/nspcc-dev/neo-go/pkg/core/interop/storage"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/neotest"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/gas"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/stretchr/testify/require"
)
@ -395,3 +398,34 @@ func TestNNSResolve(t *testing.T) {
c.Invoke(t, records, "resolve", "test.com.", int64(nns.TXT))
c.InvokeFail(t, "invalid domain name format", "resolve", "test.com..", int64(nns.TXT))
}
func TestNNSAndProxy(t *testing.T) {
c := newNNSInvoker(t, false)
proxyHash := deployProxyContract(t, c.Executor)
proxySigner := neotest.NewContractSigner(proxyHash, func(*transaction.Transaction) []any { return nil })
g := c.NewInvoker(gas.Hash, c.Validator)
g.Invoke(t, true, "transfer",
c.Validator.ScriptHash(), proxyHash, 100_0000_0000, nil)
cc := c.WithSigners(proxySigner, c.Committee)
cc.Invoke(t, true, "register", "ns", proxyHash,
"ops@frostfs.info", 100, 100, 100, 100)
checkBalance := func(t *testing.T, owner util.Uint160, balance int64) {
s, err := cc.TestInvoke(t, "balanceOf", owner)
require.NoError(t, err)
require.Equal(t, 1, s.Len())
require.Equal(t, int64(balance), s.Pop().BigInt().Int64())
}
checkBalance(t, proxyHash, 1)
checkBalance(t, c.CommitteeHash, 0)
t.Run("ensure domain is not lost", func(t *testing.T) {
cc.Invoke(t, true, "transfer", c.CommitteeHash, "ns", nil)
checkBalance(t, proxyHash, 0)
checkBalance(t, c.CommitteeHash, 1)
})
}

View file

@ -15,27 +15,18 @@ import (
const proxyPath = "../proxy"
func deployProxyContract(t *testing.T, e *neotest.Executor, addrNetmap util.Uint160) util.Uint160 {
args := make([]any, 1)
args[0] = addrNetmap
func deployProxyContract(t *testing.T, e *neotest.Executor) util.Uint160 {
c := neotest.CompileFile(t, e.CommitteeHash, proxyPath, path.Join(proxyPath, "config.yml"))
e.DeployContract(t, c, args)
e.DeployContract(t, c, []any{})
return c.Hash
}
func newProxyInvoker(t *testing.T) *neotest.ContractInvoker {
e := newExecutor(t)
ctrNetmap := neotest.CompileFile(t, e.CommitteeHash, netmapPath, path.Join(netmapPath, "config.yml"))
ctrBalance := neotest.CompileFile(t, e.CommitteeHash, balancePath, path.Join(balancePath, "config.yml"))
ctrContainer := neotest.CompileFile(t, e.CommitteeHash, containerPath, path.Join(containerPath, "config.yml"))
ctrProxy := neotest.CompileFile(t, e.CommitteeHash, proxyPath, path.Join(proxyPath, "config.yml"))
proxyHash := deployProxyContract(t, e)
deployNetmapContract(t, e, ctrBalance.Hash, ctrContainer.Hash)
deployProxyContract(t, e, ctrNetmap.Hash)
return e.CommitteeInvoker(ctrProxy.Hash)
return e.CommitteeInvoker(proxyHash)
}
func TestVerify(t *testing.T) {