neo-go/pkg/core/unspent_coint_state_test.go
Roman Khimov d1a4e43c48 io: redo Serializable to return errors in BinReader/BinWriter
Further simplifies error handling.
2019-09-17 13:21:52 +03:00

61 lines
1.2 KiB
Go

package core
import (
"testing"
"github.com/CityOfZion/neo-go/pkg/core/storage"
"github.com/CityOfZion/neo-go/pkg/io"
"github.com/stretchr/testify/assert"
)
func TestDecodeEncodeUnspentCoinState(t *testing.T) {
unspent := &UnspentCoinState{
states: []CoinState{
CoinStateConfirmed,
CoinStateSpent,
CoinStateSpent,
CoinStateSpent,
CoinStateConfirmed,
},
}
buf := io.NewBufBinWriter()
unspent.EncodeBinary(buf.BinWriter)
assert.Nil(t, buf.Err)
unspentDecode := &UnspentCoinState{}
r := io.NewBinReaderFromBuf(buf.Bytes())
unspentDecode.DecodeBinary(r)
assert.Nil(t, r.Err)
}
func TestCommitUnspentCoins(t *testing.T) {
var (
store = storage.NewMemoryStore()
batch = store.Batch()
unspentCoins = make(UnspentCoins)
)
txA := randomUint256()
txB := randomUint256()
txC := randomUint256()
unspentCoins[txA] = &UnspentCoinState{
states: []CoinState{CoinStateConfirmed},
}
unspentCoins[txB] = &UnspentCoinState{
states: []CoinState{
CoinStateConfirmed,
CoinStateConfirmed,
},
}
unspentCoins[txC] = &UnspentCoinState{
states: []CoinState{
CoinStateConfirmed,
CoinStateConfirmed,
CoinStateConfirmed,
},
}
assert.Nil(t, unspentCoins.commit(batch))
assert.Nil(t, store.PutBatch(batch))
}