2019-11-25 17:39:11 +00:00
|
|
|
package entities
|
2018-04-16 20:15:30 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-11-25 17:39:11 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/testutil"
|
2018-04-16 20:15:30 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/transaction"
|
2019-11-25 17:39:11 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/crypto/keys"
|
2019-09-16 09:18:13 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/io"
|
2018-04-16 20:15:30 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEncodeDecodeAssetState(t *testing.T) {
|
|
|
|
asset := &AssetState{
|
2019-11-25 17:39:11 +00:00
|
|
|
ID: testutil.RandomUint256(),
|
2018-04-16 20:15:30 +00:00
|
|
|
AssetType: transaction.Token,
|
|
|
|
Name: "super cool token",
|
|
|
|
Amount: util.Fixed8(1000000),
|
|
|
|
Available: util.Fixed8(100),
|
|
|
|
Precision: 0,
|
|
|
|
FeeMode: feeMode,
|
2019-11-25 17:39:11 +00:00
|
|
|
Owner: keys.PublicKey{},
|
|
|
|
Admin: testutil.RandomUint160(),
|
|
|
|
Issuer: testutil.RandomUint160(),
|
2018-04-16 20:15:30 +00:00
|
|
|
Expiration: 10,
|
|
|
|
IsFrozen: false,
|
|
|
|
}
|
|
|
|
|
2019-09-16 09:18:13 +00:00
|
|
|
buf := io.NewBufBinWriter()
|
2019-09-16 16:31:49 +00:00
|
|
|
asset.EncodeBinary(buf.BinWriter)
|
|
|
|
assert.Nil(t, buf.Err)
|
2018-04-16 20:15:30 +00:00
|
|
|
assetDecode := &AssetState{}
|
2019-09-16 16:31:49 +00:00
|
|
|
r := io.NewBinReaderFromBuf(buf.Bytes())
|
|
|
|
assetDecode.DecodeBinary(r)
|
|
|
|
assert.Nil(t, r.Err)
|
2018-04-16 20:15:30 +00:00
|
|
|
assert.Equal(t, asset, assetDecode)
|
|
|
|
}
|
2019-11-26 15:47:07 +00:00
|
|
|
|
|
|
|
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())
|
|
|
|
}
|