Skip to content

Commit

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

// mine blocks if testing on regnet
var stop chan struct{}
var stop func()
isRegnet := chains.IsBitcoinRegnet(r.GetBitcoinChainID())
if isRegnet {
stop = r.MineBlocks()
Expand Down Expand Up @@ -119,7 +119,7 @@ func withdrawBTCZRC20(r *runner.E2ERunner, to btcutil.Address, amount *big.Int)

// stop mining
if isRegnet {
stop <- struct{}{}
stop()
}

return rawTx
Expand Down
4 changes: 2 additions & 2 deletions e2e/e2etests/test_bitcoin_withdraw_invalid_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func withdrawToInvalidAddress(r *runner.E2ERunner, amount *big.Int) {
}

// mine blocks if testing on regnet
var stop chan struct{}
var stop func()
isRegnet := chains.IsBitcoinRegnet(r.GetBitcoinChainID())
if isRegnet {
stop = r.MineBlocks()
Expand All @@ -66,6 +66,6 @@ func withdrawToInvalidAddress(r *runner.E2ERunner, amount *big.Int) {

// stop mining
if isRegnet {
stop <- struct{}{}
stop()
}
}
4 changes: 2 additions & 2 deletions e2e/e2etests/test_crosschain_swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) {
}

// mine blocks if testing on regnet
var stop chan struct{}
var stop func()
isRegnet := chains.IsBitcoinRegnet(r.GetBitcoinChainID())
if isRegnet {
stop = r.MineBlocks()
Expand Down Expand Up @@ -240,6 +240,6 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) {

// stop mining
if isRegnet {
stop <- struct{}{}
stop()
}
}
11 changes: 7 additions & 4 deletions e2e/runner/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,12 @@ func (runner *E2ERunner) GetBitcoinChainID() int64 {

// 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() chan struct{} {
stop := make(chan struct{})
func (runner *E2ERunner) MineBlocks() func() {
stopChan := make(chan struct{})
go func() {
for {
select {
case <-stop:
case <-stopChan:
return
default:
_, err := runner.BtcRPCClient.GenerateToAddress(1, runner.BTCDeployerAddress, nil)
Expand All @@ -382,7 +382,10 @@ func (runner *E2ERunner) MineBlocks() chan struct{} {
}
}
}()
return stop

return func() {
close(stopChan)
}
}

// ProveBTCTransaction proves that a BTC transaction is in a block header and that the block header is in ZetaChain
Expand Down

0 comments on commit 90fd73c

Please sign in to comment.