Skip to content

Commit 3f6ca74

Browse files
committed
fix(wire): move wire_test to package wire to prevent init dependency
Signed-off-by: Minh Huy Tran <[email protected]>
1 parent 03ce1db commit 3f6ca74

File tree

3 files changed

+13
-50
lines changed

3 files changed

+13
-50
lines changed

Diff for: wire/address.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func NewAddress() *Address {
3636
}
3737

3838
// Equal returns whether the two addresses are equal.
39-
func (a Address) Equal(b wire.Address) bool {
39+
func (a *Address) Equal(b wire.Address) bool {
4040
bTyped, ok := b.(*Address)
4141
if !ok {
4242
panic("wrong type")
@@ -47,7 +47,7 @@ func (a Address) Equal(b wire.Address) bool {
4747

4848
// Cmp compares the byte representation of two addresses. For `a.Cmp(b)`
4949
// returns -1 if a < b, 0 if a == b, 1 if a > b.
50-
func (a Address) Cmp(b wire.Address) int {
50+
func (a *Address) Cmp(b wire.Address) int {
5151
bTyped, ok := b.(*Address)
5252
if !ok {
5353
panic("wrong type")
@@ -63,7 +63,7 @@ func NewRandomAddress(rng *rand.Rand) *Address {
6363

6464
// Verify verifies a message signature.
6565
// It returns an error if the signature is invalid.
66-
func (a Address) Verify(msg []byte, sig []byte) error {
66+
func (a *Address) Verify(msg []byte, sig []byte) error {
6767
hash := PrefixedHash(msg)
6868
sigCopy := make([]byte, SigLen)
6969
copy(sigCopy, sig)

Diff for: wire/init_test.go

-37
This file was deleted.

Diff for: wire/wire_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"math/rand"
1919
"testing"
2020

21-
"github.com/perun-network/perun-eth-backend/wire"
21+
ethwire "github.com/perun-network/perun-eth-backend/wire"
2222
"github.com/stretchr/testify/assert"
2323
perunwire "perun.network/go-perun/wire"
2424
"perun.network/go-perun/wire/test"
@@ -29,24 +29,24 @@ var dataToSign = []byte("SomeLongDataThatShouldBeSignedPlease")
2929

3030
func TestAddress(t *testing.T) {
3131
test.TestAddressImplementation(t, func() perunwire.Address {
32-
return wire.NewAddress()
32+
return ethwire.NewAddress()
3333
}, func(rng *rand.Rand) perunwire.Address {
34-
return wire.NewRandomAddress(rng)
34+
return ethwire.NewRandomAddress(rng)
3535
})
3636
}
3737

3838
func TestSignatures_Success(t *testing.T) {
39-
acc := wire.NewRandomAccount(pkgtest.Prng(t))
39+
acc := ethwire.NewRandomAccount(pkgtest.Prng(t))
4040
sig, err := acc.Sign(dataToSign)
4141
assert.NoError(t, err, "Sign with new account should succeed")
4242
assert.NotNil(t, sig)
43-
assert.Equal(t, len(sig), wire.SigLen, "Ethereum signature has wrong length")
43+
assert.Equal(t, len(sig), ethwire.SigLen, "Ethereum signature has wrong length")
4444
err = acc.Address().Verify(dataToSign, sig)
4545
assert.NoError(t, err, "Verification should succeed")
4646
}
4747

4848
func TestSignatures_ModifyData_Failure(t *testing.T) {
49-
acc := wire.NewRandomAccount(pkgtest.Prng(t))
49+
acc := ethwire.NewRandomAccount(pkgtest.Prng(t))
5050
sig, err := acc.Sign(dataToSign)
5151
assert.NoError(t, err, "Sign with new account should succeed")
5252
assert.NotNil(t, sig)
@@ -61,7 +61,7 @@ func TestSignatures_ModifyData_Failure(t *testing.T) {
6161
}
6262

6363
func TestSignatures_ModifySignature_Failure(t *testing.T) {
64-
acc := wire.NewRandomAccount(pkgtest.Prng(t))
64+
acc := ethwire.NewRandomAccount(pkgtest.Prng(t))
6565
sig, err := acc.Sign(dataToSign)
6666
assert.NoError(t, err, "Sign with new account should succeed")
6767
assert.NotNil(t, sig)
@@ -76,7 +76,7 @@ func TestSignatures_ModifySignature_Failure(t *testing.T) {
7676
}
7777

7878
func TestSignatures_ModifyLastByteOfSignature_Failure(t *testing.T) {
79-
acc := wire.NewRandomAccount(pkgtest.Prng(t))
79+
acc := ethwire.NewRandomAccount(pkgtest.Prng(t))
8080
sig, err := acc.Sign(dataToSign)
8181
assert.NoError(t, err, "Sign with new account should succeed")
8282
assert.NotNil(t, sig)
@@ -91,13 +91,13 @@ func TestSignatures_ModifyLastByteOfSignature_Failure(t *testing.T) {
9191
}
9292

9393
func TestSignatures_WrongAccount_Failure(t *testing.T) {
94-
acc := wire.NewRandomAccount(pkgtest.Prng(t))
94+
acc := ethwire.NewRandomAccount(pkgtest.Prng(t))
9595
sig, err := acc.Sign(dataToSign)
9696
assert.NoError(t, err, "Sign with new account should succeed")
9797
assert.NotNil(t, sig)
9898

9999
// Verify with a wrong account
100-
wrongAcc := wire.NewRandomAccount(pkgtest.Prng(t))
100+
wrongAcc := ethwire.NewRandomAccount(pkgtest.Prng(t))
101101
err = wrongAcc.Address().Verify(dataToSign, sig)
102102
assert.Error(t, err, "Verification should fail with wrong account")
103103
}

0 commit comments

Comments
 (0)