mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 13:38:35 +00:00
b77e533d13
And drop associated _pkg.dev remnants (refs. #307). Original `dev` branch had two separate packages for public and private keys, but those are so intertwined (`TestHelper` subpackage is a proof) that it's better unite them and all associated code (like WIF and NEP-2) in one package. This patch also: * creates internal `keytestcases` package to share things with wallet (maybe it'll be changed in some future) * ports some tests from `dev` * ports Verify() method for public key from `dev` * expands TestPrivateKey() with public key check
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package core
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/crypto"
|
|
"github.com/CityOfZion/neo-go/pkg/crypto/keys"
|
|
"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([]*keys.PublicKey, n)
|
|
)
|
|
for i := 0; i < n; i++ {
|
|
balances[randomUint256()] = util.Fixed8(int64(randomInt(1, 10000)))
|
|
votes[i] = &keys.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)
|
|
}
|