mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
3375484f79
* Use cosmossdk.io/errors for deprecated error methods * Update error registration with cosmossdk.io/errors * Use cosmossdk.io/math for deprecated sdk.Int alias * Fix modified proto file * Update sdk.Int usage in swap hooks * Update e2e test deprecated method usage
85 lines
2.3 KiB
Go
85 lines
2.3 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
|
|
sdkmath "cosmossdk.io/math"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/kava-labs/kava/x/issuance/types"
|
|
)
|
|
|
|
func (suite *KeeperTestSuite) TestIncrementCurrentAssetSupply() {
|
|
type args struct {
|
|
assets []types.Asset
|
|
supplies []types.AssetSupply
|
|
coin sdk.Coin
|
|
}
|
|
type errArgs struct {
|
|
expectPass bool
|
|
contains string
|
|
}
|
|
testCases := []struct {
|
|
name string
|
|
args args
|
|
errArgs errArgs
|
|
}{
|
|
{
|
|
"valid supply increase",
|
|
args{
|
|
assets: []types.Asset{
|
|
types.NewAsset(suite.addrs[0], "usdtoken", []string{suite.addrs[1]}, false, true, types.NewRateLimit(true, sdkmath.NewInt(10000000000), time.Hour*24)),
|
|
},
|
|
supplies: []types.AssetSupply{
|
|
types.NewAssetSupply(sdk.NewCoin("usdtoken", sdk.ZeroInt()), time.Hour),
|
|
},
|
|
coin: sdk.NewCoin("usdtoken", sdkmath.NewInt(100000)),
|
|
},
|
|
errArgs{
|
|
expectPass: true,
|
|
contains: "",
|
|
},
|
|
},
|
|
{
|
|
"over limit increase",
|
|
args{
|
|
assets: []types.Asset{
|
|
types.NewAsset(suite.addrs[0], "usdtoken", []string{suite.addrs[1]}, false, true, types.NewRateLimit(true, sdkmath.NewInt(10000000000), time.Hour*24)),
|
|
},
|
|
supplies: []types.AssetSupply{
|
|
types.NewAssetSupply(sdk.NewCoin("usdtoken", sdk.ZeroInt()), time.Hour),
|
|
},
|
|
coin: sdk.NewCoin("usdtoken", sdkmath.NewInt(10000000001)),
|
|
},
|
|
errArgs{
|
|
expectPass: false,
|
|
contains: "asset supply over limit",
|
|
},
|
|
},
|
|
}
|
|
for _, tc := range testCases {
|
|
suite.Run(tc.name, func() {
|
|
suite.SetupTest()
|
|
params := types.NewParams(tc.args.assets)
|
|
suite.keeper.SetParams(suite.ctx, params)
|
|
for _, supply := range tc.args.supplies {
|
|
suite.keeper.SetAssetSupply(suite.ctx, supply, supply.GetDenom())
|
|
}
|
|
err := suite.keeper.IncrementCurrentAssetSupply(suite.ctx, tc.args.coin)
|
|
if tc.errArgs.expectPass {
|
|
suite.Require().NoError(err, tc.name)
|
|
for _, expectedSupply := range tc.args.supplies {
|
|
expectedSupply.CurrentSupply = expectedSupply.CurrentSupply.Add(tc.args.coin)
|
|
actualSupply, found := suite.keeper.GetAssetSupply(suite.ctx, expectedSupply.GetDenom())
|
|
suite.Require().True(found)
|
|
suite.Require().Equal(expectedSupply, actualSupply, tc.name)
|
|
}
|
|
} else {
|
|
suite.Require().Error(err, tc.name)
|
|
suite.Require().True(strings.Contains(err.Error(), tc.errArgs.contains))
|
|
}
|
|
})
|
|
}
|
|
}
|