1
1
package keeper
2
2
3
3
import (
4
+ "encoding/json"
4
5
"github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting"
5
6
"github.com/CosmWasm/wasmd/x/wasm/types"
6
7
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
@@ -311,6 +312,31 @@ func TestIBCQuerier(t *testing.T) {
311
312
312
313
}
313
314
315
+ func TestBankQuerierBalance (t * testing.T ) {
316
+ mock := bankKeeperMock {GetBalanceFn : func (ctx sdk.Context , addr sdk.AccAddress , denom string ) sdk.Coin {
317
+ return sdk .NewCoin (denom , sdk .NewInt (1 ))
318
+ }}
319
+
320
+ ctx := sdk.Context {}
321
+ q := BankQuerier (mock )
322
+ gotBz , gotErr := q (ctx , & wasmvmtypes.BankQuery {
323
+ Balance : & wasmvmtypes.BalanceQuery {
324
+ Address : RandomBech32AccountAddress (t ),
325
+ Denom : "ALX" ,
326
+ },
327
+ })
328
+ require .NoError (t , gotErr )
329
+ var got wasmvmtypes.BalanceResponse
330
+ require .NoError (t , json .Unmarshal (gotBz , & got ))
331
+ exp := wasmvmtypes.BalanceResponse {
332
+ Amount : wasmvmtypes.Coin {
333
+ Denom : "ALX" ,
334
+ Amount : "1" ,
335
+ },
336
+ }
337
+ assert .Equal (t , exp , got )
338
+ }
339
+
314
340
type wasmKeeperMock struct {
315
341
GetContractInfoFn func (ctx sdk.Context , contractAddress sdk.AccAddress ) * types.ContractInfo
316
342
}
@@ -325,3 +351,22 @@ func (m wasmKeeperMock) GetContractInfo(ctx sdk.Context, contractAddress sdk.Acc
325
351
}
326
352
return m .GetContractInfoFn (ctx , contractAddress )
327
353
}
354
+
355
+ type bankKeeperMock struct {
356
+ GetBalanceFn func (ctx sdk.Context , addr sdk.AccAddress , denom string ) sdk.Coin
357
+ GetAllBalancesFn func (ctx sdk.Context , addr sdk.AccAddress ) sdk.Coins
358
+ }
359
+
360
+ func (m bankKeeperMock ) GetBalance (ctx sdk.Context , addr sdk.AccAddress , denom string ) sdk.Coin {
361
+ if m .GetBalanceFn == nil {
362
+ panic ("not expected to be called" )
363
+ }
364
+ return m .GetBalanceFn (ctx , addr , denom )
365
+ }
366
+
367
+ func (m bankKeeperMock ) GetAllBalances (ctx sdk.Context , addr sdk.AccAddress ) sdk.Coins {
368
+ if m .GetAllBalancesFn == nil {
369
+ panic ("not expected to be called" )
370
+ }
371
+ return m .GetAllBalancesFn (ctx , addr )
372
+ }
0 commit comments