neoneo-go/pkg/compiler/util_test.go

35 lines
933 B
Go
Raw Normal View History

package compiler_test
2018-04-22 18:11:37 +00:00
import (
"testing"
"github.com/nspcc-dev/neo-go/pkg/core/interop"
"github.com/nspcc-dev/neo-go/pkg/core/interop/crypto"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
"github.com/stretchr/testify/require"
2018-04-22 18:11:37 +00:00
)
func TestSHA256(t *testing.T) {
src := `
package foo
import (
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
2018-04-22 18:11:37 +00:00
)
func Main() []byte {
src := []byte{0x97}
hash := crypto.SHA256(src)
return hash
}
`
v := vmAndCompile(t, src)
ic := &interop.Context{Trigger: trigger.Verification}
2020-08-07 11:37:49 +00:00
ic.VM = v
crypto.Register(ic)
v.SyscallHandler = ic.SyscallHandler
require.NoError(t, v.Run())
require.True(t, v.Estack().Len() >= 1)
2018-04-22 18:11:37 +00:00
h := []byte{0x2a, 0xa, 0xb7, 0x32, 0xb4, 0xe9, 0xd8, 0x5e, 0xf7, 0xdc, 0x25, 0x30, 0x3b, 0x64, 0xab, 0x52, 0x7c, 0x25, 0xa4, 0xd7, 0x78, 0x15, 0xeb, 0xb5, 0x79, 0xf3, 0x96, 0xec, 0x6c, 0xac, 0xca, 0xd3}
require.Equal(t, h, v.PopResult())
2018-04-22 18:11:37 +00:00
}