neo-go/pkg/core/spent_coin_state_test.go
Roman Khimov ec7e17ffa6 pkg: make use of the new crypto/hash package
Simplifies a lot of code and removes some duplication. Unfortunately I had to
move test_util random functions in same commit to avoid cycle
dependencies. One of these random functions was also used in core/transaction
testing, to simplify things I've just dropped it there and used a static
string (which is nice to have for a test anyway).

There is still sha256 left in wallet (but it needs to pass Hash structure into
the signing function).
2019-08-26 13:32:19 +03:00

51 lines
992 B
Go

package core
import (
"bytes"
"testing"
"github.com/CityOfZion/neo-go/pkg/core/storage"
"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 := new(bytes.Buffer)
assert.Nil(t, spent.EncodeBinary(buf))
spentDecode := new(SpentCoinState)
assert.Nil(t, spentDecode.DecodeBinary(buf))
assert.Equal(t, spent, spentDecode)
}
func TestCommitSpentCoins(t *testing.T) {
var (
store = storage.NewMemoryStore()
batch = store.Batch()
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(batch))
assert.Nil(t, store.PutBatch(batch))
}