io: move size calculator there

It's mostly used for Serializable and in other cases where one needs to
estimate binary-encoded size of the stucture. This also simplifies future
removal of the Size() from Serializable.
This commit is contained in:
Roman Khimov 2019-09-16 12:33:53 +03:00
parent 5bf00db2c9
commit 0da9fe6946
13 changed files with 30 additions and 38 deletions

View file

@ -6,7 +6,7 @@ import (
"github.com/CityOfZion/neo-go/config"
"github.com/CityOfZion/neo-go/pkg/core/storage"
"github.com/CityOfZion/neo-go/pkg/util"
"github.com/CityOfZion/neo-go/pkg/io"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -142,10 +142,10 @@ func TestGetTransaction(t *testing.T) {
assert.Equal(t, block.Index, height)
assert.Equal(t, block.Transactions[0], tx)
assert.Equal(t, 10, tx.Size())
assert.Equal(t, 1, util.GetVarSize(tx.Attributes))
assert.Equal(t, 1, util.GetVarSize(tx.Inputs))
assert.Equal(t, 1, util.GetVarSize(tx.Outputs))
assert.Equal(t, 1, util.GetVarSize(tx.Scripts))
assert.Equal(t, 1, io.GetVarSize(tx.Attributes))
assert.Equal(t, 1, io.GetVarSize(tx.Inputs))
assert.Equal(t, 1, io.GetVarSize(tx.Outputs))
assert.Equal(t, 1, io.GetVarSize(tx.Scripts))
}
func newTestChain(t *testing.T) *Blockchain {