diff --git a/x/airdrop/keeper/keeper_test.go b/x/airdrop/keeper/keeper_test.go index 94aa2b7d79..37e9f51a5c 100644 --- a/x/airdrop/keeper/keeper_test.go +++ b/x/airdrop/keeper/keeper_test.go @@ -17,6 +17,8 @@ var ( feeCollectorAddress = authtypes.NewModuleAddress(authtypes.FeeCollectorName) addr1 = sdk.AccAddress([]byte("addr1_______________")) addr2 = sdk.AccAddress([]byte("addr2_______________")) + addr3 = sdk.AccAddress([]byte("addr3_______________")) + addr4 = sdk.AccAddress([]byte("addr4_______________")) ) type KeeperTestSuite struct { @@ -34,9 +36,10 @@ func (s *KeeperTestSuite) SetupTest() { Height: 10, }) - s.app.AirdropKeeper.SetParams(s.ctx, types.NewParams(addr1.String(), addr2.String())) + s.app.AirdropKeeper.SetParams(s.ctx, types.NewParams(addr1.String(), addr2.String(), addr3.String(), addr4.String())) } + func (s *KeeperTestSuite) TestAddNewFund() { amount := sdk.NewInt64Coin(sdk.DefaultBondDenom, 4000) s.Require().NoError(s.app.BankKeeper.SetBalance(s.ctx, addr1, amount)) // ensure the account is funded @@ -164,6 +167,85 @@ func (s *KeeperTestSuite) TestFeeDrip() { s.Require().Equal(feeCollectorBalance, sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(4040))) } +func (s *KeeperTestSuite) TestAddNewFundWithDiffDenom() { + amount := sdk.NewInt64Coin("denom", 4000) + s.Require().NoError(s.app.BankKeeper.SetBalance(s.ctx, addr1, amount)) // ensure the account is funded + + addrBalance := s.app.BankKeeper.GetBalance(s.ctx, addr1, "denom") + moduleBalance := s.app.BankKeeper.GetBalance(s.ctx, moduleAddress, "denom") + + // sanity check + s.Require().Equal(addrBalance, sdk.NewCoin("denom", sdk.NewInt(4000))) + s.Require().Equal(moduleBalance, sdk.NewCoin("denom", sdk.NewInt(0))) + + fund := types.Fund{ + Amount: &amount, + DripAmount: sdk.NewInt(40), + } + s.Require().NoError(s.app.AirdropKeeper.AddFund(s.ctx, addr1, fund)) + + addrBalance = s.app.BankKeeper.GetBalance(s.ctx, addr1, "denom") + moduleBalance = s.app.BankKeeper.GetBalance(s.ctx, moduleAddress, "denom") + + s.Require().Equal(addrBalance, sdk.NewCoin("denom", sdk.NewInt(0))) + s.Require().Equal(moduleBalance, sdk.NewCoin("denom", sdk.NewInt(4000))) +} + +func (s *KeeperTestSuite) TestMultiDenomFeeDrip() { + amountStake := sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000) + amountDenom := sdk.NewInt64Coin("denom", 1000) + fund1 := types.Fund{ + Amount: &amountStake, + DripAmount: sdk.NewInt(500)} + + fund2 := types.Fund{ + Amount: &amountStake, + DripAmount: sdk.NewInt(800), + } + + fund3 := types.Fund{ + Amount: &amountDenom, + DripAmount: sdk.NewInt(100)} + + fund4 := types.Fund{ + Amount: &amountDenom, + DripAmount: sdk.NewInt(300), + } + s.Require().NoError(s.app.BankKeeper.SetBalance(s.ctx, addr1, amountStake)) + s.Require().NoError(s.app.BankKeeper.SetBalance(s.ctx, addr2, amountStake)) + s.Require().NoError(s.app.BankKeeper.SetBalance(s.ctx, addr3, amountDenom)) + s.Require().NoError(s.app.BankKeeper.SetBalance(s.ctx, addr4, amountDenom)) + + s.Require().NoError(s.app.AirdropKeeper.AddFund(s.ctx, addr1, fund1)) + s.Require().NoError(s.app.AirdropKeeper.AddFund(s.ctx, addr2, fund2)) + s.Require().NoError(s.app.AirdropKeeper.AddFund(s.ctx, addr3, fund3)) + s.Require().NoError(s.app.AirdropKeeper.AddFund(s.ctx, addr4, fund4)) // check the balances + + moduleBalanceStake := s.app.BankKeeper.GetBalance(s.ctx, moduleAddress, sdk.DefaultBondDenom) + moduleBalanceDenom := s.app.BankKeeper.GetBalance(s.ctx, moduleAddress, "denom") + feeCollectorBalanceStake := s.app.BankKeeper.GetBalance(s.ctx, feeCollectorAddress, sdk.DefaultBondDenom) + feeCollectorBalanceDenom := s.app.BankKeeper.GetBalance(s.ctx, feeCollectorAddress, "denom") + + s.Require().Equal(moduleBalanceStake, sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(2000))) + s.Require().Equal(moduleBalanceDenom, sdk.NewCoin("denom", sdk.NewInt(2000))) + s.Require().Equal(feeCollectorBalanceStake, sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(0))) + s.Require().Equal(feeCollectorBalanceDenom, sdk.NewCoin("denom", sdk.NewInt(0))) + + _, err := s.app.AirdropKeeper.DripAllFunds(s.ctx) // test case - drip the funds + s.Require().NoError(err) // check that the fees have been transferred + + moduleBalanceStake = s.app.BankKeeper.GetBalance(s.ctx, moduleAddress, sdk.DefaultBondDenom) + moduleBalanceDenom = s.app.BankKeeper.GetBalance(s.ctx, moduleAddress, "denom") + feeCollectorBalanceStake = s.app.BankKeeper.GetBalance(s.ctx, feeCollectorAddress, sdk.DefaultBondDenom) + feeCollectorBalanceDenom = s.app.BankKeeper.GetBalance(s.ctx, feeCollectorAddress, "denom") + + s.Require().Equal(feeCollectorBalanceStake, sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1300))) // 800 drip fund 1, 500 drip fund 2 + s.Require().Equal(feeCollectorBalanceDenom, sdk.NewCoin("denom", sdk.NewInt(400))) // 100 drip fund 3, 300 drip fund 4 + s.Require().Equal(moduleBalanceStake, sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(700))) // remainder 500 from fund 1, remainder 200 from fund 2 + s.Require().Equal(moduleBalanceDenom, sdk.NewCoin("denom", sdk.NewInt(1600))) // remainder 900 from fund 3, remainder 700 from fund 4 + +} + func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) }