2018-03-21 16:11:04 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/storage"
|
2019-09-16 09:18:13 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/io"
|
2018-03-21 16:11:04 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2018-04-16 20:15:30 +00:00
|
|
|
func TestDecodeEncodeUnspentCoinState(t *testing.T) {
|
2018-03-21 16:11:04 +00:00
|
|
|
unspent := &UnspentCoinState{
|
|
|
|
states: []CoinState{
|
|
|
|
CoinStateConfirmed,
|
|
|
|
CoinStateSpent,
|
|
|
|
CoinStateSpent,
|
|
|
|
CoinStateSpent,
|
|
|
|
CoinStateConfirmed,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-09-16 09:18:13 +00:00
|
|
|
buf := io.NewBufBinWriter()
|
2019-09-16 16:31:49 +00:00
|
|
|
unspent.EncodeBinary(buf.BinWriter)
|
|
|
|
assert.Nil(t, buf.Err)
|
2018-03-21 16:11:04 +00:00
|
|
|
unspentDecode := &UnspentCoinState{}
|
2019-09-16 16:31:49 +00:00
|
|
|
r := io.NewBinReaderFromBuf(buf.Bytes())
|
|
|
|
unspentDecode.DecodeBinary(r)
|
|
|
|
assert.Nil(t, r.Err)
|
2018-03-21 16:11:04 +00:00
|
|
|
}
|
|
|
|
|
2018-04-16 20:15:30 +00:00
|
|
|
func TestCommitUnspentCoins(t *testing.T) {
|
2018-03-21 16:11:04 +00:00
|
|
|
var (
|
|
|
|
store = storage.NewMemoryStore()
|
|
|
|
unspentCoins = make(UnspentCoins)
|
|
|
|
)
|
|
|
|
|
2019-08-23 15:50:45 +00:00
|
|
|
txA := randomUint256()
|
|
|
|
txB := randomUint256()
|
|
|
|
txC := randomUint256()
|
2018-03-21 16:11:04 +00:00
|
|
|
|
|
|
|
unspentCoins[txA] = &UnspentCoinState{
|
|
|
|
states: []CoinState{CoinStateConfirmed},
|
|
|
|
}
|
|
|
|
unspentCoins[txB] = &UnspentCoinState{
|
|
|
|
states: []CoinState{
|
|
|
|
CoinStateConfirmed,
|
|
|
|
CoinStateConfirmed,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
unspentCoins[txC] = &UnspentCoinState{
|
|
|
|
states: []CoinState{
|
|
|
|
CoinStateConfirmed,
|
|
|
|
CoinStateConfirmed,
|
|
|
|
CoinStateConfirmed,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-10-16 14:29:21 +00:00
|
|
|
assert.Nil(t, unspentCoins.commit(store))
|
2018-03-21 16:11:04 +00:00
|
|
|
}
|