Skip to content

Commit

Permalink
TestMsgServerPayoutStakeholdersLogic
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Feb 21, 2024
1 parent 2631c91 commit 3e9a44e
Showing 1 changed file with 70 additions and 10 deletions.
80 changes: 70 additions & 10 deletions x/manifest/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

func TestCalculatePayoutLogic(t *testing.T) {
func TestMsgServerPayoutStakeholdersLogic(t *testing.T) {
_, _, authority := testdata.KeyTestPubAddr()
_, _, acc := testdata.KeyTestPubAddr()
_, _, acc2 := testdata.KeyTestPubAddr()
Expand Down Expand Up @@ -44,23 +44,32 @@ func TestCalculatePayoutLogic(t *testing.T) {
Percentage: 499_999,
},
}

_, err := ms.UpdateParams(f.Ctx, &types.MsgUpdateParams{
Authority: authority.String(),
Params: types.NewParams(sh),
})
require.NoError(t, err)

// validate the full payout of 100 tokens got split up between all fractional shares as expected
res := k.CalculateShareHolderTokenPayout(f.Ctx, sdk.NewCoin("stake", sdkmath.NewInt(100_000_000)))
// wrong acc
_, err = ms.PayoutStakeholders(f.Ctx, &types.MsgPayoutStakeholders{
Authority: acc.String(),
Payout: sdk.NewCoin("stake", sdkmath.NewInt(100_000_000)),
})
require.Error(t, err)

// success
_, err = ms.PayoutStakeholders(f.Ctx, &types.MsgPayoutStakeholders{
Authority: authority.String(),
Payout: sdk.NewCoin("stake", sdkmath.NewInt(100_000_000)),
})
require.NoError(t, err)

for _, s := range sh {
for w, coin := range res {
if s.Address == w {
require.EqualValues(t, s.Percentage, coin.Amount.Int64())
}
}
}
addr := sdk.MustAccAddressFromBech32(s.Address)

accBal := f.App.BankKeeper.GetBalance(f.Ctx, addr, "stake")
require.EqualValues(t, s.Percentage, accBal.Amount.Int64())
}
}

func TestUpdateParams(t *testing.T) {
Expand Down Expand Up @@ -162,3 +171,54 @@ func TestUpdateParams(t *testing.T) {
})
}
}

// TODO: Very similar to TestMsgServerPayoutStakeholdersLogic.
func TestCalculatePayoutLogic(t *testing.T) {
_, _, authority := testdata.KeyTestPubAddr()
_, _, acc := testdata.KeyTestPubAddr()
_, _, acc2 := testdata.KeyTestPubAddr()
_, _, acc3 := testdata.KeyTestPubAddr()
_, _, acc4 := testdata.KeyTestPubAddr()

f := initFixture(t)

k := f.App.ManifestKeeper

k.SetAuthority(f.Ctx, authority.String())
ms := keeper.NewMsgServerImpl(k)

sh := []*types.StakeHolders{
{
Address: acc.String(),
Percentage: 50_000_000, // 50%
},
{
Address: acc2.String(),
Percentage: 49_000_000,
},
{
Address: acc3.String(),
Percentage: 500_001, // 0.5%
},
{
Address: acc4.String(),
Percentage: 499_999,
},
}

_, err := ms.UpdateParams(f.Ctx, &types.MsgUpdateParams{
Authority: authority.String(),
Params: types.NewParams(sh),
})
require.NoError(t, err)

// validate the full payout of 100 tokens got split up between all fractional shares as expected
res := k.CalculateShareHolderTokenPayout(f.Ctx, sdk.NewCoin("stake", sdkmath.NewInt(100_000_000)))
for _, s := range sh {
for w, coin := range res {
if s.Address == w {
require.EqualValues(t, s.Percentage, coin.Amount.Int64())
}
}
}
}

0 comments on commit 3e9a44e

Please sign in to comment.