core: unit tests for entities
This commit is contained in:
parent
c7ac4b6dff
commit
c0e59ebd4e
3 changed files with 78 additions and 0 deletions
|
@ -36,3 +36,13 @@ func TestEncodeDecodeAssetState(t *testing.T) {
|
|||
assert.Nil(t, r.Err)
|
||||
assert.Equal(t, asset, assetDecode)
|
||||
}
|
||||
|
||||
func TestAssetState_GetName_NEO(t *testing.T) {
|
||||
asset := &AssetState{AssetType: transaction.GoverningToken}
|
||||
assert.Equal(t, "NEO", asset.GetName())
|
||||
}
|
||||
|
||||
func TestAssetState_GetName_NEOGas(t *testing.T) {
|
||||
asset := &AssetState{AssetType: transaction.UtilityToken}
|
||||
assert.Equal(t, "NEOGas", asset.GetName())
|
||||
}
|
||||
|
|
44
pkg/core/entities/notification_event_test.go
Normal file
44
pkg/core/entities/notification_event_test.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package entities
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/core/testutil"
|
||||
"github.com/CityOfZion/neo-go/pkg/io"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEncodeDecodeNotificationEvent(t *testing.T) {
|
||||
event := &NotificationEvent{
|
||||
ScriptHash: testutil.RandomUint160(),
|
||||
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{
|
||||
TxHash: testutil.RandomUint256(),
|
||||
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)
|
||||
}
|
|
@ -1,2 +1,26 @@
|
|||
package entities
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/io"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestEncodeDecodeStorageItem(t *testing.T) {
|
||||
storageItem := &StorageItem{
|
||||
Value: []byte{},
|
||||
IsConst: false,
|
||||
}
|
||||
buf := io.NewBufBinWriter()
|
||||
storageItem.EncodeBinary(buf.BinWriter)
|
||||
require.NoError(t, buf.Err)
|
||||
|
||||
decodedStorageItem := &StorageItem{}
|
||||
r := io.NewBinReaderFromBuf(buf.Bytes())
|
||||
decodedStorageItem.DecodeBinary(r)
|
||||
require.NoError(t, r.Err)
|
||||
|
||||
assert.Equal(t, storageItem, decodedStorageItem)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue