Skip to content

Commit

Permalink
Merge branch 'main' into nullpointer0x00/1127-marker-ibs20-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
nullpointer0x00 committed Sep 27, 2023
2 parents 709fe2b + d1bd750 commit fc0bd2a
Show file tree
Hide file tree
Showing 28 changed files with 374 additions and 190 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
Funds with a hold on them cannot be transferred until the hold is removed.
Management of holds is internal, but there are queries for looking up holds on accounts.
Holds are also reflected in the `x/bank` module's `SpendableBalances` query.
* Add new MaxSupply param to marker module and deprecate MaxTotalSupply. [#1292](https://github.com/provenance-io/provenance/issues/1292).

### Improvements

Expand All @@ -70,6 +71,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Fix for incorrect resource-id type casting on contract specification [#1647](https://github.com/provenance-io/provenance/issues/1647).
* Allow restricted coins to be quarantined [#1626](https://github.com/provenance-io/provenance/issues/1626).
* Prevent marker forced transfers from module accounts [#1626](https://github.com/provenance-io/provenance/issues/1626).
* Change config load order so custom.toml can override other config. [#1262](https://github.com/provenance-io/provenance/issues/1262)

### Client Breaking

Expand Down Expand Up @@ -97,7 +99,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- Bump `bufbuild/buf-setup-action` from 1.25.1 to 1.26.0 ([#1645](https://github.com/provenance-io/provenance/pull/1645))
- Bump `bufbuild/buf-setup-action` from 1.25.0 to 1.25.1 ([#1642](https://github.com/provenance-io/provenance/pull/1642))
- Bump `google.golang.org/grpc` from 1.56.2 to 1.57.0 ([#1635](https://github.com/provenance-io/provenance/pull/1635))
- Bump `github.com/rs/zerolog` from 1.29.1 to 1.30.0 ([#1639](https://github.com/provenance-io/provenance/pull/1639))
- Bump `github.com/rs/zerolog` from 1.29.1 to 1.31.0 ([#1639](https://github.com/provenance-io/provenance/pull/1639), [#1691](https://github.com/provenance-io/provenance/pull/1691))
- Bump `bufbuild/buf-setup-action` from 1.24.0 to 1.25.0 ([#1632](https://github.com/provenance-io/provenance/pull/1632))
- Bump `bufbuild/buf-setup-action` from 1.23.1 to 1.24.0 ([#1631](https://github.com/provenance-io/provenance/pull/1631))
- Bump `github.com/cosmos/ibc-go/v6` from 6.1.1 to 6.2.0 ([#1629](https://github.com/provenance-io/provenance/pull/1629))
Expand Down
1 change: 1 addition & 0 deletions app/params/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
// Adjusted marker operations to a cumulative weight of 100
DefaultWeightMsgAddMarker int = 30
DefaultWeightMsgChangeStatus int = 10
DefaultWeightMsgFinalize int = 10
DefaultWeightMsgAddAccess int = 10
DefaultWeightMsgAddFinalizeActivateMarker int = 10
DefaultWeightMsgAddMarkerProposal int = 40
Expand Down
14 changes: 14 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

icqtypes "github.com/strangelove-ventures/async-icq/v6/types"

"cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/baseapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -110,6 +112,7 @@ var upgrades = map[string]appUpgrade{

removeInactiveValidatorDelegations(ctx, app)
setupICQ(ctx, app)
updateMaxSupply(ctx, app)

return vm, nil
},
Expand All @@ -128,6 +131,7 @@ var upgrades = map[string]appUpgrade{

removeInactiveValidatorDelegations(ctx, app)
setupICQ(ctx, app)
updateMaxSupply(ctx, app)

return vm, nil
},
Expand Down Expand Up @@ -326,3 +330,13 @@ func setupICQ(ctx sdk.Context, app *App) {
app.ICQKeeper.SetParams(ctx, icqtypes.NewParams(true, []string{"/provenance.oracle.v1.Query/Oracle"}))
ctx.Logger().Info("Done updating ICQ params")
}

// updateMaxSupply sets the value of max supply to the current value of MaxTotalSupply
func updateMaxSupply(ctx sdk.Context, app *App) {
ctx.Logger().Info("Updating MaxSupply marker param")
params := app.MarkerKeeper.GetParams(ctx)
//nolint:staticcheck // Populate new param with deprecated param
params.MaxSupply = math.NewIntFromUint64(params.MaxTotalSupply)
app.MarkerKeeper.SetParams(ctx, params)
ctx.Logger().Info("Done updating MaxSupply marker param")
}
4 changes: 4 additions & 0 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ func (s *UpgradeTestSuite) TestSaffronRC1() {
"INF removing all delegations from validators that have been inactive (unbonded) for 21 days",
"INF Updating ICQ params",
"INF Done updating ICQ params",
"INF Updating MaxSupply marker param",
"INF Done updating MaxSupply marker param",
}

s.AssertUpgradeHandlerLogs("saffron-rc1", expInLog, nil)
Expand All @@ -438,6 +440,8 @@ func (s *UpgradeTestSuite) TestSaffron() {
"INF removing all delegations from validators that have been inactive (unbonded) for 21 days",
"INF Updating ICQ params",
"INF Done updating ICQ params",
"INF Updating MaxSupply marker param",
"INF Done updating MaxSupply marker param",
}

s.AssertUpgradeHandlerLogs("saffron", expInLog, nil)
Expand Down
14 changes: 8 additions & 6 deletions cmd/provenanced/config/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,16 @@ func unquote(str string) string {
}

// LoadConfigFromFiles loads configurations appropriately.
func LoadConfigFromFiles(cmd *cobra.Command) error {
if err := loadUnmanagedConfig(cmd); err != nil {
return err
}
func LoadConfigFromFiles(cmd *cobra.Command) (err error) {
if IsPacked(cmd) {
return loadPackedConfig(cmd)
err = loadPackedConfig(cmd)
} else {
err = loadUnpackedConfig(cmd)
}
if err != nil {
return err
}
return loadUnpackedConfig(cmd)
return loadUnmanagedConfig(cmd)
}

// loadUnmanagedConfig reads the unmanaged config file into viper. It does not apply anything to any contexts though.
Expand Down
27 changes: 24 additions & 3 deletions cmd/provenanced/config/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (s *ConfigManagerTestSuite) TestUnmanagedConfig() {
assert.Equal(t, "bananas", actual, "unmanaged field value")
})

s.T().Run("unmanaged config entry does not override other config", func(t *testing.T) {
s.T().Run("unmanaged config entry overrides other config", func(t *testing.T) {
dCmd := s.makeDummyCmd()
configDir := GetFullPathToConfigDir(dCmd)
uFile := GetFullPathToUnmanagedConf(dCmd)
Expand All @@ -180,8 +180,8 @@ func (s *ConfigManagerTestSuite) TestUnmanagedConfig() {
ctx := client.GetClientContextFromCmd(dCmd)
vpr := ctx.Viper
actual := vpr.GetString("db_backend")
assert.NotEqual(t, "still bananas", actual, "unmanaged field value")
assert.Equal(t, DefaultTmConfig().DBBackend, actual, "unmanaged field default value")
assert.Equal(t, "still bananas", actual, "unmanaged field value")
assert.NotEqual(t, DefaultTmConfig().DBBackend, actual, "unmanaged field default value")
})

s.T().Run("unmanaged config is read with unpacked files", func(t *testing.T) {
Expand All @@ -196,6 +196,27 @@ func (s *ConfigManagerTestSuite) TestUnmanagedConfig() {
assert.Equal(t, "stuff", actual, "unmanaged field value")
})

s.T().Run("unmanaged config is read with invalid packed files", func(t *testing.T) {
dCmd := s.makeDummyCmd()
uFile := GetFullPathToUnmanagedConf(dCmd)
pFile := GetFullPathToPackedConf(dCmd)
SaveConfigs(dCmd, DefaultAppConfig(), DefaultTmConfig(), DefaultClientConfig(), false)
require.NoError(t, os.WriteFile(uFile, []byte("my-custom-entry = \"stuff\"\n"), 0o644), "writing unmanaged config")
require.NoError(t, os.WriteFile(pFile, []byte("kl234508923u5jl"), 0o644), "writing invalid data to packed config")
require.EqualError(t, LoadConfigFromFiles(dCmd), "packed config file parse error: invalid character 'k' looking for beginning of value", "should throw error with invalid packed config")
require.NoError(t, os.Remove(pFile), "removing packed config")
})

s.T().Run("unmanaged config is read with invalid unpacked files", func(t *testing.T) {
dCmd := s.makeDummyCmd()
uFile := GetFullPathToUnmanagedConf(dCmd)
pFile := GetFullPathToAppConf(dCmd)
SaveConfigs(dCmd, DefaultAppConfig(), DefaultTmConfig(), DefaultClientConfig(), false)
require.NoError(t, os.WriteFile(uFile, []byte("my-custom-entry = \"stuff\"\n"), 0o644), "writing unmanaged config")
require.NoError(t, os.WriteFile(pFile, []byte("kl234508923u5jl"), 0o644), "writing invalid data to app config")
require.EqualError(t, LoadConfigFromFiles(dCmd), "app config file merge error: While parsing config: toml: expected = after a key, but the document ends there", "should throw error with invalid packed config")
})

s.T().Run("unmanaged config is read with packed config", func(t *testing.T) {
dCmd := s.makeDummyCmd()
uFile := GetFullPathToUnmanagedConf(dCmd)
Expand Down
3 changes: 2 additions & 1 deletion docs/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1968,9 +1968,10 @@ Params defines the set of params for the account module.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `max_total_supply` | [uint64](#uint64) | | maximum amount of supply to allow a marker to be created with |
| `max_total_supply` | [uint64](#uint64) | | **Deprecated.** Deprecated: Prefer to use `max_supply` instead. Maximum amount of supply to allow a marker to be created with |
| `enable_governance` | [bool](#bool) | | indicates if governance based controls of markers is allowed. |
| `unrestricted_denom_regex` | [string](#string) | | a regular expression used to validate marker denom values from normal create requests (governance requests are only subject to platform coin validation denom expression) |
| `max_supply` | [string](#string) | | maximum amount of supply to allow a marker to be created with |



Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/otiai10/copy v1.12.0
github.com/rakyll/statik v0.1.7
github.com/regen-network/cosmos-proto v0.3.1
github.com/rs/zerolog v1.30.0
github.com/rs/zerolog v1.31.0
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
Expand Down Expand Up @@ -124,7 +124,7 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
Expand Down Expand Up @@ -161,7 +161,7 @@ require (
golang.org/x/net v0.12.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.126.0 // indirect
Expand Down
14 changes: 6 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,6 @@ github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVc
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
Expand All @@ -845,8 +844,8 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
Expand Down Expand Up @@ -1028,8 +1027,8 @@ github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U=
github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c=
github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w=
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down Expand Up @@ -1445,7 +1444,6 @@ golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210819135213-f52c844e1c1c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -1467,8 +1465,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
10 changes: 8 additions & 2 deletions proto/provenance/marker/v1/marker.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ message Params {
option (gogoproto.equal) = false;
option (gogoproto.goproto_stringer) = false;

// maximum amount of supply to allow a marker to be created with
uint64 max_total_supply = 1 [(gogoproto.customtype) = "uint64", (gogoproto.nullable) = false];
// Deprecated: Prefer to use `max_supply` instead. Maximum amount of supply to allow a marker to be created with
uint64 max_total_supply = 1 [(gogoproto.customtype) = "uint64", (gogoproto.nullable) = false, deprecated = true];
// indicates if governance based controls of markers is allowed.
bool enable_governance = 2;
// a regular expression used to validate marker denom values from normal create requests (governance
// requests are only subject to platform coin validation denom expression)
string unrestricted_denom_regex = 3;
// maximum amount of supply to allow a marker to be created with
string max_supply = 4 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "json:\"max_supply\" yaml:\"max_supply\""
];
}

// MarkerAccount holds the marker configuration information in addition to a base account structure.
Expand Down
3 changes: 2 additions & 1 deletion x/marker/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
var markerData markertypes.GenesisState
markerData.Params.EnableGovernance = true
markerData.Params.MaxTotalSupply = 1000000
markerData.Params.MaxSupply = sdk.NewInt(1000000)
// Note: These account numbers get ignored.
markerData.Markers = []markertypes.MarkerAccount{
{
Expand Down Expand Up @@ -455,7 +456,7 @@ func (s *IntegrationTestSuite) TestMarkerQueryCommands() {
[]string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
`{"max_total_supply":"1000000","enable_governance":true,"unrestricted_denom_regex":""}`,
`{"max_total_supply":"1000000","enable_governance":true,"unrestricted_denom_regex":"","max_supply":"1000000"}`,
},
{
"get testcoin marker json",
Expand Down
4 changes: 3 additions & 1 deletion x/marker/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"github.com/tendermint/tendermint/libs/log"

"cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -268,7 +270,7 @@ func (k Keeper) SetNetAssetValue(ctx sdk.Context, marker types.MarkerAccountI, n

key := types.NetAssetValueKey(marker.GetAddress(), netAssetValue.Price.Denom)
store := ctx.KVStore(k.storeKey)
if netAssetValue.Volume > marker.GetSupply().Amount.Uint64() {
if math.NewIntFromUint64(netAssetValue.Volume).GT(marker.GetSupply().Amount) {
return fmt.Errorf("volume(%v) cannot exceed marker %q supply(%v) ", netAssetValue.Volume, marker.GetDenom(), marker.GetSupply())
}

Expand Down
21 changes: 21 additions & 0 deletions x/marker/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,16 @@ func TestMsgSupplyIncreaseProposalRequest(t *testing.T) {
err = app.MarkerKeeper.AddMarkerAccount(ctx, nonActiveDenom)
require.NoError(t, err)

// exceed max supply
kneesBees := types.NewEmptyMarkerAccount(
"knees-bees",
user.String(),
[]types.AccessGrant{})
kneesBees.Status = types.StatusActive

err = app.MarkerKeeper.AddMarkerAccount(ctx, kneesBees)
require.NoError(t, err)

// all good
beesKnees := types.NewEmptyMarkerAccount(
"bees-knees",
Expand Down Expand Up @@ -1168,6 +1178,17 @@ func TestMsgSupplyIncreaseProposalRequest(t *testing.T) {
shouldFail: false,
expectedError: "",
},
{
name: "supply increase exceeds max supply",
amount: sdk.Coin{
Amount: types.StringToBigInt("1000000000000000000000"),
Denom: kneesBees.Denom,
},
targetAddress: authority,
authority: authority,
shouldFail: true,
expectedError: "requested supply 1000000000000000000000 exceeds maximum allowed value 100000000000000000000",
},
}

for _, tc := range testCases {
Expand Down
4 changes: 2 additions & 2 deletions x/marker/keeper/marker.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,10 @@ func (k Keeper) IncreaseSupply(ctx sdk.Context, marker types.MarkerAccountI, coi

inCirculation := sdk.NewCoin(marker.GetDenom(), k.bankKeeper.GetSupply(ctx, marker.GetDenom()).Amount)
total := inCirculation.Add(coin)
maxAllowed := sdk.NewCoin(marker.GetDenom(), sdk.NewIntFromUint64(k.GetParams(ctx).MaxTotalSupply))
maxAllowed := sdk.NewCoin(marker.GetDenom(), k.GetParams(ctx).MaxSupply)
if total.Amount.GT(maxAllowed.Amount) {
return fmt.Errorf(
"requested supply %d exceeds maximum allowed value %d", total.Amount, maxAllowed.Amount)
"requested supply %s exceeds maximum allowed value %s", total.Amount.String(), maxAllowed.Amount.String())
}

// If the marker has a fixed supply then adjust the supply to match the new total
Expand Down
Loading

0 comments on commit fc0bd2a

Please sign in to comment.