Skip to content

Commit

Permalink
simplify some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Jun 3, 2024
1 parent 4661bde commit 9d91610
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 64 deletions.
18 changes: 2 additions & 16 deletions e2e/e2etests/test_crosschain_swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,7 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) {
memo = append(r.ZEVMSwapAppAddr.Bytes(), memo...)
r.Logger.Info("memo length %d", len(memo))

txID, err := r.SendToTSSFromDeployerWithMemo(
r.BTCTSSAddress,
0.01,
utxos[0:1],
r.BtcRPCClient,
memo,
r.BTCDeployerAddress,
)
txID, err := r.SendToTSSFromDeployerWithMemo(0.01, utxos[0:1], memo)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -200,14 +193,7 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) {
r.Logger.Info("memo length %d", len(memo))

amount := 0.1
txid, err := r.SendToTSSFromDeployerWithMemo(
r.BTCTSSAddress,
amount,
utxos[1:2],
r.BtcRPCClient,
memo,
r.BTCDeployerAddress,
)
txid, err := r.SendToTSSFromDeployerWithMemo(amount, utxos[1:2], memo)
if err != nil {
panic(err)
}
Expand Down
61 changes: 13 additions & 48 deletions e2e/runner/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/rpcclient"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
Expand Down Expand Up @@ -81,13 +80,7 @@ func (runner *E2ERunner) DepositBTCWithAmount(amount float64) (txHash *chainhash
runner.Logger.Info("Now sending two txs to TSS address...")

amount = amount + zetabitcoin.DefaultDepositorFee
txHash, err = runner.SendToTSSFromDeployerToDeposit(
runner.BTCTSSAddress,
amount,
utxos,
runner.BtcRPCClient,
runner.BTCDeployerAddress,
)
txHash, err = runner.SendToTSSFromDeployerToDeposit(amount, utxos)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -133,38 +126,19 @@ func (runner *E2ERunner) DepositBTC(testHeader bool) {

// send two transactions to the TSS address
amount1 := 1.1 + zetabitcoin.DefaultDepositorFee
txHash1, err := runner.SendToTSSFromDeployerToDeposit(
runner.BTCTSSAddress,
amount1,
utxos[:2],
runner.BtcRPCClient,
runner.BTCDeployerAddress,
)
txHash1, err := runner.SendToTSSFromDeployerToDeposit(amount1, utxos[:2])
if err != nil {
panic(err)
}
amount2 := 0.05 + zetabitcoin.DefaultDepositorFee
txHash2, err := runner.SendToTSSFromDeployerToDeposit(
runner.BTCTSSAddress,
amount2,
utxos[2:4],
runner.BtcRPCClient,
runner.BTCDeployerAddress,
)
txHash2, err := runner.SendToTSSFromDeployerToDeposit(amount2, utxos[2:4])
if err != nil {
panic(err)
}

// send a donation to the TSS address to compensate for the funds minted automatically during pool creation
// and prevent accounting errors
_, err = runner.SendToTSSFromDeployerWithMemo(
runner.BTCTSSAddress,
0.11,
utxos[4:5],
runner.BtcRPCClient,
[]byte(constant.DonationMessage),
runner.BTCDeployerAddress,
)
_, err = runner.SendToTSSFromDeployerWithMemo(0.11, utxos[4:5], []byte(constant.DonationMessage))
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -201,31 +175,22 @@ func (runner *E2ERunner) DepositBTC(testHeader bool) {
}
}

func (runner *E2ERunner) SendToTSSFromDeployerToDeposit(
to btcutil.Address,
amount float64,
inputUTXOs []btcjson.ListUnspentResult,
btc *rpcclient.Client,
btcDeployerAddress *btcutil.AddressWitnessPubKeyHash,
) (*chainhash.Hash, error) {
return runner.SendToTSSFromDeployerWithMemo(
to,
amount,
inputUTXOs,
btc,
runner.DeployerAddress.Bytes(),
btcDeployerAddress,
)
func (runner *E2ERunner) SendToTSSFromDeployerToDeposit(amount float64, inputUTXOs []btcjson.ListUnspentResult) (
*chainhash.Hash,
error,
) {
return runner.SendToTSSFromDeployerWithMemo(amount, inputUTXOs, runner.DeployerAddress.Bytes())
}

func (runner *E2ERunner) SendToTSSFromDeployerWithMemo(
to btcutil.Address,
amount float64,
inputUTXOs []btcjson.ListUnspentResult,
btcRPC *rpcclient.Client,
memo []byte,
btcDeployerAddress *btcutil.AddressWitnessPubKeyHash,
) (*chainhash.Hash, error) {
btcRPC := runner.BtcRPCClient
to := runner.BTCTSSAddress
btcDeployerAddress := runner.BTCDeployerAddress

// prepare inputs
inputs := make([]btcjson.TransactionInput, len(inputUTXOs))
inputSats := btcutil.Amount(0)
Expand Down

0 comments on commit 9d91610

Please sign in to comment.