-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contracts: Add some helpers functions for testing purposes.
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |