Skip to content

Commit

Permalink
fix(e2e): remove inflation logic, add new payout
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed May 30, 2024
1 parent cda6b08 commit 1a98c5f
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 263 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</p>

<p align="center">
<a href="https://codecov.io/gh/liftedinit/manifest-ledger" >
<img src="https://codecov.io/gh/liftedinit/manifest-ledger/graph/badge.svg?token=s7zzdGQ7Gh"/>
<a href="https://codecov.io/gh/liftedinit/manifest-ledger" >
<img src="https://codecov.io/gh/liftedinit/manifest-ledger/graph/badge.svg?token=s7zzdGQ7Gh"/>
</a>
<a href="https://goreportcard.com/report/github.com/liftedinit/manifest-ledger">
<img src="https://goreportcard.com/badge/github.com/liftedinit/manifest-ledger" alt="Go Report Card"/>
Expand Down
26 changes: 18 additions & 8 deletions interchaintest/helpers/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package helpers
import (
"context"
"fmt"
"strings"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -12,15 +13,24 @@ import (
manifesttypes "github.com/liftedinit/manifest-ledger/x/manifest/types"
)

func ManifestUpdateParams(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, poaAdmin ibc.Wallet, addressPairs string, automaticInflation string, coinInflationPerYear string, flags ...string) (sdk.TxResponse, error) {
txCmd := []string{"tx", "manifest", "update-params", addressPairs, automaticInflation, coinInflationPerYear}
fmt.Println("ManifestUpdateParams", txCmd)
cmd := TxCommandBuilder(ctx, chain, txCmd, poaAdmin.KeyName(), flags...)
return ExecuteTransaction(ctx, chain, cmd)
}
// func ManifestUpdateParams(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, poaAdmin ibc.Wallet, addressPairs string, automaticInflation string, coinInflationPerYear string, flags ...string) (sdk.TxResponse, error) {
// txCmd := []string{"tx", "manifest", "update-params", addressPairs, automaticInflation, coinInflationPerYear}
// fmt.Println("ManifestUpdateParams", txCmd)
// cmd := TxCommandBuilder(ctx, chain, txCmd, poaAdmin.KeyName(), flags...)
// return ExecuteTransaction(ctx, chain, cmd)
// }

func ManifestStakeholderPayout(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, poaAdmin ibc.Wallet, payouts []manifesttypes.PayoutPair, flags ...string) (sdk.TxResponse, error) {
output := ""
for _, payout := range payouts {
output += fmt.Sprintf("%s:%s%s,", payout.Address, payout.Coin.Amount.String(), payout.Coin.Denom)
}

if strings.HasSuffix(output, ",") {
output = output[:len(output)-1]
}

func ManifestStakeholderPayout(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, poaAdmin ibc.Wallet, coinAmount string, flags ...string) (sdk.TxResponse, error) {
txCmd := []string{"tx", "manifest", "stakeholder-payout", coinAmount}
txCmd := []string{"tx", "manifest", "payout", output}
fmt.Println("ManifestStakeholderPayout", txCmd)
cmd := TxCommandBuilder(ctx, chain, txCmd, poaAdmin.KeyName(), flags...)
return ExecuteTransaction(ctx, chain, cmd)
Expand Down
154 changes: 31 additions & 123 deletions interchaintest/mainfest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/testreporter"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest"

"github.com/liftedinit/manifest-ledger/interchaintest/helpers"
manifesttypes "github.com/liftedinit/manifest-ledger/x/manifest/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -82,154 +82,62 @@ func TestManifestModule(t *testing.T) {
p, err := helpers.ManifestQueryParams(ctx, node)
require.NoError(t, err)
fmt.Println(p)
require.True(t, p.Inflation.AutomaticEnabled)
require.EqualValues(t, p.Inflation.MintDenom, Denom)
inflationAddr := p.StakeHolders[0].Address

t.Run("Ensure the account's balance gets auto paid out with auto inflation on", func(t *testing.T) {
oldBal, err := appChain.GetBalance(ctx, inflationAddr, Denom)
require.NoError(t, err)

require.NoError(t, testutil.WaitForBlocks(ctx, 2, appChain))

newBal, err := appChain.GetBalance(ctx, inflationAddr, Denom)
require.NoError(t, err)

require.Greater(t, newBal.Uint64(), oldBal.Uint64())
})

t.Run("fail; Perform a manual distribution payout from the PoA admin (fails due to auto inflation being on)", func(t *testing.T) {
c := sdk.NewCoin(Denom, sdkmath.NewInt(9999999999))
txRes, _ := helpers.ManifestStakeholderPayout(t, ctx, appChain, poaAdmin, c.String())
require.EqualValues(t, 0, txRes.Code)

// ensure the new balance is not > c.Amount (a manual payout)
latestBal, err := appChain.GetBalance(ctx, inflationAddr, Denom)
require.NoError(t, err)
require.LessOrEqual(t, latestBal.Uint64(), c.Amount.Uint64())
})

t.Run("success; disable auto inflation. Set new stakeholders", func(t *testing.T) {
txRes, _ := helpers.ManifestUpdateParams(
t, ctx, appChain, poaAdmin,
fmt.Sprintf("%s:1_000_000,%s:98_000_000,%s:1_000_000", uaddr, addr2, addr3),
"false",
sdk.NewCoin(Denom, sdkmath.NewIntFromUint64(p.Inflation.YearlyAmount)).String(), // it's off, this just matches genesis
)
require.EqualValues(t, 0, txRes.Code)

t.Run("success; query params", func(t *testing.T) {
p, err = helpers.ManifestQueryParams(ctx, node)
require.NoError(t, err)
require.False(t, p.Inflation.AutomaticEnabled)
require.Len(t, p.StakeHolders, 3)
})

t.Run("success; Perform a manual distribution payout from the PoA admin", func(t *testing.T) {

beforeBal1, _ := appChain.GetBalance(ctx, uaddr, Denom)
beforeBal2, _ := appChain.GetBalance(ctx, addr2, Denom)
beforeBal3, _ := appChain.GetBalance(ctx, addr3, Denom)

c := sdk.NewCoin(Denom, sdkmath.NewInt(100_000000))
txRes, _ := helpers.ManifestStakeholderPayout(t, ctx, appChain, poaAdmin, c.String())
require.EqualValues(t, 0, txRes.Code)
payouts := []manifesttypes.PayoutPair{
manifesttypes.NewPayoutPair(sdk.MustAccAddressFromBech32(uaddr), Denom, 1_000_000),
manifesttypes.NewPayoutPair(sdk.MustAccAddressFromBech32(addr2), Denom, 2_000_000),
manifesttypes.NewPayoutPair(sdk.MustAccAddressFromBech32(addr3), Denom, 3_000_000),
}

// print beforeBal1
fmt.Println(beforeBal1)

_, err := helpers.ManifestStakeholderPayout(t, ctx, appChain, poaAdmin, payouts)
require.NoError(t, err)

// validate new user1 balance is 1_000_000 higher
user1bal, err := appChain.GetBalance(ctx, uaddr, Denom)
require.NoError(t, err)
require.EqualValues(t, user1bal.Uint64(), beforeBal1.Uint64()+1_000_000)
fmt.Println(user1bal)
fmt.Println(user1bal.Uint64())
fmt.Println(user1bal.Int64())
require.EqualValues(t, user1bal.Uint64(), beforeBal1.Uint64()+1_000_000, "user1 balance should be 1_000_000 higher")

user2bal, err := appChain.GetBalance(ctx, addr2, Denom)
require.NoError(t, err)
require.EqualValues(t, user2bal.Uint64(), beforeBal2.Uint64()+98_000_000)
require.EqualValues(t, user2bal.Uint64(), beforeBal2.Uint64()+2_000_000)

user3bal, err := appChain.GetBalance(ctx, addr3, Denom)
require.NoError(t, err)
require.EqualValues(t, user3bal.Uint64(), beforeBal3.Uint64()+1_000_000)

})
require.EqualValues(t, user3bal.Uint64(), beforeBal3.Uint64()+3_000_000)

t.Run("fail: invalid payout coin", func(t *testing.T) {
_, err := helpers.ManifestStakeholderPayout(t, ctx, appChain, poaAdmin, "foobar")
require.Error(t, err)
require.ErrorContains(t, err, "invalid decimal coin expression")
})

t.Run("fail: invalid stakeholder addr", func(t *testing.T) {
_, err := helpers.ManifestUpdateParams(
t, ctx, appChain, poaAdmin,
fmt.Sprintf("%s:1_000_000,%s:99_000_000", uaddr, "foobar"),
"false",
sdk.NewCoin(Denom, sdkmath.NewIntFromUint64(p.Inflation.YearlyAmount)).String(), // it's off, this just matches genesis
)
require.Error(t, err)
require.ErrorContains(t, err, "invalid address")
})

t.Run("fail: invalid stakeholder percentage (>100%)", func(t *testing.T) {
_, err := helpers.ManifestUpdateParams(
t, ctx, appChain, poaAdmin,
fmt.Sprintf("%s:2_000_000,%s:99_000_000", uaddr, addr2),
"false",
sdk.NewCoin(Denom, sdkmath.NewIntFromUint64(p.Inflation.YearlyAmount)).String(), // it's off, this just matches genesis
)
require.Error(t, err)
require.ErrorContains(t, err, "stakeholders should add up to")
})

t.Run("fail: invalid stakeholder percentage (<100%)", func(t *testing.T) {
_, err := helpers.ManifestUpdateParams(
t, ctx, appChain, poaAdmin,
fmt.Sprintf("%s:1_000_000,%s:98_000_000", uaddr, addr2),
"false",
sdk.NewCoin(Denom, sdkmath.NewIntFromUint64(p.Inflation.YearlyAmount)).String(), // it's off, this just matches genesis
)
require.Error(t, err)
require.ErrorContains(t, err, "stakeholders should add up to")
})

t.Run("fail: invalid stakeholder", func(t *testing.T) {
_, err := helpers.ManifestUpdateParams(
t, ctx, appChain, poaAdmin,
"foobar",
"false",
sdk.NewCoin(Denom, sdkmath.NewIntFromUint64(p.Inflation.YearlyAmount)).String(), // it's off, this just matches genesis
)
require.Error(t, err)
require.ErrorContains(t, err, "invalid stakeholder")
})

t.Run("fail: invalid percentage", func(t *testing.T) {
_, err := helpers.ManifestUpdateParams(
t, ctx, appChain, poaAdmin,
fmt.Sprintf("%s:foobar", uaddr),
"false",
sdk.NewCoin(Denom, sdkmath.NewIntFromUint64(p.Inflation.YearlyAmount)).String(), // it's off, this just matches genesis
)
require.Error(t, err)
require.ErrorContains(t, err, "invalid percentage")
})

t.Run("fail: invalid automatic inflation", func(t *testing.T) {
_, err := helpers.ManifestUpdateParams(
t, ctx, appChain, poaAdmin,
fmt.Sprintf("%s:1_000_000,%s:99_000_000", uaddr, addr2),
"foobar",
sdk.NewCoin(Denom, sdkmath.NewIntFromUint64(p.Inflation.YearlyAmount)).String(), // it's off, this just matches genesis
)
t.Run("fail: invalid payout 0 coin", func(t *testing.T) {
_, err := helpers.ManifestStakeholderPayout(t, ctx, appChain, poaAdmin, []manifesttypes.PayoutPair{
manifesttypes.NewPayoutPair(sdk.MustAccAddressFromBech32(uaddr), Denom, 0),
})
require.Error(t, err)
require.ErrorContains(t, err, "invalid syntax")
require.ErrorContains(t, err, "strconv.ParseBool")
})

t.Run("fail: invalid inflation coin", func(t *testing.T) {
_, err := helpers.ManifestUpdateParams(
t, ctx, appChain, poaAdmin,
fmt.Sprintf("%s:1_000_000,%s:99_000_000", uaddr, addr2),
"false",
"foobar",
)
t.Run("fail: invalid payout addr", func(t *testing.T) {
_, err = helpers.ManifestStakeholderPayout(t, ctx, appChain, poaAdmin, []manifesttypes.PayoutPair{
{
Address: "abcdefg",
Coin: sdk.NewCoin(Denom, sdkmath.NewInt(1)),
},
})
require.Error(t, err)
require.ErrorContains(t, err, "invalid decimal coin expression")
})

t.Cleanup(func() {
Expand Down
Loading

0 comments on commit 1a98c5f

Please sign in to comment.