diff --git a/contracts/deploys.go b/contracts/deploys.go new file mode 100644 index 00000000..0b1d96f4 --- /dev/null +++ b/contracts/deploys.go @@ -0,0 +1,78 @@ +package contracts + +import ( + "testing" + "time" + + "github.com/nspcc-dev/neo-go/pkg/neotest" + "github.com/nspcc-dev/neo-go/pkg/util" + "github.com/stretchr/testify/require" +) + +type ( + // RegContractNNSParams is a param struct for RegContractNNS func. + RegContractNNSParams struct { + // Name is a contract name. Name must not be a top level domain. For instance: netmap. + // The final registered domain name will be concatenated with `.neofs`. + Name string + ContractHash util.Uint160 + Email string + Refresh int64 + Retry int64 + // Expire in milliseconds + Expire int64 + TTL int64 + } +) + +const ( + msPerYear = 365 * 24 * time.Hour / time.Millisecond +) + +// NewRegContractNNSParams is a constructor for RegContractNNSParams. +func NewRegContractNNSParams(name string, contractHash util.Uint160) RegContractNNSParams { + return RegContractNNSParams{ + Name: name, + ContractHash: contractHash, + Email: "ops@nspcc.ru", + Refresh: 3600, + Retry: 600, + Expire: int64(10 * msPerYear), + TTL: 3600, + } +} + +// RegContractNNS make registration of the contract hash in nns contract. +func RegContractNNS(t *testing.T, e *neotest.Executor, params RegContractNNSParams) { + nnsHash, err := e.Chain.GetContractScriptHash(1) + require.NoError(t, err) + + nnsInv := e.CommitteeInvoker(nnsHash) + + nnsInv.Invoke(t, true, "register", params.Name+".neofs", e.CommitteeHash, params.Email, params.Refresh, params.Retry, params.Email, params.TTL) + nnsInv.Invoke(t, nil, "addRecord", params.Name+".neofs", 16, params.ContractHash.StringLE()) +} + +// TickEpoch increase epoch value by one. +func TickEpoch(t *testing.T, e *neotest.Executor, signers ...neotest.Signer) { + nnsHash, err := e.Chain.GetContractScriptHash(1) + require.NoError(t, err) + + nnsInv := e.CommitteeInvoker(nnsHash) + resolveResult, err := nnsInv.TestInvoke(t, "resolve", "netmap.neofs", 16) + require.NoError(t, err) + + contractHashBytes, err := resolveResult.Pop().Array()[0].TryBytes() + require.NoError(t, err) + + netMapContractHash, err := util.Uint160DecodeStringLE(string(contractHashBytes)) + require.NoError(t, err) + + netMapInvoker := e.NewInvoker(netMapContractHash, signers...) + + epochResult, err := netMapInvoker.TestInvoke(t, "epoch") + require.NoError(t, err) + + epoch := epochResult.Pop().BigInt().Int64() + netMapInvoker.Invoke(t, nil, "newEpoch", epoch+1) +}