Skip to content

Commit

Permalink
🚨 Fix 'thelper'.
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
ggwpez committed Nov 18, 2021
1 parent 9a02add commit b7d6cd9
Show file tree
Hide file tree
Showing 44 changed files with 127 additions and 48 deletions.
1 change: 1 addition & 0 deletions backend/ethereum/channel/adjudicator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
const defaultTxTimeout = 2 * time.Second

func testSignState(t *testing.T, accounts []*keystore.Account, state *channel.State) channel.Transaction {
t.Helper()
tx, err := signState(accounts, state)
assert.NoError(t, err, "Sign should not return error")
return tx
Expand Down
1 change: 1 addition & 0 deletions backend/ethereum/channel/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func testValidateAssetHolder(t *testing.T,
deployer accounts.Account) (common.Address, error),
validator func(ctx context.Context,
backend bind.ContractBackend, assetHolderETH, adjudicator common.Address) error) {
t.Helper()
// Test setup
rng := pkgtest.Prng(t, "validate")
s := test.NewSimSetup(t, rng, TxFinalityDepth, blockInterval)
Expand Down
2 changes: 2 additions & 0 deletions backend/ethereum/channel/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestAdjudicator_PureFunctions(t *testing.T) {
}

func testCalcID(t *testing.T, rng *rand.Rand, contr *adjudicator.Adjudicator, opts *bind.CallOpts) {
t.Helper()
for i := 0; i < 100; i++ {
params := test.NewRandomParams(rng)
ethParams := channel.ToEthParams(params)
Expand All @@ -73,6 +74,7 @@ func testCalcID(t *testing.T, rng *rand.Rand, contr *adjudicator.Adjudicator, op
}

func testHashState(t *testing.T, rng *rand.Rand, contr *adjudicator.Adjudicator, opts *bind.CallOpts) {
t.Helper()
for i := 0; i < 100; i++ {
state := test.NewRandomState(rng)
ethState := channel.ToEthState(state)
Expand Down
1 change: 1 addition & 0 deletions backend/ethereum/channel/conclude_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestAdjudicator_ConcludeFinal(t *testing.T) {
}

func testConcludeFinal(t *testing.T, numParts int) {
t.Helper()
t.Parallel()
rng := pkgtest.Prng(t)
// create test setup
Expand Down
6 changes: 6 additions & 0 deletions backend/ethereum/channel/funder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func TestFunder_OneForAllFunding(t *testing.T) {
}

func testFunderOneForAllFunding(t *testing.T, n int) {
t.Helper()
t.Parallel()
rng := pkgtest.Prng(t, n)
ct := pkgtest.NewConcurrent(t)
Expand Down Expand Up @@ -156,6 +157,7 @@ func TestFunder_CrossOverFunding(t *testing.T) {
}

func testFunderCrossOverFunding(t *testing.T, n int) {
t.Helper()
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), defaultTxTimeout*time.Duration(n))
defer cancel()
Expand Down Expand Up @@ -194,6 +196,7 @@ func TestFunder_ZeroBalance(t *testing.T) {
}

func testFunderZeroBalance(t *testing.T, n int) {
t.Helper()
t.Parallel()
rng := pkgtest.Prng(t, n)
ct := pkgtest.NewConcurrent(t)
Expand Down Expand Up @@ -283,6 +286,7 @@ func TestFunder_PeerTimeout(t *testing.T) {
}

func testFundingTimeout(t *testing.T, faultyPeer, n int) {
t.Helper()
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), defaultTxTimeout*time.Duration(n))
defer cancel()
Expand Down Expand Up @@ -343,6 +347,7 @@ func TestFunder_Fund_multi(t *testing.T) {
}

func testFunderFunding(t *testing.T, n int) {
t.Helper()
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), defaultTxTimeout*time.Duration(n))
defer cancel()
Expand Down Expand Up @@ -378,6 +383,7 @@ func newNFunders(
params *channel.Params,
allocation *channel.Allocation,
) {
t.Helper()
simBackend := test.NewSimulatedBackend()
// Start the auto-mining of blocks.
simBackend.StartMining(blockInterval)
Expand Down
1 change: 1 addition & 0 deletions backend/ethereum/channel/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestAdjudicator_MultipleRegisters(t *testing.T) {
}

func registerMultiple(t *testing.T, numParts int, parallel bool) {
t.Helper()
rng := pkgtest.Prng(t)
// create test setup
s := test.NewSetup(t, rng, numParts, blockInterval, TxFinalityDepth)
Expand Down
2 changes: 2 additions & 0 deletions backend/ethereum/channel/test/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type (
// NewSimSetup return a simulated backend test setup. The rng is used to
// generate the random account for sending of transaction.
func NewSimSetup(t *testing.T, rng *rand.Rand, txFinalityDepth uint64, blockInterval time.Duration, opts ...SimBackendOpt) *SimSetup {
t.Helper()
simBackend := NewSimulatedBackend(opts...)
ksWallet := wallettest.RandomWallet().(*keystore.Wallet)
txAccount := ksWallet.NewRandomAccount(rng).(*keystore.Account)
Expand Down Expand Up @@ -89,6 +90,7 @@ func NewSimSetup(t *testing.T, rng *rand.Rand, txFinalityDepth uint64, blockInte
// Accs.
// `blockInterval` enables the auto-mining feature if set to a value != 0.
func NewSetup(t *testing.T, rng *rand.Rand, n int, blockInterval time.Duration, txFinalityDepth uint64) *Setup {
t.Helper()
s := &Setup{
SimSetup: *NewSimSetup(t, rng, txFinalityDepth, blockInterval),
Accs: make([]*keystore.Account, n),
Expand Down
1 change: 1 addition & 0 deletions backend/ethereum/channel/test/tokensetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const (

// NewTokenSetup creates a new TokenSetup.
func NewTokenSetup(ctx context.Context, t *testing.T, rng *rand.Rand, txFinalityDepth uint64) *TokenSetup {
t.Helper()
// Simulated chain setup.
sb := NewSimulatedBackend()
ksWallet := wallettest.RandomWallet().(*keystore.Wallet)
Expand Down
2 changes: 2 additions & 0 deletions backend/ethereum/channel/test/transactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type TransactorSetup struct {
// GenericSignerTest tests that a transactor produces the correct signatures
// for the passed signer.
func GenericSignerTest(t *testing.T, rng *rand.Rand, setup TransactorSetup) {
t.Helper()
signer := setup.Signer
chainID := setup.ChainID
data := make([]byte, rng.Int31n(100)+1)
Expand Down Expand Up @@ -79,6 +80,7 @@ func GenericSignerTest(t *testing.T, rng *rand.Rand, setup TransactorSetup) {
}

func sigFromRSV(t *testing.T, r, s, _v *big.Int, chainID int64) []byte {
t.Helper()
sig := make([]byte, 65)
copy(sig[32-len(r.Bytes()):32], r.Bytes())
copy(sig[64-len(s.Bytes()):64], s.Bytes())
Expand Down
4 changes: 4 additions & 0 deletions backend/ethereum/channel/withdraw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func TestAdjudicator_MultipleWithdraws_FinalState(t *testing.T) {
}

func withdrawMultipleConcurrentFinal(t *testing.T, numParts int, parallel bool) {
t.Helper()
rng := pkgtest.Prng(t)
// create test setup
s := test.NewSetup(t, rng, numParts, blockInterval, TxFinalityDepth)
Expand Down Expand Up @@ -119,6 +120,7 @@ func TestWithdrawZeroBalance(t *testing.T) {

// shouldFunders decides who should fund. 1 indicates funding, 0 indicates skipping.
func testWithdrawZeroBalance(t *testing.T, n int) {
t.Helper()
rng := pkgtest.Prng(t)
s := test.NewSetup(t, rng, n, blockInterval, TxFinalityDepth)
// create valid state and params
Expand Down Expand Up @@ -192,6 +194,7 @@ func TestWithdraw(t *testing.T) {
}

testWithdraw := func(t *testing.T, shouldWork bool) {
t.Helper()
ctx, cancel := context.WithTimeout(context.Background(), defaultTxTimeout)
defer cancel()
req.Tx = testSignState(t, s.Accs, state)
Expand Down Expand Up @@ -266,6 +269,7 @@ func TestWithdrawNonFinal(t *testing.T) {
}

func assertHoldingsZero(ctx context.Context, t *testing.T, cb *ethchannel.ContractBackend, params *channel.Params, _assets []channel.Asset) {
t.Helper()
alloc, err := getOnChainAllocation(ctx, cb, params, _assets)
require.NoError(t, err, "Getting on-chain allocs should succeed")
for i, assetalloc := range alloc {
Expand Down
4 changes: 2 additions & 2 deletions backend/ethereum/client/dispute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func TestDisputeMalloryCarol(t *testing.T) {
s := test.NewSetup(t, rng, 2, ctest.BlockInterval, TxFinalityDepth)
setup = ctest.MakeRoleSetups(s, name)

role[A] = clienttest.NewMallory(setup[A], t)
role[B] = clienttest.NewCarol(setup[B], t)
role[A] = clienttest.NewMallory(t, setup[A])
role[B] = clienttest.NewCarol(t, setup[B])

execConfig := &clienttest.MalloryCarolExecConfig{
BaseExecConfig: clienttest.MakeBaseExecConfig(
Expand Down
4 changes: 2 additions & 2 deletions backend/ethereum/client/happy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func TestHappyAliceBob(t *testing.T) {
s := test.NewSetup(t, rng, 2, ctest.BlockInterval, TxFinalityDepth)
setup = ctest.MakeRoleSetups(s, name)

role[A] = clienttest.NewAlice(setup[A], t)
role[B] = clienttest.NewBob(setup[B], t)
role[A] = clienttest.NewAlice(t, setup[A])
role[B] = clienttest.NewBob(t, setup[B])
// enable stages synchronization
stages := role[A].EnableStages()
role[B].SetStages(stages)
Expand Down
1 change: 1 addition & 0 deletions backend/ethereum/client/progression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func TestProgression(t *testing.T) {
}

func deployMockApp(t *testing.T, s *test.Setup) wallet.Address {
t.Helper()
ctx, cancel := context.WithTimeout(context.Background(), ctest.DefaultTimeout)
defer cancel()
addr, err := ethchannel.DeployTrivialApp(ctx, *s.CB, s.TxSender.Account)
Expand Down
1 change: 1 addition & 0 deletions backend/ethereum/wallet/hd/transactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func TestTransactor(t *testing.T) {

// nolint:interfacer // rand.Rand is preferred over io.Reader here.
func newTransactorSetup(t *testing.T, prng *rand.Rand, hideSignHash bool, signer types.Signer, chainID int64) test.TransactorSetup {
t.Helper()
walletSeed := make([]byte, 20)
prng.Read(walletSeed)
mnemonic, err := hdwallet.NewMnemonicFromEntropy(walletSeed)
Expand Down
1 change: 1 addition & 0 deletions backend/sim/channel/channel_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestGenericTests(t *testing.T) {
}

func newChannelSetup(t *testing.T) *chtest.Setup {
t.Helper()
rng := pkgtest.Prng(t)

params, state := chtest.NewRandomParamsAndState(rng, chtest.WithNumLocked(int(rng.Int31n(4)+1)))
Expand Down
1 change: 1 addition & 0 deletions channel/allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func TestBalancesSub(t *testing.T) {
}

func testBalancesOperation(t *testing.T, op func(channel.Balances, channel.Balances) channel.Balances, elementOp func(channel.Bal, channel.Bal) channel.Bal) {
t.Helper()
assert := assert.New(t)
rng := pkgtest.Prng(t)
const rngBase = 10
Expand Down
3 changes: 3 additions & 0 deletions channel/appregistry_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func TestAppRegistry(t *testing.T) {
}

func testAppRegistryPanicsAndErrors(t *testing.T) {
t.Helper()
resetAppRegistry()
assert.Panics(t, func() { RegisterAppResolver(nil, nil) })
assert.Panics(t, func() { RegisterAppResolver(func(wallet.Address) bool { return true }, nil) })
Expand All @@ -78,6 +79,7 @@ func (r defaultRes) Resolve(wallet.Address) (App, error) {
}

func testAppRegistryIdentity(t *testing.T, rng *rand.Rand) {
t.Helper()
resetAppRegistry()
a0 := newRandomMockApp(rng)
RegisterApp(a0)
Expand All @@ -93,6 +95,7 @@ func testAppRegistryIdentity(t *testing.T, rng *rand.Rand) {
}

func assertIdentity(t *testing.T, expected App) {
t.Helper()
actual, err := Resolve(expected.Def())
assert.NoError(t, err)
assert.True(t, actual.Def().Equals(expected.Def()))
Expand Down
1 change: 1 addition & 0 deletions channel/backendtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

// SetBackendTest is a generic backend test.
func SetBackendTest(t *testing.T) {
t.Helper()
assert.Panics(t, func() { SetBackend(nil) }, "nil backend set should panic")
require.NotNil(t, backend, "backend should be already set by init()")
assert.Panics(t, func() { SetBackend(backend) }, "setting a backend twice should panic")
Expand Down
2 changes: 2 additions & 0 deletions channel/mock_app_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func TestMockApp(t *testing.T) {
}

func MockStateAppTest(t *testing.T, app MockApp) {
t.Helper()
stateValid := createState(OpValid)
stateErr := createState(OpErr)
stateTransErr := createState(OpTransitionErr)
Expand All @@ -87,6 +88,7 @@ func MockStateAppTest(t *testing.T, app MockApp) {
}

func MockActionAppTest(t *testing.T, app MockApp) {
t.Helper()
actValid := NewMockOp(OpValid)
actErr := NewMockOp(OpErr)
actTransErr := NewMockOp(OpTransitionErr)
Expand Down
1 change: 1 addition & 0 deletions channel/persistence/test/persistrestorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type PersistRestorer struct {
// NewPersistRestorer creates a new testing PersistRestorer that reports assert
// errors on the passed *testing.T t.
func NewPersistRestorer(t *testing.T) *PersistRestorer {
t.Helper()
return &PersistRestorer{
t: t,
chans: make(map[channel.ID]*persistence.Channel),
Expand Down
2 changes: 2 additions & 0 deletions channel/persistence/test/persistrestorertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Client struct {

// NewClient creates a client.
func NewClient(ctx context.Context, t *testing.T, rng *rand.Rand, pr persistence.PersistRestorer) *Client {
t.Helper()
return &Client{
addr: wtest.NewRandomAddress(rng),
rng: rng,
Expand Down Expand Up @@ -79,6 +80,7 @@ func GenericPersistRestorerTest(
pr persistence.PersistRestorer,
numPeers int,
numChans int) {
t.Helper()
t.Run("RestoreChannel error", func(t *testing.T) {
var id channel.ID
ch, err := pr.RestoreChannel(context.Background(), id)
Expand Down
5 changes: 5 additions & 0 deletions channel/test/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func mergeTestOpts(opts ...GenericTestOption) GenericTestOptions {

// GenericBackendTest tests the interface functions of the global channel.Backend with the passed test data.
func GenericBackendTest(t *testing.T, s *Setup, opts ...GenericTestOption) {
t.Helper()
require := require.New(t)
ID := channel.CalcID(s.Params)
require.Equal(ID, s.State.ID, "ChannelID(params) should match the States ID")
Expand All @@ -92,6 +93,7 @@ func GenericBackendTest(t *testing.T, s *Setup, opts ...GenericTestOption) {
}

func genericChannelIDTest(t *testing.T, s *Setup) {
t.Helper()
require.NotNil(t, s.Params.Parts, "params.Parts can not be nil")
assert.Panics(t, func() { channel.CalcID(nil) }, "ChannelID(nil) should panic")

Expand All @@ -104,11 +106,13 @@ func genericChannelIDTest(t *testing.T, s *Setup) {
}

func genericSignTest(t *testing.T, s *Setup) {
t.Helper()
_, err := channel.Sign(s.Account, s.State)
assert.NoError(t, err, "Sign should not return an error")
}

func genericVerifyTest(t *testing.T, s *Setup, opts ...GenericTestOption) {
t.Helper()
addr := s.Account.Address()
require.Equal(t, channel.CalcID(s.Params), s.Params.ID(), "Invalid test params")
sig, err := channel.Sign(s.Account, s.State)
Expand Down Expand Up @@ -356,6 +360,7 @@ func ensureBalanceVectorLength(bals []channel.Bal, l int) []channel.Bal {

// GenericStateEqualTest tests the State.Equal function.
func GenericStateEqualTest(t *testing.T, s1, s2 *channel.State, opts ...GenericTestOption) {
t.Helper()
assert.NoError(t, s1.Equal(s1))
assert.NoError(t, s2.Equal(s2))

Expand Down
7 changes: 4 additions & 3 deletions client/client_persistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ func TestPersistencePetraRobert(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), twoPartyTestTimeout)
defer cancel()

runTwoPartyTest(ctx, t, func(rng *rand.Rand) (setups []ctest.RoleSetup, roles [2]ctest.Executer) {
runTwoPartyTest(t, ctx, func(rng *rand.Rand) (setups []ctest.RoleSetup, roles [2]ctest.Executer) {
setups = NewSetupsPersistence(t, rng, []string{"Petra", "Robert"})
roles = [2]ctest.Executer{
ctest.NewPetra(setups[0], t),
ctest.NewRobert(setups[1], t),
ctest.NewPetra(t, setups[0]),
ctest.NewRobert(t, setups[1]),
}
return
})
}

func NewSetupsPersistence(t *testing.T, rng *rand.Rand, names []string) []ctest.RoleSetup {
t.Helper()
setups := NewSetups(rng, names)
for i := range names {
setups[i].PR = chprtest.NewPersistRestorer(t)
Expand Down
6 changes: 4 additions & 2 deletions client/client_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ type Client struct {
ctest.RoleSetup
}

func NewClients(rng *rand.Rand, names []string, t *testing.T) []*Client {
func NewClients(t *testing.T, rng *rand.Rand, names []string) []*Client {
t.Helper()
setups := NewSetups(rng, names)
clients := make([]*Client, len(setups))
for i, setup := range setups {
Expand All @@ -89,7 +90,8 @@ func NewClients(rng *rand.Rand, names []string, t *testing.T) []*Client {
return clients
}

func runTwoPartyTest(ctx context.Context, t *testing.T, setup func(*rand.Rand) ([]ctest.RoleSetup, [2]ctest.Executer)) {
func runTwoPartyTest(t *testing.T, ctx context.Context, setup func(*rand.Rand) ([]ctest.RoleSetup, [2]ctest.Executer)) {
t.Helper()
rng := test.Prng(t)
for i := 0; i < 2; i++ {
setups, roles := setup(rng)
Expand Down
4 changes: 2 additions & 2 deletions client/dispute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func TestDispute(t *testing.T) {
const mallory, carol = 0, 1 // Indices of Mallory and Carol
setups := NewSetups(rng, []string{"Mallory", "Carol"})
roles := [2]ctest.Executer{
ctest.NewMallory(setups[0], t),
ctest.NewCarol(setups[1], t),
ctest.NewMallory(t, setups[0]),
ctest.NewCarol(t, setups[1]),
}

cfg := &ctest.MalloryCarolExecConfig{
Expand Down
6 changes: 3 additions & 3 deletions client/happy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ func TestHappyAliceBob(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), twoPartyTestTimeout)
defer cancel()

runTwoPartyTest(ctx, t, func(rng *rand.Rand) (setups []ctest.RoleSetup, roles [2]ctest.Executer) {
runTwoPartyTest(t, ctx, func(rng *rand.Rand) (setups []ctest.RoleSetup, roles [2]ctest.Executer) {
setups = NewSetups(rng, []string{"Alice", "Bob"})
roles = [2]ctest.Executer{
ctest.NewAlice(setups[0], t),
ctest.NewBob(setups[1], t),
ctest.NewAlice(t, setups[0]),
ctest.NewBob(t, setups[1]),
}
return
})
Expand Down
Loading

0 comments on commit b7d6cd9

Please sign in to comment.