This repository has been archived by the owner on Oct 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
273 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
x/registry/keeper/msg_server_withdraw_registration_fee_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/mycel-domain/mycel/testutil" | ||
"github.com/mycel-domain/mycel/x/registry/types" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestWithdrawRegistrationFee() { | ||
testCases := []struct { | ||
withdrawer string | ||
topLevelDomainName string | ||
expErr error | ||
fn func() | ||
}{ | ||
{ | ||
withdrawer: testutil.Alice, | ||
topLevelDomainName: "bar", | ||
}, | ||
{ | ||
withdrawer: testutil.Bob, | ||
topLevelDomainName: "bar", | ||
expErr: errorsmod.Wrapf(types.ErrNoPermissionToWithdrawFees, "%s", testutil.Bob), | ||
}, | ||
} | ||
|
||
for i, tc := range testCases { | ||
suite.Run(fmt.Sprintf("Case %d", i), func() { | ||
suite.SetupTest() | ||
|
||
// Register top level domain | ||
registerTopLevelDomainMsg := &types.MsgRegisterTopLevelDomain{ | ||
Creator: testutil.Alice, | ||
Name: tc.topLevelDomainName, | ||
RegistrationPeriodInYear: 1, | ||
} | ||
_, err := suite.msgServer.RegisterTopLevelDomain(suite.ctx, registerTopLevelDomainMsg) | ||
suite.Require().Nil(err) | ||
|
||
// Register second level domain | ||
registerSecondLevelDomainMsg := &types.MsgRegisterSecondLevelDomain{ | ||
Creator: testutil.Bob, | ||
Name: "foo", | ||
Parent: tc.topLevelDomainName, | ||
RegistrationPeriodInYear: 1, | ||
} | ||
_, err = suite.msgServer.RegisterSecondLevelDomain(suite.ctx, registerSecondLevelDomainMsg) | ||
suite.Require().Nil(err) | ||
|
||
// Before balance | ||
withdrawerAddress, err := sdk.AccAddressFromBech32(tc.withdrawer) | ||
suite.Require().Nil(err) | ||
beforeBalance := suite.app.BankKeeper.GetAllBalances(suite.ctx, withdrawerAddress) | ||
|
||
// Withdraw registration fee | ||
withdrawMsg := &types.MsgWithdrawRegistrationFee{ | ||
Creator: tc.withdrawer, | ||
Name: tc.topLevelDomainName, | ||
} | ||
fees, err := suite.msgServer.WithdrawRegistrationFee(suite.ctx, withdrawMsg) | ||
|
||
if tc.expErr == nil { | ||
suite.Require().Nil(err) | ||
|
||
// Check event | ||
events, found := testutil.FindEventsByType(suite.ctx.EventManager().Events(), types.EventTypeWithdrawRegistrationFees) | ||
suite.Require().True(found) | ||
for _, event := range events { | ||
suite.Require().Equal(tc.topLevelDomainName, event.Attributes[0].Value) | ||
suite.Require().Equal(fees.RegistrationFees.String(), event.Attributes[1].Value) | ||
} | ||
|
||
// Check balance | ||
afterBalance := suite.app.BankKeeper.GetAllBalances(suite.ctx, withdrawerAddress) | ||
suite.Require().Equal(beforeBalance.Add(fees.RegistrationFees...), afterBalance) | ||
} else { | ||
suite.Require().EqualError(err, tc.expErr.Error()) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.