From 54b452f77d31b8079aa32dc3d64793c970104329 Mon Sep 17 00:00:00 2001 From: Charlie Chen Date: Wed, 27 Nov 2024 12:41:05 -0600 Subject: [PATCH] update signet,testnet4 database file name pattern; add unit test --- zetaclient/orchestrator/bootstap_test.go | 40 ++++++++++++++++++++++++ zetaclient/orchestrator/bootstrap.go | 9 +++--- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/zetaclient/orchestrator/bootstap_test.go b/zetaclient/orchestrator/bootstap_test.go index d5f64c8500..95c52beeee 100644 --- a/zetaclient/orchestrator/bootstap_test.go +++ b/zetaclient/orchestrator/bootstap_test.go @@ -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) diff --git a/zetaclient/orchestrator/bootstrap.go b/zetaclient/orchestrator/bootstrap.go index ce9632383d..86d6325ed5 100644 --- a/zetaclient/orchestrator/bootstrap.go +++ b/zetaclient/orchestrator/bootstrap.go @@ -2,6 +2,7 @@ package orchestrator import ( "context" + "fmt" ethcommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" @@ -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) } }