31 lines
953 B
Go
31 lines
953 B
Go
|
package crypto
|
||
|
|
||
|
import (
|
||
|
"encoding/hex"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"github.com/stretchr/testify/require"
|
||
|
)
|
||
|
|
||
|
func TestSHA256(t *testing.T) {
|
||
|
// 0x0100 hashes to 47dc540c94ceb704a23875c11273e16bb0b8a87aed84de911f2133568115f254
|
||
|
res := "47dc540c94ceb704a23875c11273e16bb0b8a87aed84de911f2133568115f254"
|
||
|
buf := io.NewBufBinWriter()
|
||
|
emit.Bytes(buf.BinWriter, []byte{1, 0})
|
||
|
emit.Syscall(buf.BinWriter, "Neo.Crypto.SHA256")
|
||
|
prog := buf.Bytes()
|
||
|
v := vm.New()
|
||
|
ic := &interop.Context{Trigger: trigger.Verification}
|
||
|
v.RegisterInteropGetter(GetInterop(ic))
|
||
|
v.Load(prog)
|
||
|
require.NoError(t, v.Run())
|
||
|
assert.Equal(t, 1, v.Estack().Len())
|
||
|
assert.Equal(t, res, hex.EncodeToString(v.Estack().Pop().Bytes()))
|
||
|
}
|