Allow proxy to own domains #74
2 changed files with 43 additions and 0 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue