mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-28 23:27:36 +00:00
d1a4e43c48
Further simplifies error handling.
61 lines
1.2 KiB
Go
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))
|
|
}
|