summaryrefslogtreecommitdiff
path: root/test/e2e-go/features/p2p/p2p_basic_test.go
blob: 6f3e8aae47fbb35d5450151736b5b4dd09573ec4 (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
63
// 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/>.

package p2p

import (
	"path/filepath"
	"testing"
	"time"

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

func testP2PWithConfig(t *testing.T, cfgname string) {
	r := require.New(fixtures.SynchronizedTest(t))

	var fixture fixtures.RestClientFixture

	// Make protocol faster for shorter tests
	consensus := make(config.ConsensusProtocols)
	fastProtocol := config.Consensus[protocol.ConsensusCurrentVersion]
	fastProtocol.ApprovedUpgrades = map[protocol.ConsensusVersion]uint64{}
	fastProtocol.AgreementFilterTimeoutPeriod0 = 400 * time.Millisecond
	fastProtocol.AgreementFilterTimeout = 400 * time.Millisecond
	consensus[protocol.ConsensusCurrentVersion] = fastProtocol
	fixture.SetConsensus(consensus)

	fixture.Setup(t, filepath.Join("nettemplates", cfgname))
	defer fixture.ShutdownImpl(true) // preserve logs in testdir

	_, err := fixture.NC.AlgodClient()
	r.NoError(err)

	err = fixture.WaitForRound(10, 30*time.Second)
	r.NoError(err)
}

func TestP2PTwoNodes(t *testing.T) {
	partitiontest.PartitionTest(t)
	testP2PWithConfig(t, "TwoNodes50EachP2P.json")
}

func TestP2PFiveNodes(t *testing.T) {
	partitiontest.PartitionTest(t)
	testP2PWithConfig(t, "FiveNodesP2P.json")
}