code.vegaprotocol.io/vega@v0.79.0/datanode/sqlstore/network_limits_test.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 sqlstore_test
    17  
    18  import (
    19  	"testing"
    20  	"time"
    21  
    22  	"code.vegaprotocol.io/vega/datanode/entities"
    23  	"code.vegaprotocol.io/vega/datanode/sqlstore"
    24  
    25  	"github.com/stretchr/testify/assert"
    26  	"github.com/stretchr/testify/require"
    27  )
    28  
    29  func TestNetworkLimits(t *testing.T) {
    30  	ctx := tempTransaction(t)
    31  
    32  	bs := sqlstore.NewBlocks(connectionSource)
    33  	block := addTestBlock(t, ctx, bs)
    34  	block2 := addTestBlock(t, ctx, bs)
    35  	nls := sqlstore.NewNetworkLimits(connectionSource)
    36  
    37  	nl := entities.NetworkLimits{
    38  		VegaTime:                 block.VegaTime,
    39  		CanProposeMarket:         true,
    40  		CanProposeAsset:          false,
    41  		ProposeMarketEnabled:     false,
    42  		ProposeAssetEnabled:      true,
    43  		GenesisLoaded:            false,
    44  		ProposeMarketEnabledFrom: time.Now().Truncate(time.Millisecond),
    45  		ProposeAssetEnabledFrom:  time.Now().Add(time.Second * 10).Truncate(time.Millisecond),
    46  	}
    47  
    48  	err := nls.Add(ctx, nl)
    49  	require.NoError(t, err)
    50  
    51  	nl2 := nl
    52  	nl2.VegaTime = block2.VegaTime
    53  	err = nls.Add(ctx, nl2)
    54  	require.NoError(t, err)
    55  
    56  	fetched, err := nls.GetLatest(ctx)
    57  	require.NoError(t, err)
    58  	assert.Equal(t, nl2, fetched)
    59  }