Skip to content

Commit e09ff52

Browse files
authored
Merge pull request #399 from perun-network/395_fix_failing_unit_tests
#395_Fix_Falling_Unit_Tests
2 parents a0a85bd + 927fd6b commit e09ff52

File tree

8 files changed

+34
-5
lines changed

8 files changed

+34
-5
lines changed

MAINTAINERS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
| Steffen Rattay | [@rmbrt](https://github.com/rmbrt) | rmbrt |
1010
| Ilja von Hoessle | [@iljabvh](https://github.com/iljabvh) | iljabvh |
1111
| Jens Winkle | [@DragonDev1906](https://github.com/DragonDev1906) | jens#4601 |
12+
| Minh Huy Tran | [@NhoxxKienn](https://github.com/NhoxxKienn) | NhoxxKienn |
1213

1314
## Emeritus Maintainers
1415

NOTICE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ PolyCrypt GmbH
4343
Oliver Tale-Yazdi <oliver@perun.network>
4444
Ilja von Hoessle <ilja@perun.network>
4545
Jens Winkle <jens@perun.network>
46+
Minh Huy Tran <huy@perun.network>
4647

4748
Robert Bosch GmbH
4849
Manoranjith <ponraj.manoranjitha@in.bosch.com>

channel/test/app_randomizer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type AppRandomizer interface {
2727
NewRandomData(*rand.Rand) channel.Data
2828
}
2929

30-
var appRandomizer AppRandomizer = &MockAppRandomizer{}
30+
var appRandomizer AppRandomizer = NewMockAppRandomizer()
3131

3232
// isAppRandomizerSet tracks whether the AppRandomizer was already set
3333
// with `SetAppRandomizer`.

channel/test/app_randomizer_internal_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ func TestAppRandomizerSet(t *testing.T) {
2929
assert.False(t, isAppRandomizerSet, "isAppRandomizerSet should be defaulted to false")
3030

3131
old := appRandomizer
32-
assert.NotPanics(t, func() { SetAppRandomizer(&MockAppRandomizer{}) }, "first SetAppRandomizer() should work")
32+
assert.NotPanics(t, func() { SetAppRandomizer(NewMockAppRandomizer()) }, "first SetAppRandomizer() should work")
3333
assert.True(t, isAppRandomizerSet, "isAppRandomizerSet should be true")
3434
assert.NotNil(t, appRandomizer, "appRandomizer should not be nil")
3535
assert.False(t, old == appRandomizer, "appRandomizer should have changed")
3636

3737
old = appRandomizer
38-
assert.Panics(t, func() { SetAppRandomizer(&MockAppRandomizer{}) }, "second SetAppRandomizer() should panic")
38+
assert.Panics(t, func() { SetAppRandomizer(NewMockAppRandomizer()) }, "second SetAppRandomizer() should panic")
3939
assert.True(t, isAppRandomizerSet, "isAppRandomizerSet should be true")
4040
assert.NotNil(t, appRandomizer, "appRandomizer should not be nil")
4141
assert.True(t, old == appRandomizer, "appRandomizer should not have changed")

channel/test/mock_app_randomizer.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@ package test
1717
import (
1818
"math/rand"
1919

20+
"github.com/google/uuid"
2021
"perun.network/go-perun/channel"
2122
)
2223

2324
// MockAppRandomizer implements the AppRandomizer interface.
24-
type MockAppRandomizer struct{}
25+
type MockAppRandomizer struct {
26+
id uuid.UUID // Unique identifier for each instance
27+
}
28+
29+
// NewMockAppRandomizer creates a new instance of MockAppRandomizer with a unique identifier.
30+
func NewMockAppRandomizer() *MockAppRandomizer {
31+
return &MockAppRandomizer{id: uuid.New()}
32+
}
2533

2634
// NewRandomApp creates a new MockApp with a random address.
2735
func (MockAppRandomizer) NewRandomApp(rng *rand.Rand) channel.App {
@@ -32,3 +40,8 @@ func (MockAppRandomizer) NewRandomApp(rng *rand.Rand) channel.App {
3240
func (MockAppRandomizer) NewRandomData(rng *rand.Rand) channel.Data {
3341
return channel.NewMockOp(channel.MockOp(rng.Uint64()))
3442
}
43+
44+
// Equal returns false for any comparison, ensuring two MockAppRandomizers are always considered different.
45+
func (m *MockAppRandomizer) Equal(other *MockAppRandomizer) bool {
46+
return m.id != other.id
47+
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/davecgh/go-spew v1.1.1 // indirect
1818
github.com/golang/snappy v0.0.4 // indirect
1919
github.com/google/go-cmp v0.5.4 // indirect
20+
github.com/google/uuid v1.6.0
2021
github.com/kr/text v0.2.0 // indirect
2122
github.com/pmezard/go-difflib v1.0.0 // indirect
2223
github.com/stretchr/objx v0.1.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
1919
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
2020
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
2121
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
22+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
23+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
2224
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
2325
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
2426
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=

wire/net/simple/init.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,21 @@
1414

1515
package simple
1616

17-
import "perun.network/go-perun/wire"
17+
import (
18+
"math/rand"
19+
20+
"perun.network/go-perun/wire"
21+
"perun.network/go-perun/wire/test"
22+
)
1823

1924
func init() {
2025
wire.SetNewAddressFunc(func() wire.Address {
2126
return NewAddress("")
2227
})
28+
test.SetNewRandomAddress(func(rng *rand.Rand) wire.Address {
29+
return NewRandomAddress(rng)
30+
})
31+
test.SetNewRandomAccount(func(rng *rand.Rand) wire.Account {
32+
return NewRandomAccount(rng)
33+
})
2334
}

0 commit comments

Comments
 (0)