mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 23:30:36 +00:00
2245fedbb1
commit methods duplicated putSmthIntoStore functions, but have MemCachedStore now that can easily substitute for a Batch, especially given that interop needs something like that for its storage purposes anyway.
52 lines
1 KiB
Go
52 lines
1 KiB
Go
package core
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/storage"
|
|
"github.com/CityOfZion/neo-go/pkg/io"
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestEncodeDecodeSpentCoinState(t *testing.T) {
|
|
spent := &SpentCoinState{
|
|
txHash: randomUint256(),
|
|
txHeight: 1001,
|
|
items: map[uint16]uint32{
|
|
1: 3,
|
|
2: 8,
|
|
4: 100,
|
|
},
|
|
}
|
|
|
|
buf := io.NewBufBinWriter()
|
|
spent.EncodeBinary(buf.BinWriter)
|
|
assert.Nil(t, buf.Err)
|
|
spentDecode := new(SpentCoinState)
|
|
r := io.NewBinReaderFromBuf(buf.Bytes())
|
|
spentDecode.DecodeBinary(r)
|
|
assert.Nil(t, r.Err)
|
|
assert.Equal(t, spent, spentDecode)
|
|
}
|
|
|
|
func TestCommitSpentCoins(t *testing.T) {
|
|
var (
|
|
store = storage.NewMemoryStore()
|
|
spentCoins = make(SpentCoins)
|
|
)
|
|
|
|
txx := []util.Uint256{
|
|
randomUint256(),
|
|
randomUint256(),
|
|
randomUint256(),
|
|
}
|
|
|
|
for i := 0; i < len(txx); i++ {
|
|
spentCoins[txx[i]] = &SpentCoinState{
|
|
txHash: txx[i],
|
|
txHeight: 1,
|
|
}
|
|
}
|
|
assert.Nil(t, spentCoins.commit(store))
|
|
}
|