Skip to content

Commit

Permalink
Add Contract Registration Helper
Browse files Browse the repository at this point in the history
  • Loading branch information
joelsmith-2019 committed Oct 9, 2023
1 parent e9d4487 commit 808d6be
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 80 deletions.
12 changes: 12 additions & 0 deletions x/feepay/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,15 @@ func (s *IntegrationTestSuite) InstantiateContract(sender string, admin string)

return result.Address
}

// Helper method for quickly registering a fee pay contract
func (s *IntegrationTestSuite) registerFeePayContract(senderAddress string, contractAddress string, walletLimit uint64) {
_, err := s.app.AppKeepers.FeePayKeeper.RegisterFeePayContract(s.ctx, &types.MsgRegisterFeePayContract{
SenderAddress: senderAddress,
FeePayContract: &types.FeePayContract{
ContractAddress: contractAddress,
WalletLimit: walletLimit,
},
})
s.Require().NoError(err)
}
50 changes: 6 additions & 44 deletions x/feepay/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,8 @@ func (s *IntegrationTestSuite) TestUnregisterFeePayContract() {
creatorContract := s.InstantiateContract(sender.String(), "")
adminContract := s.InstantiateContract(sender.String(), admin.String())

_, err := s.app.AppKeepers.FeePayKeeper.RegisterFeePayContract(s.ctx, &types.MsgRegisterFeePayContract{
SenderAddress: sender.String(),
FeePayContract: &types.FeePayContract{
ContractAddress: creatorContract,
WalletLimit: 1,
},
})
s.Require().NoError(err)

_, err = s.app.AppKeepers.FeePayKeeper.RegisterFeePayContract(s.ctx, &types.MsgRegisterFeePayContract{
SenderAddress: admin.String(),
FeePayContract: &types.FeePayContract{
ContractAddress: adminContract,
WalletLimit: 0,
},
})
s.Require().NoError(err)
s.registerFeePayContract(sender.String(), creatorContract, 1)
s.registerFeePayContract(admin.String(), adminContract, 0)

for _, tc := range []struct {
desc string
Expand Down Expand Up @@ -173,20 +158,12 @@ func (s *IntegrationTestSuite) TestUnregisterFeePayContract() {
func (s *IntegrationTestSuite) TestFundFeePayContract() {
_, _, sender := testdata.KeyTestPubAddr()
_, _, admin := testdata.KeyTestPubAddr()
_ = s.FundAccount(s.ctx, sender, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1_000_000))))
_ = s.FundAccount(s.ctx, sender, sdk.NewCoins(sdk.NewCoin("ujuno", sdk.NewInt(100_000_000))))
_ = s.FundAccount(s.ctx, sender, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1_000_000)), sdk.NewCoin("ujuno", sdk.NewInt(100_000_000))))
_ = s.FundAccount(s.ctx, admin, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1_000_000))))

contract := s.InstantiateContract(sender.String(), "")

err := s.app.AppKeepers.FeePayKeeper.RegisterContract(s.ctx, &types.MsgRegisterFeePayContract{
SenderAddress: sender.String(),
FeePayContract: &types.FeePayContract{
ContractAddress: contract,
WalletLimit: 1,
},
})
s.Require().NoError(err)
s.registerFeePayContract(sender.String(), contract, 1)

for _, tc := range []struct {
desc string
Expand Down Expand Up @@ -259,23 +236,8 @@ func (s *IntegrationTestSuite) TestUpdateFeePayContractWalletLimit() {
creatorContract := s.InstantiateContract(sender.String(), "")
adminContract := s.InstantiateContract(sender.String(), admin.String())

_, err := s.app.AppKeepers.FeePayKeeper.RegisterFeePayContract(s.ctx, &types.MsgRegisterFeePayContract{
SenderAddress: sender.String(),
FeePayContract: &types.FeePayContract{
ContractAddress: creatorContract,
WalletLimit: 1,
},
})
s.Require().NoError(err)

_, err = s.app.AppKeepers.FeePayKeeper.RegisterFeePayContract(s.ctx, &types.MsgRegisterFeePayContract{
SenderAddress: admin.String(),
FeePayContract: &types.FeePayContract{
ContractAddress: adminContract,
WalletLimit: 0,
},
})
s.Require().NoError(err)
s.registerFeePayContract(sender.String(), creatorContract, 1)
s.registerFeePayContract(admin.String(), adminContract, 0)

for _, tc := range []struct {
desc string
Expand Down
44 changes: 8 additions & 36 deletions x/feepay/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,7 @@ func (s *IntegrationTestSuite) TestQueryContract() {
// Instantiate the contractAddr
contractAddr := s.InstantiateContract(sender.String(), "")

// Register the fee pay contract
_, err := s.app.AppKeepers.FeePayKeeper.RegisterFeePayContract(s.ctx, &types.MsgRegisterFeePayContract{
SenderAddress: sender.String(),
FeePayContract: &types.FeePayContract{
ContractAddress: contractAddr,
WalletLimit: 1,
},
})
s.Require().NoError(err)
s.registerFeePayContract(sender.String(), contractAddr, 1)

s.Run("QueryContract", func() {
// Query for the contract
Expand Down Expand Up @@ -60,14 +52,7 @@ func (s *IntegrationTestSuite) TestQueryContracts() {
contractAddr := s.InstantiateContract(sender.String(), "")

// Register the fee pay contract
_, err := s.app.AppKeepers.FeePayKeeper.RegisterFeePayContract(s.ctx, &types.MsgRegisterFeePayContract{
SenderAddress: sender.String(),
FeePayContract: &types.FeePayContract{
ContractAddress: contractAddr,
WalletLimit: 1,
},
})
s.Require().NoError(err)
s.registerFeePayContract(sender.String(), contractAddr, 1)

// Query for the contract
res, err := s.queryClient.FeePayContract(s.ctx, &types.QueryFeePayContract{
Expand Down Expand Up @@ -135,21 +120,13 @@ func (s *IntegrationTestSuite) TestQueryContracts() {
func (s *IntegrationTestSuite) TestQueryEligibility() {
// Get & fund creator
_, _, sender := testdata.KeyTestPubAddr()
_ = s.FundAccount(s.ctx, sender, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1_000_000))))
_ = s.FundAccount(s.ctx, sender, sdk.NewCoins(sdk.NewCoin("ujuno", sdk.NewInt(100_000_000))))
_ = s.FundAccount(s.ctx, sender, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1_000_000)), sdk.NewCoin("ujuno", sdk.NewInt(100_000_000))))

// Instantiate the contractAddr
contractAddr := s.InstantiateContract(sender.String(), "")

// Register the fee pay contract
_, err := s.app.AppKeepers.FeePayKeeper.RegisterFeePayContract(s.ctx, &types.MsgRegisterFeePayContract{
SenderAddress: sender.String(),
FeePayContract: &types.FeePayContract{
ContractAddress: contractAddr,
WalletLimit: 1,
},
})
s.Require().NoError(err)
s.registerFeePayContract(sender.String(), contractAddr, 1)

s.Run("QueryEligibilityNoFunds", func() {
// Query for the contract
Expand All @@ -164,11 +141,12 @@ func (s *IntegrationTestSuite) TestQueryEligibility() {
})

// Add funds
_, err = s.app.AppKeepers.FeePayKeeper.FundFeePayContract(s.ctx, &types.MsgFundFeePayContract{
_, err := s.app.AppKeepers.FeePayKeeper.FundFeePayContract(s.ctx, &types.MsgFundFeePayContract{
SenderAddress: sender.String(),
ContractAddress: contractAddr,
Amount: sdk.NewCoins(sdk.NewCoin("ujuno", sdk.NewInt(1_000_000))),
})
s.Require().NoError(err)

s.Run("QueryEligibilityWithFunds", func() {
// Query for the contract
Expand All @@ -188,6 +166,7 @@ func (s *IntegrationTestSuite) TestQueryEligibility() {
ContractAddress: contractAddr,
WalletLimit: 0,
})
s.Require().NoError(err)

s.Run("QueryEligibilityWithLimit", func() {
// Query for the contract
Expand All @@ -211,14 +190,7 @@ func (s *IntegrationTestSuite) TestQueryUses() {
contractAddr := s.InstantiateContract(sender.String(), "")

// Register the fee pay contract
_, err := s.app.AppKeepers.FeePayKeeper.RegisterFeePayContract(s.ctx, &types.MsgRegisterFeePayContract{
SenderAddress: sender.String(),
FeePayContract: &types.FeePayContract{
ContractAddress: contractAddr,
WalletLimit: 1,
},
})
s.Require().NoError(err)
s.registerFeePayContract(sender.String(), contractAddr, 1)

s.Run("QueryUses", func() {
// Query for the contract
Expand Down

0 comments on commit 808d6be

Please sign in to comment.