From cdda55af788aaa4de8a7a828476a4955e155a888 Mon Sep 17 00:00:00 2001 From: Bruno Gomes Date: Fri, 15 May 2026 13:58:30 -0300 Subject: [PATCH] acp_core bump --- go.mod | 6 +- go.sum | 6 + .../policy_creation_store_determinism_test.go | 113 ++++++++++++++++++ x/acp/types/keys.go | 2 + 4 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 tests/integration/acp/suite/policy/policy_creation_store_determinism_test.go diff --git a/go.mod b/go.mod index 3d6e4c06..f2a93632 100644 --- a/go.mod +++ b/go.mod @@ -46,8 +46,8 @@ require ( github.com/ignite/cli/v28 v28.6.1 github.com/lestrrat-go/jwx/v2 v2.1.6 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 @@ -402,7 +402,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 diff --git a/go.sum b/go.sum index 776e2d8c..9c100666 100644 --- a/go.sum +++ b/go.sum @@ -2316,14 +2316,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= diff --git a/tests/integration/acp/suite/policy/policy_creation_store_determinism_test.go b/tests/integration/acp/suite/policy/policy_creation_store_determinism_test.go new file mode 100644 index 00000000..d2e60c4d --- /dev/null +++ b/tests/integration/acp/suite/policy/policy_creation_store_determinism_test.go @@ -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") + + 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() +} diff --git a/x/acp/types/keys.go b/x/acp/types/keys.go index f80867a6..2d4f4201 100644 --- a/x/acp/types/keys.go +++ b/x/acp/types/keys.go @@ -7,6 +7,8 @@ const ( // StoreKey defines the primary module store key StoreKey = ModuleName + MemStoreKey = "mem_acp" + // AccessDecisionRepositoryKeyPrefix defines the namespace for Access Decisions AccessDecisionRepositoryKeyPrefix = "access_decision/"