Merge pull request #2043 from nspcc-dev/runtime-getnetwork
interop/runtime: add `System.Runtime.GetNetwork`, fix #2038
This commit is contained in:
commit
bc5a1b7bcd
6 changed files with 37 additions and 0 deletions
|
@ -74,6 +74,7 @@ func TestSyscallExecution(t *testing.T) {
|
||||||
"runtime.GetEntryScriptHash": {interopnames.SystemRuntimeGetEntryScriptHash, nil, false},
|
"runtime.GetEntryScriptHash": {interopnames.SystemRuntimeGetEntryScriptHash, nil, false},
|
||||||
"runtime.GetExecutingScriptHash": {interopnames.SystemRuntimeGetExecutingScriptHash, nil, false},
|
"runtime.GetExecutingScriptHash": {interopnames.SystemRuntimeGetExecutingScriptHash, nil, false},
|
||||||
"runtime.GetInvocationCounter": {interopnames.SystemRuntimeGetInvocationCounter, nil, false},
|
"runtime.GetInvocationCounter": {interopnames.SystemRuntimeGetInvocationCounter, nil, false},
|
||||||
|
"runtime.GetNetwork": {interopnames.SystemRuntimeGetNetwork, nil, false},
|
||||||
"runtime.GetNotifications": {interopnames.SystemRuntimeGetNotifications, []string{u160}, false},
|
"runtime.GetNotifications": {interopnames.SystemRuntimeGetNotifications, []string{u160}, false},
|
||||||
"runtime.GetScriptContainer": {interopnames.SystemRuntimeGetScriptContainer, nil, false},
|
"runtime.GetScriptContainer": {interopnames.SystemRuntimeGetScriptContainer, nil, false},
|
||||||
"runtime.GetTime": {interopnames.SystemRuntimeGetTime, nil, false},
|
"runtime.GetTime": {interopnames.SystemRuntimeGetTime, nil, false},
|
||||||
|
|
|
@ -24,6 +24,7 @@ const (
|
||||||
SystemRuntimeGetEntryScriptHash = "System.Runtime.GetEntryScriptHash"
|
SystemRuntimeGetEntryScriptHash = "System.Runtime.GetEntryScriptHash"
|
||||||
SystemRuntimeGetExecutingScriptHash = "System.Runtime.GetExecutingScriptHash"
|
SystemRuntimeGetExecutingScriptHash = "System.Runtime.GetExecutingScriptHash"
|
||||||
SystemRuntimeGetInvocationCounter = "System.Runtime.GetInvocationCounter"
|
SystemRuntimeGetInvocationCounter = "System.Runtime.GetInvocationCounter"
|
||||||
|
SystemRuntimeGetNetwork = "System.Runtime.GetNetwork"
|
||||||
SystemRuntimeGetNotifications = "System.Runtime.GetNotifications"
|
SystemRuntimeGetNotifications = "System.Runtime.GetNotifications"
|
||||||
SystemRuntimeGetScriptContainer = "System.Runtime.GetScriptContainer"
|
SystemRuntimeGetScriptContainer = "System.Runtime.GetScriptContainer"
|
||||||
SystemRuntimeGetTime = "System.Runtime.GetTime"
|
SystemRuntimeGetTime = "System.Runtime.GetTime"
|
||||||
|
@ -61,6 +62,7 @@ var names = []string{
|
||||||
SystemRuntimeGetEntryScriptHash,
|
SystemRuntimeGetEntryScriptHash,
|
||||||
SystemRuntimeGetExecutingScriptHash,
|
SystemRuntimeGetExecutingScriptHash,
|
||||||
SystemRuntimeGetInvocationCounter,
|
SystemRuntimeGetInvocationCounter,
|
||||||
|
SystemRuntimeGetNetwork,
|
||||||
SystemRuntimeGetNotifications,
|
SystemRuntimeGetNotifications,
|
||||||
SystemRuntimeGetScriptContainer,
|
SystemRuntimeGetScriptContainer,
|
||||||
SystemRuntimeGetTime,
|
SystemRuntimeGetTime,
|
||||||
|
|
|
@ -67,3 +67,10 @@ func GetInvocationCounter(ic *interop.Context) error {
|
||||||
ic.VM.Estack().PushVal(count)
|
ic.VM.Estack().PushVal(count)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetNetwork returns chain network number.
|
||||||
|
func GetNetwork(ic *interop.Context) error {
|
||||||
|
m := ic.Chain.GetConfig().Magic
|
||||||
|
ic.VM.Estack().PushVal(uint32(m))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/internal/random"
|
"github.com/nspcc-dev/neo-go/internal/random"
|
||||||
|
"github.com/nspcc-dev/neo-go/internal/testchain"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/contract"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/contract"
|
||||||
|
@ -1202,6 +1203,25 @@ func TestLoadToken(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRuntimeGetNetwork(t *testing.T) {
|
||||||
|
bc := newTestChain(t)
|
||||||
|
|
||||||
|
w := io.NewBufBinWriter()
|
||||||
|
emit.Syscall(w.BinWriter, interopnames.SystemRuntimeGetNetwork)
|
||||||
|
require.NoError(t, w.Err)
|
||||||
|
|
||||||
|
tx := transaction.New(w.Bytes(), 10_000)
|
||||||
|
tx.ValidUntilBlock = bc.BlockHeight() + 1
|
||||||
|
addSigners(neoOwner, tx)
|
||||||
|
require.NoError(t, testchain.SignTx(bc, tx))
|
||||||
|
|
||||||
|
require.NoError(t, bc.AddBlock(bc.newBlock(tx)))
|
||||||
|
|
||||||
|
aer, err := bc.GetAppExecResults(tx.Hash(), trigger.Application)
|
||||||
|
require.NoError(t, err)
|
||||||
|
checkResult(t, &aer[0], stackitem.Make(uint32(bc.config.Magic)))
|
||||||
|
}
|
||||||
|
|
||||||
func TestRuntimeBurnGas(t *testing.T) {
|
func TestRuntimeBurnGas(t *testing.T) {
|
||||||
bc := newTestChain(t)
|
bc := newTestChain(t)
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ var systemInterops = []interop.Function{
|
||||||
{Name: interopnames.SystemRuntimeGetEntryScriptHash, Func: runtime.GetEntryScriptHash, Price: 1 << 4},
|
{Name: interopnames.SystemRuntimeGetEntryScriptHash, Func: runtime.GetEntryScriptHash, Price: 1 << 4},
|
||||||
{Name: interopnames.SystemRuntimeGetExecutingScriptHash, Func: runtime.GetExecutingScriptHash, Price: 1 << 4},
|
{Name: interopnames.SystemRuntimeGetExecutingScriptHash, Func: runtime.GetExecutingScriptHash, Price: 1 << 4},
|
||||||
{Name: interopnames.SystemRuntimeGetInvocationCounter, Func: runtime.GetInvocationCounter, Price: 1 << 4},
|
{Name: interopnames.SystemRuntimeGetInvocationCounter, Func: runtime.GetInvocationCounter, Price: 1 << 4},
|
||||||
|
{Name: interopnames.SystemRuntimeGetNetwork, Func: runtime.GetNetwork, Price: 1 << 3},
|
||||||
{Name: interopnames.SystemRuntimeGetNotifications, Func: runtime.GetNotifications, Price: 1 << 8, ParamCount: 1},
|
{Name: interopnames.SystemRuntimeGetNotifications, Func: runtime.GetNotifications, Price: 1 << 8, ParamCount: 1},
|
||||||
{Name: interopnames.SystemRuntimeGetScriptContainer, Func: engineGetScriptContainer, Price: 1 << 3},
|
{Name: interopnames.SystemRuntimeGetScriptContainer, Func: engineGetScriptContainer, Price: 1 << 3},
|
||||||
{Name: interopnames.SystemRuntimeGetTime, Func: runtime.GetTime, Price: 1 << 3, RequiredFlags: callflag.ReadStates},
|
{Name: interopnames.SystemRuntimeGetTime, Func: runtime.GetTime, Price: 1 << 3, RequiredFlags: callflag.ReadStates},
|
||||||
|
|
|
@ -46,6 +46,12 @@ func Notify(name string, args ...interface{}) {
|
||||||
neogointernal.Syscall2NoReturn("System.Runtime.Notify", name, args)
|
neogointernal.Syscall2NoReturn("System.Runtime.Notify", name, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetNetwork returns network magic number. This function uses
|
||||||
|
// `System.Runtime.GetNetwork` syscall.
|
||||||
|
func GetNetwork() int {
|
||||||
|
return neogointernal.Syscall0("System.Runtime.GetNetwork").(int)
|
||||||
|
}
|
||||||
|
|
||||||
// GetTime returns the timestamp of the most recent block. Note that when running
|
// GetTime returns the timestamp of the most recent block. Note that when running
|
||||||
// script in test mode this would be the last accepted (persisted) block in the
|
// script in test mode this would be the last accepted (persisted) block in the
|
||||||
// chain, but when running as a part of the new block the time returned is the
|
// chain, but when running as a part of the new block the time returned is the
|
||||||
|
|
Loading…
Reference in a new issue