Skip to content

Commit

Permalink
update signet,testnet4 database file name pattern; add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Nov 27, 2024
1 parent 92eb8ad commit 54b452f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
40 changes: 40 additions & 0 deletions zetaclient/orchestrator/bootstap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,46 @@ func TestCreateChainObserverMap(t *testing.T) {
})
}

func TestBtcDatabaseFileName(t *testing.T) {
tests := []struct {
name string
chain chains.Chain
expected string
}{
{
name: "should use legacy file name for bitcoin mainnet",
chain: chains.BitcoinMainnet,
expected: "btc_chain_client",
},
{
name: "should use legacy file name for bitcoin testnet3",
chain: chains.BitcoinTestnet,
expected: "btc_chain_client",
},
{
name: "should use new file name for bitcoin regtest",
chain: chains.BitcoinRegtest,
expected: "btc_chain_client_18444",
},
{
name: "should use new file name for bitcoin signet",
chain: chains.BitcoinSignetTestnet,
expected: "btc_chain_client_18333",
},
{
name: "should use new file name for bitcoin testnet4",
chain: chains.BitcoinTestnet4,
expected: "btc_chain_client_18334",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, btcDatabaseFileName(tt.chain))
})
}
}

func chainParams(supportedChains []chains.Chain) ([]chains.Chain, map[int64]*observertypes.ChainParams) {
params := make(map[int64]*observertypes.ChainParams)

Expand Down
9 changes: 5 additions & 4 deletions zetaclient/orchestrator/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package orchestrator

import (
"context"
"fmt"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
Expand Down Expand Up @@ -479,16 +480,16 @@ func syncObserverMap(
}

func btcDatabaseFileName(chain chains.Chain) string {
// btcDatabaseFilename is the Bitcoin database file name now used in mainnet and testnet3
// legacyBTCDatabaseFilename is the Bitcoin database file name now used in mainnet and testnet3
// so we keep using it here for backward compatibility
const btcDatabaseFilename = "btc_chain_client"
const legacyBTCDatabaseFilename = "btc_chain_client"

// For additional bitcoin networks, we use the chain name as the database file name
switch chain.ChainId {
case chains.BitcoinMainnet.ChainId, chains.BitcoinTestnet.ChainId:
return btcDatabaseFilename
return legacyBTCDatabaseFilename
default:
return chain.Name
return fmt.Sprintf("%s_%d", legacyBTCDatabaseFilename, chain.ChainId)
}
}

Expand Down

0 comments on commit 54b452f

Please sign in to comment.