From b7d6cd96cfa0795b576b13812509a63378692aff Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 15 Nov 2021 15:18:31 +0100 Subject: [PATCH] :rotating_light: Fix 'thelper'. Signed-off-by: Oliver Tale-Yazdi --- backend/ethereum/channel/adjudicator_test.go | 1 + backend/ethereum/channel/asset_test.go | 1 + backend/ethereum/channel/backend_test.go | 2 ++ backend/ethereum/channel/conclude_test.go | 1 + backend/ethereum/channel/funder_test.go | 6 ++++++ backend/ethereum/channel/register_test.go | 1 + backend/ethereum/channel/test/setup.go | 2 ++ backend/ethereum/channel/test/tokensetup.go | 1 + backend/ethereum/channel/test/transactor.go | 2 ++ backend/ethereum/channel/withdraw_test.go | 4 ++++ backend/ethereum/client/dispute_test.go | 4 ++-- backend/ethereum/client/happy_test.go | 4 ++-- backend/ethereum/client/progression_test.go | 1 + backend/ethereum/wallet/hd/transactor_test.go | 1 + backend/sim/channel/channel_internal_test.go | 1 + channel/allocation_test.go | 1 + channel/appregistry_internal_test.go | 3 +++ channel/backendtest.go | 1 + channel/mock_app_internal_test.go | 2 ++ channel/persistence/test/persistrestorer.go | 1 + channel/persistence/test/persistrestorertest.go | 2 ++ channel/test/backend.go | 5 +++++ client/client_persistence_test.go | 7 ++++--- client/client_role_test.go | 6 ++++-- client/dispute_test.go | 4 ++-- client/happy_test.go | 6 +++--- client/subchannel_dispute_test.go | 4 ++-- client/subchannel_happy_test.go | 4 ++-- client/test/alice.go | 5 +++-- client/test/bob.go | 5 +++-- client/test/carol.go | 5 +++-- client/test/mallory.go | 5 +++-- client/test/persistence.go | 15 +++++++++------ client/test/progression.go | 6 ++++-- client/test/proposer.go | 5 +++-- client/test/responder.go | 5 +++-- client/test/role.go | 3 ++- client/test/subchannel.go | 10 ++++++---- client/test/subchannel_dispute.go | 10 ++++++---- client/virtual_channel_test.go | 4 +++- wallet/test/wallet.go | 1 + wallet/test/walletbench.go | 5 +++++ watcher/local/watcher_test.go | 10 ++++++++++ wire/test/bustest.go | 3 +++ 44 files changed, 127 insertions(+), 48 deletions(-) diff --git a/backend/ethereum/channel/adjudicator_test.go b/backend/ethereum/channel/adjudicator_test.go index 6f545502..56fcf0b2 100644 --- a/backend/ethereum/channel/adjudicator_test.go +++ b/backend/ethereum/channel/adjudicator_test.go @@ -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 diff --git a/backend/ethereum/channel/asset_test.go b/backend/ethereum/channel/asset_test.go index 4df6fcc3..9ac7ac58 100644 --- a/backend/ethereum/channel/asset_test.go +++ b/backend/ethereum/channel/asset_test.go @@ -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) diff --git a/backend/ethereum/channel/backend_test.go b/backend/ethereum/channel/backend_test.go index 19cf03ca..604b27cf 100644 --- a/backend/ethereum/channel/backend_test.go +++ b/backend/ethereum/channel/backend_test.go @@ -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) @@ -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) diff --git a/backend/ethereum/channel/conclude_test.go b/backend/ethereum/channel/conclude_test.go index e75d2186..29f39545 100644 --- a/backend/ethereum/channel/conclude_test.go +++ b/backend/ethereum/channel/conclude_test.go @@ -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 diff --git a/backend/ethereum/channel/funder_test.go b/backend/ethereum/channel/funder_test.go index 2253dd71..81b55483 100644 --- a/backend/ethereum/channel/funder_test.go +++ b/backend/ethereum/channel/funder_test.go @@ -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) @@ -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() @@ -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) @@ -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() @@ -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() @@ -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) diff --git a/backend/ethereum/channel/register_test.go b/backend/ethereum/channel/register_test.go index 7c134a11..67f1a120 100644 --- a/backend/ethereum/channel/register_test.go +++ b/backend/ethereum/channel/register_test.go @@ -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) diff --git a/backend/ethereum/channel/test/setup.go b/backend/ethereum/channel/test/setup.go index 9c934eb5..cb9f52ad 100644 --- a/backend/ethereum/channel/test/setup.go +++ b/backend/ethereum/channel/test/setup.go @@ -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) @@ -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), diff --git a/backend/ethereum/channel/test/tokensetup.go b/backend/ethereum/channel/test/tokensetup.go index d2731317..8e381e94 100644 --- a/backend/ethereum/channel/test/tokensetup.go +++ b/backend/ethereum/channel/test/tokensetup.go @@ -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) diff --git a/backend/ethereum/channel/test/transactor.go b/backend/ethereum/channel/test/transactor.go index 4edbf818..19b22521 100644 --- a/backend/ethereum/channel/test/transactor.go +++ b/backend/ethereum/channel/test/transactor.go @@ -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) @@ -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()) diff --git a/backend/ethereum/channel/withdraw_test.go b/backend/ethereum/channel/withdraw_test.go index 46456c12..4d122811 100644 --- a/backend/ethereum/channel/withdraw_test.go +++ b/backend/ethereum/channel/withdraw_test.go @@ -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) @@ -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 @@ -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) @@ -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 { diff --git a/backend/ethereum/client/dispute_test.go b/backend/ethereum/client/dispute_test.go index c8b031f6..7863ece8 100644 --- a/backend/ethereum/client/dispute_test.go +++ b/backend/ethereum/client/dispute_test.go @@ -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( diff --git a/backend/ethereum/client/happy_test.go b/backend/ethereum/client/happy_test.go index 65df08c5..7d5e9a7c 100644 --- a/backend/ethereum/client/happy_test.go +++ b/backend/ethereum/client/happy_test.go @@ -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) diff --git a/backend/ethereum/client/progression_test.go b/backend/ethereum/client/progression_test.go index ea6205cd..898c21c5 100644 --- a/backend/ethereum/client/progression_test.go +++ b/backend/ethereum/client/progression_test.go @@ -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) diff --git a/backend/ethereum/wallet/hd/transactor_test.go b/backend/ethereum/wallet/hd/transactor_test.go index ed33b29b..4256d0a7 100644 --- a/backend/ethereum/wallet/hd/transactor_test.go +++ b/backend/ethereum/wallet/hd/transactor_test.go @@ -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) diff --git a/backend/sim/channel/channel_internal_test.go b/backend/sim/channel/channel_internal_test.go index 2435d1db..2980df34 100644 --- a/backend/sim/channel/channel_internal_test.go +++ b/backend/sim/channel/channel_internal_test.go @@ -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))) diff --git a/channel/allocation_test.go b/channel/allocation_test.go index 16ee3f09..263904f0 100644 --- a/channel/allocation_test.go +++ b/channel/allocation_test.go @@ -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 diff --git a/channel/appregistry_internal_test.go b/channel/appregistry_internal_test.go index f1d21c0b..2a777b6a 100644 --- a/channel/appregistry_internal_test.go +++ b/channel/appregistry_internal_test.go @@ -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) }) @@ -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) @@ -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())) diff --git a/channel/backendtest.go b/channel/backendtest.go index 08619848..087f04ed 100644 --- a/channel/backendtest.go +++ b/channel/backendtest.go @@ -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") diff --git a/channel/mock_app_internal_test.go b/channel/mock_app_internal_test.go index 660b817a..98c0220a 100644 --- a/channel/mock_app_internal_test.go +++ b/channel/mock_app_internal_test.go @@ -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) @@ -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) diff --git a/channel/persistence/test/persistrestorer.go b/channel/persistence/test/persistrestorer.go index ad4b84fd..f1b286de 100644 --- a/channel/persistence/test/persistrestorer.go +++ b/channel/persistence/test/persistrestorer.go @@ -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), diff --git a/channel/persistence/test/persistrestorertest.go b/channel/persistence/test/persistrestorertest.go index c775044c..9e34e6ac 100644 --- a/channel/persistence/test/persistrestorertest.go +++ b/channel/persistence/test/persistrestorertest.go @@ -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, @@ -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) diff --git a/channel/test/backend.go b/channel/test/backend.go index 9ae57e22..347a60a1 100644 --- a/channel/test/backend.go +++ b/channel/test/backend.go @@ -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") @@ -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") @@ -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) @@ -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)) diff --git a/client/client_persistence_test.go b/client/client_persistence_test.go index 01684674..7e8c21fb 100644 --- a/client/client_persistence_test.go +++ b/client/client_persistence_test.go @@ -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) diff --git a/client/client_role_test.go b/client/client_role_test.go index a974c2f4..b077c6a3 100644 --- a/client/client_role_test.go +++ b/client/client_role_test.go @@ -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 { @@ -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) diff --git a/client/dispute_test.go b/client/dispute_test.go index 8a90eb66..2ea4875e 100644 --- a/client/dispute_test.go +++ b/client/dispute_test.go @@ -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{ diff --git a/client/happy_test.go b/client/happy_test.go index f72710fe..73a3d782 100644 --- a/client/happy_test.go +++ b/client/happy_test.go @@ -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 }) diff --git a/client/subchannel_dispute_test.go b/client/subchannel_dispute_test.go index e63fa9e6..2966f10b 100644 --- a/client/subchannel_dispute_test.go +++ b/client/subchannel_dispute_test.go @@ -32,8 +32,8 @@ func TestSubChannelDispute(t *testing.T) { setups := NewSetups(rng, []string{"DisputeSusie", "DisputeTim"}) roles := [2]ctest.Executer{ - ctest.NewDisputeSusie(setups[0], t), - ctest.NewDisputeTim(setups[1], t), + ctest.NewDisputeSusie(t, setups[0]), + ctest.NewDisputeTim(t, setups[1]), } baseCfg := ctest.MakeBaseExecConfig( diff --git a/client/subchannel_happy_test.go b/client/subchannel_happy_test.go index b9e51c39..33125e40 100644 --- a/client/subchannel_happy_test.go +++ b/client/subchannel_happy_test.go @@ -33,8 +33,8 @@ func TestSubChannelHappy(t *testing.T) { setups := NewSetups(rng, []string{"Susie", "Tim"}) roles := [2]ctest.Executer{ - ctest.NewSusie(setups[0], t), - ctest.NewTim(setups[1], t), + ctest.NewSusie(t, setups[0]), + ctest.NewTim(t, setups[1]), } cfg := ctest.NewSusieTimExecConfig( diff --git a/client/test/alice.go b/client/test/alice.go index 61d5da4f..2d725531 100644 --- a/client/test/alice.go +++ b/client/test/alice.go @@ -33,8 +33,9 @@ type Alice struct { } // NewAlice creates a new Proposer that executes the Alice protocol. -func NewAlice(setup RoleSetup, t *testing.T) *Alice { - return &Alice{Proposer: *NewProposer(setup, t, 3)} +func NewAlice(t *testing.T, setup RoleSetup) *Alice { + t.Helper() + return &Alice{Proposer: *NewProposer(t, setup, 3)} } // Execute executes the Alice protocol. diff --git a/client/test/bob.go b/client/test/bob.go index a70dd4e2..0d25576c 100644 --- a/client/test/bob.go +++ b/client/test/bob.go @@ -25,8 +25,9 @@ type Bob struct { } // NewBob creates a new Responder that executes the Bob protocol. -func NewBob(setup RoleSetup, t *testing.T) *Bob { - return &Bob{Responder: *NewResponder(setup, t, 3)} +func NewBob(t *testing.T, setup RoleSetup) *Bob { + t.Helper() + return &Bob{Responder: *NewResponder(t, setup, 3)} } // Execute executes the Bob protocol. diff --git a/client/test/carol.go b/client/test/carol.go index b5113939..b31e6aa0 100644 --- a/client/test/carol.go +++ b/client/test/carol.go @@ -38,9 +38,10 @@ func (r *Carol) HandleAdjudicatorEvent(e channel.AdjudicatorEvent) { } // NewCarol creates a new Responder that executes the Carol protocol. -func NewCarol(setup RoleSetup, t *testing.T) *Carol { +func NewCarol(t *testing.T, setup RoleSetup) *Carol { + t.Helper() return &Carol{ - Responder: *NewResponder(setup, t, 3), + Responder: *NewResponder(t, setup, 3), registered: make(chan *channel.RegisteredEvent), } } diff --git a/client/test/mallory.go b/client/test/mallory.go index 59d779a8..66c4759b 100644 --- a/client/test/mallory.go +++ b/client/test/mallory.go @@ -39,8 +39,9 @@ type Mallory struct { } // NewMallory creates a new party that executes the Mallory protocol. -func NewMallory(setup RoleSetup, t *testing.T) *Mallory { - return &Mallory{Proposer: *NewProposer(setup, t, 3)} +func NewMallory(t *testing.T, setup RoleSetup) *Mallory { + t.Helper() + return &Mallory{Proposer: *NewProposer(t, setup, 3)} } // Execute executes the Mallory protocol. diff --git a/client/test/persistence.go b/client/test/persistence.go index 6154d056..afd5f04d 100644 --- a/client/test/persistence.go +++ b/client/test/persistence.go @@ -49,18 +49,21 @@ func (r *multiClientRole) ReplaceClient() { r.setClient(cl) } -func makeMultiClientRole(setup RoleSetup, t *testing.T, stages int) multiClientRole { - return multiClientRole{role: makeRole(setup, t, stages)} +func makeMultiClientRole(t *testing.T, setup RoleSetup, stages int) multiClientRole { + t.Helper() + return multiClientRole{role: makeRole(t, setup, stages)} } // NewPetra creates a new Proposer that executes the Petra protocol. -func NewPetra(setup RoleSetup, t *testing.T) *Petra { - return &Petra{makeMultiClientRole(setup, t, 6)} +func NewPetra(t *testing.T, setup RoleSetup) *Petra { + t.Helper() + return &Petra{makeMultiClientRole(t, setup, 6)} } // NewRobert creates a new Responder that executes the Robert protocol. -func NewRobert(setup RoleSetup, t *testing.T) *Robert { - return &Robert{makeMultiClientRole(setup, t, 6)} +func NewRobert(t *testing.T, setup RoleSetup) *Robert { + t.Helper() + return &Robert{makeMultiClientRole(t, setup, 6)} } // Execute executes the Petra protocol. diff --git a/client/test/progression.go b/client/test/progression.go index 82a16cd5..9647900a 100644 --- a/client/test/progression.go +++ b/client/test/progression.go @@ -65,7 +65,8 @@ type Paul struct { // NewPaul creates a new party that executes the Paul protocol. func NewPaul(t *testing.T, setup RoleSetup) *Paul { - p := NewProposer(setup, t, 1) + t.Helper() + p := NewProposer(t, setup, 1) return &Paul{ Proposer: *p, Watcher: makeWatcher(p.log), @@ -126,7 +127,8 @@ type Paula struct { // NewPaula creates a new party that executes the Paula protocol. func NewPaula(t *testing.T, setup RoleSetup) *Paula { - r := NewResponder(setup, t, 1) + t.Helper() + r := NewResponder(t, setup, 1) return &Paula{ Responder: *r, Watcher: makeWatcher(r.log), diff --git a/client/test/proposer.go b/client/test/proposer.go index 92d92930..4ea2c8b5 100644 --- a/client/test/proposer.go +++ b/client/test/proposer.go @@ -27,8 +27,9 @@ type Proposer struct { } // NewProposer creates a new party that executes the Proposer protocol. -func NewProposer(setup RoleSetup, t *testing.T, numStages int) *Proposer { - return &Proposer{role: makeRole(setup, t, numStages)} +func NewProposer(t *testing.T, setup RoleSetup, numStages int) *Proposer { + t.Helper() + return &Proposer{role: makeRole(t, setup, numStages)} } // Execute executes the Proposer protocol. diff --git a/client/test/responder.go b/client/test/responder.go index 046a85ff..13882900 100644 --- a/client/test/responder.go +++ b/client/test/responder.go @@ -27,8 +27,9 @@ type Responder struct { } // NewResponder creates a new party that executes the Responder protocol. -func NewResponder(setup RoleSetup, t *testing.T, numStages int) *Responder { - return &Responder{role: makeRole(setup, t, numStages)} +func NewResponder(t *testing.T, setup RoleSetup, numStages int) *Responder { + t.Helper() + return &Responder{role: makeRole(t, setup, numStages)} } // Execute executes the Responder protocol. diff --git a/client/test/role.go b/client/test/role.go index dbf3a0ed..c9db84c4 100644 --- a/client/test/role.go +++ b/client/test/role.go @@ -169,7 +169,8 @@ func (c *BaseExecConfig) App() client.ProposalOpts { } // makeRole creates a client for the given setup and wraps it into a Role. -func makeRole(setup RoleSetup, t *testing.T, numStages int) (r role) { +func makeRole(t *testing.T, setup RoleSetup, numStages int) (r role) { + t.Helper() r = role{ chans: &channelMap{entries: make(map[channel.ID]*paymentChannel)}, setup: setup, diff --git a/client/test/subchannel.go b/client/test/subchannel.go index 229d63a6..b7c39566 100644 --- a/client/test/subchannel.go +++ b/client/test/subchannel.go @@ -57,8 +57,9 @@ type Susie struct { } // NewSusie creates a new Proposer that executes the Susie protocol. -func NewSusie(setup RoleSetup, t *testing.T) *Susie { - return &Susie{Proposer: *NewProposer(setup, t, 7)} +func NewSusie(t *testing.T, setup RoleSetup) *Susie { + t.Helper() + return &Susie{Proposer: *NewProposer(t, setup, 7)} } // Execute executes the Susie protocol. @@ -151,8 +152,9 @@ type Tim struct { } // NewTim creates a new Responder that executes the Tim protocol. -func NewTim(setup RoleSetup, t *testing.T) *Tim { - return &Tim{Responder: *NewResponder(setup, t, 7)} +func NewTim(t *testing.T, setup RoleSetup) *Tim { + t.Helper() + return &Tim{Responder: *NewResponder(t, setup, 7)} } // Execute executes the Tim protocol. diff --git a/client/test/subchannel_dispute.go b/client/test/subchannel_dispute.go index 360c786e..c53c1b51 100644 --- a/client/test/subchannel_dispute.go +++ b/client/test/subchannel_dispute.go @@ -41,8 +41,9 @@ type DisputeSusie struct { } // NewDisputeSusie creates a new Proposer that executes the DisputeSusie protocol. -func NewDisputeSusie(setup RoleSetup, t *testing.T) *DisputeSusie { - return &DisputeSusie{Proposer: *NewProposer(setup, t, nStagesDisputeSusieTime)} +func NewDisputeSusie(t *testing.T, setup RoleSetup) *DisputeSusie { + t.Helper() + return &DisputeSusie{Proposer: *NewProposer(t, setup, nStagesDisputeSusieTime)} } // Execute executes the DisputeSusie protocol. @@ -139,9 +140,10 @@ func (r *DisputeTim) HandleAdjudicatorEvent(e channel.AdjudicatorEvent) { } // NewDisputeTim creates a new Responder that executes the DisputeTim protocol. -func NewDisputeTim(setup RoleSetup, t *testing.T) *DisputeTim { +func NewDisputeTim(t *testing.T, setup RoleSetup) *DisputeTim { + t.Helper() return &DisputeTim{ - Responder: *NewResponder(setup, t, nStagesDisputeSusieTime), + Responder: *NewResponder(t, setup, nStagesDisputeSusieTime), registered: make(chan *channel.RegisteredEvent), } } diff --git a/client/virtual_channel_test.go b/client/virtual_channel_test.go index 0791a680..837e1028 100644 --- a/client/virtual_channel_test.go +++ b/client/virtual_channel_test.go @@ -99,6 +99,7 @@ func TestVirtualChannelsDispute(t *testing.T) { } func (vct *virtualChannelTest) testFinalBalancesDispute(t *testing.T) { + t.Helper() assert := assert.New(t) backend, asset := vct.balanceReader, vct.asset got, expected := backend.Balance(vct.alice.Identity.Address(), asset), vct.finalBalsAlice[0] @@ -129,6 +130,7 @@ type virtualChannelTest struct { } func setupVirtualChannelTest(t *testing.T, ctx context.Context) (vct virtualChannelTest) { + t.Helper() rng := test.Prng(t) require := require.New(t) @@ -146,9 +148,9 @@ func setupVirtualChannelTest(t *testing.T, ctx context.Context) (vct virtualChan // Setup clients. clients := NewClients( + t, rng, []string{"Alice", "Bob", "Ingrid"}, - t, ) alice, bob, ingrid := clients[0], clients[1], clients[2] vct.alice, vct.bob, vct.ingrid = alice, bob, ingrid diff --git a/wallet/test/wallet.go b/wallet/test/wallet.go index 58539099..6a39195c 100644 --- a/wallet/test/wallet.go +++ b/wallet/test/wallet.go @@ -103,6 +103,7 @@ func TestAccountWithWalletAndBackend(t *testing.T, s *Setup) { // GenericSignatureSizeTest tests that the size of the signatures produced by // Account.Sign(…) does not vary between executions (tested with 2048 samples). func GenericSignatureSizeTest(t *testing.T, s *Setup) { + t.Helper() acc, err := s.Wallet.Unlock(s.AddressInWallet) require.NoError(t, err) // get a signature diff --git a/wallet/test/walletbench.go b/wallet/test/walletbench.go index 9e9d01ea..d8f811c2 100644 --- a/wallet/test/walletbench.go +++ b/wallet/test/walletbench.go @@ -24,10 +24,12 @@ import ( // GenericAccountBenchmark runs a suite designed to benchmark the general speed of an implementation of an Account. // This function should be called by every implementation of the Account interface. func GenericAccountBenchmark(b *testing.B, s *Setup) { + b.Helper() b.Run("Sign", func(b *testing.B) { benchAccountSign(b, s) }) } func benchAccountSign(b *testing.B, s *Setup) { + b.Helper() perunAcc, err := s.Wallet.Unlock(s.AddressInWallet) require.Nil(b, err) @@ -43,11 +45,13 @@ func benchAccountSign(b *testing.B, s *Setup) { // GenericBackendBenchmark runs a suite designed to benchmark the general speed of an implementation of a Backend. // This function should be called by every implementation of the Backend interface. func GenericBackendBenchmark(b *testing.B, s *Setup) { + b.Helper() b.Run("VerifySig", func(b *testing.B) { benchBackendVerifySig(b, s) }) b.Run("DecodeAddress", func(b *testing.B) { benchBackendDecodeAddress(b, s) }) } func benchBackendVerifySig(b *testing.B, s *Setup) { + b.Helper() // We dont want to measure the SignDataWithPW here, just need it for the verification b.StopTimer() perunAcc, err := s.Wallet.Unlock(s.AddressInWallet) @@ -66,6 +70,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 := s.Backend.DecodeAddress(bytes.NewReader(s.AddressEncoded)) diff --git a/watcher/local/watcher_test.go b/watcher/local/watcher_test.go index 734a1ee0..ab20364d 100644 --- a/watcher/local/watcher_test.go +++ b/watcher/local/watcher_test.go @@ -203,6 +203,7 @@ func Test_Watcher_Working(t *testing.T) { t *testing.T, eventConstructor func(txs ...channel.Transaction, ) []channel.AdjudicatorEvent) { + t.Helper() // Setup: Generate the params and off-chain states for a ledger channel. params, txs := randomTxsForSingleCh(rng, 2) @@ -433,6 +434,7 @@ func Test_Watcher_Working(t *testing.T) { t *testing.T, eventConstructor func(txs ...channel.Transaction, ) []channel.AdjudicatorEvent) { + t.Helper() // Setup: Generate the params and off-chain states for a ledger channel and a sub-channel. parentParams, parentTxs := randomTxsForSingleCh(rng, 2) childParams, childTxs := randomTxsForSingleCh(rng, 2) @@ -473,10 +475,12 @@ func Test_Watcher_Working(t *testing.T) { } func Test_Watcher_StopWatching(t *testing.T) { + t.Helper() rng := test.Prng(t) t.Run("ledger_channel_without_sub_channel", func(t *testing.T) { f := func(t *testing.T, errOnClose error) { + t.Helper() defer goleak.VerifyNone(t, goleak.IgnoreCurrent()) params, txs := randomTxsForSingleCh(rng, 1) @@ -826,6 +830,7 @@ type channelTree struct { // for the given channel tree and fails the test if incorrect. The return value // of "Register" calls is always nil. func setExpectationRegisterCalls(t *testing.T, rs *mock.RegisterSubscriber, channelTrees ...*channelTree) { + t.Helper() limit := len(channelTrees) mtx := sync.Mutex{} iChannelTree := 0 @@ -858,6 +863,7 @@ func setExpectationRegisterCalls(t *testing.T, rs *mock.RegisterSubscriber, chan } func assertEqualAdjudicatorReq(t *testing.T, got channel.AdjudicatorReq, want *channel.State) bool { + t.Helper() if nil != got.Tx.State.Equal(want) { t.Logf("Got %+v, expected %+v", got.Tx.State, want) return false @@ -866,6 +872,7 @@ func assertEqualAdjudicatorReq(t *testing.T, got channel.AdjudicatorReq, want *c } func assertEqualSignedStates(t *testing.T, got []channel.SignedState, want []channel.Transaction) bool { + t.Helper() if len(got) != len(want) { t.Logf("Got %d sub states, expected %d sub states", len(got), len(want)) return false @@ -930,6 +937,7 @@ func startWatchingForLedgerChannel( w *local.Watcher, signedState channel.SignedState, ) (watcher.StatesPub, watcher.AdjudicatorSub) { + t.Helper() statesPub, eventsSub, err := w.StartWatchingLedgerChannel(context.TODO(), signedState) require.NoError(t, err) @@ -945,6 +953,7 @@ func startWatchingForSubChannel( signedState channel.SignedState, parentID channel.ID, ) (watcher.StatesPub, watcher.AdjudicatorSub) { + t.Helper() statesPub, eventsSub, err := w.StartWatchingSubChannel(context.TODO(), parentID, signedState) require.NoError(t, err) @@ -958,6 +967,7 @@ func triggerAdjEventAndExpectNotification( trigger adjEventSource, eventsForClient watcher.AdjudicatorSub, ) { + t.Helper() wantEvent := trigger.trigger() t.Logf("waiting for adjudicator event for ch %x, version: %v", wantEvent.ID(), wantEvent.Version()) gotEvent := <-eventsForClient.EventStream() diff --git a/wire/test/bustest.go b/wire/test/bustest.go index 3ddaeaeb..6e49c261 100644 --- a/wire/test/bustest.go +++ b/wire/test/bustest.go @@ -34,6 +34,7 @@ import ( // perform any necessary work to make clients able to communicate with each // other (such as setting up dialers and listeners, in case of networking). func GenericBusTest(t *testing.T, busAssigner func(wire.Account) wire.Bus, numClients, numMsgs int) { + t.Helper() require.Greater(t, numClients, 1) require.Greater(t, numMsgs, 0) @@ -54,6 +55,7 @@ func GenericBusTest(t *testing.T, busAssigner func(wire.Account) wire.Bus, numCl // Here, we have common, reused code. testNoReceive := func(t *testing.T) { + t.Helper() ct := test.NewConcurrent(t) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond) defer cancel() @@ -72,6 +74,7 @@ func GenericBusTest(t *testing.T, busAssigner func(wire.Account) wire.Bus, numCl } testPublishAndReceive := func(t *testing.T, waiting func()) { + t.Helper() ct := test.NewConcurrent(t) ctx, cancel := context.WithTimeout( context.Background(),