Skip to content

Commit

Permalink
compiler: add tests for System.Runtime.CurrentSigners
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
  • Loading branch information
AnnaShaleva committed Nov 20, 2023
1 parent 2fba044 commit e63a93b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/compiler/interop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/core/storage"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/encoding/base58"
Expand Down Expand Up @@ -247,6 +248,35 @@ func TestAssertMsg(t *testing.T) {
require.True(t, strings.Contains(err.Error(), "ASSERTMSG is executed with false result. Reason: some message"), err)
}

func TestCurrentSigners(t *testing.T) {
bc, acc := chain.NewSingle(t)
e := neotest.NewExecutor(t, bc, acc, acc)
src := `package foo
import (
"github.com/nspcc-dev/neo-go/pkg/interop/native/ledger"
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
)
func Main() []ledger.TransactionSigner {
return runtime.CurrentSigners()
}`
ctr := neotest.CompileSource(t, e.CommitteeHash, strings.NewReader(src), &compiler.Options{Name: "Helper"})
e.DeployContract(t, ctr, nil)
c := e.CommitteeInvoker(ctr.Hash)

t.Run("non-empty", func(t *testing.T) {
expected := stackitem.NewArray([]stackitem.Item{
stackitem.NewArray([]stackitem.Item{
stackitem.NewByteArray(e.CommitteeHash.BytesBE()),
stackitem.NewBigInteger(big.NewInt(int64(transaction.Global))),
stackitem.NewArray([]stackitem.Item{}),
stackitem.NewArray([]stackitem.Item{}),
stackitem.NewArray([]stackitem.Item{}),
}),
})
c.Invoke(t, expected, "main")
})
}

func spawnVM(t *testing.T, ic *interop.Context, src string) *vm.VM {
b, di, err := compiler.CompileWithOptions("foo.go", strings.NewReader(src), nil)
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions pkg/compiler/syscall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func TestSyscallExecution(t *testing.T) {
"iterator.Value": {interopnames.SystemIteratorValue, []string{"iterator.Iterator{}"}, false},
"runtime.BurnGas": {interopnames.SystemRuntimeBurnGas, []string{"1"}, true},
"runtime.CheckWitness": {interopnames.SystemRuntimeCheckWitness, []string{b}, false},
"runtime.CurrentSigners": {interopnames.SystemRuntimeCurrentSigners, nil, false},
"runtime.GasLeft": {interopnames.SystemRuntimeGasLeft, nil, false},
"runtime.GetAddressVersion": {interopnames.SystemRuntimeGetAddressVersion, nil, false},
"runtime.GetCallingScriptHash": {interopnames.SystemRuntimeGetCallingScriptHash, nil, false},
Expand Down

0 comments on commit e63a93b

Please sign in to comment.