Skip to content

Commit

Permalink
Merge branch 'main' into dwedul/1789-exchange-commitments
Browse files Browse the repository at this point in the history
  • Loading branch information
SpicyLemon committed Jan 27, 2024
2 parents d00ec98 + 1342662 commit c5ebedc
Show file tree
Hide file tree
Showing 48 changed files with 3,803 additions and 516 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Features

* Add the ibcratelimit module [#1498](https://github.com/provenance-io/provenance/issues/1498).
* Add NAV support for metadata scopes [#1749](https://github.com/provenance-io/provenance/issues/1749).
* Add fix for NAV units to tourmaline upgrade handler [#1815](https://github.com/provenance-io/provenance/issues/1815).

### Improvements
Expand All @@ -53,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

* Remove deleted marker send deny entries [#1666](https://github.com/provenance-io/provenance/issues/1666).
* Update protos, naming, and documentation to use mills [#1813](https://github.com/provenance-io/provenance/issues/1813).
* Update marker transfer to work with groups [#1818](https://github.com/provenance-io/provenance/issues/1818).

### Dependencies

Expand Down
10 changes: 6 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,6 @@ func New(
appCodec, keys[attributetypes.StoreKey], app.GetSubspace(attributetypes.ModuleName), app.AccountKeeper, &app.NameKeeper,
)

app.MetadataKeeper = metadatakeeper.NewKeeper(
appCodec, keys[metadatatypes.StoreKey], app.GetSubspace(metadatatypes.ModuleName), app.AccountKeeper, app.AuthzKeeper, app.AttributeKeeper,
)

markerReqAttrBypassAddrs := []sdk.AccAddress{
authtypes.NewModuleAddress(authtypes.FeeCollectorName), // Allow collecting fees in restricted coins.
authtypes.NewModuleAddress(rewardtypes.ModuleName), // Allow rewards to hold onto restricted coins.
Expand All @@ -576,10 +572,16 @@ func New(
authtypes.NewModuleAddress(stakingtypes.BondedPoolName), // Allow bond denom to be a restricted coin.
authtypes.NewModuleAddress(stakingtypes.NotBondedPoolName), // Allow bond denom to be a restricted coin.
}

app.MarkerKeeper = markerkeeper.NewKeeper(
appCodec, keys[markertypes.StoreKey], app.GetSubspace(markertypes.ModuleName),
app.AccountKeeper, app.BankKeeper, app.AuthzKeeper, app.FeeGrantKeeper,
app.AttributeKeeper, app.NameKeeper, app.TransferKeeper, markerReqAttrBypassAddrs,
NewGroupCheckerFunc(app.GroupKeeper),
)

app.MetadataKeeper = metadatakeeper.NewKeeper(
appCodec, keys[metadatatypes.StoreKey], app.GetSubspace(metadatatypes.ModuleName), app.AccountKeeper, app.AuthzKeeper, app.AttributeKeeper, app.MarkerKeeper,
)

app.HoldKeeper = holdkeeper.NewKeeper(
Expand Down
34 changes: 34 additions & 0 deletions app/group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package app

import (
"context"

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

// GroupCheckerFunc convenient type to match the GroupChecker interface.
type GroupCheckerFunc func(sdk.Context, sdk.AccAddress) bool

// GroupPolicyQuerier provides functionality to query group policies.
type GroupPolicyQuerier interface {
GroupPolicyInfo(goCtx context.Context, request *group.QueryGroupPolicyInfoRequest) (*group.QueryGroupPolicyInfoResponse, error)
}

// IsGroupAddress checks if the account is a group address.
func (t GroupCheckerFunc) IsGroupAddress(ctx sdk.Context, account sdk.AccAddress) bool {
if account == nil {
return false
}
return t(ctx, account)
}

// NewGroupCheckerFunc creates a new GroupChecker function for checking if an account is in a group.
func NewGroupCheckerFunc(querier GroupPolicyQuerier) GroupCheckerFunc {
return GroupCheckerFunc(func(ctx sdk.Context, account sdk.AccAddress) bool {
msg := &group.QueryGroupPolicyInfoRequest{Address: account.String()}
goCtx := sdk.WrapSDKContext(ctx)
_, err := querier.GroupPolicyInfo(goCtx, msg)
return err == nil
})
}
74 changes: 74 additions & 0 deletions app/group_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package app

import (
"context"
"testing"

"github.com/stretchr/testify/assert"

cerrs "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/group"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

func TestNewGroupCheckerFunc(t *testing.T) {
querier := NewMockGroupPolicyQuerier(true)
checker := NewGroupCheckerFunc(querier)
assert.NotNil(t, checker, "should return a group checker function")
}

func TestIsGroupAddress(t *testing.T) {
tests := []struct {
name string
querySuccess bool
address sdk.AccAddress
}{
{
name: "should be true with group address",
querySuccess: true,
address: sdk.AccAddress("test"),
},
{
name: "should return false with non group address",
querySuccess: false,
address: sdk.AccAddress("test"),
},
{
name: "should return false with nil address",
querySuccess: false,
address: nil,
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
querier := NewMockGroupPolicyQuerier(tc.querySuccess)
checker := NewGroupCheckerFunc(querier)
ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil)
success := checker.IsGroupAddress(ctx, tc.address)
assert.Equal(t, tc.querySuccess, success, "should correctly detect if the supplied address is a group address")
})
}
}

// MockGroupPolicyQuerier mocks the querier so a GroupKeeper isn't needed.
type MockGroupPolicyQuerier struct {
isGroupAddress bool
}

// NewMockGroupPolicyQuerier creates a new MockGroupPolicyQuerier.
func NewMockGroupPolicyQuerier(isGroupAddress bool) *MockGroupPolicyQuerier {
return &MockGroupPolicyQuerier{
isGroupAddress: isGroupAddress,
}
}

// GroupPolicyInfo provides a stubbed implementation of the GroupPolicyInfo method.
func (t MockGroupPolicyQuerier) GroupPolicyInfo(goCtx context.Context, request *group.QueryGroupPolicyInfoRequest) (*group.QueryGroupPolicyInfoResponse, error) {
var err error
if !t.isGroupAddress {
err = cerrs.New("", 1, "")
}
return nil, err
}
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

129 changes: 129 additions & 0 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39670,6 +39670,76 @@ paths:
format: boolean
tags:
- Query
'/provenance/metadata/v1/netassetvalues/{id}':
get:
summary: ScopeNetAssetValues returns net asset values for scope
operationId: ScopeNetAssetValues
responses:
'200':
description: A successful response.
schema:
type: object
properties:
net_asset_values:
type: array
items:
type: object
properties:
price:
title: price is the complete value of the asset's volume
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.


NOTE: The amount field is an Int which implements the
custom method

signatures required by gogoproto.
updated_block_height:
type: string
format: uint64
title: updated_block_height is the block height of last update
title: NetAssetValue defines a scope's net asset value
title: net asset values for scope
description: >-
QueryNetAssetValuesRequest is the response type for the
Query/NetAssetValues method.
default:
description: An unexpected error response
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
parameters:
- name: id
description: scopeid metadata address
in: path
required: true
type: string
tags:
- Query
'/provenance/metadata/v1/ownership/{address}':
get:
summary: >-
Expand Down Expand Up @@ -85796,6 +85866,27 @@ definitions:
on or off chain) to define an input

parameter
provenance.metadata.v1.NetAssetValue:
type: object
properties:
price:
title: price is the complete value of the asset's volume
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
updated_block_height:
type: string
format: uint64
title: updated_block_height is the block height of last update
title: NetAssetValue defines a scope's net asset value
provenance.metadata.v1.OSAllLocatorsRequest:
type: object
properties:
Expand Down Expand Up @@ -86612,6 +86703,39 @@ definitions:
include_request is a flag for whether to include this request in
your result.
description: QueryParamsResponse is the response type for the Query/Params RPC method.
provenance.metadata.v1.QueryScopeNetAssetValuesResponse:
type: object
properties:
net_asset_values:
type: array
items:
type: object
properties:
price:
title: price is the complete value of the asset's volume
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.


NOTE: The amount field is an Int which implements the custom
method

signatures required by gogoproto.
updated_block_height:
type: string
format: uint64
title: updated_block_height is the block height of last update
title: NetAssetValue defines a scope's net asset value
title: net asset values for scope
description: >-
QueryNetAssetValuesRequest is the response type for the
Query/NetAssetValues method.
provenance.metadata.v1.Record:
type: object
properties:
Expand Down Expand Up @@ -93518,6 +93642,11 @@ definitions:
description: >-
MsgAddContractSpecToScopeSpecResponse is the response type for the
Msg/AddContractSpecToScopeSpec RPC method.
provenance.metadata.v1.MsgAddNetAssetValuesResponse:
type: object
title: >-
MsgAddNetAssetValuesResponse defines the Msg/AddNetAssetValue response
type
provenance.metadata.v1.MsgAddScopeDataAccessResponse:
type: object
title: >-
Expand Down
Loading

0 comments on commit c5ebedc

Please sign in to comment.