Skip to content

Commit

Permalink
remove dumpPrivKey from e2e
Browse files Browse the repository at this point in the history
- Upgrade bitcoind version

- Use descriptors to import priv key
  • Loading branch information
Lazar955 committed Aug 15, 2024
1 parent bb8ad7e commit 3928f78
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 16 deletions.
8 changes: 7 additions & 1 deletion e2etest/bitcoind_node_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (h *BitcoindTestHandler) CreateWallet(walletName string, passphrase string)
// last false on the list will create legacy wallet. This is needed, as currently
// we are signing all taproot transactions by dumping the private key and signing it
// on app level. Descriptor wallets do not allow dumping private keys.
buff, _, err := h.m.ExecBitcoindCliCmd(h.t, []string{"createwallet", walletName, "false", "false", passphrase, "false", "false"})
buff, _, err := h.m.ExecBitcoindCliCmd(h.t, []string{"createwallet", walletName, "false", "false", passphrase, "false", "true"})
require.NoError(h.t, err)

var response CreateWalletResponse
Expand All @@ -108,3 +108,9 @@ func (h *BitcoindTestHandler) InvalidateBlock(blockHash string) {
_, _, err := h.m.ExecBitcoindCliCmd(h.t, []string{"invalidateblock", blockHash})
require.NoError(h.t, err)
}

// ImportDescriptors - todo
func (h *BitcoindTestHandler) ImportDescriptors(descriptor string) {
_, _, err := h.m.ExecBitcoindCliCmd(h.t, []string{"importdescriptors", descriptor})
require.NoError(h.t, err)
}
2 changes: 1 addition & 1 deletion e2etest/container/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type ImageConfig struct {
//nolint:deadcode
const (
dockerBitcoindRepository = "lncm/bitcoind"
dockerBitcoindVersionTag = "v24.0.1"
dockerBitcoindVersionTag = "v26.1"
)

// NewImageConfig returns ImageConfig needed for running e2e test.
Expand Down
2 changes: 1 addition & 1 deletion e2etest/submitter_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestSubmitterSubmissionReplace(t *testing.T) {
// 3. different signatures
require.Equal(t, sendTransactions[1].MsgTx().TxIn[0].PreviousOutPoint, resendTx2.MsgTx().TxIn[0].PreviousOutPoint)

const addrSize = 22
const addrSize = 34
resendTxOutIdx, err := relayer.IndexOfTxOut(resendTx2.MsgTx().TxOut, addrSize)
require.NoError(t, err)
ogTxOutIdx, err := relayer.IndexOfTxOut(sendTransactions[1].MsgTx().TxOut, addrSize)
Expand Down
48 changes: 41 additions & 7 deletions e2etest/test_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"context"
"encoding/hex"
"encoding/json"
"fmt"
"go.uber.org/zap"
"testing"
"time"
Expand Down Expand Up @@ -87,7 +89,6 @@ func StartManager(t *testing.T, numMatureOutputsInWallet uint32) *TestManager {
btcHandler.Start()
passphrase := "pass"
_ = btcHandler.CreateWallet("default", passphrase)
blocksResponse := btcHandler.GenerateBlocks(int(numMatureOutputsInWallet))

cfg := defaultVigilanteConfig()

Expand All @@ -102,6 +103,13 @@ func StartManager(t *testing.T, numMatureOutputsInWallet uint32) *TestManager {
}, nil)
require.NoError(t, err)

err = testRpcClient.WalletPassphrase(passphrase, 600)
require.NoError(t, err)

walletPrivKey, err := importPrivateKey(btcHandler)
require.NoError(t, err)
blocksResponse := btcHandler.GenerateBlocks(int(numMatureOutputsInWallet))

btcClient := initBTCClientWithSubscriber(t, cfg)

var buff bytes.Buffer
Expand Down Expand Up @@ -136,11 +144,8 @@ func StartManager(t *testing.T, numMatureOutputsInWallet uint32) *TestManager {
return true
}, eventuallyWaitTimeOut, eventuallyPollTime)

err = testRpcClient.WalletPassphrase(passphrase, 600)
require.NoError(t, err)

walletPrivKey, err := testRpcClient.DumpPrivKey(minerAddressDecoded)
require.NoError(t, err)
//walletPrivKey, err := testRpcClient.DumpPrivKey(minerAddressDecoded)
//require.NoError(t, err)

return &TestManager{
TestRpcClient: testRpcClient,
Expand All @@ -149,7 +154,8 @@ func StartManager(t *testing.T, numMatureOutputsInWallet uint32) *TestManager {
BitcoindHandler: btcHandler,
BTCClient: btcClient,
Config: cfg,
WalletPrivKey: walletPrivKey.PrivKey,
//WalletPrivKey: walletPrivKey.PrivKey,
WalletPrivKey: walletPrivKey,
}
}

Expand Down Expand Up @@ -227,3 +233,31 @@ func (tm *TestManager) CatchUpBTCLightClient(t *testing.T) {
_, err = tm.InsertBTCHeadersToBabylon(headers)
require.NoError(t, err)
}

func importPrivateKey(btcHandler *BitcoindTestHandler) (*btcec.PrivateKey, error) {
privKey, err := btcec.NewPrivateKey()
if err != nil {
return nil, err
}

wif, err := btcutil.NewWIF(privKey, regtestParams, true)
if err != nil {
return nil, err
}

descriptor := fmt.Sprintf("combo(%s)#%s", wif.String(), "timestamp")

// Create the JSON descriptor object.
descJSON, err := json.Marshal([]map[string]interface{}{
{
"desc": descriptor,
"active": true,
"timestamp": "now",
"label": "test key",
},
})

btcHandler.ImportDescriptors(string(descJSON))

return privKey, nil
}
1 change: 0 additions & 1 deletion e2etest/test_manager_btcstaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ func (tm *TestManager) CreateBTCDelegation(
require.NoError(t, err)
btccParams := btccParamsResp.Params
for i := 0; i < int(btccParams.BtcConfirmationDepth); i++ {
//tm.MineBlockWithTxs(t, tm.RetrieveTransactionFromMempool(t, []*chainhash.Hash{}))
tm.mineBlock(t)
}

Expand Down
9 changes: 4 additions & 5 deletions submitter/relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

const (
addrSize = 22
addrSize = 34
)

type Relayer struct {
Expand Down Expand Up @@ -327,7 +327,7 @@ func (rl *Relayer) ChainTwoTxAndSend(
}

var txOut *wire.TxOut
if len(tx1.Tx.TxOut[0].PkScript) == 22 {
if len(tx1.Tx.TxOut[0].PkScript) == addrSize {
txOut = tx1.Tx.TxOut[0]
} else {
txOut = tx1.Tx.TxOut[1]
Expand Down Expand Up @@ -417,10 +417,9 @@ func (rl *Relayer) buildTxWithData(
// return nil, err
//}

//segwit := false
fr := float64(rl.getFeeRate()) / 100000000.0 // todo decide what to use
feeRate := btcutil.Amount(rl.getFeeRate()).ToBTC() // todo decide what to use estimate of feeRate
rawTxResult, err := rl.BTCWallet.FundRawTransaction(tx, btcjson.FundRawTransactionOpts{
FeeRate: &fr,
FeeRate: &feeRate,
//EstimateMode: &btcjson.EstimateModeConservative,
}, nil)
if err != nil {
Expand Down

0 comments on commit 3928f78

Please sign in to comment.