neo-go/pkg/core/asset_state_test.go
Roman Khimov f1856bfa8b core/tx: remove publickey indirection from assets and txes
It makes very little sense having pointers here, these structures MUST have
some kind of key and this key is not gonna be wandering somewhere on its
own. Fixes a part of #519.
2019-12-09 18:33:04 +03:00

57 lines
1.4 KiB
Go

package core
import (
"testing"
"github.com/CityOfZion/neo-go/pkg/core/storage"
"github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/io"
"github.com/CityOfZion/neo-go/pkg/util"
"github.com/stretchr/testify/assert"
)
func TestEncodeDecodeAssetState(t *testing.T) {
asset := &AssetState{
ID: randomUint256(),
AssetType: transaction.Token,
Name: "super cool token",
Amount: util.Fixed8(1000000),
Available: util.Fixed8(100),
Precision: 0,
FeeMode: feeMode,
Admin: randomUint160(),
Issuer: randomUint160(),
Expiration: 10,
IsFrozen: false,
}
buf := io.NewBufBinWriter()
asset.EncodeBinary(buf.BinWriter)
assert.Nil(t, buf.Err)
assetDecode := &AssetState{}
r := io.NewBinReaderFromBuf(buf.Bytes())
assetDecode.DecodeBinary(r)
assert.Nil(t, r.Err)
assert.Equal(t, asset, assetDecode)
}
func TestPutGetAssetState(t *testing.T) {
s := storage.NewMemoryStore()
asset := &AssetState{
ID: randomUint256(),
AssetType: transaction.Token,
Name: "super cool token",
Amount: util.Fixed8(1000000),
Available: util.Fixed8(100),
Precision: 8,
FeeMode: feeMode,
Admin: randomUint160(),
Issuer: randomUint160(),
Expiration: 10,
IsFrozen: false,
}
assert.NoError(t, putAssetStateIntoStore(s, asset))
asRead := getAssetStateFromStore(s, asset.ID)
assert.NotNil(t, asRead)
assert.Equal(t, asset, asRead)
}