-
Notifications
You must be signed in to change notification settings - Fork 206
/
balances.go
82 lines (66 loc) · 2.02 KB
/
balances.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package assertion
import (
"fmt"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/NibiruChain/nibiru/app"
)
func AllBalancesEqual(account sdk.AccAddress, amount sdk.Coins) *allBalancesEqual {
return &allBalancesEqual{Account: account, Amount: amount}
}
type allBalancesEqual struct {
Account sdk.AccAddress
Amount sdk.Coins
}
func (b allBalancesEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) {
coins := app.BankKeeper.GetAllBalances(ctx, b.Account)
if !coins.IsEqual(b.Amount) {
return ctx, fmt.Errorf(
"account %s balance not equal, expected %s, got %s",
b.Account.String(),
b.Amount.String(),
coins.String(),
), false
}
return ctx, nil, false
}
func BalanceEqual(account sdk.AccAddress, denom string, amount sdkmath.Int) *balanceEqual {
return &balanceEqual{Account: account, Denom: denom, Amount: amount}
}
type balanceEqual struct {
Account sdk.AccAddress
Denom string
Amount sdkmath.Int
}
func (b balanceEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) {
coin := app.BankKeeper.GetBalance(ctx, b.Account, b.Denom)
if !coin.Amount.Equal(b.Amount) {
return ctx, fmt.Errorf(
"account %s balance not equal, expected %s, got %s",
b.Account.String(),
b.Amount.String(),
coin.String(),
), false
}
return ctx, nil, false
}
func ModuleBalanceEqual(moduleName string, denom string, amount sdkmath.Int) *moduleBalanceEqual {
return &moduleBalanceEqual{ModuleName: moduleName, Denom: denom, Amount: amount}
}
type moduleBalanceEqual struct {
ModuleName string
Denom string
Amount sdkmath.Int
}
func (b moduleBalanceEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) {
coin := app.BankKeeper.GetBalance(ctx, app.AccountKeeper.GetModuleAddress(b.ModuleName), b.Denom)
if !coin.Amount.Equal(b.Amount) {
return ctx, fmt.Errorf(
"module %s balance not equal, expected %s, got %s",
b.ModuleName,
b.Amount.String(),
coin.String(),
), false
}
return ctx, nil, false
}