Some checks failed
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
Build & Push SDK Proto Builder / build (push) Has been cancelled
126 lines
3.6 KiB
Go
126 lines
3.6 KiB
Go
package v2_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
storetypes "cosmossdk.io/store/types"
|
|
|
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
|
"github.com/cosmos/cosmos-sdk/runtime"
|
|
"github.com/cosmos/cosmos-sdk/testutil"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
|
"github.com/cosmos/cosmos-sdk/x/authz"
|
|
v2 "github.com/cosmos/cosmos-sdk/x/authz/migrations/v2"
|
|
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
|
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
|
)
|
|
|
|
func TestMigration(t *testing.T) {
|
|
encodingConfig := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{}, bank.AppModuleBasic{})
|
|
cdc := encodingConfig.Codec
|
|
|
|
authzKey := storetypes.NewKVStoreKey("authz")
|
|
ctx := testutil.DefaultContext(authzKey, storetypes.NewTransientStoreKey("transient_test"))
|
|
granter1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
|
|
grantee1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
|
|
granter2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
|
|
grantee2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
|
|
|
|
sendMsgType := banktypes.SendAuthorization{}.MsgTypeURL()
|
|
genericMsgType := sdk.MsgTypeURL(&govtypes.MsgVote{})
|
|
coins100 := sdk.NewCoins(sdk.NewInt64Coin("atom", 100))
|
|
blockTime := ctx.BlockTime()
|
|
oneDay := blockTime.AddDate(0, 0, 1)
|
|
oneYear := blockTime.AddDate(1, 0, 0)
|
|
sendAuthz := banktypes.NewSendAuthorization(coins100, nil)
|
|
|
|
grants := []struct {
|
|
granter sdk.AccAddress
|
|
grantee sdk.AccAddress
|
|
msgType string
|
|
authorization func() authz.Grant
|
|
}{
|
|
{
|
|
granter1,
|
|
grantee1,
|
|
sendMsgType,
|
|
func() authz.Grant {
|
|
cdcAny, err := codectypes.NewAnyWithValue(sendAuthz)
|
|
require.NoError(t, err)
|
|
return authz.Grant{
|
|
Authorization: cdcAny,
|
|
Expiration: &oneDay,
|
|
}
|
|
},
|
|
},
|
|
{
|
|
granter1,
|
|
grantee2,
|
|
sendMsgType,
|
|
func() authz.Grant {
|
|
cdcAny, err := codectypes.NewAnyWithValue(sendAuthz)
|
|
require.NoError(t, err)
|
|
return authz.Grant{
|
|
Authorization: cdcAny,
|
|
Expiration: &oneDay,
|
|
}
|
|
},
|
|
},
|
|
{
|
|
granter2,
|
|
grantee1,
|
|
genericMsgType,
|
|
func() authz.Grant {
|
|
cdcAny, err := codectypes.NewAnyWithValue(authz.NewGenericAuthorization(genericMsgType))
|
|
require.NoError(t, err)
|
|
return authz.Grant{
|
|
Authorization: cdcAny,
|
|
Expiration: &oneYear,
|
|
}
|
|
},
|
|
},
|
|
{
|
|
granter2,
|
|
grantee2,
|
|
genericMsgType,
|
|
func() authz.Grant {
|
|
cdcAny, err := codectypes.NewAnyWithValue(authz.NewGenericAuthorization(genericMsgType))
|
|
require.NoError(t, err)
|
|
return authz.Grant{
|
|
Authorization: cdcAny,
|
|
Expiration: &blockTime,
|
|
}
|
|
},
|
|
},
|
|
}
|
|
|
|
storeService := runtime.NewKVStoreService(authzKey)
|
|
store := storeService.OpenKVStore(ctx)
|
|
|
|
for _, g := range grants {
|
|
grant := g.authorization()
|
|
require.NoError(t, store.Set(v2.GrantStoreKey(g.grantee, g.granter, g.msgType), cdc.MustMarshal(&grant)))
|
|
}
|
|
|
|
ctx = ctx.WithBlockTime(ctx.BlockTime().Add(1 * time.Hour))
|
|
require.NoError(t, v2.MigrateStore(ctx, storeService, cdc))
|
|
|
|
bz, err := store.Get(v2.GrantStoreKey(grantee1, granter2, genericMsgType))
|
|
require.NoError(t, err)
|
|
require.NotNil(t, bz)
|
|
|
|
bz, err = store.Get(v2.GrantStoreKey(grantee1, granter1, sendMsgType))
|
|
require.NoError(t, err)
|
|
require.NotNil(t, bz)
|
|
|
|
bz, err = store.Get(v2.GrantStoreKey(grantee2, granter2, genericMsgType))
|
|
require.NoError(t, err)
|
|
require.Nil(t, bz)
|
|
}
|