Skip to content

Commit

Permalink
chore: add check for cases where btc headers are not needed to specify
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Aug 2, 2024
1 parent 8dd3deb commit 199d0dc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
4 changes: 4 additions & 0 deletions test/e2e/configurer/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ func (c *Config) TxGovVoteFromAllNodes(propID int, option govv1.VoteOption, over

// BTCHeaderBytesHexJoined join all the btc headers as byte string hex
func (c *Config) BTCHeaderBytesHexJoined() string {
if c.BTCHeaders == nil || len(c.BTCHeaders) == 0 {
return ""
}

strBtcHeaders := make([]string, len(c.BTCHeaders))
for i, btcHeader := range c.BTCHeaders {
bz, err := btcHeader.Marshal()
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/configurer/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ func NewSoftwareUpgradeConfigurer(t *testing.T, isDebugLogEnabled bool, upgradeP
}

chainA := chain.New(t, containerManager, initialization.ChainAID, validatorConfigsChainA, nil)
chainA.BTCHeaders = btcHeaders
if btcHeaders != nil {
chainA.BTCHeaders = btcHeaders
}

return NewUpgradeConfigurer(t,
[]*chain.Config{
Expand Down
30 changes: 19 additions & 11 deletions test/e2e/initialization/chain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,25 @@ func main() {
panic(err)
}

btcHeaders := btcHeaderFromFlag(btcHeadersBytesHexStr)
createdChain, err := initialization.InitChain(chainId, dataDir, valConfig, votingPeriod, expeditedVotingPeriod, forkHeight, btcHeaders)
if err != nil {
panic(err)
}

b, _ := json.Marshal(createdChain)
fileName := fmt.Sprintf("%v/%v-encode", dataDir, chainId)
if err = os.WriteFile(fileName, b, 0o777); err != nil {
panic(err)
}
}

func btcHeaderFromFlag(btcHeadersBytesHexStr string) []*btclighttypes.BTCHeaderInfo {
btcHeaders := []*btclighttypes.BTCHeaderInfo{}
if len(btcHeadersBytesHexStr) == 0 {
return btcHeaders
}

btcHeadersBytesHex := strings.Split(btcHeadersBytesHexStr, ",")
for _, btcHeaderBytesHex := range btcHeadersBytesHex {
btcHeaderBytes, err := hex.DecodeString(btcHeaderBytesHex)
Expand All @@ -64,15 +82,5 @@ func main() {

btcHeaders = append(btcHeaders, btcHeader)
}

createdChain, err := initialization.InitChain(chainId, dataDir, valConfig, votingPeriod, expeditedVotingPeriod, forkHeight, btcHeaders)
if err != nil {
panic(err)
}

b, _ := json.Marshal(createdChain)
fileName := fmt.Sprintf("%v/%v-encode", dataDir, chainId)
if err = os.WriteFile(fileName, b, 0o777); err != nil {
panic(err)
}
return btcHeaders
}

0 comments on commit 199d0dc

Please sign in to comment.