forked from maticnetwork/heimdall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler_test.go
68 lines (55 loc) · 1.98 KB
/
handler_test.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
package bank_test
import (
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/maticnetwork/heimdall/app"
authTypes "github.com/maticnetwork/heimdall/auth/types"
"github.com/maticnetwork/heimdall/bank"
"github.com/maticnetwork/heimdall/bank/types"
"github.com/maticnetwork/heimdall/helper/mocks"
hmTypes "github.com/maticnetwork/heimdall/types"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
type HandlerTestSuite struct {
suite.Suite
app *app.HeimdallApp
ctx sdk.Context
handler sdk.Handler
contractCaller mocks.IContractCaller
}
// SetupTest setup all necessary things for querier tesing
func (suite *HandlerTestSuite) SetupTest() {
suite.app, suite.ctx = createTestApp(false)
suite.contractCaller = mocks.IContractCaller{}
suite.handler = bank.NewHandler(suite.app.BankKeeper, &suite.contractCaller)
}
// TestHandlerTestSuite
func TestHandlerTestSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(HandlerTestSuite))
}
func (suite *HandlerTestSuite) TestHandleMsgUnknown() {
t, _, ctx := suite.T(), suite.app, suite.ctx
result := suite.handler(ctx, nil)
require.False(t, result.IsOK())
}
func (suite *HandlerTestSuite) TestHandlerMsgSend() {
t, app, ctx := suite.T(), suite.app, suite.ctx
amount := int64(10000000)
from := hmTypes.HexToHeimdallAddress("123")
to := hmTypes.HexToHeimdallAddress("456")
_, err := app.BankKeeper.AddCoins(ctx, from, sdk.NewCoins(sdk.NewCoin(authTypes.FeeToken, sdk.NewInt(amount*10))))
require.NoError(t, err)
msgSend := types.NewMsgSend(
from,
to,
sdk.NewCoins(sdk.NewCoin(authTypes.FeeToken, sdk.NewInt(amount))),
)
result := suite.handler(ctx, msgSend)
require.True(t, result.IsOK(), "Expected New msg to be sent")
fromAcc := app.BankKeeper.GetCoins(ctx, to)
require.Less(t, fromAcc.AmountOf(authTypes.FeeToken).Int64(), sdk.NewInt(amount*10).Int64())
toAcc := app.BankKeeper.GetCoins(ctx, to)
require.Equal(t, sdk.NewInt(amount), toAcc.AmountOf(authTypes.FeeToken))
}