neoneo-go/pkg/core/account_state_test.go
Anthony De Meulemeester 94672cb9cc
Persistance (#53)
* added publish TX for backwards compat.

* lowered the prototick for faster block syncing

* print useragent on startup

* added createMultiRedeemScript for genesis block generation.

* building genesis block from scratch.

* implemented merkle tree.

* starting blockhain with generated genesis hash

* Fixed bug in unspent coin state.

* fixed broken tests after genesis block.

* removed log line.

* bumped version -> 0.34.0
2018-03-25 12:45:54 +02:00

49 lines
1.1 KiB
Go

package core
import (
"bytes"
"testing"
"github.com/CityOfZion/neo-go/pkg/crypto"
"github.com/CityOfZion/neo-go/pkg/util"
"github.com/stretchr/testify/assert"
)
func TestDecodeEncodeAccountState(t *testing.T) {
var (
n = 10
balances = make(map[util.Uint256]util.Fixed8)
votes = make([]*crypto.PublicKey, n)
)
for i := 0; i < n; i++ {
balances[util.RandomUint256()] = util.Fixed8(int64(util.RandomInt(1, 10000)))
votes[i] = &crypto.PublicKey{crypto.RandomECPoint()}
}
a := &AccountState{
Version: 0,
ScriptHash: util.RandomUint160(),
IsFrozen: true,
Votes: votes,
Balances: balances,
}
buf := new(bytes.Buffer)
if err := a.EncodeBinary(buf); err != nil {
t.Fatal(err)
}
aDecode := &AccountState{}
if err := aDecode.DecodeBinary(buf); err != nil {
t.Fatal(err)
}
assert.Equal(t, a.Version, aDecode.Version)
assert.Equal(t, a.ScriptHash, aDecode.ScriptHash)
assert.Equal(t, a.IsFrozen, aDecode.IsFrozen)
for i, vote := range a.Votes {
assert.Equal(t, vote.X, aDecode.Votes[i].X)
}
assert.Equal(t, a.Balances, aDecode.Balances)
}