-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
refactor(simapp): Audit simapp #21311
Changes from 16 commits
4aac90e
30d72a3
45d4e67
c907e8a
06ea466
f250a18
42d7553
fe63167
819afd2
98f70e9
08ebc82
ab373f2
23c480e
acb8140
adcda83
18f424e
f201230
24d83ba
3bd4f72
e3a98f3
55701f6
404241b
f76c488
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -64,3 +64,12 @@ func getConfigTomlFromViper(v *viper.Viper) *cmtcfg.Config { | |||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
return conf.SetRoot(rootDir) | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
func getAppTomlFromViper(v *viper.Viper) *AppTomlConfig { | ||||||||||||||||||||||||||||||||||||
appTomlConfig := DefaultAppTomlConfig() | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the default should be |
||||||||||||||||||||||||||||||||||||
if err := serverv2.UnmarshalSubConfig(v, ServerName, &appTomlConfig); err != nil { | ||||||||||||||||||||||||||||||||||||
return DefaultAppTomlConfig() | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
return appTomlConfig | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review the error handling strategy in The function correctly handles configuration retrieval with a fallback to the default configuration. However, it would be beneficial to log the error when unmarshalling fails to aid in debugging and ensure that configuration issues are noticeable. Consider adding error logging before returning the default configuration: if err := serverv2.UnmarshalSubConfig(v, ServerName, &appTomlConfig); err != nil {
+ log.Errorf("Failed to unmarshal AppTomlConfig: %v", err)
return DefaultAppTomlConfig()
} Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package simapp_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/cometbft/cometbft/crypto" | ||
"github.com/stretchr/testify/require" | ||
|
||
"cosmossdk.io/simapp/v2" | ||
authtypes "cosmossdk.io/x/auth/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func TestSimGenesisAccountValidate(t *testing.T) { | ||
pubkey := secp256k1.GenPrivKey().PubKey() | ||
addr := sdk.AccAddress(pubkey.Address()) | ||
|
||
vestingStart := time.Now().UTC() | ||
|
||
coins := sdk.NewCoins(sdk.NewInt64Coin("test", 1000)) | ||
baseAcc := authtypes.NewBaseAccount(addr, pubkey, 0, 0) | ||
|
||
testCases := []struct { | ||
name string | ||
sga simapp.SimGenesisAccount | ||
wantErr bool | ||
}{ | ||
{ | ||
"valid basic account", | ||
simapp.SimGenesisAccount{ | ||
BaseAccount: baseAcc, | ||
}, | ||
false, | ||
}, | ||
{ | ||
"invalid basic account with mismatching address/pubkey", | ||
simapp.SimGenesisAccount{ | ||
BaseAccount: authtypes.NewBaseAccount(addr, secp256k1.GenPrivKey().PubKey(), 0, 0), | ||
}, | ||
true, | ||
}, | ||
{ | ||
"valid basic account with module name", | ||
simapp.SimGenesisAccount{ | ||
BaseAccount: authtypes.NewBaseAccount(sdk.AccAddress(crypto.AddressHash([]byte("testmod"))), nil, 0, 0), | ||
ModuleName: "testmod", | ||
}, | ||
false, | ||
}, | ||
{ | ||
"valid basic account with invalid module name/pubkey pair", | ||
simapp.SimGenesisAccount{ | ||
BaseAccount: baseAcc, | ||
ModuleName: "testmod", | ||
}, | ||
true, | ||
}, | ||
{ | ||
"valid basic account with valid vesting attributes", | ||
simapp.SimGenesisAccount{ | ||
BaseAccount: baseAcc, | ||
OriginalVesting: coins, | ||
StartTime: vestingStart.Unix(), | ||
EndTime: vestingStart.Add(1 * time.Hour).Unix(), | ||
}, | ||
false, | ||
}, | ||
{ | ||
"valid basic account with invalid vesting end time", | ||
simapp.SimGenesisAccount{ | ||
BaseAccount: baseAcc, | ||
OriginalVesting: coins, | ||
StartTime: vestingStart.Add(2 * time.Hour).Unix(), | ||
EndTime: vestingStart.Add(1 * time.Hour).Unix(), | ||
}, | ||
true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
t.Run(tc.name, func(t *testing.T) { | ||
require.Equal(t, tc.wantErr, tc.sga.Validate() != nil) | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update a little bit CI and server/v2/cometbft since we using cometbft queries