2018-04-16 20:15:30 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-11-25 17:39:11 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/testutil"
|
2019-09-16 09:18:13 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/io"
|
2018-04-16 20:15:30 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEncodeDecodeSpentCoinState(t *testing.T) {
|
|
|
|
spent := &SpentCoinState{
|
2019-11-25 17:39:11 +00:00
|
|
|
txHash: testutil.RandomUint256(),
|
2018-04-16 20:15:30 +00:00
|
|
|
txHeight: 1001,
|
|
|
|
items: map[uint16]uint32{
|
|
|
|
1: 3,
|
|
|
|
2: 8,
|
|
|
|
4: 100,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-09-16 09:18:13 +00:00
|
|
|
buf := io.NewBufBinWriter()
|
2019-09-16 16:31:49 +00:00
|
|
|
spent.EncodeBinary(buf.BinWriter)
|
|
|
|
assert.Nil(t, buf.Err)
|
2018-04-16 20:15:30 +00:00
|
|
|
spentDecode := new(SpentCoinState)
|
2019-09-16 16:31:49 +00:00
|
|
|
r := io.NewBinReaderFromBuf(buf.Bytes())
|
|
|
|
spentDecode.DecodeBinary(r)
|
|
|
|
assert.Nil(t, r.Err)
|
2018-04-16 20:15:30 +00:00
|
|
|
assert.Equal(t, spent, spentDecode)
|
|
|
|
}
|