| 
									
										
										
										
											2020-08-21 22:56:20 +00:00
										 |  |  | package keeper_test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"strings" | 
					
						
							|  |  |  | 	"time" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-05 23:21:59 +00:00
										 |  |  | 	sdkmath "cosmossdk.io/math" | 
					
						
							| 
									
										
										
										
											2020-08-21 22:56:20 +00:00
										 |  |  | 	sdk "github.com/cosmos/cosmos-sdk/types" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/kava-labs/kava/x/issuance/types" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *KeeperTestSuite) TestIncrementCurrentAssetSupply() { | 
					
						
							|  |  |  | 	type args struct { | 
					
						
							| 
									
										
										
										
											2022-01-08 00:39:27 +00:00
										 |  |  | 		assets   []types.Asset | 
					
						
							|  |  |  | 		supplies []types.AssetSupply | 
					
						
							| 
									
										
										
										
											2020-08-21 22:56:20 +00:00
										 |  |  | 		coin     sdk.Coin | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	type errArgs struct { | 
					
						
							|  |  |  | 		expectPass bool | 
					
						
							|  |  |  | 		contains   string | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	testCases := []struct { | 
					
						
							|  |  |  | 		name    string | 
					
						
							|  |  |  | 		args    args | 
					
						
							|  |  |  | 		errArgs errArgs | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			"valid supply increase", | 
					
						
							|  |  |  | 			args{ | 
					
						
							| 
									
										
										
										
											2022-01-08 00:39:27 +00:00
										 |  |  | 				assets: []types.Asset{ | 
					
						
							| 
									
										
										
										
											2023-04-05 23:21:59 +00:00
										 |  |  | 					types.NewAsset(suite.addrs[0], "usdtoken", []string{suite.addrs[1]}, false, true, types.NewRateLimit(true, sdkmath.NewInt(10000000000), time.Hour*24)), | 
					
						
							| 
									
										
										
										
											2020-08-21 22:56:20 +00:00
										 |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2022-01-08 00:39:27 +00:00
										 |  |  | 				supplies: []types.AssetSupply{ | 
					
						
							| 
									
										
										
										
											2020-08-21 22:56:20 +00:00
										 |  |  | 					types.NewAssetSupply(sdk.NewCoin("usdtoken", sdk.ZeroInt()), time.Hour), | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2023-04-05 23:21:59 +00:00
										 |  |  | 				coin: sdk.NewCoin("usdtoken", sdkmath.NewInt(100000)), | 
					
						
							| 
									
										
										
										
											2020-08-21 22:56:20 +00:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			errArgs{ | 
					
						
							|  |  |  | 				expectPass: true, | 
					
						
							|  |  |  | 				contains:   "", | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			"over limit increase", | 
					
						
							|  |  |  | 			args{ | 
					
						
							| 
									
										
										
										
											2022-01-08 00:39:27 +00:00
										 |  |  | 				assets: []types.Asset{ | 
					
						
							| 
									
										
										
										
											2023-04-05 23:21:59 +00:00
										 |  |  | 					types.NewAsset(suite.addrs[0], "usdtoken", []string{suite.addrs[1]}, false, true, types.NewRateLimit(true, sdkmath.NewInt(10000000000), time.Hour*24)), | 
					
						
							| 
									
										
										
										
											2020-08-21 22:56:20 +00:00
										 |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2022-01-08 00:39:27 +00:00
										 |  |  | 				supplies: []types.AssetSupply{ | 
					
						
							| 
									
										
										
										
											2020-08-21 22:56:20 +00:00
										 |  |  | 					types.NewAssetSupply(sdk.NewCoin("usdtoken", sdk.ZeroInt()), time.Hour), | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2023-04-05 23:21:59 +00:00
										 |  |  | 				coin: sdk.NewCoin("usdtoken", sdkmath.NewInt(10000000001)), | 
					
						
							| 
									
										
										
										
											2020-08-21 22:56:20 +00:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			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)) | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |