summaryrefslogtreecommitdiff
path: root/test/e2e-go/features/privatenet/privatenet_test.go
blob: 34c4119cc14410fb30418a5473344581fdca684d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (C) 2019-2024 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand.  If not, see <https://www.gnu.org/licenses/>.

// Check that private networks are started as designed.
package privatenet

import (
	"testing"

	"github.com/algorand/go-algorand/test/framework/fixtures"
	"github.com/algorand/go-algorand/test/partitiontest"
	"github.com/stretchr/testify/require"
)

// TestPrivateNetworkImportKeys tests that part keys can be exported and
// imported when starting a private network.
func TestPrivateNetworkImportKeys(t *testing.T) {
	partitiontest.PartitionTest(t)

	// This test takes 5~10 seconds.
	if testing.Short() {
		t.Skip()
	}

	// First test that keys can be exported by using `goal network pregen ...`
	// Don't start up network, just create genesis files.
	var goalFixture fixtures.GoalFixture
	tmpGenDir := t.TempDir()
	tmpNetDir := t.TempDir()
	defaultTemplate := "" // Use the default template by omitting the filepath.

	_, err := goalFixture.NetworkPregen(defaultTemplate, tmpGenDir)
	require.NoError(t, err)

	// Check that if there is an existing directory with same name, test fails.
	errStr, err := goalFixture.NetworkPregen(defaultTemplate, tmpGenDir)
	require.Error(t, err)
	require.Contains(t, errStr, "already exists and is not empty")

	// Then try importing files from same template.
	err = goalFixture.NetworkCreate(tmpNetDir, "", defaultTemplate, tmpGenDir)
	require.NoError(t, err)

	err = goalFixture.NetworkStart(tmpNetDir)
	require.NoError(t, err)

	err = goalFixture.NetworkStop(tmpNetDir)
	require.NoError(t, err)
}