mukan-sdk/x/protocolpool/keeper/validate_test.go
Mukan Erkin Törük abb1ff956e
Some checks are pending
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
refactor: complete sovereign stack cleanup — all github.com upstream refs purged
2026-05-11 03:46:06 +03:00

159 lines
3.5 KiB
Go

package keeper
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"cosmossdk.io/math"
sdk "git.cw.tr/mukan-network/mukan-sdk/types"
"git.cw.tr/mukan-network/mukan-sdk/x/protocolpool/types"
)
// TestValidateAmount tests the validateAmount function.
func TestValidateAmount(t *testing.T) {
tests := []struct {
name string
amount sdk.Coins
expErr bool
errMsg string
}{
{
name: "nil amount",
amount: nil,
expErr: true,
errMsg: "amount cannot be nil",
},
{
name: "negative coin amount",
amount: sdk.Coins{
{
Denom: "stake",
Amount: math.NewInt(-100),
},
},
expErr: true,
errMsg: "-100",
},
{
name: "valid single coin",
amount: sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(100))),
expErr: false,
},
{
name: "multiple valid coins",
amount: sdk.NewCoins(
sdk.NewCoin("stake", math.NewInt(100)),
sdk.NewCoin("token", math.NewInt(200)),
),
expErr: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
err := validateAmount(tc.amount)
if tc.expErr {
require.Error(t, err, "expected an error but got none")
require.Contains(t, err.Error(), tc.errMsg)
} else {
require.NoError(t, err)
}
})
}
}
func TestValidateContinuousFund(t *testing.T) {
now := time.Now()
future := now.Add(1 * time.Hour)
past := now.Add(-1 * time.Hour)
// Create a context with the current block time.
ctx := sdk.Context{}.WithBlockTime(now)
tests := []struct {
name string
msg types.MsgCreateContinuousFund
expErr bool
errMsg string
}{
{
name: "zero percentage",
msg: types.MsgCreateContinuousFund{
Authority: "authority",
Recipient: "recipient",
Percentage: math.LegacyZeroDec(),
Expiry: &future,
},
expErr: true,
errMsg: "percentage cannot be zero or empty",
},
{
name: "negative percentage",
msg: types.MsgCreateContinuousFund{
Authority: "authority",
Recipient: "recipient",
Percentage: math.LegacyNewDecFromInt(math.NewInt(-1)),
Expiry: &future,
},
expErr: true,
errMsg: "percentage cannot be negative",
},
{
name: "percentage greater than one",
msg: types.MsgCreateContinuousFund{
Authority: "authority",
Recipient: "recipient",
Percentage: math.LegacyMustNewDecFromStr("1.1"),
Expiry: &future,
},
expErr: true,
errMsg: "percentage cannot be greater than one",
},
{
name: "valid percentage with nil expiry",
msg: types.MsgCreateContinuousFund{
Authority: "authority",
Recipient: "recipient",
Percentage: math.LegacyNewDecWithPrec(5, 1), // 0.5
Expiry: nil,
},
expErr: false,
},
{
name: "valid percentage with future expiry",
msg: types.MsgCreateContinuousFund{
Authority: "authority",
Recipient: "recipient",
Percentage: math.LegacyNewDecWithPrec(5, 1), // 0.5
Expiry: &future,
},
expErr: false,
},
{
name: "expiry in past",
msg: types.MsgCreateContinuousFund{
Authority: "authority",
Recipient: "recipient",
Percentage: math.LegacyNewDecWithPrec(5, 1), // 0.5
Expiry: &past,
},
expErr: true,
errMsg: "cannot be less than the current block time",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
err := validateContinuousFund(ctx, tc.msg)
if tc.expErr {
require.Error(t, err, "expected an error but got none")
require.Contains(t, err.Error(), tc.errMsg)
} else {
require.NoError(t, err)
}
})
}
}