Skip to content

Commit

Permalink
fix: change AccAddressFromBech32 to MustAccAddressFromBech32 (#691)
Browse files Browse the repository at this point in the history
* fix: add error handling

* fix: use MustAccAddressFromBech32

* test: add test of GetSigners

* test: delete test of GetSigners in foundation

* fix: use MustAccAddressFromBech32

* docs: update CHANGELOG.md

* test: fix to appropriate test
  • Loading branch information
da1suk8 committed Oct 11, 2022
1 parent df29ba8 commit 580d404
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/foundation) [\#693](https://github.com/line/lbm-sdk/pull/693) add pool to the state of x/foundation
* (x/wasm,distribution) [\#696](https://github.com/line/lbm-sdk/pull/696) x/wasm,distribution - add checking a file size before reading it
* (x/foundation) [\#698](https://github.com/line/lbm-sdk/pull/698) update x/group relevant logic in x/foundation
* (x) [\#691](https://github.com/line/lbm-sdk/pull/691) change AccAddressFromBech32 to MustAccAddressFromBech32

### Bug Fixes
* (x/wasm) [\#453](https://github.com/line/lbm-sdk/pull/453) modify wasm grpc query api path
Expand Down
2 changes: 1 addition & 1 deletion x/auth/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewBaseAccountWithAddress(addr sdk.AccAddress) *BaseAccount {

// GetAddress - Implements sdk.AccountI.
func (acc BaseAccount) GetAddress() sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(acc.Address)
addr := sdk.MustAccAddressFromBech32(acc.Address)
return addr
}

Expand Down
2 changes: 1 addition & 1 deletion x/bank/types/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func SanitizeGenesisBalances(balances []Balance) []Balance {
// 1. Retrieve the address equivalents for each Balance's address.
addresses := make([]sdk.AccAddress, len(balances))
for i := range balances {
addr, _ := sdk.AccAddressFromBech32(balances[i].Address)
addr := sdk.MustAccAddressFromBech32(balances[i].Address)
addresses[i] = addr
}

Expand Down
2 changes: 1 addition & 1 deletion x/bank/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (msg MsgMultiSend) GetSignBytes() []byte {
func (msg MsgMultiSend) GetSigners() []sdk.AccAddress {
addrs := make([]sdk.AccAddress, len(msg.Inputs))
for i, in := range msg.Inputs {
addr, _ := sdk.AccAddressFromBech32(in.Address)
addr := sdk.MustAccAddressFromBech32(in.Address)
addrs[i] = addr
}

Expand Down
22 changes: 11 additions & 11 deletions x/foundation/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (m MsgFundTreasury) ValidateBasic() error {

// GetSigners implements Msg.
func (m MsgFundTreasury) GetSigners() []sdk.AccAddress {
signer, _ := sdk.AccAddressFromBech32(m.From)
signer := sdk.MustAccAddressFromBech32(m.From)
return []sdk.AccAddress{signer}
}

Expand All @@ -50,7 +50,7 @@ func (m MsgWithdrawFromTreasury) ValidateBasic() error {

// GetSigners implements Msg.
func (m MsgWithdrawFromTreasury) GetSigners() []sdk.AccAddress {
signer, _ := sdk.AccAddressFromBech32(m.Operator)
signer := sdk.MustAccAddressFromBech32(m.Operator)
return []sdk.AccAddress{signer}
}

Expand All @@ -75,7 +75,7 @@ func (m MsgUpdateMembers) ValidateBasic() error {

// GetSigners implements Msg.
func (m MsgUpdateMembers) GetSigners() []sdk.AccAddress {
signer, _ := sdk.AccAddressFromBech32(m.Operator)
signer := sdk.MustAccAddressFromBech32(m.Operator)
return []sdk.AccAddress{signer}
}

Expand All @@ -99,7 +99,7 @@ func (m MsgUpdateDecisionPolicy) ValidateBasic() error {

// GetSigners implements Msg.
func (m MsgUpdateDecisionPolicy) GetSigners() []sdk.AccAddress {
signer, _ := sdk.AccAddressFromBech32(m.Operator)
signer := sdk.MustAccAddressFromBech32(m.Operator)
return []sdk.AccAddress{signer}
}

Expand Down Expand Up @@ -179,7 +179,7 @@ func (m MsgSubmitProposal) UnpackInterfaces(unpacker codectypes.AnyUnpacker) err
func (m MsgSubmitProposal) GetSigners() []sdk.AccAddress {
signers := make([]sdk.AccAddress, len(m.Proposers))
for i, p := range m.Proposers {
proposer, _ := sdk.AccAddressFromBech32(p)
proposer := sdk.MustAccAddressFromBech32(p)
signers[i] = proposer
}
return signers
Expand All @@ -202,7 +202,7 @@ func (m MsgWithdrawProposal) ValidateBasic() error {

// GetSigners implements Msg.
func (m MsgWithdrawProposal) GetSigners() []sdk.AccAddress {
signer, _ := sdk.AccAddressFromBech32(m.Address)
signer := sdk.MustAccAddressFromBech32(m.Address)
return []sdk.AccAddress{signer}
}

Expand Down Expand Up @@ -231,7 +231,7 @@ func (m MsgVote) ValidateBasic() error {

// GetSigners implements Msg.
func (m MsgVote) GetSigners() []sdk.AccAddress {
signer, _ := sdk.AccAddressFromBech32(m.Voter)
signer := sdk.MustAccAddressFromBech32(m.Voter)
return []sdk.AccAddress{signer}
}

Expand All @@ -252,7 +252,7 @@ func (m MsgExec) ValidateBasic() error {

// GetSigners implements Msg.
func (m MsgExec) GetSigners() []sdk.AccAddress {
signer, _ := sdk.AccAddressFromBech32(m.Signer)
signer := sdk.MustAccAddressFromBech32(m.Signer)
return []sdk.AccAddress{signer}
}

Expand All @@ -269,7 +269,7 @@ func (m MsgLeaveFoundation) ValidateBasic() error {

// GetSigners implements Msg.
func (m MsgLeaveFoundation) GetSigners() []sdk.AccAddress {
signer, _ := sdk.AccAddressFromBech32(m.Address)
signer := sdk.MustAccAddressFromBech32(m.Address)
return []sdk.AccAddress{signer}
}

Expand Down Expand Up @@ -325,7 +325,7 @@ func (m MsgGrant) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {

// GetSigners implements Msg.
func (m MsgGrant) GetSigners() []sdk.AccAddress {
signer, _ := sdk.AccAddressFromBech32(m.Operator)
signer := sdk.MustAccAddressFromBech32(m.Operator)
return []sdk.AccAddress{signer}
}

Expand All @@ -350,6 +350,6 @@ func (m MsgRevoke) ValidateBasic() error {

// GetSigners implements Msg.
func (m MsgRevoke) GetSigners() []sdk.AccAddress {
signer, _ := sdk.AccAddressFromBech32(m.Operator)
signer := sdk.MustAccAddressFromBech32(m.Operator)
return []sdk.AccAddress{signer}
}
1 change: 1 addition & 0 deletions x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ func TestInstantiateWithPermissions(t *testing.T) {
srcActor: myAddr,
},
"onlyAddress with non matching address": {
srcActor: myAddr,
srcPermission: types.AccessTypeOnlyAddress.With(otherAddr),
expError: sdkerrors.ErrUnauthorized,
},
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/lbmtypes/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ func (msg MsgStoreCodeAndInstantiateContract) GetSignBytes() []byte {
}

func (msg MsgStoreCodeAndInstantiateContract) GetSigners() []sdk.AccAddress {
senderAddr, _ := sdk.AccAddressFromBech32(msg.Sender)
senderAddr := sdk.MustAccAddressFromBech32(msg.Sender)
return []sdk.AccAddress{senderAddr}
}
12 changes: 12 additions & 0 deletions x/wasm/lbmtypes/tx_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package lbmtypes

import (
"encoding/hex"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -10,6 +12,10 @@ import (
wasmTypes "github.com/line/lbm-sdk/x/wasm/types"
)

func NewMsgStoreCodeAndInstantiateContract(fromAddr sdk.AccAddress) *MsgStoreCodeAndInstantiateContract {
return &MsgStoreCodeAndInstantiateContract{Sender: fromAddr.String()}
}

func TestStoreCodeAndInstantiateContractValidation(t *testing.T) {
bad, err := sdk.AccAddressFromHex("012345")
require.NoError(t, err)
Expand Down Expand Up @@ -122,3 +128,9 @@ func TestStoreCodeAndInstantiateContractValidation(t *testing.T) {
})
}
}

func TestNewMsgStoreCodeAndInstantiateContractGetSigners(t *testing.T) {
res := NewMsgStoreCodeAndInstantiateContract(sdk.AccAddress([]byte("input111111111111111"))).GetSigners()
bytes := sdk.MustAccAddressFromBech32(res[0].String())
require.Equal(t, "696e707574313131313131313131313131313131", fmt.Sprintf("%v", hex.EncodeToString(bytes)))
}

0 comments on commit 580d404

Please sign in to comment.