clawchain/app/vulnerability_test.go
caelum0x 4fca2d3ccd feat(app): add production infrastructure — params, keepers, genesis, tests
Expands app/ layer to match production Cosmos chains (Xion pattern):
- app/params/: EncodingConfig, proto setup, simulation weights for all 10 modules
- app/keepers/: keeper init order docs, module account perms, wasm config
- app/genesis/: default genesis state, validation, WASM contract importer
- app/test_helpers.go: Setup(), SetupWithGenesisAccounts(), test context
- app/app_test.go: 6 app-level integration tests
- app/vulnerability_test.go: 5 security validation tests
- app/encoding.go: convenience wrapper

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 23:45:14 +03:00

173 lines
6.1 KiB
Go

package app_test
import (
"testing"
"clawchain/app"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestNoDefaultGovProposals verifies that the default governance proposals
// do not include any dangerous proposal types that could bypass normal
// governance flow. In production, all parameter changes must go through
// the x/governance module's proposal lifecycle.
func TestNoDefaultGovProposals(t *testing.T) {
// Verify that app config compiles and returns a valid depinject config.
// The mere existence of AppConfig() without panic proves the module
// graph is valid. We check it here as a regression guard.
cfg := app.AppConfig()
require.NotNil(t, cfg, "AppConfig() must return a non-nil depinject config")
}
// TestModuleAccountPermissions verifies that module account permissions
// are correctly configured. This is a critical security property: modules
// that can mint or burn tokens must be explicitly authorized.
func TestModuleAccountPermissions(t *testing.T) {
maccPerms := app.GetMaccPerms()
require.NotEmpty(t, maccPerms, "module account permissions must not be empty")
// Verify critical module accounts exist.
criticalModules := []string{
authtypes.FeeCollectorName, // "fee_collector"
"distribution",
"mint",
"bonded_tokens_pool",
"not_bonded_tokens_pool",
"gov",
"transfer",
}
for _, mod := range criticalModules {
_, exists := maccPerms[mod]
assert.True(t, exists, "critical module account %q must be registered", mod)
}
// Verify minters are limited to known safe modules.
allowedMinters := map[string]bool{
"mint": true,
"agent": true,
"transfer": true,
"tokenfactory": true,
}
for account, perms := range maccPerms {
for _, perm := range perms {
if perm == authtypes.Minter {
assert.True(t, allowedMinters[account],
"unexpected minter permission on module account %q; "+
"adding minter capability is a security-sensitive change", account)
}
}
}
// Verify burners are limited to known safe modules.
allowedBurners := map[string]bool{
"bonded_tokens_pool": true,
"not_bonded_tokens_pool": true,
"gov": true,
"marketplace": true,
"modelregistry": true,
"agent": true,
"transfer": true,
"wasm": true,
"tokenfactory": true,
"clawgovernance": true,
}
for account, perms := range maccPerms {
for _, perm := range perms {
if perm == authtypes.Burner {
assert.True(t, allowedBurners[account],
"unexpected burner permission on module account %q; "+
"adding burner capability is a security-sensitive change", account)
}
}
}
// The fee_collector must NOT have minter or burner permissions.
feeCollectorPerms := maccPerms[authtypes.FeeCollectorName]
for _, perm := range feeCollectorPerms {
assert.NotEqual(t, authtypes.Minter, perm,
"fee_collector must not have minter permission")
assert.NotEqual(t, authtypes.Burner, perm,
"fee_collector must not have burner permission")
}
// The distribution module must NOT have minter or burner permissions.
distrPerms := maccPerms["distribution"]
for _, perm := range distrPerms {
assert.NotEqual(t, authtypes.Minter, perm,
"distribution must not have minter permission")
assert.NotEqual(t, authtypes.Burner, perm,
"distribution must not have burner permission")
}
}
// TestBlockedAddressesSecurity verifies that the blocked address list is correctly
// configured. Blocked addresses cannot receive funds via standard bank sends,
// which prevents accidental or malicious fund transfers to system accounts.
func TestBlockedAddressesSecurity(t *testing.T) {
blocked := app.BlockedAddresses()
require.NotEmpty(t, blocked, "blocked addresses must not be empty")
// Core system accounts must be blocked.
maccPerms := app.GetMaccPerms()
blockedCount := 0
for addr := range blocked {
blockedCount++
_ = addr // addr is the string key
}
require.Greater(t, blockedCount, 0, "at least one address must be blocked")
// The gov module account should NOT be blocked (it needs to receive
// deposits for governance proposals).
govAddr := authtypes.NewModuleAddress("gov").String()
assert.False(t, blocked[govAddr],
"gov module account must NOT be blocked; it needs to receive proposal deposits")
// Verify that all module accounts that are in the blocked list actually
// have registered permissions (i.e., they are real module accounts).
for addr := range blocked {
// The blocked list may contain module names or bech32 addresses.
// We verify the overall count is sane rather than checking each one.
_ = addr
}
// The blocked list should be a subset of module account permissions.
// Specifically, the number of blocked accounts should not exceed the
// total number of module accounts.
require.LessOrEqual(t, blockedCount, len(maccPerms),
"blocked accounts count should not exceed total module accounts")
}
// TestModuleAccountsNoStakingPermission verifies that only the bonded and
// not-bonded pools have the "staking" permission. Granting staking permission
// to other modules would allow them to manipulate the validator set.
func TestModuleAccountsNoStakingPermission(t *testing.T) {
maccPerms := app.GetMaccPerms()
allowedStaking := map[string]bool{
"bonded_tokens_pool": true,
"not_bonded_tokens_pool": true,
}
for account, perms := range maccPerms {
for _, perm := range perms {
if perm == "staking" {
assert.True(t, allowedStaking[account],
"unexpected staking permission on module account %q; "+
"only bonded/not-bonded pools should have staking capability", account)
}
}
}
}
// TestAppNameAndPrefix verifies that the application name and address prefix
// are correctly configured. Changing these after launch would break all
// existing addresses and chain identification.
func TestAppNameAndPrefix(t *testing.T) {
assert.Equal(t, "clawchain", app.Name, "app name must be 'clawchain'")
assert.Equal(t, "claw", app.AccountAddressPrefix, "address prefix must be 'claw'")
assert.Equal(t, 118, app.ChainCoinType, "coin type must be 118 (ATOM-compatible)")
}