neoneo-go/pkg/core/account_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
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[randomUint256()] = util.Fixed8(int64(randomInt(1, 10000)))
votes[i] = &crypto.PublicKey{
ECPoint: crypto.RandomECPoint(),
}
}
a := &AccountState{
Version: 0,
ScriptHash: 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)
}