planetmint-go/x/dao/keeper/challenge_test.go
Lorenz Herzberger 94830df5fc
184 implement staged claim (#190)
* adjust issuePoPRewards to mint stagedCRDDL
* add GetChallengeRange
* add resolveStagedClaims on ReissueRDDLResult msg
* move claim resolve to distribution result
* add StagedDenom and ClaimDenom to config
* added the prepare4linting.sh script
* renamed PoPEpochs to PopEpochs
* renamed DistributionAddressPoP to DistributionAddressPop
* added config value ReIssuanceEpochs
* detached the re-issuance from the distribution process and schedule them independently
* changed logging messages
* added an explicit util/kv_serialize.go file to have all KV serialization done
* switched to Bigendian serialization of int64 to have the ordered list on the kvstore
* added ComputeReIssuanceValue to enable re-issuances once a day or defined by ReIssuanceEpoch
* integrated a ReIssuanceValue computation test case
* adjusted the challenges test cases to be epoch-dependent
* added ReIssuances per ReIssuanceEpoch
* extended the Reissue message
* checking ReIssuanceProposal in the ante handler
* added precision setter for the UINT to RDDL token converter (and test cases)
* add e2e test case for pop rewards


Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
Co-authored-by: Jürgen Eckel <juergen@riddleandcode.com>
2023-12-05 10:51:06 +01:00

52 lines
1.6 KiB
Go

package keeper_test
import (
"fmt"
"testing"
"github.com/planetmint/planetmint-go/config"
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
"github.com/stretchr/testify/assert"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/x/dao/keeper"
"github.com/planetmint/planetmint-go/x/dao/types"
)
// this method returns a range of challenges, each with a blockheight * PopEpochs.
// be aware: the first element start with 1 instead of 0
func createNChallenge(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Challenge {
items := make([]types.Challenge, n)
for i := range items {
blockHeight := (i + 1) * config.GetConfig().PopEpochs
items[i].Height = int64(blockHeight)
items[i].Initiator = fmt.Sprintf("initiator%v", blockHeight)
items[i].Challenger = fmt.Sprintf("challenger%v", blockHeight)
items[i].Challengee = fmt.Sprintf("challengee%v", blockHeight)
items[i].Success = false
items[i].Finished = false
keeper.StoreChallenge(ctx, items[i])
}
return items
}
func TestGetChallenge(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.DaoKeeper(t)
items := createNChallenge(keeper, ctx, 10)
for _, item := range items {
challenge, found := keeper.LookupChallenge(ctx, item.Height)
assert.True(t, found)
assert.Equal(t, item, challenge)
}
}
func TestGetChallengeRange(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.DaoKeeper(t)
createNChallenge(keeper, ctx, 10)
challenges, err := keeper.GetChallengeRange(ctx, int64((0+1)*config.GetConfig().PopEpochs), int64((9+1)*config.GetConfig().PopEpochs))
assert.NoError(t, err)
assert.Equal(t, 10, len(challenges))
}