Skip to content

Commit

Permalink
added log prints to crosschain_swap E2E test
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed May 29, 2024
1 parent 1d2edd1 commit 0f49e9c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions e2e/e2etests/test_crosschain_swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) {
if err != nil {
panic(err)
}
r.Logger.Print(fmt.Sprintf("There are %d utxos before SendToTSSFromDeployerWithMemo", len(utxos)))
r.Logger.Info("#utxos %d", len(utxos))
r.Logger.Info("memo address %s", r.ERC20ZRC20Addr)
memo, err := r.ZEVMSwapApp.EncodeMemo(&bind.CallOpts{}, r.ERC20ZRC20Addr, r.DeployerAddress.Bytes())
Expand All @@ -150,6 +151,8 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) {
memo = append(r.ZEVMSwapAppAddr.Bytes(), memo...)
r.Logger.Info("memo length %d", len(memo))

r.Logger.Print(fmt.Sprintf("SendToTSSFromDeployerWithMemo deploer address: %s\n", r.BTCDeployerAddress))
r.Logger.Print("SendToTSSFromDeployerWithMemo-1")
txID, err := r.SendToTSSFromDeployerWithMemo(
r.BTCTSSAddress,
0.01,
Expand Down Expand Up @@ -198,6 +201,7 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) {
memo = append(r.ZEVMSwapAppAddr.Bytes(), memo...)
r.Logger.Info("memo length %d", len(memo))

r.Logger.Print("SendToTSSFromDeployerWithMemo-2")
amount := 0.1
txid, err := r.SendToTSSFromDeployerWithMemo(
r.BTCTSSAddress,
Expand Down
37 changes: 35 additions & 2 deletions e2e/runner/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ func (runner *E2ERunner) SendToTSSFromDeployerWithMemo(
scriptPubkeys := make([]string, len(inputUTXOs))

for i, utxo := range inputUTXOs {
inputs[i] = btcjson.TransactionInput{utxo.TxID, utxo.Vout}
inputs[i] = btcjson.TransactionInput{
Txid: utxo.TxID,
Vout: utxo.Vout,
}
inputSats += btcutil.Amount(utxo.Amount * btcutil.SatoshiPerBitcoin)
amounts[i] = utxo.Amount
scriptPubkeys[i] = utxo.ScriptPubKey
Expand Down Expand Up @@ -253,7 +256,7 @@ func (runner *E2ERunner) SendToTSSFromDeployerWithMemo(
tx.TxOut[1], tx.TxOut[2] = tx.TxOut[2], tx.TxOut[1]

// make sure that TxOut[0] is sent to "to" address; TxOut[2] is change to oneself. TxOut[1] is memo.
if bytes.Compare(tx.TxOut[0].PkScript[2:], to.ScriptAddress()) != 0 {
if !bytes.Equal(tx.TxOut[0].PkScript[2:], to.ScriptAddress()) {
runner.Logger.Info("tx.TxOut[0].PkScript: %x", tx.TxOut[0].PkScript)
runner.Logger.Info("to.ScriptAddress(): %x", to.ScriptAddress())
runner.Logger.Info("swapping txout[0] with txout[2]")
Expand Down Expand Up @@ -281,6 +284,36 @@ func (runner *E2ERunner) SendToTSSFromDeployerWithMemo(
if err != nil {
panic(err)
}

// print transaction inputs
runner.Logger.Info("SignRawTransactionWithWallet2 input: %+v", inputsForSign)
for _, input := range inputUTXOs {
runner.Logger.Print(" txid: %s", input.TxID)
runner.Logger.Print(" vout: %d", input.Vout)
runner.Logger.Print(" address: %s", input.Address)
runner.Logger.Print(" amount: %f", input.Amount)
runner.Logger.Print(" confirmations: %d", input.Confirmations)
}

// retry for 10 times if not signed
if !signed {
for i := 0; i < 10; i++ {
runner.Logger.Print(fmt.Sprintf("retrying SignRawTransactionWithWallet2: %d", i+1))
stx, signed, err = btcRPC.SignRawTransactionWithWallet2(tx, inputsForSign)
if err != nil {
panic(err)
}
if signed {
break
}
time.Sleep(1 * time.Second)
_, err = btcRPC.GenerateToAddress(1, btcDeployerAddress, nil)
if err != nil {
panic(err)
}
}
}

if !signed {
panic("btc transaction not signed")
}
Expand Down

0 comments on commit 0f49e9c

Please sign in to comment.