Skip to content

Commit d3e8e67

Browse files
committed
test: cosmosclient.BankBalances
1 parent 6fa0f6c commit d3e8e67

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

ignite/pkg/cosmosclient/bank.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (c Client) BankBalances(ctx context.Context, address string, pagination *qu
1818
Pagination: pagination,
1919
}
2020

21-
resp, err := banktypes.NewQueryClient(c.context).AllBalances(ctx, req)
21+
resp, err := c.bankQueryClient.AllBalances(ctx, req)
2222
if err != nil {
2323
return nil, err
2424
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package cosmosclient
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"cosmossdk.io/math"
8+
sdk "github.com/cosmos/cosmos-sdk/types"
9+
"github.com/cosmos/cosmos-sdk/types/query"
10+
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
11+
"github.com/stretchr/testify/assert"
12+
"github.com/stretchr/testify/require"
13+
)
14+
15+
func TestClientBankBalances(t *testing.T) {
16+
var (
17+
ctx = context.Background()
18+
address = "address"
19+
pagination = &query.PageRequest{Offset: 1}
20+
expectedBalances = sdk.NewCoins(
21+
sdk.NewCoin("token", math.NewInt(1000)),
22+
sdk.NewCoin("stake", math.NewInt(2000)),
23+
)
24+
)
25+
c := newClient(t, func(s suite) {
26+
req := &banktypes.QueryAllBalancesRequest{
27+
Address: address,
28+
Pagination: pagination,
29+
}
30+
31+
s.bankQueryClient.EXPECT().AllBalances(ctx, req).
32+
Return(&banktypes.QueryAllBalancesResponse{
33+
Balances: expectedBalances,
34+
}, nil)
35+
})
36+
37+
balances, err := c.BankBalances(ctx, address, pagination)
38+
39+
require.NoError(t, err)
40+
assert.Equal(t, expectedBalances, balances)
41+
}

0 commit comments

Comments
 (0)