Skip to content

Commit

Permalink
feat: add some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shifty11 committed Oct 30, 2023
1 parent 3c30fc8 commit 4845bd1
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 18 deletions.
1 change: 0 additions & 1 deletion x/funders/keeper/logic_funders.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
errorsTypes "github.com/cosmos/cosmos-sdk/types/errors"
)

// TODO: should this be here or when we call the getter of the funding state?
func (k Keeper) CreateFundingState(ctx sdk.Context, poolId uint64) {
fundingState := types.FundingState{
PoolId: poolId,
Expand Down
28 changes: 28 additions & 0 deletions x/funders/keeper/logic_funders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ TEST CASES - logic_funders.go
* Charge funders until all funders run out of funds
* Charge funder with less funds than amount_per_bundle
* Charge without fundings
* Check if the lowest funding is returned correctly
*/

Expand Down Expand Up @@ -201,4 +202,31 @@ var _ = Describe("logic_funders.go", Ordered, func() {
Expect(fundersBalance).To(Equal(0 * i.KYVE))
Expect(poolBalance).To(Equal(0 * i.KYVE))
})

It("Check if the lowest funding is returned correctly", func() {
fundings := []funderstypes.Funding{
{
FunderAddress: i.DUMMY[0],
PoolId: 0,
Amount: 1000 * i.KYVE,
AmountPerBundle: 1 * i.KYVE,
},
{
FunderAddress: i.DUMMY[1],
PoolId: 0,
Amount: 900 * i.KYVE,
AmountPerBundle: 1 * i.KYVE,
},
{
FunderAddress: i.DUMMY[2],
PoolId: 0,
Amount: 1100 * i.KYVE,
AmountPerBundle: 1 * i.KYVE,
},
}

getLowestFunding, err := s.App().FundersKeeper.GetLowestFunding(fundings)
Expect(err).NotTo(HaveOccurred())
Expect(getLowestFunding.Amount).To(Equal(900 * i.KYVE))
})
})
17 changes: 0 additions & 17 deletions x/funders/keeper/msg_server_create_funder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ TEST CASES - msg_server_create_funder.go
* Create a funder with empty values except moniker
* Create a funder with all values set
* Try to create a funder that already exists
* Create two funders with the same moniker // TODO: should this be allowed?
* Create two funders
*/

Expand Down Expand Up @@ -94,22 +93,6 @@ var _ = Describe("msg_server_create_funder.go", Ordered, func() {
})
})

// TODO: should this be allowed?
PIt("Create two funders with the same moniker", func() {
// ARRANGE
moniker := "moniker"
s.RunTxFundersSuccess(&types.MsgCreateFunder{
Creator: i.ALICE,
Moniker: moniker,
})

// ACT
s.RunTxFundersError(&types.MsgCreateFunder{
Creator: i.BOB,
Moniker: moniker,
})
})

It("Create two funders", func() {
// ARRANGE
s.RunTxFundersSuccess(&types.MsgCreateFunder{
Expand Down
99 changes: 99 additions & 0 deletions x/funders/keeper/msg_server_update_funder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package keeper_test

import (
"github.com/KYVENetwork/chain/x/funders/types"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

i "github.com/KYVENetwork/chain/testutil/integration"
)

/*
TEST CASES - msg_server_update_funder.go
* Try to update a funder that does not exist
* Try to update a funder with empty moniker
* Update a funder with empty values except moniker
* Update a funder with all values set
*/

var _ = Describe("msg_server_create_funder.go", Ordered, func() {
s := i.NewCleanChain()

BeforeEach(func() {
// init new clean chain
s = i.NewCleanChain()

moniker, identity, website, contact, description := "AliceMoniker", "identity", "website", "contact", "description"
s.RunTxFundersSuccess(&types.MsgCreateFunder{
Creator: i.ALICE,
Moniker: moniker,
Identity: identity,
Website: website,
Contact: contact,
Description: description,
})
})

AfterEach(func() {
s.PerformValidityChecks()
})

It("Try to update a funder that does not exist", func() {
// ASSERT
s.RunTxFundersError(&types.MsgUpdateFunder{
Creator: i.BOB,
Moniker: "moniker",
})
})

It("Try to update a funder with empty moniker", func() {
// ASSERT
s.RunTxFundersError(&types.MsgUpdateFunder{
Creator: i.BOB,
Moniker: "",
})
})

It("Update a funder with empty values except moniker", func() {
// ACT
s.RunTxFundersSuccess(&types.MsgUpdateFunder{
Creator: i.ALICE,
Moniker: "moniker",
})

// ASSERT
funder, found := s.App().FundersKeeper.GetFunder(s.Ctx(), i.ALICE)
Expect(found).To(BeTrue())
Expect(funder.Address).To(Equal(i.ALICE))
Expect(funder.Moniker).To(Equal("moniker"))
Expect(funder.Identity).To(BeEmpty())
Expect(funder.Website).To(BeEmpty())
Expect(funder.Contact).To(BeEmpty())
Expect(funder.Description).To(BeEmpty())
})

It("Update a funder with all values set", func() {
// ACT
moniker, identity, website, contact, description := "moniker", "identity", "website", "contact", "description"
s.RunTxFundersSuccess(&types.MsgUpdateFunder{
Creator: i.ALICE,
Moniker: moniker,
Identity: identity,
Website: website,
Contact: contact,
Description: description,
})

// ASSERT
funder, found := s.App().FundersKeeper.GetFunder(s.Ctx(), i.ALICE)
Expect(found).To(BeTrue())
Expect(funder.Address).To(Equal(i.ALICE))
Expect(funder.Moniker).To(Equal(moniker))
Expect(funder.Identity).To(Equal(identity))
Expect(funder.Website).To(Equal(website))
Expect(funder.Contact).To(Equal(contact))
Expect(funder.Description).To(Equal(description))
})
})
3 changes: 3 additions & 0 deletions x/funders/types/message_update_funder.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func (msg *MsgUpdateFunder) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil {
return errors.Wrapf(errorsTypes.ErrInvalidAddress, "invalid creator address: %s", err)
}
if msg.Moniker == "" {
return errors.Wrapf(errorsTypes.ErrInvalidRequest, "moniker cannot be empty")
}

return nil
}

0 comments on commit 4845bd1

Please sign in to comment.