2019-11-28 16:06:09 +00:00
|
|
|
package state
|
2018-04-16 20:15:30 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"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-12-04 12:24:49 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/internal/random"
|
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) {
|
2019-11-28 16:06:09 +00:00
|
|
|
asset := &Asset{
|
2019-12-04 12:24:49 +00:00
|
|
|
ID: random.Uint256(),
|
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{},
|
2019-12-04 12:24:49 +00:00
|
|
|
Admin: random.Uint160(),
|
|
|
|
Issuer: random.Uint160(),
|
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)
|
2019-11-28 16:06:09 +00:00
|
|
|
assetDecode := &Asset{}
|
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) {
|
2019-11-28 16:06:09 +00:00
|
|
|
asset := &Asset{AssetType: transaction.GoverningToken}
|
2019-11-26 15:47:07 +00:00
|
|
|
assert.Equal(t, "NEO", asset.GetName())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAssetState_GetName_NEOGas(t *testing.T) {
|
2019-11-28 16:06:09 +00:00
|
|
|
asset := &Asset{AssetType: transaction.UtilityToken}
|
2019-11-26 15:47:07 +00:00
|
|
|
assert.Equal(t, "NEOGas", asset.GetName())
|
|
|
|
}
|