Skip to content

Commit

Permalink
only generate on local bitcoin
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Jun 3, 2024
1 parent 90fd73c commit 4661bde
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion e2e/e2etests/helper_bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func withdrawBTCZRC20(r *runner.E2ERunner, to btcutil.Address, amount *big.Int)
}

// mine 10 blocks to confirm the withdraw tx
_, err = r.BtcRPCClient.GenerateToAddress(10, to, nil)
_, err = r.GenerateToAddressOnLocalBitcoin(10, to)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/e2etests/test_bitcoin_withdraw_multiple.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ package e2etests
// go func() {
// for {
// time.Sleep(3 * time.Second)
// _, err = r.BtcRPCClient.GenerateToAddress(1, r.BTCDeployerAddress, nil)
// _, err = r.GenerateToAddressOnLocalBitcoin(1, r.BTCDeployerAddress)
// if err != nil {
// panic(err)
// }
Expand All @@ -64,7 +64,7 @@ package e2etests
// if receipt.Status != 1 {
// panic(fmt.Errorf("withdraw receipt status is not 1"))
// }
// _, err = r.BtcRPCClient.GenerateToAddress(10, r.BTCDeployerAddress, nil)
// _, err = r.GenerateToAddressOnLocalBitcoin(10, r.BTCDeployerAddress)
// if err != nil {
// panic(err)
// }
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_crosschain_swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) {
}

// mine 10 blocks to confirm the outbound tx
_, err = r.BtcRPCClient.GenerateToAddress(10, r.BTCDeployerAddress, nil)
_, err = r.GenerateToAddressOnLocalBitcoin(10, r.BTCDeployerAddress)
if err != nil {
panic(err)
}
Expand Down
27 changes: 20 additions & 7 deletions e2e/runner/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ import (

var blockHeaderBTCTimeout = 5 * time.Minute

// IsLocalBitcoin returns true if the runner is running on a local bitcoin network
func (runner *E2ERunner) IsLocalBitcoin() bool {
return runner.BitcoinParams.Name == chains.BitcoinRegnetParams.Name
}

// ListDeployerUTXOs list the deployer's UTXOs that have at least `minAmount`
func (runner *E2ERunner) ListDeployerUTXOs(minAmount float64) ([]btcjson.ListUnspentResult, error) {
// query UTXOs from node
Expand Down Expand Up @@ -317,7 +312,7 @@ func (runner *E2ERunner) SendToTSSFromDeployerWithMemo(
panic(err)
}
runner.Logger.Info("txid: %+v", txid)
_, err = btcRPC.GenerateToAddress(6, btcDeployerAddress, nil)
_, err = runner.GenerateToAddressOnLocalBitcoin(6, btcDeployerAddress)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -364,6 +359,24 @@ func (runner *E2ERunner) GetBitcoinChainID() int64 {
return chainID
}

// IsLocalBitcoin returns true if the runner is running on a local bitcoin network
func (runner *E2ERunner) IsLocalBitcoin() bool {
return runner.BitcoinParams.Name == chains.BitcoinRegnetParams.Name
}

// GenerateToAddressOnLocalBitcoin generates blocks to an address if the runner is interacting
// with a local bitcoin network
func (runner *E2ERunner) GenerateToAddressOnLocalBitcoin(
numBlocks int64,
address btcutil.Address,
) ([]*chainhash.Hash, error) {
// if not local bitcoin network, do nothing
if runner.IsLocalBitcoin() {
return runner.BtcRPCClient.GenerateToAddress(numBlocks, address, nil)
}
return nil, nil
}

// MineBlocks mines blocks on the BTC chain at a rate of 1 blocks every 5 seconds
// and returns a channel that can be used to stop the mining
func (runner *E2ERunner) MineBlocks() func() {
Expand All @@ -374,7 +387,7 @@ func (runner *E2ERunner) MineBlocks() func() {
case <-stopChan:
return
default:
_, err := runner.BtcRPCClient.GenerateToAddress(1, runner.BTCDeployerAddress, nil)
_, err := runner.GenerateToAddressOnLocalBitcoin(1, runner.BTCDeployerAddress)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/runner/setup_bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ func (runner *E2ERunner) SetupBitcoinAccount(initNetwork bool) {
}

// mine some blocks to get some BTC into the deployer address
_, err = runner.BtcRPCClient.GenerateToAddress(101, runner.BTCDeployerAddress, nil)
_, err = runner.GenerateToAddressOnLocalBitcoin(101, runner.BTCDeployerAddress)
if err != nil {
panic(err)
}

_, err = runner.BtcRPCClient.GenerateToAddress(4, runner.BTCDeployerAddress, nil)
_, err = runner.GenerateToAddressOnLocalBitcoin(4, runner.BTCDeployerAddress)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 4661bde

Please sign in to comment.