2019-11-28 16:06:09 +00:00
|
|
|
package state
|
2019-11-26 15:47:07 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/internal/random"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
2019-11-26 15:47:07 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEncodeDecodeNotificationEvent(t *testing.T) {
|
|
|
|
event := &NotificationEvent{
|
2019-12-04 12:24:49 +00:00
|
|
|
ScriptHash: random.Uint160(),
|
2019-11-26 15:47:07 +00:00
|
|
|
Item: nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
buf := io.NewBufBinWriter()
|
|
|
|
event.EncodeBinary(buf.BinWriter)
|
|
|
|
assert.Nil(t, buf.Err)
|
|
|
|
|
|
|
|
eventDecoded := &NotificationEvent{}
|
|
|
|
reader := io.NewBinReaderFromBuf(buf.Bytes())
|
|
|
|
eventDecoded.DecodeBinary(reader)
|
|
|
|
assert.Equal(t, event, eventDecoded)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEncodeDecodeAppExecResult(t *testing.T) {
|
|
|
|
appExecResult := &AppExecResult{
|
2019-12-04 12:24:49 +00:00
|
|
|
TxHash: random.Uint256(),
|
2019-11-26 15:47:07 +00:00
|
|
|
Trigger: 1,
|
|
|
|
VMState: "Hault",
|
|
|
|
GasConsumed: 10,
|
|
|
|
Stack: "",
|
|
|
|
Events: []NotificationEvent{},
|
|
|
|
}
|
|
|
|
buf := io.NewBufBinWriter()
|
|
|
|
appExecResult.EncodeBinary(buf.BinWriter)
|
|
|
|
assert.Nil(t, buf.Err)
|
|
|
|
|
|
|
|
appExecResultDecoded := &AppExecResult{}
|
|
|
|
reader := io.NewBinReaderFromBuf(buf.Bytes())
|
|
|
|
appExecResultDecoded.DecodeBinary(reader)
|
|
|
|
assert.Equal(t, appExecResult, appExecResultDecoded)
|
|
|
|
}
|