Skip to content

Commit

Permalink
Merge branch 'main' into collection-export-params
Browse files Browse the repository at this point in the history
  • Loading branch information
0Tech authored Mar 21, 2024
2 parents 9a102b4 + 819a938 commit be49729
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 54 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/release-sims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: install runsim
run: |
export GO111MODULE="on" && go install github.com/cosmos/tools/cmd/[email protected]
- uses: actions/[email protected].0
- uses: actions/[email protected].2
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
Expand All @@ -56,7 +56,7 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: '1.20'
- uses: actions/[email protected].0
- uses: actions/[email protected].2
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
Expand All @@ -76,7 +76,7 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: '1.20'
- uses: actions/[email protected].0
- uses: actions/[email protected].2
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
Expand All @@ -96,7 +96,7 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: '1.20'
- uses: actions/[email protected].0
- uses: actions/[email protected].2
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/sims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
run: go version
- name: Install runsim
run: export GO111MODULE="on" && go install github.com/cosmos/tools/cmd/[email protected]
- uses: actions/[email protected].0
- uses: actions/[email protected].2
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
Expand All @@ -64,7 +64,7 @@ jobs:
!**/**_test.go
go.mod
go.sum
- uses: actions/[email protected].0
- uses: actions/[email protected].2
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
go.sum
SET_ENV_NAME_INSERTIONS: 1
SET_ENV_NAME_LINES: 1
- uses: actions/[email protected].0
- uses: actions/[email protected].2
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
Expand Down Expand Up @@ -122,7 +122,7 @@ jobs:
go.sum
SET_ENV_NAME_INSERTIONS: 1
SET_ENV_NAME_LINES: 1
- uses: actions/[email protected].0
- uses: actions/[email protected].2
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
Expand Down Expand Up @@ -151,7 +151,7 @@ jobs:
go.sum
SET_ENV_NAME_INSERTIONS: 1
SET_ENV_NAME_LINES: 1
- uses: actions/[email protected].0
- uses: actions/[email protected].2
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/sims_normal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: go version
- name: Install runsim
run: export GO111MODULE="on" && go install github.com/cosmos/tools/cmd/[email protected]
- uses: actions/[email protected].0
- uses: actions/[email protected].2
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
Expand All @@ -44,7 +44,7 @@ jobs:
go-version: '1.20'
- name: Display go version
run: go version
- uses: actions/[email protected].0
- uses: actions/[email protected].2
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
Expand All @@ -62,7 +62,7 @@ jobs:
go-version: '1.20'
- name: Display go version
run: go version
- uses: actions/[email protected].0
- uses: actions/[email protected].2
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
Expand All @@ -80,7 +80,7 @@ jobs:
go-version: '1.20'
- name: Display go version
run: go version
- uses: actions/[email protected].0
- uses: actions/[email protected].2
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: install tparse
run: |
go install github.com/mfridman/[email protected]
- uses: actions/[email protected].0
- uses: actions/[email protected].2
with:
path: ~/go/bin
key: ${{ runner.os }}-go-tparse-binary
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/auth) [#1274](https://github.com/Finschia/finschia-sdk/pull/1274) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking.
* (x/collection) [\#1276](https://github.com/Finschia/finschia-sdk/pull/1276) eliminates potential risk for Insufficient Sanity Check of tokenID in Genesis
* (x/foundation) [\#1277](https://github.com/Finschia/finschia-sdk/pull/1277) add init logic of foundation module accounts to InitGenesis in order to eliminate potential panic
* (x/collection, x/token) [\#1288](https://github.com/Finschia/finschia-sdk/pull/1288) use accAddress to compare in validatebasic function in collection & token modules
* (x/collection) [\#1268](https://github.com/Finschia/finschia-sdk/pull/1268) export x/collection params into genesis

### Removed
Expand Down
18 changes: 12 additions & 6 deletions x/collection/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,17 @@ func (m MsgAuthorizeOperator) ValidateBasic() error {
return err
}

if _, err := sdk.AccAddressFromBech32(m.Holder); err != nil {
holderAcc, err := sdk.AccAddressFromBech32(m.Holder)
if err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid holder address: %s", m.Holder)
}
if _, err := sdk.AccAddressFromBech32(m.Operator); err != nil {

operatorAcc, err := sdk.AccAddressFromBech32(m.Operator)
if err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid operator address: %s", m.Operator)
}

if m.Operator == m.Holder {
if holderAcc.Equals(operatorAcc) {
return ErrApproverProxySame
}

Expand Down Expand Up @@ -471,14 +474,17 @@ func (m MsgRevokeOperator) ValidateBasic() error {
return err
}

if _, err := sdk.AccAddressFromBech32(m.Holder); err != nil {
holderAcc, err := sdk.AccAddressFromBech32(m.Holder)
if err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid holder address: %s", m.Holder)
}
if _, err := sdk.AccAddressFromBech32(m.Operator); err != nil {

operatorAcc, err := sdk.AccAddressFromBech32(m.Operator)
if err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid operator address: %s", m.Operator)
}

if m.Operator == m.Holder {
if holderAcc.Equals(operatorAcc) {
return ErrApproverProxySame
}

Expand Down
52 changes: 38 additions & 14 deletions x/collection/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,15 @@ func TestMsgOperatorSendNFT(t *testing.T) {
}

func TestMsgAuthorizeOperator(t *testing.T) {
addrs := make([]sdk.AccAddress, 2)
addrs := make([]string, 2)
for i := range addrs {
addrs[i] = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
addrs[i] = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String()
}

testCases := map[string]struct {
contractID string
holder sdk.AccAddress
operator sdk.AccAddress
holder string
operator string
err error
}{
"valid msg": {
Expand All @@ -407,36 +407,48 @@ func TestMsgAuthorizeOperator(t *testing.T) {
holder: addrs[0],
err: sdkerrors.ErrInvalidAddress,
},
"proxy and approver should be different": {
contractID: "deadbeef",
holder: addrs[0],
operator: addrs[0],
err: collection.ErrApproverProxySame,
},
"proxy and approver should be different (uppercase)": {
contractID: "deadbeef",
holder: addrs[0],
operator: strings.ToUpper(addrs[0]),
err: collection.ErrApproverProxySame,
},
}

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
msg := collection.MsgAuthorizeOperator{
ContractId: tc.contractID,
Holder: tc.holder.String(),
Operator: tc.operator.String(),
Holder: tc.holder,
Operator: tc.operator,
}

require.ErrorIs(t, msg.ValidateBasic(), tc.err)
if tc.err != nil {
return
}

require.Equal(t, []sdk.AccAddress{tc.holder}, msg.GetSigners())
require.Equal(t, []sdk.AccAddress{sdk.MustAccAddressFromBech32(tc.holder)}, msg.GetSigners())
})
}
}

func TestMsgRevokeOperator(t *testing.T) {
addrs := make([]sdk.AccAddress, 2)
addrs := make([]string, 2)
for i := range addrs {
addrs[i] = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
addrs[i] = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String()
}

testCases := map[string]struct {
contractID string
holder sdk.AccAddress
operator sdk.AccAddress
holder string
operator string
err error
}{
"valid msg": {
Expand All @@ -459,22 +471,34 @@ func TestMsgRevokeOperator(t *testing.T) {
holder: addrs[0],
err: sdkerrors.ErrInvalidAddress,
},
"proxy and approver should be different": {
contractID: "deadbeef",
holder: addrs[0],
operator: addrs[0],
err: collection.ErrApproverProxySame,
},
"proxy and approver should be different (uppercase)": {
contractID: "deadbeef",
holder: addrs[0],
operator: strings.ToUpper(addrs[0]),
err: collection.ErrApproverProxySame,
},
}

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
msg := collection.MsgRevokeOperator{
ContractId: tc.contractID,
Holder: tc.holder.String(),
Operator: tc.operator.String(),
Holder: tc.holder,
Operator: tc.operator,
}

require.ErrorIs(t, msg.ValidateBasic(), tc.err)
if tc.err != nil {
return
}

require.Equal(t, []sdk.AccAddress{tc.holder}, msg.GetSigners())
require.Equal(t, []sdk.AccAddress{sdk.MustAccAddressFromBech32(tc.holder)}, msg.GetSigners())
})
}
}
Expand Down
18 changes: 12 additions & 6 deletions x/token/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,17 @@ func (m MsgRevokeOperator) ValidateBasic() error {
return err
}

if _, err := sdk.AccAddressFromBech32(m.Holder); err != nil {
holderAcc, err := sdk.AccAddressFromBech32(m.Holder)
if err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid holder address: %s", m.Holder)
}
if _, err := sdk.AccAddressFromBech32(m.Operator); err != nil {

operatorAcc, err := sdk.AccAddressFromBech32(m.Operator)
if err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid operator address: %s", m.Operator)
}

if m.Operator == m.Holder {
if holderAcc.Equals(operatorAcc) {
return ErrApproverProxySame
}

Expand Down Expand Up @@ -146,14 +149,17 @@ func (m MsgAuthorizeOperator) ValidateBasic() error {
return err
}

if _, err := sdk.AccAddressFromBech32(m.Holder); err != nil {
holderAcc, err := sdk.AccAddressFromBech32(m.Holder)
if err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid holder address: %s", m.Holder)
}
if _, err := sdk.AccAddressFromBech32(m.Operator); err != nil {

operatorAcc, err := sdk.AccAddressFromBech32(m.Operator)
if err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid operator address: %s", m.Operator)
}

if m.Operator == m.Holder {
if holderAcc.Equals(operatorAcc) {
return ErrApproverProxySame
}

Expand Down
Loading

0 comments on commit be49729

Please sign in to comment.