From 7fc975249b1082d688fe203726d7a5c5df77bb91 Mon Sep 17 00:00:00 2001 From: istae <14264581+istae@users.noreply.github.com> Date: Wed, 24 Jul 2024 13:07:45 +0300 Subject: [PATCH] feat: swip 20 (#409) --- go.mod | 2 ++ pkg/bee/api/stake.go | 6 +++--- pkg/bee/client.go | 6 +++--- pkg/check/stake/stake.go | 9 +++++---- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 8e964afd9..2583800be 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module github.com/ethersphere/beekeeper go 1.22 +toolchain go1.22.0 + replace github.com/codahale/hdrhistogram => github.com/HdrHistogram/hdrhistogram-go v1.1.2 require ( diff --git a/pkg/bee/api/stake.go b/pkg/bee/api/stake.go index cf809147c..d02ab92a9 100644 --- a/pkg/bee/api/stake.go +++ b/pkg/bee/api/stake.go @@ -42,10 +42,10 @@ func (s *StakingService) GetStakedAmount(ctx context.Context) (stakedAmount *big return r.StakedAmount.Int, nil } -// WithdrawStake withdraws stake -func (s *StakingService) WithdrawStake(ctx context.Context) (txHash string, err error) { +// MigrateStake withdraws stake +func (s *StakingService) MigrateStake(ctx context.Context) (txHash string, err error) { r := new(stakeWithdrawResponse) - err = s.client.requestJSON(ctx, http.MethodDelete, "/stake", nil, r) + err = s.client.requestJSON(ctx, http.MethodPost, "/stake/migrate", nil, r) if err != nil { return "", err } diff --git a/pkg/bee/client.go b/pkg/bee/client.go index 7960d75d5..adce01c1d 100644 --- a/pkg/bee/client.go +++ b/pkg/bee/client.go @@ -822,9 +822,9 @@ func (c *Client) GetStake(ctx context.Context) (*big.Int, error) { return c.api.Stake.GetStakedAmount(ctx) } -// WithdrawStake withdraws stake -func (c *Client) WithdrawStake(ctx context.Context) (string, error) { - return c.api.Stake.WithdrawStake(ctx) +// MigrateStake withdraws stake +func (c *Client) MigrateStake(ctx context.Context) (string, error) { + return c.api.Stake.MigrateStake(ctx) } // WalletBalance fetches the balance for the given token diff --git a/pkg/check/stake/stake.go b/pkg/check/stake/stake.go index 4d8ad2ed1..e7b2e770f 100644 --- a/pkg/check/stake/stake.go +++ b/pkg/check/stake/stake.go @@ -4,9 +4,10 @@ import ( "context" "errors" "fmt" - "github.com/ethersphere/beekeeper/pkg/bee/api" "math/big" + "github.com/ethersphere/beekeeper/pkg/bee/api" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethersphere/beekeeper/pkg/bee" "github.com/ethersphere/beekeeper/pkg/beekeeper" @@ -84,7 +85,7 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int client := clients[node] if err := expectStakeAmountIs(ctx, client, zero); err != nil { - return errors.New("check initial staked amount") + return err } // depositing insufficient amount should fail @@ -121,7 +122,7 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int } // should not allow withdrawing from a running contract - _, err = client.WithdrawStake(ctx) + _, err = client.MigrateStake(ctx) if err == nil { return errors.New("withdraw from running contract should fail") } @@ -147,7 +148,7 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int }() // successful withdraw should set the staked amount to 0 - _, err = client.WithdrawStake(ctx) + _, err = client.MigrateStake(ctx) if err != nil { return fmt.Errorf("withdraw from paused contract: %w", err) }