diff --git a/x/distribution/keeper/allocation.go b/x/distribution/keeper/allocation.go index 1acd3e730..2e8681c5a 100644 --- a/x/distribution/keeper/allocation.go +++ b/x/distribution/keeper/allocation.go @@ -19,7 +19,10 @@ func (k Keeper) AllocateFees(ctx sdk.Context) { // get the proposer of this block proposerConsAddr := k.GetProposerConsAddr(ctx) + fmt.Printf("debug proposerConsAddr: %v\n", proposerConsAddr.String()) proposerValidator := k.stakeKeeper.ValidatorByConsAddr(ctx, proposerConsAddr) + fmt.Printf("debug in allocate proposerValidator: %v\n", proposerValidator.GetOperator()) + proposerDist := k.GetValidatorDistInfo(ctx, proposerValidator.GetOperator()) // get the fees which have been getting collected through all the diff --git a/x/distribution/keeper/allocation_test.go b/x/distribution/keeper/allocation_test.go index 7e4f8a32f..00c06ae88 100644 --- a/x/distribution/keeper/allocation_test.go +++ b/x/distribution/keeper/allocation_test.go @@ -1,6 +1,7 @@ package keeper import ( + "fmt" "testing" sdk "github.com/cosmos/cosmos-sdk/types" @@ -39,7 +40,7 @@ func TestAllocateFeesBasic(t *testing.T) { feeInputs := sdk.NewInt(100) fck.SetCollectedFees(sdk.Coins{sdk.NewCoin(denom, feeInputs)}) require.Equal(t, feeInputs, fck.GetCollectedFees(ctx).AmountOf(denom)) - ctx = ctx.WithProposer(valConsAddr1) + fmt.Printf("debug valConsAddr1: %v\n", valConsAddr1.String()) keeper.SetProposerConsAddr(ctx, valConsAddr1) keeper.SetSumPrecommitPower(ctx, sdk.NewDec(10)) keeper.AllocateFees(ctx) diff --git a/x/distribution/keeper/hooks.go b/x/distribution/keeper/hooks.go index 721a26db1..a1f73d39c 100644 --- a/x/distribution/keeper/hooks.go +++ b/x/distribution/keeper/hooks.go @@ -10,6 +10,8 @@ import ( // Create a new validator distribution record func (k Keeper) onValidatorCreated(ctx sdk.Context, addr sdk.ValAddress) { + fmt.Printf("debug asdgojasklnaslkjv addr: %v\n", addr) + height := ctx.BlockHeight() vdi := types.ValidatorDistInfo{ OperatorAddr: addr, diff --git a/x/distribution/keeper/keeper_test.go b/x/distribution/keeper/keeper_test.go new file mode 100644 index 000000000..ce9ceb807 --- /dev/null +++ b/x/distribution/keeper/keeper_test.go @@ -0,0 +1,46 @@ +package keeper + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/stretchr/testify/require" +) + +func TestSetGetProposerConsAddr(t *testing.T) { + ctx, _, keeper, _, _ := CreateTestInputDefault(t, false, 0) + + keeper.SetProposerConsAddr(ctx, valConsAddr1) + res := keeper.GetProposerConsAddr(ctx) + require.True(t, res.Equals(valConsAddr1), "expected: %v got: %v", valConsAddr1.String(), res.String()) +} + +func TestSetGetSumPrecommitPower(t *testing.T) { + ctx, _, keeper, _, _ := CreateTestInputDefault(t, false, 0) + + someDec := sdk.NewDec(333) + keeper.SetSumPrecommitPower(ctx, someDec) + res := keeper.GetSumPrecommitPower(ctx) + require.True(sdk.DecEq(t, someDec, res)) +} + +func TestSetGetCommunityTax(t *testing.T) { + ctx, _, keeper, _, _ := CreateTestInputDefault(t, false, 0) + + someDec := sdk.NewDec(333) + keeper.SetCommunityTax(ctx, someDec) + res := keeper.GetCommunityTax(ctx) + require.True(sdk.DecEq(t, someDec, res)) +} + +func TestSetGetFeePool(t *testing.T) { + ctx, _, keeper, _, _ := CreateTestInputDefault(t, false, 0) + + fp := types.InitialFeePool() + fp.ValAccum.UpdateHeight = 777 + + keeper.SetFeePool(ctx, fp) + res := keeper.GetFeePool(ctx) + require.Equal(t, fp.ValAccum, res.ValAccum) +}