code.vegaprotocol.io/vega@v0.79.0/datanode/networkhistory/snapshot/service_create_snapshot_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 snapshot_test
    17  
    18  import (
    19  	"os"
    20  	"path/filepath"
    21  	"testing"
    22  
    23  	"code.vegaprotocol.io/vega/datanode/networkhistory/snapshot"
    24  	"code.vegaprotocol.io/vega/logging"
    25  
    26  	"github.com/stretchr/testify/assert"
    27  )
    28  
    29  func TestGetHistorySnapshots(t *testing.T) {
    30  	snapshotsDir := t.TempDir()
    31  	service, err := snapshot.NewSnapshotService(logging.NewTestLogger(), snapshot.NewDefaultConfig(), nil, nil, snapshotsDir, nil, nil)
    32  	if err != nil {
    33  		panic(err)
    34  	}
    35  
    36  	os.MkdirAll(filepath.Join(snapshotsDir, "testnet-fde111-42-0-1000"), os.ModePerm)
    37  	os.MkdirAll(filepath.Join(snapshotsDir, "testnet-fde111-42-1001-2000"), os.ModePerm)
    38  	os.MkdirAll(filepath.Join(snapshotsDir, "testnet-fde111-42-3001-4000"), os.ModePerm)
    39  	os.MkdirAll(filepath.Join(snapshotsDir, "testnet-fde111-42-4001-5000"), os.ModePerm)
    40  	os.MkdirAll(filepath.Join(snapshotsDir, "testnet-fde111-42-5001-6000"), os.ModePerm)
    41  	os.MkdirAll(filepath.Join(snapshotsDir, "testnet-fde111-42-6001-7000"), os.ModePerm)
    42  	os.Create(filepath.Join(snapshotsDir, "testnet-fde111-8000.snapshotinprogress"))
    43  	os.MkdirAll(filepath.Join(snapshotsDir, "testnet-fde111-42-7001-8000"), os.ModePerm)
    44  
    45  	ss, err := service.GetUnpublishedSnapshots()
    46  	assert.NoError(t, err)
    47  	for i := range ss {
    48  		assert.Equal(t, "testnet-fde111", ss[i].ChainID)
    49  	}
    50  
    51  	assert.Equal(t, 6, len(ss))
    52  	assert.Equal(t, ss[0].HeightFrom, int64(0))
    53  	assert.Equal(t, ss[0].HeightTo, int64(1000))
    54  	assert.Equal(t, ss[5].HeightFrom, int64(6001))
    55  	assert.Equal(t, ss[5].HeightTo, int64(7000))
    56  }