Skip to content

Commit

Permalink
Mint: Unit Tests for SDK v0.44.3 Upgrade (shentufoundation#368)
Browse files Browse the repository at this point in the history
* fund community pool test

* Test Funding Shield Rewards

* minor fix

* Refactoring and a Few More Tests

* mint: modifying test

* mint: lint fix

* bank: cli test suite

* removing bank module changes

Co-authored-by: Hyoung-yoon Kim <[email protected]>
Co-authored-by: yoongbok-lee <[email protected]>
  • Loading branch information
3 people authored Feb 1, 2022
1 parent 1ff5002 commit 0d9f964
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions x/mint/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package keeper_test

import (
"testing"
"time"

"github.com/stretchr/testify/suite"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

sdksimapp "github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/tendermint/tendermint/crypto"

"github.com/certikfoundation/shentu/v2/simapp"
)

// shared setup
type KeeperTestSuite struct {
suite.Suite
app *simapp.SimApp
ctx sdk.Context
}

func (suite *KeeperTestSuite) SetupTest() {
suite.app = simapp.Setup(false)
suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{Time: time.Now().UTC()})
coins := sdk.Coins{sdk.NewInt64Coin("uctk", 80000*1e6)}
suite.Require().NoError(sdksimapp.FundModuleAccount(suite.app.BankKeeper, suite.ctx, "mint", coins))
}

func (suite *KeeperTestSuite) TestKeeper_SendToCommunityPool() {
tests := []struct {
name string
coins sdk.Coins
err bool
}{
{
name: "Funding Community Pool",
coins: sdk.NewCoins(sdk.NewInt64Coin(suite.app.StakingKeeper.BondDenom(suite.ctx), 100*1e6)),
err: false,
},
{
name: "Funding With 0",
coins: sdk.NewCoins(sdk.NewInt64Coin(suite.app.StakingKeeper.BondDenom(suite.ctx), 0)),
err: true,
},
}

for _, tc := range tests {
suite.T().Log(tc.name)
moduleAcct := sdk.AccAddress(crypto.AddressHash([]byte("mint")))
if tc.err {
err := suite.app.MintKeeper.SendToCommunityPool(suite.ctx, tc.coins)
suite.Require().Nil(err)
} else {
initalMintBalance := suite.app.BankKeeper.GetBalance(suite.ctx, moduleAcct, "uctk")
err := suite.app.MintKeeper.SendToCommunityPool(suite.ctx, tc.coins)
suite.Require().NoError(err)
deductedMintBalance := suite.app.BankKeeper.GetBalance(suite.ctx, moduleAcct, "uctk")
distributionBalance := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(crypto.AddressHash([]byte("distribution"))), "uctk")
suite.Require().Equal(initalMintBalance.Sub(deductedMintBalance), distributionBalance)
}
}
}

func (suite *KeeperTestSuite) TestKeeper_SendToShieldRewards() {
tests := []struct {
name string
coins sdk.Coins
err bool
}{
{
name: "Funding Shield Rewards",
coins: sdk.NewCoins(sdk.NewInt64Coin(suite.app.StakingKeeper.BondDenom(suite.ctx), 100*1e6)),
err: false,
},
{
name: "Funding With 0",
coins: sdk.NewCoins(sdk.NewInt64Coin(suite.app.StakingKeeper.BondDenom(suite.ctx), 0)),
err: true,
},
}

for _, tc := range tests {
suite.T().Log(tc.name)
moduleAcct := sdk.AccAddress(crypto.AddressHash([]byte("mint")))
if tc.err {
err := suite.app.MintKeeper.SendToShieldRewards(suite.ctx, tc.coins)
suite.Require().Nil(err)
} else {
initalMintBalance := suite.app.BankKeeper.GetBalance(suite.ctx, moduleAcct, "uctk")
err := suite.app.MintKeeper.SendToShieldRewards(suite.ctx, tc.coins)
suite.Require().NoError(err)
deductedMintBalance := suite.app.BankKeeper.GetBalance(suite.ctx, moduleAcct, "uctk")
shieldBalance := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(crypto.AddressHash([]byte("shield"))), "uctk")
suite.Require().Equal(initalMintBalance.Sub(deductedMintBalance), shieldBalance)
}
}
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}

0 comments on commit 0d9f964

Please sign in to comment.