Skip to content

Commit 1920294

Browse files
Schedule Helicon in the antithesis tests (#5649)
1 parent 1457ae8 commit 1920294

6 files changed

Lines changed: 88 additions & 47 deletions

File tree

tests/antithesis/avalanchego/gencomposeconfig/main.go

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package main
55

66
import (
7+
"fmt"
78
"os"
89

910
"go.uber.org/zap"
@@ -13,15 +14,46 @@ import (
1314
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
1415
)
1516

16-
const baseImageName = "antithesis-avalanchego"
17+
const (
18+
baseImageName = "antithesis-avalanchego"
19+
nodeCount = 5
20+
)
1721

1822
// Creates docker-compose.yml and its associated volumes in the target path.
1923
func main() {
20-
network := tmpnet.LocalNetworkOrPanic()
24+
log := tests.NewDefaultLogger("")
25+
network, err := newNetwork()
26+
if err != nil {
27+
log.Fatal("failed to configure network",
28+
zap.Error(err),
29+
)
30+
os.Exit(1)
31+
}
2132
if err := antithesis.GenerateComposeConfig(network, baseImageName); err != nil {
22-
tests.NewDefaultLogger("").Fatal("failed to generate compose config",
33+
log.Fatal("failed to generate compose config",
2334
zap.Error(err),
2435
)
2536
os.Exit(1)
2637
}
2738
}
39+
40+
// newNetwork returns a network with all upgrades initially active. A custom
41+
// network is required because nodes refuse to override the local network's
42+
// upgrade schedule.
43+
func newNetwork() (*tmpnet.Network, error) {
44+
network := &tmpnet.Network{
45+
Owner: baseImageName,
46+
Nodes: tmpnet.NewNodesOrPanic(nodeCount),
47+
}
48+
genesis, err := network.DefaultGenesis()
49+
if err != nil {
50+
return nil, fmt.Errorf("failed to create genesis: %w", err)
51+
}
52+
network.Genesis = genesis
53+
54+
network.DefaultFlags, err = tmpnet.UpgradeFlags(tmpnet.UpgradeConfig(0))
55+
if err != nil {
56+
return nil, fmt.Errorf("failed to get upgrade flags: %w", err)
57+
}
58+
return network, nil
59+
}

tests/antithesis/compose.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm
167167
signerKey := node.Flags[config.StakingSignerKeyContentKey]
168168

169169
env := types.Mapping{
170-
config.NetworkNameKey: constants.LocalName,
170+
config.NetworkNameKey: constants.NetworkName(network.GetNetworkID()),
171171
config.LogLevelKey: logging.Debug.String(),
172172
config.LogDisplayLevelKey: logging.Trace.String(),
173173
config.LogFormatKey: logging.JSONString,
@@ -178,10 +178,20 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm
178178
config.StakingSignerKeyContentKey: signerKey,
179179
config.ChainConfigContentKey: chainConfigContent,
180180
}
181+
if network.Genesis != nil {
182+
content, err := network.GetGenesisFileContent()
183+
if err != nil {
184+
return nil, fmt.Errorf("failed to get genesis file content: %w", err)
185+
}
186+
env[config.GenesisFileContentKey] = content
187+
}
181188

182189
// Apply configuration appropriate to a test network
183190
maps.Copy(env, tmpnet.DefaultTmpnetFlags())
184191

192+
// Apply the network's default flags (e.g. upgrade configuration)
193+
maps.Copy(env, network.DefaultFlags)
194+
185195
serviceName := getServiceName(i)
186196

187197
volumes := []types.ServiceVolumeConfig{

tests/e2e/BUILD.bazel

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ go_test(
1313
srcs = ["e2e_test.go"],
1414
tags = ["manual"], # keep
1515
deps = [
16-
"//config",
1716
"//graft/coreth/plugin/evm",
1817
"//tests/e2e/banff",
1918
"//tests/e2e/c",
@@ -24,8 +23,6 @@ go_test(
2423
"//tests/e2e/x/transfer",
2524
"//tests/fixture/e2e",
2625
"//tests/fixture/tmpnet",
27-
"//upgrade",
28-
"//upgrade/upgradetest",
2926
"@com_github_onsi_ginkgo_v2//:ginkgo",
3027
"@com_github_stretchr_testify//require",
3128
"@org_uber_go_zap//:zap",

tests/e2e/e2e_test.go

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
package e2e_test
55

66
import (
7-
"encoding/base64"
8-
"encoding/json"
97
"testing"
10-
"time"
118

129
"github.com/onsi/ginkgo/v2"
1310
"github.com/stretchr/testify/require"
@@ -21,13 +18,10 @@ import (
2118
_ "github.com/ava-labs/avalanchego/tests/e2e/x"
2219
_ "github.com/ava-labs/avalanchego/tests/e2e/x/transfer"
2320

24-
"github.com/ava-labs/avalanchego/config"
2521
"github.com/ava-labs/avalanchego/graft/coreth/plugin/evm"
2622
"github.com/ava-labs/avalanchego/tests/e2e/vms"
2723
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
2824
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
29-
"github.com/ava-labs/avalanchego/upgrade"
30-
"github.com/ava-labs/avalanchego/upgrade/upgradetest"
3125
)
3226

3327
func TestE2E(t *testing.T) {
@@ -41,29 +35,6 @@ func init() {
4135
flagVars = e2e.RegisterFlags(e2e.WithDefaultOwner("avalanchego-e2e"))
4236
}
4337

44-
// upgradeConfig configures the latest upgrade:
45-
// - activateLatestAfter < 0: leave latest unscheduled
46-
// - activateLatestAfter == 0: activate latest from genesis
47-
// - activateLatestAfter > 0: schedule latest that duration after starting
48-
func upgradeConfig(activateLatestAfter time.Duration) upgrade.Config {
49-
const previous = upgradetest.Latest - 1
50-
var upgrades upgrade.Config
51-
switch {
52-
case activateLatestAfter < 0:
53-
upgrades = upgradetest.GetConfig(previous)
54-
case activateLatestAfter == 0:
55-
upgrades = upgradetest.GetConfig(upgradetest.Latest)
56-
default:
57-
upgrades = upgradetest.GetConfigWithUpgradeTime(
58-
upgradetest.Latest,
59-
time.Now().Add(activateLatestAfter),
60-
)
61-
upgradetest.SetTimesTo(&upgrades, previous, upgrade.InitiallyActiveTime)
62-
}
63-
upgrades.GraniteEpochDuration = 4 * time.Second
64-
return upgrades
65-
}
66-
6738
var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
6839
// Run only once in the first ginkgo process
6940

@@ -74,22 +45,13 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
7445
nodes := tmpnet.NewNodesOrPanic(nodeCount)
7546
subnets := vms.XSVMSubnetsOrPanic(nodes...)
7647

77-
upgrades := upgradeConfig(flagVars.ActivateLatestAfter())
48+
upgrades := tmpnet.UpgradeConfig(flagVars.ActivateLatestAfter())
7849
tc.Log().Info("setting upgrades",
7950
zap.Reflect("upgrades", upgrades),
8051
)
8152

82-
upgradeJSON, err := json.Marshal(upgrades)
53+
defaultFlags, err := tmpnet.UpgradeFlags(upgrades)
8354
require.NoError(tc, err)
84-
85-
upgradeBase64 := base64.StdEncoding.EncodeToString(upgradeJSON)
86-
87-
defaultFlags := tmpnet.FlagsMap{
88-
config.UpgradeFileContentKey: upgradeBase64,
89-
// Ensure a min stake duration compatible with testing staking logic
90-
config.MinStakeDurationKey: "2s",
91-
config.HeliconMinStakeDurationKey: "1s",
92-
}
9355
defaultFlags.SetDefaults(tmpnet.DefaultE2EFlags())
9456

9557
return e2e.NewTestEnvironment(

tests/fixture/tmpnet/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ go_library(
4141
"//staking",
4242
"//tests/fixture/stacktrace",
4343
"//upgrade",
44+
"//upgrade/upgradetest",
4445
"//utils/constants",
4546
"//utils/crypto/bls/signer/localsigner",
4647
"//utils/crypto/secp256k1",

tests/fixture/tmpnet/network.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
"github.com/ava-labs/avalanchego/genesis"
3030
"github.com/ava-labs/avalanchego/ids"
3131
"github.com/ava-labs/avalanchego/tests/fixture/stacktrace"
32+
"github.com/ava-labs/avalanchego/upgrade"
33+
"github.com/ava-labs/avalanchego/upgrade/upgradetest"
3234
"github.com/ava-labs/avalanchego/utils/constants"
3335
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
3436
"github.com/ava-labs/avalanchego/utils/logging"
@@ -368,6 +370,43 @@ func (n *Network) DefaultGenesis() (*genesis.UnparsedConfig, error) {
368370
return NewTestGenesis(defaultNetworkID, n.Nodes, keysToFund)
369371
}
370372

373+
// UpgradeConfig configures the latest upgrade:
374+
// - activateLatestAfter < 0: leave latest unscheduled
375+
// - activateLatestAfter == 0: activate latest from genesis
376+
// - activateLatestAfter > 0: schedule latest that duration after starting
377+
func UpgradeConfig(activateLatestAfter time.Duration) upgrade.Config {
378+
const previous = upgradetest.Latest - 1
379+
var upgrades upgrade.Config
380+
switch {
381+
case activateLatestAfter < 0:
382+
upgrades = upgradetest.GetConfig(previous)
383+
case activateLatestAfter == 0:
384+
upgrades = upgradetest.GetConfig(upgradetest.Latest)
385+
default:
386+
upgrades = upgradetest.GetConfigWithUpgradeTime(
387+
upgradetest.Latest,
388+
time.Now().Add(activateLatestAfter),
389+
)
390+
upgradetest.SetTimesTo(&upgrades, previous, upgrade.InitiallyActiveTime)
391+
}
392+
upgrades.GraniteEpochDuration = 4 * time.Second
393+
return upgrades
394+
}
395+
396+
// UpgradeFlags returns flags applying the provided upgrade schedule
397+
// and a min stake duration compatible with testing staking logic.
398+
func UpgradeFlags(upgrades upgrade.Config) (FlagsMap, error) {
399+
upgradeJSON, err := json.Marshal(upgrades)
400+
if err != nil {
401+
return nil, stacktrace.Errorf("failed to marshal upgrade config: %w", err)
402+
}
403+
return FlagsMap{
404+
config.UpgradeFileContentKey: base64.StdEncoding.EncodeToString(upgradeJSON),
405+
config.MinStakeDurationKey: DefaultMinStakeDuration,
406+
config.HeliconMinStakeDurationKey: DefaultHeliconMinStakeDuration,
407+
}, nil
408+
}
409+
371410
// Starts the specified nodes
372411
func (n *Network) StartNodes(ctx context.Context, log logging.Logger, nodesToStart ...*Node) error {
373412
if len(nodesToStart) == 0 {

0 commit comments

Comments
 (0)