Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ require (
github.com/lestrrat-go/jwx/v2 v2.1.6
github.com/mizufinance/decaf377-go v0.1.0
github.com/skip-mev/block-sdk/v2 v2.1.5
github.com/sourcenetwork/acp_core v0.8.1
github.com/sourcenetwork/raccoondb v0.2.1-0.20240722161350-d4a78b691ec8
github.com/sourcenetwork/acp_core v0.8.2-0.20260515161012-1ff695ed0fa0
github.com/sourcenetwork/raccoondb v0.2.1-0.20260514175348-017fdf639300
github.com/sourcenetwork/raccoondb/v2 v2.0.0
github.com/spf13/cobra v1.10.1
github.com/spf13/pflag v1.0.10
Expand Down Expand Up @@ -405,7 +405,7 @@ require (
github.com/sonatard/noctx v0.0.2 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/sourcegraph/go-diff v0.7.0 // indirect
github.com/sourcenetwork/zanzi v0.3.1-0.20251104182341-4b1bd0f7be5a // indirect
github.com/sourcenetwork/zanzi v0.3.1-0.20260514183406-33141096311f // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2322,14 +2322,20 @@ github.com/sourcegraph/go-diff v0.7.0 h1:9uLlrd5T46OXs5qpp8L/MTltk0zikUGi0sNNyCp
github.com/sourcegraph/go-diff v0.7.0/go.mod h1:iBszgVvyxdc8SFZ7gm69go2KDdt3ag071iBaWPF6cjs=
github.com/sourcenetwork/acp_core v0.8.1 h1:xCbFGs9HqQTG/LjfNa7aoD8dc6XhIYLgRdZCQrRcML0=
github.com/sourcenetwork/acp_core v0.8.1/go.mod h1:vmxU/mBphMaU2NjKYEFJLSpk5lbRdWDqgsJZNd+WfZ0=
github.com/sourcenetwork/acp_core v0.8.2-0.20260515161012-1ff695ed0fa0 h1:x1B/w2qRrM29HxKRPzmkljuBYHvtrZ4T7kKj7WakqqE=
github.com/sourcenetwork/acp_core v0.8.2-0.20260515161012-1ff695ed0fa0/go.mod h1:ecaSdQoRK433BJexbrr1LzYuG/I/D47tAeXt7C2e0O0=
github.com/sourcenetwork/corekv v0.0.0-20250122161438-c4cec0f30dbe h1:xML1pxD5zf14MAqjCkW584ri6yjp6go+ud83wpMzWtM=
github.com/sourcenetwork/corekv v0.0.0-20250122161438-c4cec0f30dbe/go.mod h1:hap4+bqs9JcHPcAMALLj2Vu+QDxmHwYBlRyv8mlwsw4=
github.com/sourcenetwork/raccoondb v0.2.1-0.20240722161350-d4a78b691ec8 h1:d0jNogSYqMt+dC05tnd+x7lmzEcBHpKoIU5woZSSHFM=
github.com/sourcenetwork/raccoondb v0.2.1-0.20240722161350-d4a78b691ec8/go.mod h1:/WJdZWouiY199DypsN0xaP5PF0zy3rka3FxH5Y8o9Bc=
github.com/sourcenetwork/raccoondb v0.2.1-0.20260514175348-017fdf639300 h1:Cg44ZTo3jot8806J91dFd0Un6gcYjheUy4sz7XnI7k4=
github.com/sourcenetwork/raccoondb v0.2.1-0.20260514175348-017fdf639300/go.mod h1:/WJdZWouiY199DypsN0xaP5PF0zy3rka3FxH5Y8o9Bc=
github.com/sourcenetwork/raccoondb/v2 v2.0.0 h1:Gb0SjsZUbrbkHCEg7PyyNs0+2IzPxjE/BkEQnlu1nfA=
github.com/sourcenetwork/raccoondb/v2 v2.0.0/go.mod h1:tPKAWHUgYcSoXNMt01iWJ+Y51AQYc2knY93IjmmbejY=
github.com/sourcenetwork/zanzi v0.3.1-0.20251104182341-4b1bd0f7be5a h1:TlnRmk1v4+nIKGUdzMht4qnrf8AxCUAvpxSIqJ2CX94=
github.com/sourcenetwork/zanzi v0.3.1-0.20251104182341-4b1bd0f7be5a/go.mod h1:j7QmuHK+zfA0JO6FliJzQHijVNSXDuQy8hUzFC5pucA=
github.com/sourcenetwork/zanzi v0.3.1-0.20260514183406-33141096311f h1:uURLAfIX+KnaQJqNFLy+Sr8MKRcQ2bAmwilHBB4lg7I=
github.com/sourcenetwork/zanzi v0.3.1-0.20260514183406-33141096311f/go.mod h1:Elj7mNEfkthXGmHOdyfbPMBaJQqKIZlTRmSD0R5FYfs=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package policy

import (
"testing"

"cosmossdk.io/log"
"cosmossdk.io/store"
"cosmossdk.io/store/metrics"
storetypes "cosmossdk.io/store/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
"github.com/stretchr/testify/require"

coretypes "github.com/sourcenetwork/acp_core/pkg/types"
"github.com/sourcenetwork/sourcehub/x/acp/keeper"
"github.com/sourcenetwork/sourcehub/x/acp/testutil"
"github.com/sourcenetwork/sourcehub/x/acp/types"
hubtestutil "github.com/sourcenetwork/sourcehub/x/hub/testutil"
)

func TestCreatePolicyCommittedRootHashIsDeterministicAcrossStores(t *testing.T) {
policy := `
name: Source Policy
description: A policy with enough metadata to exercise map serialization.
meta:
alpha: one
bravo: two
charlie: three
delta: four
echo: five
foxtrot: six
resources:
- name: file
permissions:
- name: read
expr: reader
relations:
- name: reader
`

hashes := make([][]byte, 0, 3)
policyIDs := make([]string, 0, 3)

for i := 0; i < 3; i++ {
ctx, k, cms, creator := setupACPCommitStore(t)

resp, err := k.CreatePolicy(ctx, &types.MsgCreatePolicy{
Creator: creator,
Policy: policy,
MarshalType: coretypes.PolicyMarshalingType_YAML,
})
require.NoError(t, err)
require.NotNil(t, resp)

policyIDs = append(policyIDs, resp.Record.Policy.Id)
hashes = append(hashes, cms.Commit().Hash)
}

for i := 0; i < 2; i++ {
require.Equal(t, policyIDs[i], policyIDs[i+1])
require.Equal(t, hashes[i], hashes[i+1])
}
}

func setupACPCommitStore(t *testing.T) (sdk.Context, keeper.Keeper, storetypes.CommitMultiStore, string) {
t.Helper()

acpStoreKey := storetypes.NewKVStoreKey(types.StoreKey)
capabilityStoreKey := storetypes.NewKVStoreKey("capkeeper")
capabilityMemStoreKey := storetypes.NewKVStoreKey("capkeepermem")
Comment thread
Lodek marked this conversation as resolved.

db := dbm.NewMemDB()
cms := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
cms.MountStoreWithDB(acpStoreKey, storetypes.StoreTypeDB, db)
cms.MountStoreWithDB(capabilityStoreKey, storetypes.StoreTypeDB, db)
cms.MountStoreWithDB(capabilityMemStoreKey, storetypes.StoreTypeDB, db)
require.NoError(t, cms.LoadLatestVersion())

registry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(registry)
authority := authtypes.NewModuleAddress(govtypes.ModuleName)

capKeeper := capabilitykeeper.NewKeeper(cdc, capabilityStoreKey, capabilityMemStoreKey)
acpCapKeeper := capKeeper.ScopeToModule(types.ModuleName)

accKeeper := &testutil.AccountKeeperStub{}
pubKey := secp256k1.GenPrivKeyFromSecret([]byte("acp-create-policy-store-determinism")).PubKey()
account := accKeeper.NewAccount(pubKey)

acpKeeper := keeper.NewKeeper(
cdc,
runtime.NewKVStoreService(acpStoreKey),
log.NewNopLogger(),
authority.String(),
accKeeper,
&acpCapKeeper,
hubtestutil.NewHubKeeperStub(),
)

ctx := sdk.NewContext(cms, cmtproto.Header{}, false, log.NewNopLogger())
ctx = ctx.WithEventManager(sdk.NewEventManager())
acpKeeper.SetParams(ctx, types.DefaultParams())

return ctx, acpKeeper, cms, account.GetAddress().String()
}
Loading