code.vegaprotocol.io/vega@v0.79.0/datanode/sqlstore/helpers/accounts.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package helpers
    17  
    18  import (
    19  	"context"
    20  	"testing"
    21  
    22  	"code.vegaprotocol.io/vega/core/types"
    23  	"code.vegaprotocol.io/vega/datanode/entities"
    24  	"code.vegaprotocol.io/vega/datanode/sqlstore"
    25  
    26  	"github.com/stretchr/testify/require"
    27  )
    28  
    29  func AddTestAccount(t *testing.T,
    30  	ctx context.Context,
    31  	accountStore *sqlstore.Accounts,
    32  	party entities.Party,
    33  	asset entities.Asset,
    34  	accountType types.AccountType,
    35  	block entities.Block,
    36  ) entities.Account {
    37  	t.Helper()
    38  	account := entities.Account{
    39  		PartyID:  party.ID,
    40  		AssetID:  asset.ID,
    41  		MarketID: entities.MarketID(GenerateID()),
    42  		Type:     accountType,
    43  		VegaTime: block.VegaTime,
    44  	}
    45  
    46  	err := accountStore.Add(ctx, &account)
    47  	require.NoError(t, err)
    48  	return account
    49  }
    50  
    51  func AddTestAccountWithTxHash(t *testing.T,
    52  	ctx context.Context,
    53  	accountStore *sqlstore.Accounts,
    54  	party entities.Party,
    55  	asset entities.Asset,
    56  	accountType types.AccountType,
    57  	block entities.Block,
    58  	txHash entities.TxHash,
    59  ) entities.Account {
    60  	t.Helper()
    61  	account := entities.Account{
    62  		PartyID:  party.ID,
    63  		AssetID:  asset.ID,
    64  		MarketID: entities.MarketID(GenerateID()),
    65  		Type:     accountType,
    66  		VegaTime: block.VegaTime,
    67  		TxHash:   txHash,
    68  	}
    69  
    70  	err := accountStore.Add(ctx, &account)
    71  	require.NoError(t, err)
    72  	return account
    73  }
    74  
    75  func AddTestAccountWithMarketAndType(t *testing.T,
    76  	ctx context.Context,
    77  	accountStore *sqlstore.Accounts,
    78  	party entities.Party,
    79  	asset entities.Asset,
    80  	block entities.Block,
    81  	market entities.MarketID,
    82  	accountType types.AccountType,
    83  ) entities.Account {
    84  	t.Helper()
    85  	account := entities.Account{
    86  		PartyID:  party.ID,
    87  		AssetID:  asset.ID,
    88  		MarketID: market,
    89  		Type:     accountType,
    90  		VegaTime: block.VegaTime,
    91  	}
    92  
    93  	err := accountStore.Add(ctx, &account)
    94  	require.NoError(t, err)
    95  	return account
    96  }