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

Use the bank module to keep track of scope value owners #2140

Merged
merged 162 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 155 commits
Commits
Show all changes
162 commits
Select commit Hold shift + click to select a range
da69d47
[2137]: Remove the MetadataKeeperI interface since it wasn't being us…
SpicyLemon Aug 26, 2024
c99cd35
[2137]: Add the bank keeper to the metadata keeper.
SpicyLemon Aug 26, 2024
633c577
[2137]: Add a Denom method to the MetadataAddress type.
SpicyLemon Aug 26, 2024
4bc387e
[2137]: Add BurnCoins to the BankKeeper interface since that'll be ne…
SpicyLemon Aug 26, 2024
94d7bf3
[2137]: Remove all of the value-owner -> index stuff with a couple TO…
SpicyLemon Aug 27, 2024
cc45639
[2137]: Create a struct that associates an acc address with a metadat…
SpicyLemon Aug 27, 2024
9bdad02
[2137]: Fix the import name of bank types in expected keepers.
SpicyLemon Aug 28, 2024
0604df1
[2137]: Create GetScopeValueOwner and GetScopeValueOwners keeper meth…
SpicyLemon Aug 28, 2024
b206244
[2137]: Expand the Denom test to include all the different types.
SpicyLemon Aug 28, 2024
8141a6d
[2137]: Create a Coin method on the MetadataAddress type.
SpicyLemon Aug 28, 2024
6d44a79
[2137]: Create ValidateAllAreScopes and Coins methods on the AccMDLin…
SpicyLemon Aug 28, 2024
5d58d65
[2137]: Remove InputOutputCoins from the interface and add GetSupply.
SpicyLemon Aug 28, 2024
4ffc996
[2137]: Add the module address to the metadata keeper so it can be re…
SpicyLemon Aug 28, 2024
caa7c62
[2137]: Rip out some more stuff from the UpdateValueOwners and Migrat…
SpicyLemon Aug 28, 2024
fd77599
[2137]: Create a method on the AccMDLinks type that will return a new…
SpicyLemon Aug 28, 2024
569e5bc
[2137]: Refactor SetScopeValueOwners to use the bank module for the s…
SpicyLemon Aug 28, 2024
582f2fb
[2137]: Remove the GetAccAddrs and GetMetadataAddrs methods from AccM…
SpicyLemon Aug 28, 2024
6e33891
[2137]: Put the MetadataAddress Prefix method back to the way it was …
SpicyLemon Aug 28, 2024
64ceecf
[2137]: Update IterateScopes to populate the value owner field. Creat…
SpicyLemon Aug 29, 2024
287acab
[2137]: In SetScope, clear out the value owner so that it'll always b…
SpicyLemon Aug 29, 2024
c66c259
[2137]: Create a PopulateScopeValueOwner method and use that in Itera…
SpicyLemon Aug 29, 2024
5c4d33e
[2137]: Update the queries that get scopes to get them with the value…
SpicyLemon Aug 29, 2024
1723ae8
[2137]: In ValidateWriteScope, get the scope with the value owner sin…
SpicyLemon Aug 29, 2024
7a260a8
[2137]: Refactor ValidateAllAreScopes into ValidateForScopes and have…
SpicyLemon Aug 30, 2024
77547f4
[2137]: Create ValidateIsScopeAddress since I was using that same cod…
SpicyLemon Aug 30, 2024
e669e63
[2137]: Tweak an ordering of checks and include the offending string …
SpicyLemon Aug 30, 2024
5e73cc7
[2137]: Create SetScopeValueOwner as the only place to mint/burn stuf…
SpicyLemon Aug 30, 2024
75af8e9
[2137]: Remove GetSupply and SpendableCoins from the BankKeeper inter…
SpicyLemon Aug 30, 2024
c98fb88
[2137]: In SetScopeValueOwner, do the DenomOwner lookup after checkin…
SpicyLemon Aug 30, 2024
217a075
[2137]: Unit tests on SetScopeValueOwner.
SpicyLemon Aug 30, 2024
3c630af
[2137]: Add a comment about the error string (that's still todo, but …
SpicyLemon Aug 30, 2024
a5fed4a
[2137]: Create a function to convert a denom back into the metadata a…
SpicyLemon Aug 30, 2024
d8c244c
[2137]: Re-implement the ValueOwnership query.
SpicyLemon Aug 30, 2024
5c31617
[2137]: Add the metedate module to the list of module accounts and gi…
SpicyLemon Aug 31, 2024
85e56ba
[2137]: Add a mint coins restriction to the metadata module that ensu…
SpicyLemon Aug 31, 2024
a35282e
[2137]: Update SetScope and RemoveScope to set/update/delete the valu…
SpicyLemon Aug 31, 2024
d77d9c3
[2137]: In the UpdateValueOwnersCmd, make it return the error when it…
SpicyLemon Sep 3, 2024
760f080
[2137]: Add cosmossdk.io/collections to the allowed imports list.
SpicyLemon Sep 3, 2024
a0700b1
[2137]: Fix import ordering in expected keepers.
SpicyLemon Sep 3, 2024
7f0dd55
[2137]: Pay attention to the new new error return value from SetScope…
SpicyLemon Sep 3, 2024
2691113
[2137]: Update the pagination in ValueOwnership to use CollectionPagi…
SpicyLemon Sep 3, 2024
36e2e53
[2137]: Create the GetAccAddrs method on AccMDLinks (again) since I n…
SpicyLemon Sep 3, 2024
f690914
[2137]: Update the marker context helpers to allow providing more tha…
SpicyLemon Sep 4, 2024
ff6f00e
[2137]: Update the ValidateUpdateValueOwners method and re-implement …
SpicyLemon Sep 4, 2024
c59de1e
[2137]: Remove MsgUpdateValueOwnersRequest and MsgMigrateValueOwnerRe…
SpicyLemon Sep 4, 2024
b40da81
[2137]: Fix a couple uses of %w in non-error format strings.
SpicyLemon Sep 4, 2024
f8f0160
[2137]: Remove a struct initilization that I originally used to have …
SpicyLemon Sep 5, 2024
fb4dc5d
[2137]: Redo unit tests on ValidateUpdateValueOwners and tweak it to …
SpicyLemon Sep 5, 2024
f1e667f
[2137]: Add a todo to the bank keeper wrapper thingy to make it easie…
SpicyLemon Sep 6, 2024
60c0493
[2137]: Create ValidateScopeValueOwnerSigned as a replacement to Vali…
SpicyLemon Sep 6, 2024
0cfd456
[2137]: Remove the DefaultParamspace variable since it's unused and f…
SpicyLemon Sep 6, 2024
c9a0e82
[2137]: Create VerifyMetadataAddressHasType as a generic way to both …
SpicyLemon Sep 6, 2024
52e92d2
[2137]: Update Scope.ValidateBasic to use the new ValidateIsScopeAddr…
SpicyLemon Sep 6, 2024
6f6f721
[2137]: Split the scope writing portion of SetScope out into writeSco…
SpicyLemon Sep 6, 2024
5e10256
Merge branch 'main' into dwedul/2137-bank-scope-value-owners
SpicyLemon Sep 6, 2024
04e2673
[2137]: In MetadataAddress.String(), if it's not valid, have it outpu…
SpicyLemon Sep 7, 2024
8dfe1ee
[2137]: Add the transfer agents to the context in the endpoints that …
SpicyLemon Sep 9, 2024
e64b3fc
[2137]: Get rid of the AccMDLinks.Coins method since it wasn't used a…
SpicyLemon Sep 9, 2024
bf01ad2
[2137]: Fix a few unit tests. TestSetScopeValueOwner started failling…
SpicyLemon Sep 9, 2024
17b53ba
[2137]: Update RemoveScope to return an error instead of panicking. F…
SpicyLemon Sep 10, 2024
4396ee2
[2137]: Delete the GetMarkerAndCheckAuthority, validateScopeValueOwne…
SpicyLemon Sep 10, 2024
657ceda
[2137]: Get rid of the GetBalancesCollection method on MDBankKeeper, …
SpicyLemon Sep 11, 2024
7b35ead
[2137]: Unit tests on the DenomOwner MDBankKeeper method.
SpicyLemon Sep 11, 2024
d425d1c
[2137]: Finish unit tests on the MDBankKeeper.
SpicyLemon Sep 12, 2024
7925490
[2137]: Remove the mintCoinsRestriction since we're only minting in o…
SpicyLemon Sep 12, 2024
c6e9537
[2137]: Replace the ValidateScopeValueOwnerSigned keeper method with …
SpicyLemon Sep 16, 2024
0bc6668
[2137]: Take out the part where a value owner is required to write a …
SpicyLemon Sep 16, 2024
1842a76
[2137]: Expand marker unit tests to account for the allowance of mult…
SpicyLemon Sep 16, 2024
5284895
[2137]: Update marker flowcharts to reflect the possibility of multip…
SpicyLemon Sep 16, 2024
886d01b
[2137]: In TestValidateDeleteScope, make it run all the tests when on…
SpicyLemon Sep 16, 2024
0823282
[2137]: Unit tests on IsMarkerAddr.
SpicyLemon Sep 16, 2024
5d91f32
[2137]: Create the IsMarkerAccount method on the marker keeper that d…
SpicyLemon Sep 16, 2024
5338549
[2137]: Get rid of the metadata module's version of IsMarkerAddr and …
SpicyLemon Sep 16, 2024
cd1642b
[2137]: Have ValidateScopeValueOwnersSigners return the transfer agen…
SpicyLemon Sep 17, 2024
ad6ea3a
[2137]: Unit tests on ValidateScopeValueOwnersSigners.
SpicyLemon Sep 17, 2024
af7da92
[2137]: Redo the tests on ValidateUpdateValueOwners since a bulk of t…
SpicyLemon Sep 17, 2024
457bac7
[2137]: Identify all of the keeper tests that fail and add TODOs to t…
SpicyLemon Sep 17, 2024
9ef824c
[2137]: Identify all of the cli tests that fail and add TODOs to them.
SpicyLemon Sep 17, 2024
e81b3b4
[2137]: Move PartyDetails, UsedSignersMap, and the AuthzCache stuff o…
SpicyLemon Sep 18, 2024
9badbe6
[2137]: Unit tests on Ternary and Pluralize and the rest of the signe…
SpicyLemon Sep 18, 2024
7bedd86
[2137]: Update ValidateScopeValueOwnersSigners: If there's no existin…
SpicyLemon Sep 19, 2024
d2e7926
[2137]: In ValidateWriteScope, make sure there's a spec id. Update Te…
SpicyLemon Sep 19, 2024
67a6706
[2137]: Fix TestWriteScopeSmartContractValueOwnerAuthz.
SpicyLemon Sep 19, 2024
6d8f5ea
[2137]: Overhaul and fix TestSetScopeValueOwners.
SpicyLemon Sep 19, 2024
3412c62
[2137]: Fix TestValidateDeleteScope and add a couple cases.
SpicyLemon Sep 19, 2024
0e5d796
[2137]: Fix TestAddAndDeleteScopeDataAccess and TestAddAndDeleteScope…
SpicyLemon Sep 19, 2024
3483fde
[2137]: Redo the unit tests on the Scope query since they were failin…
SpicyLemon Sep 21, 2024
2ac9713
[2137]: Unit tests on the ScopesAll query.
SpicyLemon Sep 21, 2024
304cd1c
[2137]: Remove the keeper's needsUpdate function since it's not neede…
SpicyLemon Sep 21, 2024
0d162f4
Merge branch 'main' into dwedul/2137-bank-scope-value-owners
SpicyLemon Sep 21, 2024
c0333eb
[2137]: Delete a couple TODO comments that are TODONE.
SpicyLemon Sep 23, 2024
88ed8c8
[2137]: Initial work on WriteScope tests.
SpicyLemon Sep 23, 2024
da63f00
[2137]: When reading a scope from state, clear out the ValueOwnerAddr…
SpicyLemon Sep 24, 2024
3dc6ad2
[2137]: Finish the unit tests on WriteScope.
SpicyLemon Sep 24, 2024
082036b
[2137]: Create a Coins() method on the MetadataAddress struct that ju…
SpicyLemon Sep 24, 2024
3285984
[2137]: Create the EventsBuilder in an attempt to make it easier to c…
SpicyLemon Sep 24, 2024
d47f086
[2137]: Create a non-method way to write all the stuff in a dataSetup.
SpicyLemon Sep 24, 2024
32016ef
[2137]: Unit tests on the DeleteScope endpoint. Switch the WriteScope…
SpicyLemon Sep 24, 2024
82bfb5a
[2137]: Fix TestScopesPagination.
SpicyLemon Sep 25, 2024
924d0e4
[2137]: Re-enable TestScopeTxCommands. I must have fixed whatever had…
SpicyLemon Sep 25, 2024
2acfe29
[2137]: Add a couple test cases to TestUpdateValueOwners, one of whic…
SpicyLemon Sep 25, 2024
8319648
[2137]: Re-enable TestUpdateMigrateValueOwnersCmds and fix one of the…
SpicyLemon Sep 25, 2024
052a803
[2137]: Delete an empty line from the end of the TestDeleteOSLocator …
SpicyLemon Sep 25, 2024
9fbcf00
[2137]: Create some helpers for writing stuff to the test logs.
SpicyLemon Sep 25, 2024
d784467
[2137]: Create a GetMDAddrsForAccAddr method on the AccMDAddrs type.
SpicyLemon Sep 25, 2024
aca9d44
[2137]: Add t.Helper() to the testlog stuff so that the log messages …
SpicyLemon Sep 25, 2024
b2b3c81
[2137]: Get rid of the namedValue stuff in the metadata module and sw…
SpicyLemon Sep 25, 2024
7e32957
[2137]: Switch GetMDAddrsForAccAddr to take in a string since that's …
SpicyLemon Sep 25, 2024
45eede6
[2137]: In ValidateUpdateValueOwners, return an error if any of the s…
SpicyLemon Sep 25, 2024
f6abb2c
[2137]: Fix a test case in TestUpdateValueOwners that still had a TOD…
SpicyLemon Sep 25, 2024
97f5710
[2137]: Fix TestGetOwnershipCmd. It's the last of the broken unit tests.
SpicyLemon Sep 26, 2024
17593be
[2137]: Fix the import section of keeper/signers_utils.go.
SpicyLemon Sep 26, 2024
74c822b
[2137]: In Scope.ValidateBasic, don't allow the spec id to be empty.
SpicyLemon Sep 26, 2024
f67c972
[2137]: Bump the metadata consensus version to 4 and create an empty …
SpicyLemon Sep 26, 2024
8902681
[2137]: Add TODO to update the spec docs.
SpicyLemon Sep 26, 2024
d7f4a95
[2137]: Create a Pair struct. Ugh.
SpicyLemon Sep 26, 2024
1714816
[2137]: Write the metadata 3 to 4 migration.
SpicyLemon Sep 27, 2024
5296c31
[2137]: Remove the ValueOwnerScopeCacheKeyPrefix since it's now only …
SpicyLemon Sep 27, 2024
f9e4b48
[2137]: Delete the GetMaccPerms function since it's not used.
SpicyLemon Sep 27, 2024
2e7da4e
[2137]: Add the viridian upgrade.
SpicyLemon Sep 27, 2024
5dfb8a4
[2137]: Create V3CreateScope to help facilitate testing, and switch t…
SpicyLemon Sep 27, 2024
a16b8b1
[2137]: Fix import ordering in app/upgrades.go.
SpicyLemon Sep 27, 2024
798f5b6
[2137]: Change the name of the panic-checking func in TestValidateWri…
SpicyLemon Sep 27, 2024
32bbc2a
[2137]: Write an upgrades test that creates 300,005 scopes and migrat…
SpicyLemon Sep 27, 2024
78762fa
[2137]: Bypass the marker send restriction in the metadata migration.
SpicyLemon Sep 27, 2024
99d1e90
[2137]: Update the comment on the value_owner_address field in the pr…
SpicyLemon Sep 30, 2024
bac2748
[2137]: Update the line numbers in the spec docs links to scope.proto…
SpicyLemon Sep 30, 2024
4579f67
[2137]: Update the spec docs to reflect the new value owner storage. …
SpicyLemon Sep 30, 2024
3feeca2
Merge branch 'main' into dwedul/2137-bank-scope-value-owners
SpicyLemon Sep 30, 2024
e9c0ab2
[2137]: Add some changelog entries.
SpicyLemon Sep 30, 2024
34de853
[2137]: Add a changelog entry for the viridian upgrade.
SpicyLemon Sep 30, 2024
0899ba2
[2137]: Create a GetNetAssetValue method in the metadata module so th…
SpicyLemon Sep 30, 2024
8c399e1
[2137]: In the exchange module, record scope navs when applicable.
SpicyLemon Sep 30, 2024
5cfa116
Merge branch 'main' into dwedul/2137-bank-scope-value-owners
SpicyLemon Sep 30, 2024
c8075c7
[2137]: Use the correct formatting verb when logging the error about …
SpicyLemon Sep 30, 2024
3dd85af
[2137]: Update unit tests on the exchange keeper's GetNav method.
SpicyLemon Oct 1, 2024
5f0b18b
[2137]: Add some exchange test stuff involving scopes.
SpicyLemon Oct 1, 2024
5ca0f19
[2137]: Update the comments related to #2160.
SpicyLemon Oct 1, 2024
c431f76
[2137]: Tweak the migration to remove a panic that would happen if an…
SpicyLemon Oct 1, 2024
b7ee85b
[2137]: Unit tests on AtLeastOneAddrHasAccess and ValidateAtLeastOneA…
SpicyLemon Oct 2, 2024
6109fce
[2137]: Update WithTransferAgents to set the value to a nil list of a…
SpicyLemon Oct 2, 2024
9ca0d46
[2137]: Fix a couple typos in the testlog stuff.
SpicyLemon Oct 2, 2024
a72dce1
[2137]: Change the first arg of AddBurnCoinsStrs to moduleAddr for co…
SpicyLemon Oct 2, 2024
5a9be42
[2137]: Fix a typo in a slices test case.
SpicyLemon Oct 2, 2024
0132712
[2137]: Provide the scope id to emitMetadataNAVEvents.
SpicyLemon Oct 2, 2024
3357840
[2137]: Remove SpendableCoin from the BankKeeper and fix a couple Moc…
SpicyLemon Oct 2, 2024
0c9964f
[2137]: Remove the panic from RemoveScope and instead return an error.
SpicyLemon Oct 2, 2024
73150eb
[2137]: In TestUsedSignersMap, move the isUsed checks into the test r…
SpicyLemon Oct 2, 2024
d96d84d
Merge branch 'main' into dwedul/2137-bank-scope-value-owners
SpicyLemon Oct 2, 2024
a89c2ad
[2137]: Swap out some TODOs involving metadata nav volume in the keep…
SpicyLemon Oct 2, 2024
bd72fe9
[2137]: In the metadata keeper's GetNetAssetValue method, default the…
SpicyLemon Oct 2, 2024
05a2aa5
[2137]: Update the stuff in the exchange module that needs to use the…
SpicyLemon Oct 2, 2024
357c8b3
[2137]: Fix the WriteScope tests that should not be expecting a NAV i…
SpicyLemon Oct 2, 2024
7aa4cdb
[2137]: Fix the exchange tests that failed with the addition of Volum…
SpicyLemon Oct 2, 2024
010a3dc
Merge branch 'main' into dwedul/2137-bank-scope-value-owners
SpicyLemon Oct 2, 2024
711cbfe
Merge branch 'main' into dwedul/2137-bank-scope-value-owners
SpicyLemon Oct 7, 2024
1881743
[2137]: Remove a couple unused proto imports.
SpicyLemon Oct 7, 2024
4fa80b7
[2137]: Regenerate stuff from the protos.
SpicyLemon Oct 7, 2024
089e7f8
Merge branch 'main' into dwedul/2137-bank-scope-value-owners
SpicyLemon Oct 7, 2024
72b6033
Merge branch 'main' into dwedul/2137-bank-scope-value-owners
SpicyLemon Oct 8, 2024
18b2136
[2137]: Remove incorrect comments from PartyDetails.
SpicyLemon Oct 8, 2024
02a0858
[2137]: Update BuildPartyDetails to use some slices stuff so we don't…
SpicyLemon Oct 8, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
* The `Ownership` query in the `x/metadata` module now only returns scopes that have the provided address in the `owners` list [#2137](https://github.com/provenance-io/provenance/issues/2137).
Previously, if an address was the value owner of a scope, but not in the `owners` list, the scope would be returned
by the `Ownership` query when given that address. That is no longer the case.
The `ValueOwnership` query can be to identify scopes with a specific value owner (like before).
If a scope has a value owner that is also in its `owners` list, it will still be returned by both queries.
* The `WriteScope` endpoint now uses the `scope.value_owner_address` differently [#2137](https://github.com/provenance-io/provenance/issues/2137).
If it is empty, it indicates that there is no change to the value owner of the scope and the releated lookups and validation
are skipped. If it isn't empty, the current value owner will be looked up and the coin for the scope will be transferred to
the provided address (assuming signer validation passed).
* An authz grant on `MsgWriteScope` no longer also applies to the `UpdateValueOwners` or `MigrateValueOwner` endpoints [#2137](https://github.com/provenance-io/provenance/issues/2137).
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Create the `viridian` upgrade. [#2137](https://github.com/provenance-io/provenance/issues/2137).
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Use the bank module to keep track of the value owner of scopes. [#2137](https://github.com/provenance-io/provenance/issues/2137).
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ linters-settings:

- cosmossdk.io/api
- cosmossdk.io/client/v2/autocli
- cosmossdk.io/collections
- cosmossdk.io/core
- cosmossdk.io/errors
- cosmossdk.io/log
Expand Down
13 changes: 3 additions & 10 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ var (
wasmtypes.ModuleName: {authtypes.Burner},
triggertypes.ModuleName: nil,
oracletypes.ModuleName: nil,
metadatatypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}
)

Expand Down Expand Up @@ -580,7 +581,7 @@ func New(
)

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

app.HoldKeeper = holdkeeper.NewKeeper(
Expand All @@ -590,6 +591,7 @@ func New(
app.ExchangeKeeper = exchangekeeper.NewKeeper(
appCodec, keys[exchange.StoreKey], authtypes.FeeCollectorName,
app.AccountKeeper, app.AttributeKeeper, app.BankKeeper, app.HoldKeeper, app.MarkerKeeper,
app.MetadataKeeper,
)

pioMessageRouter := MessageRouterFunc(func(msg sdk.Msg) baseapp.MsgServiceHandler {
Expand Down Expand Up @@ -1312,15 +1314,6 @@ func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router, swaggerEnabled bool)
return nil
}

// GetMaccPerms returns a copy of the module account permissions
func GetMaccPerms() map[string][]string {
dupMaccPerms := make(map[string][]string)
for k, v := range maccPerms {
dupMaccPerms[k] = v
}
return dupMaccPerms
}

// initParamsKeeper init params keeper and its subspaces
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)
Expand Down
5 changes: 0 additions & 5 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) {
require.NoError(t, err, "ExportAppStateAndValidators at zero height")
}

func TestGetMaccPerms(t *testing.T) {
dup := GetMaccPerms()
require.Equal(t, maccPerms, dup, "duplicated module account permissions differed from actual module account permissions")
}

func TestExportAppStateAndValidators(t *testing.T) {
opts := SetupOptions{
Logger: log.NewTestLogger(t),
Expand Down
26 changes: 26 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,32 @@ var upgrades = map[string]appUpgrade{
return vm, nil
},
},
"viridian-rc1": { // upgrade for v1.20.0-rc1
Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) {
var err error
if err = pruneIBCExpiredConsensusStates(ctx, app); err != nil {
return nil, err
}
if vm, err = runModuleMigrations(ctx, app, vm); err != nil {
return nil, err
}
removeInactiveValidatorDelegations(ctx, app)
return vm, nil
},
},
"viridian": { // upgrade for v1.20.0
Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) {
var err error
if err = pruneIBCExpiredConsensusStates(ctx, app); err != nil {
return nil, err
}
if vm, err = runModuleMigrations(ctx, app, vm); err != nil {
return nil, err
}
removeInactiveValidatorDelegations(ctx, app)
return vm, nil
},
},
// TODO - Add new upgrade definitions here.
}

Expand Down
234 changes: 234 additions & 0 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

internalsdk "github.com/provenance-io/provenance/internal/sdk"
metadatakeeper "github.com/provenance-io/provenance/x/metadata/keeper"
metadatatypes "github.com/provenance-io/provenance/x/metadata/types"
)

Expand Down Expand Up @@ -1022,3 +1023,236 @@ func (s *UpgradeTestSuite) TestExecuteStoreCodeMsg() {
})
}
}

func (s *UpgradeTestSuite) TestViridianRC1() {
expInLog := []string{
"INF Pruning expired consensus states for IBC.",
"INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.",
"INF Removing inactive validator delegations.",
}
s.AssertUpgradeHandlerLogs("viridian-rc1", expInLog, nil)
}
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved

func (s *UpgradeTestSuite) TestViridian() {
expInLog := []string{
"INF Pruning expired consensus states for IBC.",
"INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.",
"INF Removing inactive validator delegations.",
}
s.AssertUpgradeHandlerLogs("viridian", expInLog, nil)
}

func (s *UpgradeTestSuite) TestMetadataMigration() {
// TODO: Delete this test with the rest of the viridian stuff.
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
newAddr := func(name string) sdk.AccAddress {
switch {
case len(name) < 20:
// If it's less than 19 bytes long, pad it to 20 chars.
return sdk.AccAddress(name + strings.Repeat("_", 20-len(name)))
case len(name) > 20 && len(name) < 32:
// If it's 21 to 31 bytes long, pad it to 32 chars.
return sdk.AccAddress(name + strings.Repeat("_", 32-len(name)))
}
// If the name is exactly 20 long already, or longer than 32, don't include any padding.
return sdk.AccAddress(name)
}
addrs := make([]string, 1000)
for i := range addrs {
addrs[i] = newAddr(fmt.Sprintf("%03d", i)).String()
}

newUUID := func(i int) uuid.UUID {
// Sixteen 9's is the largest number we can handle; one more and it's 17 digits.
s.Require().LessOrEqual(i, 9999999999999999, "value provided to newScopeID")
str := fmt.Sprintf("________________%d", i)
str = str[len(str)-16:]
rv, err := uuid.FromBytes([]byte(str))
s.Require().NoError(err, "uuid.FromBytes([]byte(%q))", str)
return rv
}
newScopeID := func(i int) metadatatypes.MetadataAddress {
return metadatatypes.ScopeMetadataAddress(newUUID(i))
}
newSpecID := func(i int) metadatatypes.MetadataAddress {
// The spec id shouldn't really matter in here, but I want it different from a scope's index.
// So I do some math to make it seem kind of random, but is still deterministic.
// 7, 39, and 79 were picked randomly and have no special meaning.
// 4,999 was chosen so that there's 3,333 possible results.
// This will overflow at 2,097,112, but it shouldn't get bigger than 300,000 in here, so we ignore that.
j := ((i + 7) * (i + 39) * (i + 79)) % 49_999
return metadatatypes.ScopeSpecMetadataAddress(newUUID(j))
}
newScope := func(i int) metadatatypes.Scope {
rv := metadatatypes.Scope{
ScopeId: newScopeID(i),
SpecificationId: newSpecID(i),
RequirePartyRollup: i%6 > 2, // 50% chance, three false, then three true, repeated.
}

// 1 in 7 does not have a value owner.
incVO := i%7 != 0
if incVO {
rv.ValueOwnerAddress = addrs[i%len(addrs)]
}

// Include 1 to 5 owners and make one of them the value owner in just under 1 in 11 scopes.
ownerCount := (i % 5) + 1
incVOInOwners := incVO && i%11 == 0
incVOAt := i % ownerCount
rv.Owners = make([]metadatatypes.Party, ownerCount)
for o := range rv.Owners {
a := i + (o+1)*300
if incVOInOwners && o == incVOAt {
a = i
}
rv.Owners[o].Address = addrs[a%len(addrs)]
rv.Owners[o].Role = metadatatypes.PartyType(1 + (i+o)%11) // 11 different roles, 1 to 11.
}

daCount := (i % 3) // 0 to 2.
for d := 0; d < daCount; d++ {
a := i + (d+1)*33
rv.DataAccess = append(rv.DataAccess, addrs[a%len(addrs)])
}

return rv
}
voInOwners := func(scope metadatatypes.Scope) bool {
if len(scope.ValueOwnerAddress) == 0 {
return false
}
for _, owner := range scope.Owners {
if owner.Address == scope.ValueOwnerAddress {
return true
}
}
return false
}

// Create 300,005 scopes and write them to state.
// 6 of 7 have a value owner = 257_147 = 300_005 * 6 / 7 (truncated).
// 1 of 7 do not = 42_858 = 300_005 - 257_147 .
// There's 23,377 scopes that have the value owner in owners.
// So we expect 490,917 keys to delete = 257,147 * 2 - 23,377.
expCoin := make([]metadatatypes.MetadataAddress, 0, 257_147)
expNoCoin := make([]metadatatypes.MetadataAddress, 0, 42_858)
expDelInds := make([][]byte, 0, 490_917)
expBals := make(map[string]sdk.Coins)
t1 := time.Now()
for i := 0; i < 300_005; i++ {
scope := newScope(i)
s.Require().NoError(s.app.MetadataKeeper.V3WriteNewScope(s.ctx, scope), "[%d]: V3WriteNewScope", i)

if len(scope.ValueOwnerAddress) == 0 {
expNoCoin = append(expNoCoin, scope.ScopeId)
continue
}

expCoin = append(expCoin, scope.ScopeId)

vo := scope.ValueOwnerAddress
voAddr := sdk.MustAccAddressFromBech32(vo)
expDelInds = append(expDelInds, metadatakeeper.GetValueOwnerScopeCacheKey(voAddr, scope.ScopeId))
if !voInOwners(scope) {
expDelInds = append(expDelInds, metadatatypes.GetAddressScopeCacheKey(voAddr, scope.ScopeId))
}

expBals[vo] = expBals[vo].Add(scope.ScopeId.Coin())
}
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
t2 := time.Now()
s.T().Logf("setup took %s", t2.Sub(t1))
s.T().Logf("len(expDelInds) = %d", len(expDelInds))
s.T().Logf("len(expCoin) = %d", len(expCoin))
s.T().Logf("len(expNoCoin) = %d", len(expNoCoin))

mdStore := s.ctx.KVStore(s.app.GetKey(metadatatypes.ModuleName))
for _, ind := range expDelInds {
has := mdStore.Has(ind)
s.Assert().True(has, "mdStore.Has(%v) before running the migrations", ind)
}
mdStore = nil

expLogs := []string{
"INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.",
"INF Starting migration of x/metadata from 3 to 4. module=x/metadata",
"INF Moving scope value owner data into x/bank ledger. module=x/metadata",
"INF Progress update: module=x/metadata scopes=10000 value owners=8571",
"INF Progress update: module=x/metadata scopes=20000 value owners=17143",
"INF Progress update: module=x/metadata scopes=30000 value owners=25714",
"INF Progress update: module=x/metadata scopes=40000 value owners=34286",
"INF Progress update: module=x/metadata scopes=50000 value owners=42857",
"INF Progress update: module=x/metadata scopes=60000 value owners=51428",
"INF Progress update: module=x/metadata scopes=70000 value owners=60000",
"INF Progress update: module=x/metadata scopes=80000 value owners=68571",
"INF Progress update: module=x/metadata scopes=90000 value owners=77143",
"INF Progress update: module=x/metadata scopes=100000 value owners=85714",
"INF Progress update: module=x/metadata scopes=110000 value owners=94286",
"INF Progress update: module=x/metadata scopes=120000 value owners=102857",
"INF Progress update: module=x/metadata scopes=130000 value owners=111428",
"INF Progress update: module=x/metadata scopes=140000 value owners=120000",
"INF Progress update: module=x/metadata scopes=150000 value owners=128571",
"INF Progress update: module=x/metadata scopes=160000 value owners=137143",
"INF Progress update: module=x/metadata scopes=170000 value owners=145714",
"INF Progress update: module=x/metadata scopes=180000 value owners=154286",
"INF Progress update: module=x/metadata scopes=190000 value owners=162857",
"INF Progress update: module=x/metadata scopes=200000 value owners=171428",
"INF Progress update: module=x/metadata scopes=210000 value owners=180000",
"INF Progress update: module=x/metadata scopes=220000 value owners=188572",
"INF Progress update: module=x/metadata scopes=230000 value owners=197143",
"INF Progress update: module=x/metadata scopes=240000 value owners=205714",
"INF Progress update: module=x/metadata scopes=250000 value owners=214286",
"INF Progress update: module=x/metadata scopes=260000 value owners=222857",
"INF Progress update: module=x/metadata scopes=270000 value owners=231429",
"INF Progress update: module=x/metadata scopes=280000 value owners=240000",
"INF Progress update: module=x/metadata scopes=290000 value owners=248572",
"INF Progress update: module=x/metadata scopes=300000 value owners=257143",
"INF Done moving scope value owners into bank module. module=x/metadata scopes=300005 value owners=257147",
"INF Done migrating x/metadata from 3 to 4. module=x/metadata",
"INF Module migrations completed.",
}

vm, err := s.app.UpgradeKeeper.GetModuleVersionMap(s.ctx)
s.Require().NoError(err, "GetModuleVersionMap")
s.Require().Equal(4, int(vm[metadatatypes.ModuleName]), "%s module version", metadatatypes.ModuleName)
// Drop it back to 3 so the migration runs.
vm[metadatatypes.ModuleName] = 3

runner := func() {
t1 = time.Now()
vm, err = runModuleMigrations(s.ctx, s.app, vm)
t2 = time.Now()
}
s.ExecuteAndAssertLogs(runner, expLogs, nil, true, "runModuleMigrations")
s.Assert().NoError(err, "error from runModuleMigrations")
s.Assert().Equal(4, int(vm[metadatatypes.ModuleName]), "vm[metadatatypes.ModuleName]")
s.T().Logf("runModuleMigrations took %s", t2.Sub(t1))

for _, scopeID := range expCoin {
denom := scopeID.Denom()
supply := s.app.BankKeeper.GetSupply(s.ctx, denom)
s.Assert().Equal("1"+denom, supply.String(), "GetSupply(%q)", denom)
}

for _, scopeID := range expNoCoin {
denom := scopeID.Denom()
supply := s.app.BankKeeper.GetSupply(s.ctx, denom)
s.Assert().Equal("0"+denom, supply.String(), "GetSupply(%q)", denom)
}

for i, addr := range addrs {
accAddr := sdk.MustAccAddressFromBech32(addr)
actBal := s.app.BankKeeper.GetAllBalances(s.ctx, accAddr)
for _, expCoin := range expBals[addr] {
found, actCoin := actBal.Find(expCoin.Denom)
if s.Assert().True(found, "[%d]%q: found bool from actBal.Find(%q)", i, addr, expCoin.Denom) {
s.Assert().Equal(expCoin.String(), actCoin.String(), "[%d]%q: balance coin for %q", i, addr, expCoin.Denom)
}
}
}

mdStore = s.ctx.KVStore(s.app.GetKey(metadatatypes.ModuleName))
for _, ind := range expDelInds {
has := mdStore.Has(ind)
s.Assert().False(has, "mdStore.Has(%v) after running the migrations", ind)
}
}
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading