diff --git a/internal/db/fetcher/versioned.go b/internal/db/fetcher/versioned.go index cdf73ed713..85e793e82b 100644 --- a/internal/db/fetcher/versioned.go +++ b/internal/db/fetcher/versioned.go @@ -326,6 +326,12 @@ func (vf *VersionedFetcher) merge(c cid.Cid) error { var mcrdt merklecrdt.MerkleCRDT switch { + case block.Delta.IsCollection(): + mcrdt = merklecrdt.NewMerkleCollection( + vf.store, + keys.CollectionSchemaVersionKey{}, + keys.NewHeadstoreColKey(vf.col.Description().RootID), + ) case block.Delta.IsComposite(): mcrdt = merklecrdt.NewMerkleCompositeDAG( vf.store, diff --git a/tests/integration/query/simple/with_cid_branchable_test.go b/tests/integration/query/simple/with_cid_branchable_test.go new file mode 100644 index 0000000000..eec3d70120 --- /dev/null +++ b/tests/integration/query/simple/with_cid_branchable_test.go @@ -0,0 +1,59 @@ +// Copyright 2024 Democratized Data Foundation +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithCidOfBranchableCollection_FirstCid(t *testing.T) { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users @branchable { + name: String + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Fred" + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John" + }`, + }, + testUtils.Request{ // bafyreiewwsnu2ld5qlntamdm77ayb7xtmxz3p5difvaaakaome7zbtpo4u + Request: `query { + Users ( + cid: "bafyreiewwsnu2ld5qlntamdm77ayb7xtmxz3p5difvaaakaome7zbtpo4u" + ) { + name + } + }`, + Results: map[string]any{ + "Users": []map[string]any{ + { + "name": "Fred", + }, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +}