Skip to content

Commit

Permalink
fix: comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
notanatol committed Mar 11, 2024
1 parent 9b99a71 commit 7caa117
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkg/bee/debugapi/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,13 @@ func (n *NodeService) Wallet(ctx context.Context) (resp Wallet, err error) {

// Withdraw calls wallet withdraw endpoint
func (n *NodeService) Withdraw(ctx context.Context, token, addr string) (tx common.Hash, err error) {
endpoint := fmt.Sprintf("/wallet/withdraw/%s?address=%s&amount=1", token, addr)
endpoint := fmt.Sprintf("/wallet/withdraw/%s?address=%s&amount=10000000000000000", token, addr)

r := struct {
TransactionHash common.Hash `json:"transactionHash"`
}{}

err = n.client.requestJSON(ctx, http.MethodPost, endpoint, nil, r)
err = n.client.requestJSON(ctx, http.MethodPost, endpoint, nil, &r)
if err != nil {
return
}
Expand Down
11 changes: 7 additions & 4 deletions pkg/check/withdraw/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"

"github.com/ethereum/go-ethereum/common"
"github.com/ethersphere/beekeeper/pkg/beekeeper"
"github.com/ethersphere/beekeeper/pkg/logging"
"github.com/ethersphere/beekeeper/pkg/orchestration"
Expand Down Expand Up @@ -48,7 +49,7 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
return err
}

target := checkCase.RandomBee()
target := checkCase.Bee(1)

c.logger.Infof("target is %s", target.Name())
c.logger.Info("withdrawing bzz...")
Expand All @@ -60,14 +61,16 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
c.logger.Info("success")
c.logger.Info("withdrawing native...")

if err := target.Withdraw(ctx, "sETH", o.TargetAddr); err != nil {
return fmt.Errorf("withdraw bzz: %w", err)
if err := target.Withdraw(ctx, "xDAI", o.TargetAddr); err != nil {
return fmt.Errorf("withdraw native: %w", err)
}

c.logger.Info("success")
c.logger.Info("withdrawing to a non whitelisted address")

if err := target.Withdraw(ctx, "sETH", "0x0000000000000000000000"); err == nil {
var zeroAddr common.Address

if err := target.Withdraw(ctx, "sETH", zeroAddr.String()); err == nil {
return errors.New("withdraw to non-whitelisted address expected to fail")
}

Expand Down
11 changes: 8 additions & 3 deletions pkg/test/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"math/big"
"math/rand"
"time"

"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/beekeeper/pkg/bee"
Expand Down Expand Up @@ -113,14 +114,18 @@ func (b *BeeV2) Withdraw(ctx context.Context, token, addr string) error {
return fmt.Errorf("(%s) withdraw balance %w", b.name, err)
}

time.Sleep(2 * time.Second)

after, err := b.client.WalletBalance(ctx, token)
if err != nil {
return fmt.Errorf("(%s) wallet balance %w", b.name, err)
}

if after.Cmp(before) < 0 {
return nil
want := big.NewInt(0).Sub(before, big.NewInt(10000000000000000))

if after.Cmp(want) > 0 {
return errors.New("incorrect balance after withdraw")
}

return errors.New("incorrect balance after withdraw")
return nil
}

0 comments on commit 7caa117

Please sign in to comment.