forked from TrueCloudLab/neoneo-go
core: add putAssetStateIntoStore()
Will be used by interops.
This commit is contained in:
parent
96934cfeab
commit
35824728eb
2 changed files with 34 additions and 0 deletions
|
@ -27,6 +27,17 @@ func (a Assets) commit(b storage.Batch) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// putAssetStateIntoStore puts given asset state into the given store.
|
||||||
|
func putAssetStateIntoStore(s storage.Store, as *AssetState) error {
|
||||||
|
buf := io.NewBufBinWriter()
|
||||||
|
as.EncodeBinary(buf.BinWriter)
|
||||||
|
if buf.Err != nil {
|
||||||
|
return buf.Err
|
||||||
|
}
|
||||||
|
key := storage.AppendPrefix(storage.STAsset, as.ID.Bytes())
|
||||||
|
return s.Put(key, buf.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
// AssetState represents the state of an NEO registered Asset.
|
// AssetState represents the state of an NEO registered Asset.
|
||||||
type AssetState struct {
|
type AssetState struct {
|
||||||
ID util.Uint256
|
ID util.Uint256
|
||||||
|
|
|
@ -3,6 +3,7 @@ package core
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/CityOfZion/neo-go/pkg/core/storage"
|
||||||
"github.com/CityOfZion/neo-go/pkg/core/transaction"
|
"github.com/CityOfZion/neo-go/pkg/core/transaction"
|
||||||
"github.com/CityOfZion/neo-go/pkg/crypto/keys"
|
"github.com/CityOfZion/neo-go/pkg/crypto/keys"
|
||||||
"github.com/CityOfZion/neo-go/pkg/io"
|
"github.com/CityOfZion/neo-go/pkg/io"
|
||||||
|
@ -35,3 +36,25 @@ func TestEncodeDecodeAssetState(t *testing.T) {
|
||||||
assert.Nil(t, r.Err)
|
assert.Nil(t, r.Err)
|
||||||
assert.Equal(t, asset, assetDecode)
|
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,
|
||||||
|
Owner: &keys.PublicKey{},
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue