Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: more tests and cleanup #69

Merged
merged 12 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ concurrency:
cancel-in-progress: true

env:
GO_VERSION: 1.22.3
GO_VERSION: 1.22.4

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ concurrency:
cancel-in-progress: true

env:
GO_VERSION: 1.22.3
GO_VERSION: 1.22.4

jobs:
analyze:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ permissions:
packages: write

env:
GO_VERSION: 1.22.3
GO_VERSION: 1.22.4
TAR_PATH: /tmp/manifest-docker-image.tar
IMAGE_NAME: manifest-docker-image

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-bin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

- uses: actions/setup-go@v2
with:
go-version: '1.22.3'
go-version: '1.22.4'

- name: Clean up dist directory
run: rm -rf dist
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
types: [opened, reopened, synchronize]

env:
GO_VERSION: 1.22.3
GO_VERSION: 1.22.4

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true make $BUILD_CMD \
&& (file /code/build/manifestd | grep "statically linked")

# --------------------------------------------------------
FROM alpine:3.16
FROM alpine:3.20
fmorency marked this conversation as resolved.
Show resolved Hide resolved

COPY --from=go-builder /code/build/manifestd /usr/bin/manifestd

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ local-image:
ifeq (,$(shell which heighliner))
echo 'heighliner' binary not found. Consider running `make get-heighliner`
else
heighliner build -c manifest --local -f ./chains.yaml
heighliner build -c manifest --local -f ./chains.yaml --alpine-version 3.20
endif

.PHONY: get-heighliner local-image
Expand Down
4 changes: 2 additions & 2 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
)

// Upgrades list of chain upgrades
var Upgrades = []upgrades.Upgrade{}
var Upgrades []upgrades.Upgrade

// RegisterUpgradeHandlers registers the chain upgrade handlers
func (app ManifestApp) RegisterUpgradeHandlers() {
func (app *ManifestApp) RegisterUpgradeHandlers() {
if len(Upgrades) == 0 {
// always have a unique upgrade registered for the current version to test in system tests
Upgrades = append(Upgrades, noop.NewUpgrade(app.Version()))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/liftedinit/manifest-ledger

go 1.22.3
go 1.22.4

replace (
// core v0.12 was tagged wrong (SDK v51)
Expand Down
2 changes: 1 addition & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.22.3
go 1.22.4

use (
.
Expand Down
2 changes: 1 addition & 1 deletion interchaintest/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/liftedinit/manifest-ledger/interchaintest

go 1.22.3
go 1.22.4

replace (
cosmossdk.io/core => cosmossdk.io/core v0.11.0 // proper SDK v50 version
Expand Down
7 changes: 4 additions & 3 deletions x/manifest/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ func NewKeeper(
return k
}

func (k Keeper) Logger() log.Logger {
func (k *Keeper) Logger() log.Logger {
return k.logger
}

// SetAuthority is only used for testing
func (k *Keeper) SetAuthority(authority string) {
k.authority = authority
}
Expand All @@ -88,7 +89,7 @@ func (k *Keeper) ExportGenesis(ctx context.Context) *types.GenesisState {
}

// Payout mints and sends coins to stakeholders.
func (k Keeper) Payout(ctx context.Context, payouts []types.PayoutPair) error {
func (k *Keeper) Payout(ctx context.Context, payouts []types.PayoutPair) error {
for _, p := range payouts {
p := p
addr := p.Address
Expand All @@ -113,7 +114,7 @@ func (k Keeper) Payout(ctx context.Context, payouts []types.PayoutPair) error {
return nil
}

func (k Keeper) mintCoinsToAccount(ctx context.Context, sdkAddr sdk.AccAddress, coin sdk.Coin) error {
func (k *Keeper) mintCoinsToAccount(ctx context.Context, sdkAddr sdk.AccAddress, coin sdk.Coin) error {
coins := sdk.NewCoins(coin)
if err := k.bankKeeper.MintCoins(ctx, types.ModuleName, coins); err != nil {
return err
Expand Down
88 changes: 88 additions & 0 deletions x/manifest/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ package keeper_test
import (
"testing"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

sdkmath "cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"

"github.com/liftedinit/manifest-ledger/app"
"github.com/liftedinit/manifest-ledger/app/apptesting"
appparams "github.com/liftedinit/manifest-ledger/app/params"
"github.com/liftedinit/manifest-ledger/x/manifest/types"
)

// Sets up the keeper test suite.
Expand Down Expand Up @@ -44,3 +49,86 @@ func initFixture(t *testing.T) *testFixture {

return &s
}

func TestPayout(t *testing.T) {
_, _, authority := testdata.KeyTestPubAddr()
_, _, acc := testdata.KeyTestPubAddr()
f := initFixture(t)

k := f.App.ManifestKeeper
k.SetAuthority(authority.String())

type testcase struct {
name string
payouts []types.PayoutPair
errMsg string
}

cases := []testcase{
{
name: "fail: invalid destination address",
payouts: []types.PayoutPair{
types.NewPayoutPair(acc, "umfx", 1),
{Address: "badaddr", Coin: sdk.NewCoin("umfx", sdkmath.NewInt(2))},
},
errMsg: "decoding bech32 failed",
},
{
name: "fail: invalid coin denom",
payouts: []types.PayoutPair{
types.NewPayoutPair(acc, "umfx", 1),
{Address: acc.String(), Coin: sdk.Coin{Denom: ":::", Amount: sdkmath.NewInt(2)}},
},
errMsg: "invalid payout",
},
{
name: "fail: invalid coin amount",
payouts: []types.PayoutPair{
types.NewPayoutPair(acc, "umfx", 1),
{Address: acc.String(), Coin: sdk.Coin{Denom: "umfx", Amount: sdkmath.NewInt(-2)}},
},
errMsg: "invalid payout",
},
}

for _, c := range cases {
c := c

t.Run(c.name, func(t *testing.T) {
err := k.Payout(f.Ctx, c.payouts)

if c.errMsg != "" {
require.Error(t, err)
require.ErrorContains(t, err, c.errMsg)
return
}

require.NoError(t, err)

for _, p := range c.payouts {
p := p
addr := p.Address
coin := p.Coin

accAddr, err := sdk.AccAddressFromBech32(addr)
require.NoError(t, err)

balance := f.App.BankKeeper.GetBalance(f.Ctx, accAddr, coin.Denom)
require.EqualValues(t, coin.Amount, balance.Amount, "expected %s, got %s", coin.Amount, balance.Amount)
}
})
}
}

func TestExportGenesis(t *testing.T) {
f := initFixture(t)

k := f.App.ManifestKeeper

_, err := k.Params.Get(f.Ctx)
require.NoError(t, err)

genState := k.ExportGenesis(f.Ctx)

require.NotNil(t, genState.Params)
}
Loading
Loading