From 81b947ba2adc86b4f2ed87e8a7e1020d798384d2 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 20 Nov 2024 21:59:48 -0300 Subject: [PATCH] fix: lint --- .../transaction/transactions_test.go | 7 +-- itest/containers/containers.go | 16 ++----- itest/e2e_test.go | 5 ++- itest/manager.go | 44 ++++++++++++++----- 4 files changed, 43 insertions(+), 29 deletions(-) diff --git a/cmd/stakercli/transaction/transactions_test.go b/cmd/stakercli/transaction/transactions_test.go index f0da5d4..c2a403e 100644 --- a/cmd/stakercli/transaction/transactions_test.go +++ b/cmd/stakercli/transaction/transactions_test.go @@ -70,9 +70,6 @@ var ( Versions: []*parser.VersionedGlobalParams{&defaultParam}, } - //nolint:errchkjson - paramsMarshalled, _ = json.Marshal(globalParams) - parsedGlobalParams, _ = parser.ParseGlobalParams(&globalParams) lastParams = parsedGlobalParams.Versions[len(parsedGlobalParams.Versions)-1] ) @@ -189,8 +186,8 @@ func appRunCreatePhase1WithdrawalTx(r *rand.Rand, t *testing.T, app *cli.App, ar return data } -func randRange(_ *rand.Rand, min, max int) int { - return rand.Intn(max+1-min) + min +func randRange(_ *rand.Rand, minV, maxV int) int { + return rand.Intn(maxV+1-minV) + minV } type StakeParameters struct { diff --git a/itest/containers/containers.go b/itest/containers/containers.go index 841a84c..41d538b 100644 --- a/itest/containers/containers.go +++ b/itest/containers/containers.go @@ -179,19 +179,11 @@ func (m *Manager) RunBabylondResource( coventantQuorum int, baseHeaderHex string, slashingPkScript string, - covenantPk1 *btcec.PublicKey, - covenantPk2 *btcec.PublicKey, - covenantPk3 *btcec.PublicKey, + covenantPks ...*btcec.PublicKey, ) (*dockertest.Resource, error) { - covenantPks := []*bbn.BIP340PubKey{ - bbn.NewBIP340PubKeyFromBTCPK(covenantPk1), - bbn.NewBIP340PubKeyFromBTCPK(covenantPk2), - bbn.NewBIP340PubKeyFromBTCPK(covenantPk3), - } - - var covenantPksStr []string - for _, pk := range covenantPks { - covenantPksStr = append(covenantPksStr, pk.MarshalHex()) + covenantPksStr := make([]string, len(covenantPks)) + for i, cvPk := range covenantPks { + covenantPksStr[i] = bbn.NewBIP340PubKeyFromBTCPK(cvPk).MarshalHex() } cmd := []string{ diff --git a/itest/e2e_test.go b/itest/e2e_test.go index 1e2b80d..180b716 100644 --- a/itest/e2e_test.go +++ b/itest/e2e_test.go @@ -931,5 +931,8 @@ func TestStakeFromPhase1(t *testing.T) { stkTxResult, err := rpcBtc.GetTransaction(txHash) require.NoError(t, err) require.NotNil(t, stkTxResult) - // tm.createAndRegisterFinalityProviders(t, testStakingData) + + // at this point the BTC staking transaction is confirmed and was mined in BTC + // so the babylon chain can start and try to transition this staking BTC tx + // into a babylon BTC delegation in the cosmos side. } diff --git a/itest/manager.go b/itest/manager.go index b12eb24..0f3bc9e 100644 --- a/itest/manager.go +++ b/itest/manager.go @@ -146,6 +146,12 @@ func btcRpcTestClient(t *testing.T, bitcoindHost string) *rpcclient.Client { } type TestManager struct { + manager *containers.Manager + TestManagerStakerApp + TestManagerBTC +} + +type TestManagerStakerApp struct { Config *stakercfg.Config Db kvdb.Backend Sa *staker.App @@ -154,8 +160,6 @@ type TestManager struct { serviceAddress string StakerClient *dc.StakerServiceJSONRPCClient CovenantPrivKeys []*btcec.PrivateKey - manager *containers.Manager - TestManagerBTC } type TestManagerBTC struct { @@ -305,10 +309,32 @@ func StartManager( tmBTC := StartManagerBtc(t, ctx, numMatureOutputsInWallet, manager) quorum := 2 - coventantPrivKeys := genCovenants(t, 3) + covenantsNum := 3 + tmStakerApp := StartManagerStakerApp(t, ctx, tmBTC, manager, quorum, covenantsNum) + + return &TestManager{ + manager: manager, + TestManagerStakerApp: *tmStakerApp, + TestManagerBTC: *tmBTC, + } +} + +func StartManagerStakerApp( + t *testing.T, + ctx context.Context, + tmBTC *TestManagerBTC, + manager *containers.Manager, + covenantQuorum int, + covenantNum int, +) *TestManagerStakerApp { + coventantPrivKeys := genCovenants(t, covenantNum) + coventantPubKeys := make([]*btcec.PublicKey, covenantNum) + for i, cvPrivKey := range coventantPrivKeys { + coventantPubKeys[i] = cvPrivKey.PubKey() + } var buff bytes.Buffer - err = regtestParams.GenesisBlock.Header.Serialize(&buff) + err := regtestParams.GenesisBlock.Header.Serialize(&buff) require.NoError(t, err) baseHeaderHex := hex.EncodeToString(buff.Bytes()) @@ -320,12 +346,10 @@ func StartManager( babylond, err := manager.RunBabylondResource( t, tmpDir, - quorum, + covenantQuorum, baseHeaderHex, hex.EncodeToString(pkScript), // all slashing will be sent back to wallet - coventantPrivKeys[0].PubKey(), - coventantPrivKeys[1].PubKey(), - coventantPrivKeys[2].PubKey(), + coventantPubKeys..., ) require.NoError(t, err) @@ -391,7 +415,7 @@ func StartManager( stakerClient, err := dc.NewStakerServiceJSONRPCClient("tcp://" + addressString) require.NoError(t, err) - return &TestManager{ + return &TestManagerStakerApp{ Config: cfg, Db: dbbackend, Sa: stakerApp, @@ -400,8 +424,6 @@ func StartManager( serviceAddress: addressString, StakerClient: stakerClient, CovenantPrivKeys: coventantPrivKeys, - manager: manager, - TestManagerBTC: *tmBTC, } }