Skip to content
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

Add marker module #9

Merged
merged 24 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
760abf1
fix thirdparty cosmos proto target for 0.40
iramiller Jan 13, 2021
5440f3c
initial import of marker module
iramiller Jan 13, 2021
4f23027
initial integratoin testing of marker module
iramiller Jan 14, 2021
85d186d
Merge branch 'main' into add-marker-module
iramiller Jan 20, 2021
c4bcdbe
update tests to match nil error when marker not found
iramiller Jan 20, 2021
d612b5a
fix handler_test in marker module
iramiller Jan 20, 2021
0dca071
update marker tests for new empty account
iramiller Jan 20, 2021
55f7d64
add log_level flag to root command
iramiller Jan 21, 2021
e3540a0
initialize marker module param space
iramiller Jan 21, 2021
0fc7adc
add marker genesis command, include in run target
iramiller Jan 22, 2021
1c46c20
Merge branch 'main' into add-marker-module
iramiller Jan 22, 2021
4a9cf49
go format and lint work
iramiller Jan 22, 2021
08e6875
wire up markers in genesis
iramiller Jan 22, 2021
3bbcd87
update marker query results to use any fields
iramiller Jan 22, 2021
0db8d98
manage sendenabled configuration for denoms
iramiller Jan 22, 2021
b55f54e
update markers with denom metadata support
iramiller Jan 22, 2021
28475fd
test coverage for brokered transfer/restricted_coin
iramiller Jan 22, 2021
cb3828c
set supply and governance control defaults
iramiller Jan 22, 2021
7e02b3c
cli tests for marker module txs
iramiller Jan 23, 2021
edd64a7
marker cli query tests
iramiller Jan 23, 2021
99c3e61
update golang lint tool version, switch to docker buf
iramiller Jan 23, 2021
8ebe90c
fix issue with supply burn during begin block
iramiller Jan 25, 2021
802608d
rewrite rest tx error handling to sdk spec
iramiller Jan 25, 2021
7cf2d32
rewrite rest query error handling per sdk spec
iramiller Jan 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
initial integratoin testing of marker module
removed marker amino support temporarily for these tests
  • Loading branch information
iramiller committed Jan 14, 2021
commit 4f23027cc26b59cfffe064292545cef5f21f82e8
26 changes: 25 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ import (
appparams "github.com/provenance-io/provenance/app/params"
tmjson "github.com/tendermint/tendermint/libs/json"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/provenance-io/provenance/x/marker"
markerkeeper "github.com/provenance-io/provenance/x/marker/keeper"
markertypes "github.com/provenance-io/provenance/x/marker/types"
)

const (
Expand Down Expand Up @@ -120,6 +124,8 @@ var (
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},

marker.AppModuleBasic{},
)

// module account permissions
Expand All @@ -131,6 +137,7 @@ var (
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
markertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}

// module accounts that are allowed to receive tokens
Expand Down Expand Up @@ -179,6 +186,8 @@ type App struct {
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper

MarkerKeeper markerkeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -212,6 +221,8 @@ func New(
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,

markertypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -272,7 +283,9 @@ func New(
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
)

// ... other modules keepers
app.MarkerKeeper = markerkeeper.NewKeeper(
appCodec, keys[markertypes.StoreKey], app.GetSubspace(markertypes.ModuleName), app.AccountKeeper, app.BankKeeper,
)

// Create IBC Keeper
app.IBCKeeper = ibckeeper.NewKeeper(
Expand Down Expand Up @@ -335,6 +348,9 @@ func New(
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),

marker.NewAppModule(appCodec, app.MarkerKeeper, app.AccountKeeper, app.BankKeeper),

upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
Expand Down Expand Up @@ -368,6 +384,7 @@ func New(
govtypes.ModuleName,
minttypes.ModuleName,
crisistypes.ModuleName,
markertypes.ModuleName,
ibchost.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
Expand All @@ -387,6 +404,10 @@ func New(
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),

// TODO -- add simulation to marker module
//marker.NewAppModule(appCodec, app.MarkerKeeper, app.AccountKeeper, app.BankKeeper),

params.NewAppModule(app.ParamsKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
Expand Down Expand Up @@ -600,6 +621,9 @@ func initParamsKeeper(appCodec codec.BinaryMarshaler, legacyAmino *codec.LegacyA
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)

paramsKeeper.Subspace(markertypes.ModuleName)

paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)

Expand Down
6 changes: 3 additions & 3 deletions x/marker/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/types/rest"

"github.com/provenance-io/provenance/x/marker/types"
Expand Down Expand Up @@ -111,7 +110,8 @@ func queryMarkerHandlerFn(cliCtx client.Context, fn string) http.HandlerFunc {

func queryMarkerAssetsHandlerFn(cliCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 200)
//_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 200)
_, _, _, err := rest.ParseHTTPArgsWithLimit(r, 200)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
Expand All @@ -138,7 +138,7 @@ func queryMarkerAssetsHandlerFn(cliCtx client.Context) http.HandlerFunc {
// Address: addr.String(),
// }

bz, err := nil, error("todo: import metadata module") //cliCtx.LegacyAmino.MarshalJSON(params)
bz, err := []byte{}, fmt.Errorf("todo: import metadata module") //cliCtx.LegacyAmino.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
Expand Down
68 changes: 0 additions & 68 deletions x/marker/keeper/integration_test.go

This file was deleted.

7 changes: 6 additions & 1 deletion x/marker/keeper/invariants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

simapp "github.com/provenance-io/provenance/app"

markerkeeper "github.com/provenance-io/provenance/x/marker/keeper"
markertypes "github.com/provenance-io/provenance/x/marker/types"
)

func TestMarkerInvariant(t *testing.T) {
app, ctx := createTestApp(true)
//app, ctx := createTestApp(true)
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

user := testUserAddress("test")

Expand Down
4 changes: 2 additions & 2 deletions x/marker/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// Handler is a handler function for use with IterateRecords.
type Handler func(record types.MarkerAccountI) error

// MarkerKeeper provides a read/write iterate interface to marker acccounts in the auth account keeper store
// MarkerKeeperI provides a read/write iterate interface to marker acccounts in the auth account keeper store
type MarkerKeeperI interface {
// Returns a new marker instance with the address and baseaccount assigned. Does not save to auth store
NewMarker(sdk.Context, types.MarkerAccountI) types.MarkerAccountI
Expand Down Expand Up @@ -121,7 +121,7 @@ func (k Keeper) RemoveMarker(ctx sdk.Context, marker types.MarkerAccountI) {
store.Delete(types.MarkerStoreKey(marker.GetAddress()))
}

// IterateMarkerAccounts iterates all markers with the given handler function.
// IterateMarkers iterates all markers with the given handler function.
func (k Keeper) IterateMarkers(ctx sdk.Context, cb func(marker types.MarkerAccountI) (stop bool)) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.MarkerStoreKeyPrefix)
Expand Down
35 changes: 27 additions & 8 deletions x/marker/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package keeper_test
import (
"testing"

simapp "github.com/provenance-io/provenance/app"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

Expand All @@ -13,7 +16,9 @@ import (
)

func TestAccountMapperGetSet(t *testing.T) {
app, ctx := createTestApp(true)
//app, ctx := createTestApp(true)
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

addr := types.MustGetMarkerAddress("testcoin")
user := testUserAddress("test")
Expand Down Expand Up @@ -51,7 +56,9 @@ func TestAccountMapperGetSet(t *testing.T) {
}

func TestAccountKeeperReader(t *testing.T) {
app, ctx := createTestApp(true)
//app, ctx := createTestApp(true)
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

addr := types.MustGetMarkerAddress("testcoin")
user := testUserAddress("test")
Expand Down Expand Up @@ -85,7 +92,9 @@ func TestAccountKeeperReader(t *testing.T) {

// nolint:funlen
func TestAccountKeeperManageAccess(t *testing.T) {
app, ctx := createTestApp(true)
//app, ctx := createTestApp(true)
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

addr := types.MustGetMarkerAddress("testcoin")
// Easiest way to create a valid bech32 address for testing.
Expand Down Expand Up @@ -187,7 +196,9 @@ func TestAccountKeeperManageAccess(t *testing.T) {
}

func TestAccountKeeperCancelProposedByManager(t *testing.T) {
app, ctx := createTestApp(true)
//app, ctx := createTestApp(true)
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

addr := types.MustGetMarkerAddress("testcoin")
// Easiest way to create a valid bech32 address for testing.
Expand Down Expand Up @@ -219,7 +230,9 @@ func TestAccountKeeperCancelProposedByManager(t *testing.T) {

// nolint:funlen
func TestAccountKeeperMintBurnCoins(t *testing.T) {
app, ctx := createTestApp(true)
//app, ctx := createTestApp(true)
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
addr := types.MustGetMarkerAddress("testcoin")
user := testUserAddress("test")

Expand Down Expand Up @@ -316,7 +329,9 @@ func TestAccountKeeperMintBurnCoins(t *testing.T) {
}

func TestAccountKeeperGetAll(t *testing.T) {
app, ctx := createTestApp(true)
//app, ctx := createTestApp(true)
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

user := testUserAddress("test")
mac := types.NewEmptyMarkerAccount("testcoin",
Expand Down Expand Up @@ -350,7 +365,9 @@ func TestAccountKeeperGetAll(t *testing.T) {
}

func TestAccountInsufficientExisting(t *testing.T) {
app, ctx := createTestApp(true)
//app, ctx := createTestApp(true)
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

pubkey := secp256k1.GenPrivKey().PubKey()
user := sdk.AccAddress(pubkey.Address())
Expand Down Expand Up @@ -388,7 +405,9 @@ func TestAccountInsufficientExisting(t *testing.T) {
}

func TestAccountImplictControl(t *testing.T) {
app, ctx := createTestApp(true)
//app, ctx := createTestApp(true)
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
user := testUserAddress("test")
user2 := testUserAddress("test2")

Expand Down
4 changes: 3 additions & 1 deletion x/marker/keeper/marker.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ func (k Keeper) FinalizeMarker(ctx sdk.Context, caller sdk.AccAddress, denom str
return nil
}

// ActivateMarker transistions a marker into the active status, enforcing permissions, supply constraints, and minting
// any supply as required.
func (k Keeper) ActivateMarker(ctx sdk.Context, caller sdk.AccAddress, denom string) error {
m, err := k.GetMarkerByDenom(ctx, denom)
if err != nil {
Expand Down Expand Up @@ -488,7 +490,7 @@ func (k Keeper) DeleteMarker(ctx sdk.Context, caller sdk.AccAddress, denom strin
return nil
}

// TransfeCoin transfers restricted coins between to accounts when the administrator account holds the transfer
// TransferCoin transfers restricted coins between to accounts when the administrator account holds the transfer
// access right and the marker type is restricted_coin
func (k Keeper) TransferCoin(ctx sdk.Context, from, to, admin sdk.AccAddress, amount sdk.Coin) error {
m, err := k.GetMarkerByDenom(ctx, amount.Denom)
Expand Down
2 changes: 1 addition & 1 deletion x/marker/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/provenance-io/provenance/x/marker/types"
)

// The module level router for state queries (using the Legacy Amino Codec)
// NewQuerier is the module level router for state queries (using the Legacy Amino Codec)
func NewQuerier(keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) {
switch path[0] {
Expand Down
Loading