Skip to content

Commit

Permalink
fix: set specific btc network type
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Dec 6, 2024
1 parent e093709 commit 2a700cf
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
39 changes: 35 additions & 4 deletions test/e2e/configurer/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/babylonlabs-io/babylon/test/e2e/configurer/chain"
"github.com/babylonlabs-io/babylon/test/e2e/containers"
"github.com/babylonlabs-io/babylon/test/e2e/initialization"
bbn "github.com/babylonlabs-io/babylon/types"
btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
)

Expand All @@ -34,6 +35,10 @@ type Configurer interface {
RunIBCTransferChannel() error
}

const (
btcNetworkStr = string(bbn.BtcSimnet)
)

var (
// Last nodes are non validator nodes to serve as the ones using relayer. Out
// validators are constantly sending bls transactions which make relayer operations
Expand All @@ -52,6 +57,7 @@ var (
SnapshotInterval: 25,
SnapshotKeepRecent: 10,
IsValidator: true,
BtcNetwork: btcNetworkStr,
},
{
Name: "babylon-default-a-2",
Expand All @@ -61,6 +67,7 @@ var (
SnapshotInterval: 1500,
SnapshotKeepRecent: 2,
IsValidator: true,
BtcNetwork: btcNetworkStr,
},
{
Name: "babylon-default-a-3",
Expand All @@ -70,6 +77,7 @@ var (
SnapshotInterval: 1500,
SnapshotKeepRecent: 2,
IsValidator: false,
BtcNetwork: btcNetworkStr,
},
}
validatorConfigsChainB = []*initialization.NodeConfig{
Expand All @@ -81,6 +89,7 @@ var (
SnapshotInterval: 1500,
SnapshotKeepRecent: 2,
IsValidator: true,
BtcNetwork: btcNetworkStr,
},
{
Name: "babylon-default-b-2",
Expand All @@ -90,6 +99,7 @@ var (
SnapshotInterval: 1500,
SnapshotKeepRecent: 2,
IsValidator: true,
BtcNetwork: btcNetworkStr,
},
{
Name: "babylon-default-b-3",
Expand All @@ -99,6 +109,7 @@ var (
SnapshotInterval: 1500,
SnapshotKeepRecent: 2,
IsValidator: false,
BtcNetwork: btcNetworkStr,
},
}
)
Expand Down Expand Up @@ -204,7 +215,20 @@ func NewSoftwareUpgradeConfigurer(t *testing.T, isDebugLogEnabled bool, upgradeP
return nil, err
}

chainA := chain.New(t, containerManager, initialization.ChainAID, updateNodeConfigNameWithIdentifier(validatorConfigsChainA, identifier), nil)
cfgs := updateNodeConfigs(validatorConfigsChainA, func(cfg *initialization.NodeConfig) *initialization.NodeConfig {
return &initialization.NodeConfig{
Name: fmt.Sprintf("%s-%s", cfg.Name, identifier),
Pruning: cfg.Pruning,
PruningKeepRecent: cfg.PruningKeepRecent,
PruningInterval: cfg.PruningInterval,
SnapshotInterval: cfg.SnapshotInterval,
SnapshotKeepRecent: cfg.SnapshotKeepRecent,
IsValidator: cfg.IsValidator,
BtcNetwork: string(bbn.BtcSignet),
}
})

chainA := chain.New(t, containerManager, initialization.ChainAID, cfgs, nil)
if btcHeaders != nil {
chainA.BTCHeaders = btcHeaders
}
Expand Down Expand Up @@ -234,17 +258,24 @@ func identifierName(t *testing.T) string {
}

func updateNodeConfigNameWithIdentifier(cfgs []*initialization.NodeConfig, identifier string) []*initialization.NodeConfig {
result := make([]*initialization.NodeConfig, len(cfgs))
for i, cfg := range cfgs {
result[i] = &initialization.NodeConfig{
return updateNodeConfigs(cfgs, func(cfg *initialization.NodeConfig) *initialization.NodeConfig {
return &initialization.NodeConfig{
Name: fmt.Sprintf("%s-%s", cfg.Name, identifier),
Pruning: cfg.Pruning,
PruningKeepRecent: cfg.PruningKeepRecent,
PruningInterval: cfg.PruningInterval,
SnapshotInterval: cfg.SnapshotInterval,
SnapshotKeepRecent: cfg.SnapshotKeepRecent,
IsValidator: cfg.IsValidator,
BtcNetwork: cfg.BtcNetwork,
}
})
}

func updateNodeConfigs(cfgs []*initialization.NodeConfig, f func(cfg *initialization.NodeConfig) *initialization.NodeConfig) []*initialization.NodeConfig {
result := make([]*initialization.NodeConfig, len(cfgs))
for i, cfg := range cfgs {
result[i] = f(cfg)
}
return result
}
1 change: 1 addition & 0 deletions test/e2e/initialization/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type NodeConfig struct {
SnapshotInterval uint64 // statesync snapshot every Nth block (0 to disable)
SnapshotKeepRecent uint32 // number of recent snapshots to keep and serve (0 to keep all)
IsValidator bool // flag indicating whether a node should be a validator
BtcNetwork string // The Bitcoin network used
}

const (
Expand Down
11 changes: 10 additions & 1 deletion test/e2e/software_upgrade_e2e_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,33 @@ func (s *SoftwareUpgradeV1TestnetTestSuite) SetupSuite() {
preUpgradeFunc := func(chains []*chain.Config) {
node := chains[0].NodeConfigs[1]
uniqueAddrs := make(map[string]any)
uniqueAddrsToMint := make(map[string]any)

for addr, amountToMint := range balanceToMintByAddr {
uniqueAddrs[addr] = struct{}{}
if amountToMint <= 0 {
continue
}

uniqueAddrsToMint[addr] = struct{}{}
amountToSend := sdk.NewCoin(appparams.BaseCoinUnit, sdkmath.NewInt(amountToMint))
node.BankSendFromNode(addr, amountToSend.String())
}

// needs to wait for a block to make sure the send tx was processed and
// it queries the real balances before upgrade.
node.WaitForNextBlock()

// This does not work for 50k addresses
for addr := range uniqueAddrs {
// assume that the balance prior to upgrade of each addr is zero.
s.balancesBeforeUpgrade[addr] = sdk.NewCoin(appparams.DefaultBondDenom, sdkmath.ZeroInt())
}

// only verifies the ones that did received something
for addr := range uniqueAddrsToMint {
balance, err := node.QueryBalance(addr, appparams.DefaultBondDenom)
s.NoError(err)

s.balancesBeforeUpgrade[addr] = *balance
}
}
Expand Down

0 comments on commit 2a700cf

Please sign in to comment.