Skip to content

Commit

Permalink
chore: add last err to debug
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Nov 21, 2024
1 parent 7c745dd commit 323cdcf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
35 changes: 20 additions & 15 deletions itest/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/babylonlabs-io/btc-staker/stakerservice"
"github.com/babylonlabs-io/networks/parameters/parser"

"github.com/babylonlabs-io/babylon/btcstaking"
"github.com/babylonlabs-io/babylon/crypto/bip322"
btcctypes "github.com/babylonlabs-io/babylon/x/btccheckpoint/types"

Expand Down Expand Up @@ -860,10 +859,6 @@ func TestStakeFromPhase1(t *testing.T) {
require.NoError(t, err)

tmBTC := StartManagerBtc(t, ctx, numMatureOutputsInWallet, manager)
defer func() {
cancel()
manager.ClearResources()
}()

minStakingTime := uint16(100)
stakerAddr := datagen.GenRandomAccount().GetAddress()
Expand All @@ -873,18 +868,11 @@ func TestStakeFromPhase1(t *testing.T) {
btcStakerPkHex := hex.EncodeToString(schnorr.SerializePubKey(testStakingData.StakerKey))

appCli := testutil.TestApp()
tagHex := datagen.GenRandomHexStr(r, btcstaking.TagLen)

coventantPrivKeys := genCovenants(t, 1)
covenantPkSerializedHex := hex.EncodeToString(schnorr.SerializePubKey(coventantPrivKeys[0].PubKey()))
covenantPkHex := hex.EncodeToString(coventantPrivKeys[0].PubKey().SerializeCompressed())

commonFlags := []string{
fmt.Sprintf("--covenant-committee-pks=%s", covenantPkSerializedHex),
fmt.Sprintf("--tag=%s", tagHex),
"--covenant-quorum=1", "--network=regtest",
}

lastParams := &parser.VersionedGlobalParams{
Version: 0,
ActivationHeight: 100,
Expand Down Expand Up @@ -918,6 +906,12 @@ func TestStakeFromPhase1(t *testing.T) {
inclusionHeight := lastParams.ActivationHeight + 1
stakingTime := lastParams.MaxStakingTime

commonFlags := []string{
fmt.Sprintf("--covenant-committee-pks=%s", covenantPkSerializedHex),
fmt.Sprintf("--tag=%s", lastParams.Tag),
"--covenant-quorum=1", "--network=regtest",
}

createTxCmdArgs := []string{
paramsFilePath,
fmt.Sprintf("--staker-pk=%s", btcStakerPkHex),
Expand Down Expand Up @@ -965,7 +959,7 @@ func TestStakeFromPhase1(t *testing.T) {
parsedGlobalParams, err := parser.ParseGlobalParams(&globalParams)
require.NoError(t, err)

// just to make sure it is able to parse the staking tx
// Makes sure it is able to parse the staking tx
paserdStkTx, err := stakerservice.ParseV0StakingTx(parsedGlobalParams, regtestParams, signedStkTx)
require.NoError(t, err)
require.NotNil(t, paserdStkTx)
Expand All @@ -982,15 +976,26 @@ func TestStakeFromPhase1(t *testing.T) {
}
defer tm.Stop(t, cancel)

// verify that the chain is healthy
require.Eventually(t, func() bool {
_, err := tm.BabylonClient.Params()
return err == nil
}, time.Minute, 200*time.Millisecond)

// funds the fpd
_, _, err = tm.manager.BabylondTxBankMultiSend(t, "node0", "1000000ubbn", testStakingData.FinalityProviderBabylonAddrs[0].String())
require.NoError(t, err)

tm.insertAllMinedBlocksToBabylon(t)
tm.createAndRegisterFinalityProviders(t, testStakingData)

// tmBTC.WalletAddrInfo.
stakerAddrStr := tmBTC.MinerAddr.String()
stkTxHash := txHash.String()
// miner address and the staker addr are the same guy
// stakerAddrStr := tmBTC.WalletPubKey
// stakerAddrStr := btcStakerPkHex
stkTxHash := signedStkTx.TxHash().String()

// miner address and the staker addr are the same guy, maybe not
res, err := tmStakerApp.StakerClient.BtcDelegationFromBtcStakingTx(ctx, stakerAddrStr, stkTxHash, parsedGlobalParams)
require.NoError(t, err)
require.NotNil(t, res)
Expand Down
3 changes: 3 additions & 0 deletions itest/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/babylonlabs-io/btc-staker/walletcontroller"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
Expand Down Expand Up @@ -170,6 +171,7 @@ type TestManagerBTC struct {
WalletPassphrase string
BitcoindHost string
WalletPubKey *btcec.PublicKey
WalletAddrInfo *btcjson.GetAddressInfoResult
TestRpcBtcClient *rpcclient.Client
}

Expand Down Expand Up @@ -294,6 +296,7 @@ func StartManagerBtc(
WalletPassphrase: passphrase,
BitcoindHost: bitcoindHost,
WalletPubKey: walletPubKey,
WalletAddrInfo: info,
TestRpcBtcClient: rpcBtc,
}
}
Expand Down
4 changes: 3 additions & 1 deletion stakerservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func (s *StakerService) btcDelegationFromBtcStakingTx(
}

func ParseV0StakingTx(globalParams *parser.ParsedGlobalParams, btcParams *chaincfg.Params, wireStkTx *wire.MsgTx) (*btcstaking.ParsedV0StakingTx, error) {
var lastErr error
for i := len(globalParams.Versions) - 1; i >= 0; i-- {
params := globalParams.Versions[i]
parsedStakingTx, err := btcstaking.ParseV0StakingTx(
Expand All @@ -178,11 +179,12 @@ func ParseV0StakingTx(globalParams *parser.ParsedGlobalParams, btcParams *chainc
btcParams,
)
if err != nil {
lastErr = err
continue
}
return parsedStakingTx, nil
}
return nil, fmt.Errorf("failed to parse BTC staking tx %s using the global params %+v", wireStkTx.TxHash().String(), globalParams)
return nil, fmt.Errorf("err: %s failed to parse BTC staking tx %s using the global params %+v", lastErr.Error(), wireStkTx.TxHash().String(), globalParams)
}

func (s *StakerService) stakingDetails(_ *rpctypes.Context,
Expand Down

0 comments on commit 323cdcf

Please sign in to comment.