From 4392ab6805ad1669cfd25a2cfcb462b6f0e407f3 Mon Sep 17 00:00:00 2001 From: Manoranjith Date: Tue, 7 Dec 2021 18:01:47 +0530 Subject: [PATCH] [pkg/io,wire/perun] Move pkg/io to wire/perunio - pkg/io implements the a custom encoding/decoding logic for sending messages on the wire. - Hence, moving it to a more appropriate path wire/perun. - Note: persistence/keyvalue also uses the wire/perun encoding for storing the channels to the keyvalue store. Signed-off-by: Manoranjith --- backend/ethereum/channel/backend.go | 2 +- backend/ethereum/channel_test.go | 2 +- .../ethereum/wallet/address_internal_test.go | 2 +- backend/ethereum/wallet/backend.go | 2 +- backend/ethereum/wallet/hd/wallet_test.go | 4 +-- .../ethereum/wallet/keystore/wallet_test.go | 8 ++--- backend/ethereum/wallet/simple/wallet_test.go | 4 +-- backend/sim/channel/asset.go | 2 +- backend/sim/channel/asset_test.go | 2 +- backend/sim/channel/backend.go | 2 +- backend/sim/wallet/address_internal_test.go | 2 +- backend/sim/wallet/backend.go | 2 +- backend/sim/wallet/wallet_internal_test.go | 4 +-- channel/actionmachine.go | 2 +- channel/allocation.go | 2 +- channel/allocation_test.go | 4 +-- channel/app.go | 2 +- channel/machine.go | 14 ++++---- channel/mock_app_internal_test.go | 2 +- channel/params.go | 12 +++---- channel/params_test.go | 6 ++-- .../persistence/keyvalue/persistedstate.go | 2 +- channel/persistence/keyvalue/persister.go | 2 +- channel/persistence/keyvalue/restorer.go | 2 +- channel/persistence/test/peerchans.go | 6 ++-- channel/state.go | 2 +- channel/state_test.go | 2 +- channel/transaction.go | 2 +- channel/transaction_test.go | 2 +- client/proposal.go | 4 +-- client/proposalmsgs.go | 2 +- client/serialize.go | 2 +- client/syncmsgs.go | 2 +- client/updatemsgs.go | 2 +- wallet/address.go | 16 ++++----- wallet/address_test.go | 2 +- wallet/sig.go | 2 +- wallet/test/address.go | 8 ++--- wallet/test/wallet.go | 8 ++--- wallet/test/walletbench.go | 4 +-- wire/address.go | 6 ++-- wire/controlmsgs.go | 2 +- wire/msg.go | 2 +- wire/msg_internal_test.go | 2 +- wire/msgtest.go | 2 +- {pkg/io => wire/perunio}/bigint.go | 2 +- .../perunio}/bigint_external_test.go | 34 +++++++++---------- {pkg/io => wire/perunio}/byteslice.go | 2 +- .../perunio}/byteslice_external_test.go | 14 ++++---- {pkg/io => wire/perunio}/doc.go | 5 +-- {pkg/io => wire/perunio}/equal_binary.go | 2 +- {pkg/io => wire/perunio}/equal_encoding.go | 2 +- .../perunio}/equal_encoding_external_test.go | 22 ++++++------ {pkg/io => wire/perunio}/serialize.go | 6 ++-- {pkg/io => wire/perunio}/serializer.go | 2 +- {pkg/io => wire/perunio}/string.go | 2 +- .../perunio}/string_internal_test.go | 2 +- {pkg/io => wire/perunio}/test/doc.go | 2 +- .../io => wire/perunio}/test/marshalertest.go | 0 .../perunio}/test/serializertest.go | 2 +- .../io => wire/perunio}/wire_internal_test.go | 2 +- 61 files changed, 135 insertions(+), 134 deletions(-) rename {pkg/io => wire/perunio}/bigint.go (99%) rename {pkg/io => wire/perunio}/bigint_external_test.go (72%) rename {pkg/io => wire/perunio}/byteslice.go (98%) rename {pkg/io => wire/perunio}/byteslice_external_test.go (82%) rename {pkg/io => wire/perunio}/doc.go (80%) rename {pkg/io => wire/perunio}/equal_binary.go (98%) rename {pkg/io => wire/perunio}/equal_encoding.go (98%) rename {pkg/io => wire/perunio}/equal_encoding_external_test.go (79%) rename {pkg/io => wire/perunio}/serialize.go (96%) rename {pkg/io => wire/perunio}/serializer.go (98%) rename {pkg/io => wire/perunio}/string.go (99%) rename {pkg/io => wire/perunio}/string_internal_test.go (99%) rename {pkg/io => wire/perunio}/test/doc.go (91%) rename {pkg/io => wire/perunio}/test/marshalertest.go (100%) rename {pkg/io => wire/perunio}/test/serializertest.go (98%) rename {pkg/io => wire/perunio}/wire_internal_test.go (99%) diff --git a/backend/ethereum/channel/backend.go b/backend/ethereum/channel/backend.go index 08ba9c01..a4ee4937 100644 --- a/backend/ethereum/channel/backend.go +++ b/backend/ethereum/channel/backend.go @@ -29,8 +29,8 @@ import ( "perun.network/go-perun/backend/ethereum/bindings/adjudicator" ethwallet "perun.network/go-perun/backend/ethereum/wallet" "perun.network/go-perun/channel" - perunio "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet" + "perun.network/go-perun/wire/perunio" ) const ( diff --git a/backend/ethereum/channel_test.go b/backend/ethereum/channel_test.go index 22c9604d..3038e334 100644 --- a/backend/ethereum/channel_test.go +++ b/backend/ethereum/channel_test.go @@ -20,7 +20,7 @@ import ( pkgtest "polycry.pt/poly-go/test" ethwallettest "perun.network/go-perun/backend/ethereum/wallet/test" - "perun.network/go-perun/pkg/io/test" + "perun.network/go-perun/wire/perunio/test" ) func Test_Asset_GenericMarshaler(t *testing.T) { diff --git a/backend/ethereum/wallet/address_internal_test.go b/backend/ethereum/wallet/address_internal_test.go index 698066fd..b3a0b42e 100644 --- a/backend/ethereum/wallet/address_internal_test.go +++ b/backend/ethereum/wallet/address_internal_test.go @@ -20,7 +20,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" - "perun.network/go-perun/pkg/io/test" + "perun.network/go-perun/wire/perunio/test" pkgtest "polycry.pt/poly-go/test" ) diff --git a/backend/ethereum/wallet/backend.go b/backend/ethereum/wallet/backend.go index a673f45d..10ec7272 100644 --- a/backend/ethereum/wallet/backend.go +++ b/backend/ethereum/wallet/backend.go @@ -20,8 +20,8 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/pkg/errors" - perunio "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet" + "perun.network/go-perun/wire/perunio" ) // Backend implements the utility interface defined in the wallet package. diff --git a/backend/ethereum/wallet/hd/wallet_test.go b/backend/ethereum/wallet/hd/wallet_test.go index 14065c86..f0991f05 100644 --- a/backend/ethereum/wallet/hd/wallet_test.go +++ b/backend/ethereum/wallet/hd/wallet_test.go @@ -28,8 +28,8 @@ import ( ethwallet "perun.network/go-perun/backend/ethereum/wallet" "perun.network/go-perun/backend/ethereum/wallet/hd" ethwallettest "perun.network/go-perun/backend/ethereum/wallet/test" - "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet/test" + "perun.network/go-perun/wire/perunio" pkgtest "polycry.pt/poly-go/test" ) @@ -123,7 +123,7 @@ func newSetup(t require.TestingT, prng *rand.Rand) (*test.Setup, accounts.Wallet addressNotInWallet := ethwallettest.NewRandomAddress(prng) var buff bytes.Buffer - err = io.Encode(&buff, &addressNotInWallet) + err = perunio.Encode(&buff, &addressNotInWallet) if err != nil { panic(err) } diff --git a/backend/ethereum/wallet/keystore/wallet_test.go b/backend/ethereum/wallet/keystore/wallet_test.go index 6da42fa1..0f0c7558 100644 --- a/backend/ethereum/wallet/keystore/wallet_test.go +++ b/backend/ethereum/wallet/keystore/wallet_test.go @@ -26,8 +26,8 @@ import ( ethwallet "perun.network/go-perun/backend/ethereum/wallet" ethwallettest "perun.network/go-perun/backend/ethereum/wallet/test" - "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet/test" + "perun.network/go-perun/wire/perunio" pkgtest "polycry.pt/poly-go/test" ) @@ -75,12 +75,12 @@ func TestBackend(t *testing.T) { buff := bytes.NewReader(s.AddressEncoded) addr := backend.NewAddress() - err := io.Decode(buff, addr) + err := perunio.Decode(buff, addr) assert.NoError(t, err, "NewAddress from Bytes should work") buff = bytes.NewReader([]byte(invalidAddr)) addr = backend.NewAddress() - err = io.Decode(buff, addr) + err = perunio.Decode(buff, addr) assert.Error(t, err, "Conversion from wrong address should fail") } @@ -89,7 +89,7 @@ func newSetup(t require.TestingT, prng *rand.Rand) *test.Setup { addressNotInWallet := ethwallettest.NewRandomAddress(prng) var buff bytes.Buffer - err := io.Encode(&buff, &addressNotInWallet) + err := perunio.Encode(&buff, &addressNotInWallet) if err != nil { panic(err) } diff --git a/backend/ethereum/wallet/simple/wallet_test.go b/backend/ethereum/wallet/simple/wallet_test.go index e9321028..d41f083e 100644 --- a/backend/ethereum/wallet/simple/wallet_test.go +++ b/backend/ethereum/wallet/simple/wallet_test.go @@ -29,8 +29,8 @@ import ( ethwallet "perun.network/go-perun/backend/ethereum/wallet" "perun.network/go-perun/backend/ethereum/wallet/simple" ethwallettest "perun.network/go-perun/backend/ethereum/wallet/test" - "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet/test" + "perun.network/go-perun/wire/perunio" pkgtest "polycry.pt/poly-go/test" ) @@ -104,7 +104,7 @@ func newSetup(t require.TestingT, prng *rand.Rand) (*test.Setup, *simple.Wallet) addressNotInWallet := ethwallettest.NewRandomAddress(prng) var buff bytes.Buffer - err = io.Encode(&buff, &addressNotInWallet) + err = perunio.Encode(&buff, &addressNotInWallet) if err != nil { panic(err) } diff --git a/backend/sim/channel/asset.go b/backend/sim/channel/asset.go index 3f29c540..ff88b10a 100644 --- a/backend/sim/channel/asset.go +++ b/backend/sim/channel/asset.go @@ -20,7 +20,7 @@ import ( "math/rand" "perun.network/go-perun/channel" - perunio "perun.network/go-perun/pkg/io" + "perun.network/go-perun/wire/perunio" ) // AssetBinaryLen is the length of binary representation of asset, in bytes. diff --git a/backend/sim/channel/asset_test.go b/backend/sim/channel/asset_test.go index 0d3804d3..f1d43a87 100644 --- a/backend/sim/channel/asset_test.go +++ b/backend/sim/channel/asset_test.go @@ -17,7 +17,7 @@ import ( "testing" "perun.network/go-perun/backend/sim/channel" - "perun.network/go-perun/pkg/io/test" + "perun.network/go-perun/wire/perunio/test" pkgtest "polycry.pt/poly-go/test" ) diff --git a/backend/sim/channel/backend.go b/backend/sim/channel/backend.go index 987a411c..2ebfafa5 100644 --- a/backend/sim/channel/backend.go +++ b/backend/sim/channel/backend.go @@ -22,8 +22,8 @@ import ( "perun.network/go-perun/channel" "perun.network/go-perun/log" - perunio "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet" + "perun.network/go-perun/wire/perunio" ) // backend implements the utility interface defined in the channel package. diff --git a/backend/sim/wallet/address_internal_test.go b/backend/sim/wallet/address_internal_test.go index 3232d1a4..8063f953 100644 --- a/backend/sim/wallet/address_internal_test.go +++ b/backend/sim/wallet/address_internal_test.go @@ -21,7 +21,7 @@ import ( "github.com/stretchr/testify/assert" pkgtest "polycry.pt/poly-go/test" - "perun.network/go-perun/pkg/io/test" + "perun.network/go-perun/wire/perunio/test" ) func TestGenericMarshaler(t *testing.T) { diff --git a/backend/sim/wallet/backend.go b/backend/sim/wallet/backend.go index e364e173..c26ce614 100644 --- a/backend/sim/wallet/backend.go +++ b/backend/sim/wallet/backend.go @@ -23,8 +23,8 @@ import ( "github.com/pkg/errors" "perun.network/go-perun/log" - perunio "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet" + "perun.network/go-perun/wire/perunio" ) var curve = elliptic.P256() diff --git a/backend/sim/wallet/wallet_internal_test.go b/backend/sim/wallet/wallet_internal_test.go index 88535cd7..48281baf 100644 --- a/backend/sim/wallet/wallet_internal_test.go +++ b/backend/sim/wallet/wallet_internal_test.go @@ -22,8 +22,8 @@ import ( "github.com/stretchr/testify/assert" - "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet/test" + "perun.network/go-perun/wire/perunio" pkgtest "polycry.pt/poly-go/test" ) @@ -102,7 +102,7 @@ func newWalletSetup(rng *rand.Rand) *test.Setup { addressNotInWallet := NewRandomAccount(rng).Address() var buff bytes.Buffer - err = io.Encode(&buff, addressNotInWallet) + err = perunio.Encode(&buff, addressNotInWallet) if err != nil { panic(err) } diff --git a/channel/actionmachine.go b/channel/actionmachine.go index 650f9551..dde35716 100644 --- a/channel/actionmachine.go +++ b/channel/actionmachine.go @@ -20,8 +20,8 @@ import ( "github.com/pkg/errors" - perunio "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet" + "perun.network/go-perun/wire/perunio" ) // An ActionMachine is the channel pushdown automaton around an ActionApp. diff --git a/channel/allocation.go b/channel/allocation.go index d5ead882..9289764a 100644 --- a/channel/allocation.go +++ b/channel/allocation.go @@ -20,7 +20,7 @@ import ( "log" "math/big" - perunio "perun.network/go-perun/pkg/io" + "perun.network/go-perun/wire/perunio" perunbig "polycry.pt/poly-go/math/big" "github.com/ethereum/go-ethereum/accounts/abi" diff --git a/channel/allocation_test.go b/channel/allocation_test.go index 8dcd180e..fbbb448c 100644 --- a/channel/allocation_test.go +++ b/channel/allocation_test.go @@ -24,8 +24,8 @@ import ( "perun.network/go-perun/channel" "perun.network/go-perun/channel/test" - perunio "perun.network/go-perun/pkg/io" - iotest "perun.network/go-perun/pkg/io/test" + "perun.network/go-perun/wire/perunio" + iotest "perun.network/go-perun/wire/perunio/test" pkgbig "polycry.pt/poly-go/math/big" pkgtest "polycry.pt/poly-go/test" ) diff --git a/channel/app.go b/channel/app.go index d6be2db5..1e066bf3 100644 --- a/channel/app.go +++ b/channel/app.go @@ -20,8 +20,8 @@ import ( "github.com/pkg/errors" - perunio "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet" + "perun.network/go-perun/wire/perunio" ) type ( diff --git a/channel/machine.go b/channel/machine.go index 975977e3..b44b1c9a 100644 --- a/channel/machine.go +++ b/channel/machine.go @@ -21,8 +21,8 @@ import ( "github.com/pkg/errors" "perun.network/go-perun/log" - "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet" + "perun.network/go-perun/wire/perunio" "polycry.pt/poly-go/math/big" ) @@ -31,13 +31,13 @@ type Index uint16 // Encode encodes the object onto an io.Writer. func (i Index) Encode(w stdio.Writer) error { - return io.Encode(w, uint16(i)) + return perunio.Encode(w, uint16(i)) } // Decode decodes an object from an io.Reader. func (i *Index) Decode(r stdio.Reader) error { var _i uint16 - err := io.Decode(r, &_i) + err := perunio.Decode(r, &_i) *i = Index(_i) return err } @@ -65,8 +65,8 @@ type ( ) var ( - _ Source = (*machine)(nil) - _ io.Serializer = (*Phase)(nil) + _ Source = (*machine)(nil) + _ perunio.Serializer = (*Phase)(nil) ) // Phases known to the channel machine. @@ -106,12 +106,12 @@ func (p Phase) String() string { // Encode serializes a Phase. func (p Phase) Encode(w stdio.Writer) error { - return io.Encode(w, uint8(p)) + return perunio.Encode(w, uint8(p)) } // Decode deserializes a Phase. func (p *Phase) Decode(r stdio.Reader) error { - return io.Decode(r, (*uint8)(p)) + return perunio.Decode(r, (*uint8)(p)) } func (t PhaseTransition) String() string { diff --git a/channel/mock_app_internal_test.go b/channel/mock_app_internal_test.go index 97bd8941..a0f1d702 100644 --- a/channel/mock_app_internal_test.go +++ b/channel/mock_app_internal_test.go @@ -19,8 +19,8 @@ import ( "github.com/stretchr/testify/assert" - iotest "perun.network/go-perun/pkg/io/test" wallettest "perun.network/go-perun/wallet/test" + iotest "perun.network/go-perun/wire/perunio/test" pkgtest "polycry.pt/poly-go/test" ) diff --git a/channel/params.go b/channel/params.go index 39b3fca2..ea0e9fb3 100644 --- a/channel/params.go +++ b/channel/params.go @@ -22,8 +22,8 @@ import ( "github.com/pkg/errors" "perun.network/go-perun/log" - "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet" + "perun.network/go-perun/wire/perunio" ) // IDLen the length of a channelID. @@ -52,7 +52,7 @@ func NonceFromBytes(b []byte) Nonce { // Zero is the default channelID. var Zero = ID{} -var _ io.Serializer = (*Params)(nil) +var _ perunio.Serializer = (*Params)(nil) // Params are a channel's immutable parameters. A channel's id is the hash of // (some of) its parameter, as determined by the backend. All fields should be @@ -150,12 +150,12 @@ func (p *Params) Clone() *Params { clonedParts := make([]wallet.Address, len(p.Parts)) for i, v := range p.Parts { var buff bytes.Buffer - if err := io.Encode(&buff, v); err != nil { + if err := perunio.Encode(&buff, v); err != nil { log.WithError(err).Panic("Could not encode part") } addr := wallet.NewAddress() - if err := io.Decode(&buff, addr); err != nil { + if err := perunio.Decode(&buff, addr); err != nil { log.WithError(err).Panic("Could not clone params' addresses") } clonedParts[i] = addr @@ -174,7 +174,7 @@ func (p *Params) Clone() *Params { // Encode uses the pkg/io module to serialize a params instance. func (p *Params) Encode(w stdio.Writer) error { - return io.Encode(w, + return perunio.Encode(w, p.ChallengeDuration, wallet.AddressesWithLen(p.Parts), OptAppEnc{p.App}, @@ -195,7 +195,7 @@ func (p *Params) Decode(r stdio.Reader) error { virtual bool ) - err := io.Decode(r, + err := perunio.Decode(r, &challengeDuration, &parts, OptAppDec{App: &app}, diff --git a/channel/params_test.go b/channel/params_test.go index 60243927..9b668922 100644 --- a/channel/params_test.go +++ b/channel/params_test.go @@ -19,8 +19,8 @@ import ( "perun.network/go-perun/channel" "perun.network/go-perun/channel/test" - "perun.network/go-perun/pkg/io" - iotest "perun.network/go-perun/pkg/io/test" + "perun.network/go-perun/wire/perunio" + iotest "perun.network/go-perun/wire/perunio/test" pkgtest "polycry.pt/poly-go/test" ) @@ -32,7 +32,7 @@ func TestParams_Clone(t *testing.T) { func TestParams_Serializer(t *testing.T) { rng := pkgtest.Prng(t) - params := make([]io.Serializer, 10) + params := make([]perunio.Serializer, 10) for i := range params { var p *channel.Params if i&1 == 0 { diff --git a/channel/persistence/keyvalue/persistedstate.go b/channel/persistence/keyvalue/persistedstate.go index 893d6ead..dd625f43 100644 --- a/channel/persistence/keyvalue/persistedstate.go +++ b/channel/persistence/keyvalue/persistedstate.go @@ -18,7 +18,7 @@ import ( "io" "perun.network/go-perun/channel" - perunio "perun.network/go-perun/pkg/io" + "perun.network/go-perun/wire/perunio" ) var ( diff --git a/channel/persistence/keyvalue/persister.go b/channel/persistence/keyvalue/persister.go index 624eebd4..6f606cce 100644 --- a/channel/persistence/keyvalue/persister.go +++ b/channel/persistence/keyvalue/persister.go @@ -26,8 +26,8 @@ import ( "github.com/pkg/errors" "perun.network/go-perun/channel" - perunio "perun.network/go-perun/pkg/io" "perun.network/go-perun/wire" + "perun.network/go-perun/wire/perunio" "polycry.pt/poly-go/sortedkv" ) diff --git a/channel/persistence/keyvalue/restorer.go b/channel/persistence/keyvalue/restorer.go index 16bba972..3f71aed4 100644 --- a/channel/persistence/keyvalue/restorer.go +++ b/channel/persistence/keyvalue/restorer.go @@ -24,9 +24,9 @@ import ( "perun.network/go-perun/channel" "perun.network/go-perun/channel/persistence" - perunio "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet" "perun.network/go-perun/wire" + "perun.network/go-perun/wire/perunio" "polycry.pt/poly-go/sortedkv" ) diff --git a/channel/persistence/test/peerchans.go b/channel/persistence/test/peerchans.go index 550ebd1e..5861340f 100644 --- a/channel/persistence/test/peerchans.go +++ b/channel/persistence/test/peerchans.go @@ -18,8 +18,8 @@ import ( "bytes" "perun.network/go-perun/channel" - "perun.network/go-perun/pkg/io" "perun.network/go-perun/wire" + "perun.network/go-perun/wire/perunio" ) type peerChans map[string][]channel.ID @@ -76,7 +76,7 @@ func (pc peerChans) Delete(id channel.ID) { func peerKey(a wire.Address) string { key := new(bytes.Buffer) - err := io.Encode(key, a) + err := perunio.Encode(key, a) if err != nil { panic("error encoding peer key: " + err.Error()) } @@ -85,7 +85,7 @@ func peerKey(a wire.Address) string { func peerFromKey(s string) wire.Address { p := wire.NewAddress() - err := io.Decode(bytes.NewBuffer([]byte(s)), p) + err := perunio.Decode(bytes.NewBuffer([]byte(s)), p) if err != nil { panic("error decoding peer key: " + err.Error()) } diff --git a/channel/state.go b/channel/state.go index 7d6963b5..f3c57164 100644 --- a/channel/state.go +++ b/channel/state.go @@ -20,7 +20,7 @@ import ( "github.com/pkg/errors" - perunio "perun.network/go-perun/pkg/io" + "perun.network/go-perun/wire/perunio" ) type ( diff --git a/channel/state_test.go b/channel/state_test.go index 1c5d9b1f..83111091 100644 --- a/channel/state_test.go +++ b/channel/state_test.go @@ -20,7 +20,7 @@ import ( _ "perun.network/go-perun/backend/sim" // backend init "perun.network/go-perun/channel" "perun.network/go-perun/channel/test" - iotest "perun.network/go-perun/pkg/io/test" + iotest "perun.network/go-perun/wire/perunio/test" pkgtest "polycry.pt/poly-go/test" ) diff --git a/channel/transaction.go b/channel/transaction.go index d382589f..1539d2f8 100644 --- a/channel/transaction.go +++ b/channel/transaction.go @@ -19,8 +19,8 @@ import ( "github.com/pkg/errors" - perunio "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet" + "perun.network/go-perun/wire/perunio" ) // Transaction is a channel state together with valid signatures from the diff --git a/channel/transaction_test.go b/channel/transaction_test.go index eb6a8c4f..7963943f 100644 --- a/channel/transaction_test.go +++ b/channel/transaction_test.go @@ -19,7 +19,7 @@ import ( "perun.network/go-perun/channel" "perun.network/go-perun/channel/test" - iotest "perun.network/go-perun/pkg/io/test" + iotest "perun.network/go-perun/wire/perunio/test" pkgtest "polycry.pt/poly-go/test" ) diff --git a/client/proposal.go b/client/proposal.go index 0c22fc48..438beaa3 100644 --- a/client/proposal.go +++ b/client/proposal.go @@ -24,9 +24,9 @@ import ( "perun.network/go-perun/channel" "perun.network/go-perun/log" - "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet" "perun.network/go-perun/wire" + "perun.network/go-perun/wire/perunio" pcontext "polycry.pt/poly-go/context" "polycry.pt/poly-go/sync/atomic" ) @@ -496,7 +496,7 @@ func nonceShares(proposer, proposee NonceShare) []NonceShare { func calcNonce(nonceShares []NonceShare) channel.Nonce { hasher := newHasher() for i, share := range nonceShares { - if err := io.Encode(hasher, share); err != nil { + if err := perunio.Encode(hasher, share); err != nil { log.Panicf("Failed to encode nonce share %d for hashing", i) } } diff --git a/client/proposalmsgs.go b/client/proposalmsgs.go index 282dc8a2..33ed20da 100644 --- a/client/proposalmsgs.go +++ b/client/proposalmsgs.go @@ -24,9 +24,9 @@ import ( "perun.network/go-perun/channel" "perun.network/go-perun/log" - perunio "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet" "perun.network/go-perun/wire" + "perun.network/go-perun/wire/perunio" perunbig "polycry.pt/poly-go/math/big" ) diff --git a/client/serialize.go b/client/serialize.go index 11246591..8a696ae0 100644 --- a/client/serialize.go +++ b/client/serialize.go @@ -19,7 +19,7 @@ import ( "github.com/pkg/errors" "perun.network/go-perun/channel" - perunio "perun.network/go-perun/pkg/io" + "perun.network/go-perun/wire/perunio" ) type ( diff --git a/client/syncmsgs.go b/client/syncmsgs.go index 4e585413..8652f4ae 100644 --- a/client/syncmsgs.go +++ b/client/syncmsgs.go @@ -18,8 +18,8 @@ import ( "io" "perun.network/go-perun/channel" - perunio "perun.network/go-perun/pkg/io" "perun.network/go-perun/wire" + "perun.network/go-perun/wire/perunio" ) func init() { diff --git a/client/updatemsgs.go b/client/updatemsgs.go index 82b39828..716435b2 100644 --- a/client/updatemsgs.go +++ b/client/updatemsgs.go @@ -18,9 +18,9 @@ import ( "io" "perun.network/go-perun/channel" - perunio "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet" "perun.network/go-perun/wire" + "perun.network/go-perun/wire/perunio" ) func init() { diff --git a/wallet/address.go b/wallet/address.go index 26bd67b0..a8ca1002 100644 --- a/wallet/address.go +++ b/wallet/address.go @@ -23,7 +23,7 @@ import ( "github.com/pkg/errors" - "perun.network/go-perun/pkg/io" + "perun.network/go-perun/wire/perunio" ) // Address represents a identifier used in a cryptocurrency. @@ -86,7 +86,7 @@ type AddrKey string // following decode operation. func (a Addresses) Encode(w stdio.Writer) error { for i, addr := range a { - if err := io.Encode(w, addr); err != nil { + if err := perunio.Encode(w, addr); err != nil { return errors.WithMessagef(err, "encoding %d-th address", i) } } @@ -97,7 +97,7 @@ func (a Addresses) Encode(w stdio.Writer) error { // Encode encodes a wallet address slice, the length of which is unknown to the // following decode operation. func (a AddressesWithLen) Encode(w stdio.Writer) error { - return io.Encode(w, + return perunio.Encode(w, addressSliceLen(len(a)), (Addresses)(a)) } @@ -107,7 +107,7 @@ func (a AddressesWithLen) Encode(w stdio.Writer) error { func (a Addresses) Decode(r stdio.Reader) (err error) { for i := range a { a[i] = NewAddress() - err = io.Decode(r, a[i]) + err = perunio.Decode(r, a[i]) if err != nil { return errors.WithMessagef(err, "decoding %d-th address", i) } @@ -118,7 +118,7 @@ func (a Addresses) Decode(r stdio.Reader) (err error) { // Decode decodes a wallet address slice of unknown length. func (a *AddressesWithLen) Decode(r stdio.Reader) (err error) { var parts addressSliceLen - if err = io.Decode(r, &parts); err != nil { + if err = perunio.Decode(r, &parts); err != nil { return errors.WithMessage(err, "decoding count") } @@ -129,7 +129,7 @@ func (a *AddressesWithLen) Decode(r stdio.Reader) (err error) { // Decode decodes a single wallet address. func (a AddressDec) Decode(r stdio.Reader) (err error) { *a.Addr = NewAddress() - err = io.Decode(r, *a.Addr) + err = perunio.Decode(r, *a.Addr) return err } @@ -138,7 +138,7 @@ func (a AddressDec) Decode(r stdio.Reader) (err error) { // Panics when the `Address` can't be encoded. func Key(a Address) AddrKey { var buff strings.Builder - if err := io.Encode(&buff, a); err != nil { + if err := perunio.Encode(&buff, a); err != nil { panic("Could not encode address in AddrKey: " + err.Error()) } return AddrKey(buff.String()) @@ -149,7 +149,7 @@ func Key(a Address) AddrKey { // Panics when the `Address` can't be decoded. func FromKey(k AddrKey) Address { a := NewAddress() - err := io.Decode(bytes.NewBuffer([]byte(k)), a) + err := perunio.Decode(bytes.NewBuffer([]byte(k)), a) if err != nil { panic("Could not decode address in FromKey: " + err.Error()) } diff --git a/wallet/address_test.go b/wallet/address_test.go index 32f691e3..5ed19f8a 100644 --- a/wallet/address_test.go +++ b/wallet/address_test.go @@ -21,9 +21,9 @@ import ( "github.com/stretchr/testify/require" _ "perun.network/go-perun/backend/sim/wallet" - iotest "perun.network/go-perun/pkg/io/test" "perun.network/go-perun/wallet" wallettest "perun.network/go-perun/wallet/test" + iotest "perun.network/go-perun/wire/perunio/test" pkgtest "polycry.pt/poly-go/test" ) diff --git a/wallet/sig.go b/wallet/sig.go index 98570327..98a0375e 100644 --- a/wallet/sig.go +++ b/wallet/sig.go @@ -21,7 +21,7 @@ import ( "github.com/pkg/errors" - perunio "perun.network/go-perun/pkg/io" + "perun.network/go-perun/wire/perunio" ) // Sig is a single signature. diff --git a/wallet/test/address.go b/wallet/test/address.go index 9602d31f..d7d4c52c 100644 --- a/wallet/test/address.go +++ b/wallet/test/address.go @@ -21,7 +21,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "perun.network/go-perun/pkg/io" + "perun.network/go-perun/wire/perunio" ) // TestAddress runs a test suite designed to test the general functionality of @@ -29,7 +29,7 @@ import ( func TestAddress(t *testing.T, s *Setup) { //nolint:revive // `test.Test...` stutters, but we accept that here. null := s.ZeroAddress addr := s.Backend.NewAddress() - err := io.Decode(bytes.NewReader(s.AddressEncoded), addr) + err := perunio.Decode(bytes.NewReader(s.AddressEncoded), addr) assert.NoError(t, err, "Byte deserialization of address should work") // Test Address.String. @@ -58,9 +58,9 @@ func TestAddress(t *testing.T, s *Setup) { //nolint:revive // `test.Test...` stu // a.Equal(Decode(Encode(a))) t.Run("Serialize Equal Test", func(t *testing.T) { buff := new(bytes.Buffer) - require.NoError(t, io.Encode(buff, addr)) + require.NoError(t, perunio.Encode(buff, addr)) addr2 := s.Backend.NewAddress() - err := io.Decode(buff, addr2) + err := perunio.Decode(buff, addr2) require.NoError(t, err) assert.True(t, addr.Equal(addr2)) diff --git a/wallet/test/wallet.go b/wallet/test/wallet.go index f1a81b40..b465aa91 100644 --- a/wallet/test/wallet.go +++ b/wallet/test/wallet.go @@ -21,8 +21,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet" + "perun.network/go-perun/wire/perunio" ) // InitWallet initializes a wallet. @@ -54,7 +54,7 @@ func TestAccountWithWalletAndBackend(t *testing.T, s *Setup) { //nolint:revive / assert.NoError(t, err, "Verification should not produce error") addr := s.Backend.NewAddress() - err = io.Decode(bytes.NewReader(s.AddressEncoded), addr) + err = perunio.Decode(bytes.NewReader(s.AddressEncoded), addr) assert.NoError(t, err, "Byte deserialization of address should work") valid, err = s.Backend.VerifySignature(s.DataToSign, sig, addr) assert.False(t, valid, "Verification with wrong address should fail") @@ -87,14 +87,14 @@ func TestAccountWithWalletAndBackend(t *testing.T, s *Setup) { //nolint:revive / require.NoError(t, err, "Sign with unlocked account should succeed") buff := new(bytes.Buffer) - err = io.Encode(buff, sig) + err = perunio.Encode(buff, sig) require.NoError(t, err, "encode sig") sign2, err := s.Backend.DecodeSig(buff) assert.NoError(t, err, "Decoded signature should work") assert.Equal(t, sig, sign2, "Decoded signature should be equal to the original") // Test DecodeSig on short stream - err = io.Encode(buff, sig) + err = perunio.Encode(buff, sig) require.NoError(t, err, "encode sig") shortBuff := bytes.NewBuffer(buff.Bytes()[:len(buff.Bytes())-1]) // remove one byte _, err = s.Backend.DecodeSig(shortBuff) diff --git a/wallet/test/walletbench.go b/wallet/test/walletbench.go index ec46ae00..602a4279 100644 --- a/wallet/test/walletbench.go +++ b/wallet/test/walletbench.go @@ -19,7 +19,7 @@ import ( "testing" "github.com/stretchr/testify/require" - "perun.network/go-perun/pkg/io" + "perun.network/go-perun/wire/perunio" ) // GenericAccountBenchmark runs a suite designed to benchmark the general speed of an implementation of an Account. @@ -72,7 +72,7 @@ func benchBackendVerifySig(b *testing.B, s *Setup) { func benchBackendDecodeAddress(b *testing.B, s *Setup) { b.Helper() for n := 0; n < b.N; n++ { - err := io.Decode(bytes.NewReader(s.AddressEncoded), s.Backend.NewAddress()) + err := perunio.Decode(bytes.NewReader(s.AddressEncoded), s.Backend.NewAddress()) if err != nil { b.Fatal(err) } diff --git a/wire/address.go b/wire/address.go index fca9db4e..ae28dcbf 100644 --- a/wire/address.go +++ b/wire/address.go @@ -17,13 +17,13 @@ package wire import ( stdio "io" - "perun.network/go-perun/pkg/io" "perun.network/go-perun/wallet" + "perun.network/go-perun/wire/perunio" ) var ( - _ io.Serializer = (*Addresses)(nil) - _ io.Serializer = (*AddressesWithLen)(nil) + _ perunio.Serializer = (*Addresses)(nil) + _ perunio.Serializer = (*AddressesWithLen)(nil) ) // Address is a Perun node's network address, which is used as a permanent diff --git a/wire/controlmsgs.go b/wire/controlmsgs.go index a88874de..8d2e69bc 100644 --- a/wire/controlmsgs.go +++ b/wire/controlmsgs.go @@ -18,7 +18,7 @@ import ( "io" "time" - perunio "perun.network/go-perun/pkg/io" + "perun.network/go-perun/wire/perunio" ) func init() { diff --git a/wire/msg.go b/wire/msg.go index 66a8f1b2..3b3a755b 100644 --- a/wire/msg.go +++ b/wire/msg.go @@ -21,7 +21,7 @@ import ( "github.com/pkg/errors" - perunio "perun.network/go-perun/pkg/io" + "perun.network/go-perun/wire/perunio" ) type ( diff --git a/wire/msg_internal_test.go b/wire/msg_internal_test.go index b12024d5..6ee21add 100644 --- a/wire/msg_internal_test.go +++ b/wire/msg_internal_test.go @@ -22,8 +22,8 @@ import ( "github.com/stretchr/testify/assert" - iotest "perun.network/go-perun/pkg/io/test" wtest "perun.network/go-perun/wallet/test" + iotest "perun.network/go-perun/wire/perunio/test" "polycry.pt/poly-go/test" ) diff --git a/wire/msgtest.go b/wire/msgtest.go index ab75256a..74dcdcf0 100644 --- a/wire/msgtest.go +++ b/wire/msgtest.go @@ -18,7 +18,7 @@ import ( "io" "testing" - "perun.network/go-perun/pkg/io/test" + "perun.network/go-perun/wire/perunio/test" ) type serializerMsg struct { diff --git a/pkg/io/bigint.go b/wire/perunio/bigint.go similarity index 99% rename from pkg/io/bigint.go rename to wire/perunio/bigint.go index d0c50b96..69913643 100644 --- a/pkg/io/bigint.go +++ b/wire/perunio/bigint.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package io +package perunio import ( "io" diff --git a/pkg/io/bigint_external_test.go b/wire/perunio/bigint_external_test.go similarity index 72% rename from pkg/io/bigint_external_test.go rename to wire/perunio/bigint_external_test.go index 4d28c5f9..743caa34 100644 --- a/pkg/io/bigint_external_test.go +++ b/wire/perunio/bigint_external_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package io_test +package perunio_test import ( "bytes" @@ -20,16 +20,16 @@ import ( "testing" "github.com/stretchr/testify/assert" - "perun.network/go-perun/pkg/io" - "perun.network/go-perun/pkg/io/test" + "perun.network/go-perun/wire/perunio" + "perun.network/go-perun/wire/perunio/test" ) func TestBigInt_Generic(t *testing.T) { - vars := []io.Serializer{ - &io.BigInt{Int: big.NewInt(0)}, - &io.BigInt{Int: big.NewInt(1)}, - &io.BigInt{Int: big.NewInt(123456)}, - &io.BigInt{Int: new(big.Int).SetBytes([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})}, // larger than uint64 + vars := []perunio.Serializer{ + &perunio.BigInt{Int: big.NewInt(0)}, + &perunio.BigInt{Int: big.NewInt(1)}, + &perunio.BigInt{Int: big.NewInt(123456)}, + &perunio.BigInt{Int: new(big.Int).SetBytes([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})}, // larger than uint64 } test.GenericSerializerTest(t, vars...) } @@ -38,20 +38,20 @@ func TestBigInt_DecodeZeroLength(t *testing.T) { assert := assert.New(t) buf := bytes.NewBuffer([]byte{0}) - var result io.BigInt + var result perunio.BigInt assert.NoError(result.Decode(buf), "decoding zero length big.Int should work") assert.Zero(new(big.Int).Cmp(result.Int), "decoding zero length should set big.Int to 0") } func TestBigInt_DecodeToExisting(t *testing.T) { x, buf := new(big.Int), bytes.NewBuffer([]byte{1, 42}) - wx := io.BigInt{Int: x} + wx := perunio.BigInt{Int: x} assert.NoError(t, wx.Decode(buf), "decoding {1, 42} into big.Int should work") assert.Zero(t, big.NewInt(42).Cmp(x), "decoding {1, 42} into big.Int should result in 42") } func TestBigInt_Negative(t *testing.T) { - neg, buf := io.BigInt{Int: big.NewInt(-1)}, new(bytes.Buffer) + neg, buf := perunio.BigInt{Int: big.NewInt(-1)}, new(bytes.Buffer) assert.Panics(t, func() { _ = neg.Encode(buf) }, "encoding negative big.Int should panic") assert.Zero(t, buf.Len(), "encoding negative big.Int should not write anything") } @@ -60,9 +60,9 @@ func TestBigInt_Invalid(t *testing.T) { a := assert.New(t) buf := new(bytes.Buffer) // Test integers that are too big - tooBigBitPos := []uint{io.MaxBigIntLength*8 + 1, 0xff*8 + 1} // too big uint8 and uint16 lengths + tooBigBitPos := []uint{perunio.MaxBigIntLength*8 + 1, 0xff*8 + 1} // too big uint8 and uint16 lengths for _, pos := range tooBigBitPos { - tooBig := io.BigInt{Int: big.NewInt(1)} + tooBig := perunio.BigInt{Int: big.NewInt(1)} tooBig.Lsh(tooBig.Int, pos) a.Error(tooBig.Encode(buf), "encoding too big big.Int should fail") @@ -71,12 +71,12 @@ func TestBigInt_Invalid(t *testing.T) { } // manually encode too big number to test failing of decoding - buf.Write([]byte{io.MaxBigIntLength + 1}) - for i := 0; i < io.MaxBigIntLength+1; i++ { + buf.Write([]byte{perunio.MaxBigIntLength + 1}) + for i := 0; i < perunio.MaxBigIntLength+1; i++ { buf.WriteByte(0xff) } - var result io.BigInt + var result perunio.BigInt a.Error(result.Decode(buf), "decoding of an integer that is too big should fail") buf.Reset() @@ -84,5 +84,5 @@ func TestBigInt_Invalid(t *testing.T) { buf.WriteByte(1) a.Error(result.Decode(buf), "decoding after sender only sent length should fail") - a.Panics(func() { _ = io.BigInt{Int: nil}.Encode(buf) }, "encoding nil big.Int failed to panic") + a.Panics(func() { _ = perunio.BigInt{Int: nil}.Encode(buf) }, "encoding nil big.Int failed to panic") } diff --git a/pkg/io/byteslice.go b/wire/perunio/byteslice.go similarity index 98% rename from pkg/io/byteslice.go rename to wire/perunio/byteslice.go index 0f0bfa4e..1c3f0f14 100644 --- a/pkg/io/byteslice.go +++ b/wire/perunio/byteslice.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package io +package perunio import ( "io" diff --git a/pkg/io/byteslice_external_test.go b/wire/perunio/byteslice_external_test.go similarity index 82% rename from pkg/io/byteslice_external_test.go rename to wire/perunio/byteslice_external_test.go index c4033c1f..e66e88bf 100644 --- a/pkg/io/byteslice_external_test.go +++ b/wire/perunio/byteslice_external_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package io_test +package perunio_test import ( "io" @@ -21,13 +21,13 @@ import ( "github.com/stretchr/testify/assert" - polyio "perun.network/go-perun/pkg/io" - iotest "perun.network/go-perun/pkg/io/test" + "perun.network/go-perun/wire/perunio" + iotest "perun.network/go-perun/wire/perunio/test" ctxtest "polycry.pt/poly-go/context/test" ) func TestByteSlice(t *testing.T) { - var v1, v2, v3, v4 polyio.ByteSlice = []byte{}, []byte{255}, []byte{1, 2, 3, 4, 5, 6}, make([]byte, 20000) + var v1, v2, v3, v4 perunio.ByteSlice = []byte{}, []byte{255}, []byte{1, 2, 3, 4, 5, 6}, make([]byte, 20000) testByteSlices(t, v1, v2, v3, v4) iotest.GenericBrokenPipeTest(t, &v1, &v2, &v3, &v4) } @@ -44,7 +44,7 @@ func TestStutter(t *testing.T) { } }() - var decodedValue polyio.ByteSlice = make([]byte, len(values)) + var decodedValue perunio.ByteSlice = make([]byte, len(values)) ctxtest.AssertTerminatesQuickly(t, func() { assert.NoError(t, decodedValue.Decode(r)) }) @@ -53,7 +53,7 @@ func TestStutter(t *testing.T) { } } -func testByteSlices(t *testing.T, serial ...polyio.ByteSlice) { +func testByteSlices(t *testing.T, serial ...perunio.ByteSlice) { t.Helper() a := assert.New(t) r, w := io.Pipe() @@ -68,7 +68,7 @@ func testByteSlices(t *testing.T, serial ...polyio.ByteSlice) { for i, v := range serial { d := make([]byte, len(v)) - dest := polyio.ByteSlice(d) + dest := perunio.ByteSlice(d) a.NoError(dest.Decode(r), "failed to decode element") diff --git a/pkg/io/doc.go b/wire/perunio/doc.go similarity index 80% rename from pkg/io/doc.go rename to wire/perunio/doc.go index 16797c21..258dac8c 100644 --- a/pkg/io/doc.go +++ b/wire/perunio/doc.go @@ -12,5 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package io contains functionality for the serialization of standard Go types. -package io // import "perun.network/go-perun/pkg/io" +// Package perunio contains functionality for the serialization of standard Go +// types. +package perunio // import "perun.network/go-perun/wire/perunio" diff --git a/pkg/io/equal_binary.go b/wire/perunio/equal_binary.go similarity index 98% rename from pkg/io/equal_binary.go rename to wire/perunio/equal_binary.go index 0e1e6316..348c96f0 100644 --- a/pkg/io/equal_binary.go +++ b/wire/perunio/equal_binary.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package io +package perunio import ( "bytes" diff --git a/pkg/io/equal_encoding.go b/wire/perunio/equal_encoding.go similarity index 98% rename from pkg/io/equal_encoding.go rename to wire/perunio/equal_encoding.go index a89b1eec..3afd5ad7 100644 --- a/pkg/io/equal_encoding.go +++ b/wire/perunio/equal_encoding.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package io +package perunio import ( "bytes" diff --git a/pkg/io/equal_encoding_external_test.go b/wire/perunio/equal_encoding_external_test.go similarity index 79% rename from pkg/io/equal_encoding_external_test.go rename to wire/perunio/equal_encoding_external_test.go index 2c33163e..5c4ff46b 100644 --- a/pkg/io/equal_encoding_external_test.go +++ b/wire/perunio/equal_encoding_external_test.go @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -package io_test +package perunio_test import ( "testing" "github.com/stretchr/testify/assert" - "perun.network/go-perun/pkg/io" + "perun.network/go-perun/wire/perunio" polytest "polycry.pt/poly-go/test" ) @@ -26,9 +26,9 @@ import ( // TestEqualEncoding tests EqualEncoding. func TestEqualEncoding(t *testing.T) { rng := polytest.Prng(t) - a := make(io.ByteSlice, 10) - b := make(io.ByteSlice, 10) - c := make(io.ByteSlice, 12) + a := make(perunio.ByteSlice, 10) + b := make(perunio.ByteSlice, 10) + c := make(perunio.ByteSlice, 12) rng.Read(a) rng.Read(b) @@ -36,19 +36,19 @@ func TestEqualEncoding(t *testing.T) { c2 := c tests := []struct { - a io.Encoder - b io.Encoder + a perunio.Encoder + b perunio.Encoder shouldOk bool shouldErr bool name string }{ {a, nil, false, true, "one Encoder set to nil"}, {nil, a, false, true, "one Encoder set to nil"}, - {io.Encoder(nil), b, false, true, "one Encoder set to nil"}, - {b, io.Encoder(nil), false, true, "one Encoder set to nil"}, + {perunio.Encoder(nil), b, false, true, "one Encoder set to nil"}, + {b, perunio.Encoder(nil), false, true, "one Encoder set to nil"}, {nil, nil, true, false, "both Encoders set to nil"}, - {io.Encoder(nil), io.Encoder(nil), true, false, "both Encoders set to nil"}, + {perunio.Encoder(nil), perunio.Encoder(nil), true, false, "both Encoders set to nil"}, {a, a, true, false, "same Encoders"}, {a, &a, true, false, "same Encoders"}, @@ -62,7 +62,7 @@ func TestEqualEncoding(t *testing.T) { } for _, tt := range tests { - ok, err := io.EqualEncoding(tt.a, tt.b) + ok, err := perunio.EqualEncoding(tt.a, tt.b) assert.Equalf(t, ok, tt.shouldOk, "EqualEncoding with %s should return %t as bool but got: %t", tt.name, tt.shouldOk, ok) assert.Falsef(t, (err == nil) && tt.shouldErr, "EqualEncoding with %s should return an error but got nil", tt.name) diff --git a/pkg/io/serialize.go b/wire/perunio/serialize.go similarity index 96% rename from pkg/io/serialize.go rename to wire/perunio/serialize.go index 4f96b923..0672478d 100644 --- a/pkg/io/serialize.go +++ b/wire/perunio/serialize.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package io +package perunio import ( "encoding" @@ -72,7 +72,7 @@ func Encode(writer io.Writer, values ...interface{}) (err error) { //nolint: cyc if enc, ok := value.(Encoder); ok { err = enc.Encode(writer) } else { - panic(fmt.Sprintf("polyio.Encode(): Invalid type %T", v)) + panic(fmt.Sprintf("perunio.Encode(): Invalid type %T", v)) } } @@ -129,7 +129,7 @@ func Decode(reader io.Reader, values ...interface{}) (err error) { if dec, ok := value.(Decoder); ok { err = dec.Decode(reader) } else { - panic(fmt.Sprintf("polyio.Decode(): Invalid type %T", v)) + panic(fmt.Sprintf("perunio.Decode(): Invalid type %T", v)) } } diff --git a/pkg/io/serializer.go b/wire/perunio/serializer.go similarity index 98% rename from pkg/io/serializer.go rename to wire/perunio/serializer.go index 88bbe174..ce160b9e 100644 --- a/pkg/io/serializer.go +++ b/wire/perunio/serializer.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package io +package perunio import ( "io" diff --git a/pkg/io/string.go b/wire/perunio/string.go similarity index 99% rename from pkg/io/string.go rename to wire/perunio/string.go index 7f654ddc..277bea22 100644 --- a/pkg/io/string.go +++ b/wire/perunio/string.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package io +package perunio import ( "encoding/binary" diff --git a/pkg/io/string_internal_test.go b/wire/perunio/string_internal_test.go similarity index 99% rename from pkg/io/string_internal_test.go rename to wire/perunio/string_internal_test.go index b127b7e0..7df9d020 100644 --- a/pkg/io/string_internal_test.go +++ b/wire/perunio/string_internal_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package io +package perunio import ( "bytes" diff --git a/pkg/io/test/doc.go b/wire/perunio/test/doc.go similarity index 91% rename from pkg/io/test/doc.go rename to wire/perunio/test/doc.go index f04ed10a..0966170b 100644 --- a/pkg/io/test/doc.go +++ b/wire/perunio/test/doc.go @@ -13,4 +13,4 @@ // limitations under the License. // Package test contains the generic serializer tests. -package test // import "perun.network/go-perun/pkg/io/test" +package test // import "perun.network/go-perun/wire/perunio/test" diff --git a/pkg/io/test/marshalertest.go b/wire/perunio/test/marshalertest.go similarity index 100% rename from pkg/io/test/marshalertest.go rename to wire/perunio/test/marshalertest.go diff --git a/pkg/io/test/serializertest.go b/wire/perunio/test/serializertest.go similarity index 98% rename from pkg/io/test/serializertest.go rename to wire/perunio/test/serializertest.go index 2670720e..6d7bdcfa 100644 --- a/pkg/io/test/serializertest.go +++ b/wire/perunio/test/serializertest.go @@ -21,7 +21,7 @@ import ( "testing/iotest" "github.com/stretchr/testify/assert" - perunio "perun.network/go-perun/pkg/io" + "perun.network/go-perun/wire/perunio" ) // GenericSerializerTest runs multiple tests to check whether encoding diff --git a/pkg/io/wire_internal_test.go b/wire/perunio/wire_internal_test.go similarity index 99% rename from pkg/io/wire_internal_test.go rename to wire/perunio/wire_internal_test.go index e8389829..f8c2d001 100644 --- a/pkg/io/wire_internal_test.go +++ b/wire/perunio/wire_internal_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package io +package perunio import ( "io"