2020-03-09 13:56:37 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-03-09 15:56:24 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/internal/random"
|
2020-03-09 13:56:37 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
2020-03-09 15:56:24 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2020-03-09 13:56:37 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDecodeEncodeUnspentCoin(t *testing.T) {
|
|
|
|
unspent := &UnspentCoin{
|
2020-03-09 15:56:24 +00:00
|
|
|
Height: 100500,
|
|
|
|
States: []OutputState{
|
|
|
|
{
|
|
|
|
Output: transaction.Output{
|
|
|
|
AssetID: random.Uint256(),
|
|
|
|
Amount: util.Fixed8(42),
|
|
|
|
ScriptHash: random.Uint160(),
|
|
|
|
},
|
|
|
|
SpendHeight: 201000,
|
|
|
|
State: CoinSpent,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Output: transaction.Output{
|
|
|
|
AssetID: random.Uint256(),
|
|
|
|
Amount: util.Fixed8(420),
|
|
|
|
ScriptHash: random.Uint160(),
|
|
|
|
},
|
|
|
|
SpendHeight: 0,
|
|
|
|
State: CoinConfirmed,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Output: transaction.Output{
|
|
|
|
AssetID: random.Uint256(),
|
|
|
|
Amount: util.Fixed8(4200),
|
|
|
|
ScriptHash: random.Uint160(),
|
|
|
|
},
|
|
|
|
SpendHeight: 111000,
|
|
|
|
State: CoinSpent & CoinClaimed,
|
|
|
|
},
|
2020-03-09 13:56:37 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
buf := io.NewBufBinWriter()
|
|
|
|
unspent.EncodeBinary(buf.BinWriter)
|
|
|
|
assert.Nil(t, buf.Err)
|
|
|
|
unspentDecode := &UnspentCoin{}
|
|
|
|
r := io.NewBinReaderFromBuf(buf.Bytes())
|
|
|
|
unspentDecode.DecodeBinary(r)
|
|
|
|
assert.Nil(t, r.Err)
|
|
|
|
}
|