Skip to content

Commit

Permalink
add validate
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Apr 26, 2024
1 parent 9f61496 commit d14d232
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

### Features

- [#1406](https://github.com/crypto-org-chain/cronos/pull/1406) Add set-encryption-key for encryption module.
* [#1406](https://github.com/crypto-org-chain/cronos/pull/1406) Add set-encryption-key for encryption module.

*April 8, 2024*

Expand Down
6 changes: 6 additions & 0 deletions integration_tests/configs/default.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
ibc_cro_denom: '${IBC_CRO_DENOM}',
},
},
e2ee: {
keys: [{
address: 'crc16z0herz998946wr659lr84c8c556da55dc34hh',
key: std.base64('key'),
}],
},
gov: {
params: {
expedited_voting_period: '1s',
Expand Down
1 change: 0 additions & 1 deletion integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,6 @@ def set_e2ee_key(self, key, **kwargs):
key,
"-y",
home=self.data_dir,
stderr=subprocess.DEVNULL,
**kwargs,
)
)
Expand Down
5 changes: 5 additions & 0 deletions x/e2ee/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ func DefaultGenesis() *GenesisState {
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
for _, key := range gs.Keys {
if err := key.Validate(); err != nil {
return err

Check warning on line 13 in x/e2ee/types/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/e2ee/types/genesis.go#L13

Added line #L13 was not covered by tests
}
}
return nil
}
13 changes: 13 additions & 0 deletions x/e2ee/types/keys.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
"errors"

sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand All @@ -27,3 +29,14 @@ func KeyPrefix(addr sdk.AccAddress) []byte {
copy(key[1:], addr)
return key
}

// Validate checks for address and key correctness.
func (e EncryptionKeyEntry) Validate() error {
if _, err := sdk.AccAddressFromBech32(e.Address); err != nil {
return err

Check warning on line 36 in x/e2ee/types/keys.go

View check run for this annotation

Codecov / codecov/patch

x/e2ee/types/keys.go#L36

Added line #L36 was not covered by tests
}
if e.Key == nil {
return errors.New("key can't be nil")

Check warning on line 39 in x/e2ee/types/keys.go

View check run for this annotation

Codecov / codecov/patch

x/e2ee/types/keys.go#L39

Added line #L39 was not covered by tests
}
return nil
}

0 comments on commit d14d232

Please sign in to comment.