More fixes to src/app/util/mock. (#32932)

* More fixes to src/app/util/mock.

* Remove misplaced comment

* Remove misplaced comment

* Fix compilation for esp32

* Fix typo
diff --git a/src/app/util/mock/Functions.h b/src/app/util/mock/Functions.h
index 32ba08d..16fe45d 100644
--- a/src/app/util/mock/Functions.h
+++ b/src/app/util/mock/Functions.h
@@ -36,7 +36,15 @@
 CHIP_ERROR ReadSingleMockClusterData(FabricIndex aAccessingFabricIndex, const app::ConcreteAttributePath & aPath,
                                      app::AttributeReportIBs::Builder & aAttributeReports,
                                      app::AttributeValueEncoder::AttributeEncodeState * apEncoderState);
+
+/// Increase the current value for `GetVersion`
 void BumpVersion();
+
+/// Sets GetVersion to return 0
+void ResetVersion();
+
+/// Gets the current value for the version that will
+/// be returned by emberAfDataVersionStorage
 DataVersion GetVersion();
 
 /// Configures the singular global mock attribute storage to use the specified configuration.
diff --git a/src/app/util/mock/MockNodeConfig.cpp b/src/app/util/mock/MockNodeConfig.cpp
index e7c04fa..79c886f 100644
--- a/src/app/util/mock/MockNodeConfig.cpp
+++ b/src/app/util/mock/MockNodeConfig.cpp
@@ -70,6 +70,22 @@
     mEmberCluster.mask           = CLUSTER_MASK_SERVER;
     mEmberCluster.eventCount     = static_cast<uint16_t>(mEmberEventList.size());
     mEmberCluster.eventList      = mEmberEventList.data();
+
+    for (auto & attr : attributes)
+    {
+        mAttributeMetaData.push_back(attr.attributeMetaData);
+    }
+
+    // Make sure ember side has access to attribute metadata
+    mEmberCluster.attributes = mAttributeMetaData.data();
+}
+
+MockClusterConfig::MockClusterConfig(const MockClusterConfig & other) :
+    id(other.id), attributes(other.attributes), events(other.events), mEmberCluster(other.mEmberCluster),
+    mEmberEventList(other.mEmberEventList), mAttributeMetaData(other.mAttributeMetaData)
+{
+    // Fix self-referencial dependencies after data copy
+    mEmberCluster.attributes = mAttributeMetaData.data();
 }
 
 const MockAttributeConfig * MockClusterConfig::attributeById(AttributeId attributeId, ptrdiff_t * outIndex) const
diff --git a/src/app/util/mock/MockNodeConfig.h b/src/app/util/mock/MockNodeConfig.h
index fc8f185..aa71158 100644
--- a/src/app/util/mock/MockNodeConfig.h
+++ b/src/app/util/mock/MockNodeConfig.h
@@ -18,6 +18,7 @@
 
 #pragma once
 
+#include <app-common/zap-generated/attribute-type.h>
 #include <app/util/af-types.h>
 #include <lib/core/DataModelTypes.h>
 
@@ -28,10 +29,35 @@
 namespace chip {
 namespace Test {
 
+namespace internal {
+
+constexpr EmberAfAttributeMetadata DefaultAttributeMetadata(chip::AttributeId id)
+{
+    return EmberAfAttributeMetadata{
+        .defaultValue  = EmberAfDefaultOrMinMaxAttributeValue(static_cast<uint32_t>(0)),
+        .attributeId   = id,
+        .size          = 4,
+        .attributeType = ZCL_INT32U_ATTRIBUTE_TYPE,
+        .mask          = ATTRIBUTE_MASK_WRITABLE | ATTRIBUTE_MASK_NULLABLE,
+    };
+}
+
+} // namespace internal
+
 struct MockAttributeConfig
 {
-    MockAttributeConfig(AttributeId aId) : id(aId) {}
+    MockAttributeConfig(AttributeId aId) : id(aId), attributeMetaData(internal::DefaultAttributeMetadata(aId)) {}
+    MockAttributeConfig(AttributeId aId, EmberAfAttributeType type,
+                        EmberAfAttributeMask mask = ATTRIBUTE_MASK_WRITABLE | ATTRIBUTE_MASK_NULLABLE) :
+        id(aId),
+        attributeMetaData(internal::DefaultAttributeMetadata(aId))
+    {
+        attributeMetaData.attributeType = type;
+        attributeMetaData.mask          = mask;
+    }
+
     const AttributeId id;
+    EmberAfAttributeMetadata attributeMetaData;
 };
 
 struct MockEventConfig
@@ -45,6 +71,10 @@
     MockClusterConfig(ClusterId aId, std::initializer_list<MockAttributeConfig> aAttributes = {},
                       std::initializer_list<MockEventConfig> aEvents = {});
 
+    // Cluster-config is self-referential: mEmberCluster.attributes references  mAttributeMetaData.data()
+    MockClusterConfig(const MockClusterConfig & other);
+    MockClusterConfig & operator=(const MockClusterConfig &) = delete;
+
     const MockAttributeConfig * attributeById(AttributeId attributeId, ptrdiff_t * outIndex = nullptr) const;
     const EmberAfCluster * emberCluster() const { return &mEmberCluster; }
 
@@ -55,13 +85,14 @@
 private:
     EmberAfCluster mEmberCluster;
     std::vector<EventId> mEmberEventList;
+    std::vector<EmberAfAttributeMetadata> mAttributeMetaData;
 };
 
 struct MockEndpointConfig
 {
     MockEndpointConfig(EndpointId aId, std::initializer_list<MockClusterConfig> aClusters = {});
 
-    // Cluster-config is self-referntial: mEmberCluster.clusters references  mEmberClusters
+    // Endpoint-config is self-referential: mEmberEndpoint.clusters references  mEmberClusters.data()
     MockEndpointConfig(const MockEndpointConfig & other);
     MockEndpointConfig & operator=(const MockEndpointConfig &) = delete;
 
diff --git a/src/app/util/mock/attribute-storage.cpp b/src/app/util/mock/attribute-storage.cpp
index 6aa8729..7164600 100644
--- a/src/app/util/mock/attribute-storage.cpp
+++ b/src/app/util/mock/attribute-storage.cpp
@@ -307,8 +307,14 @@
 }
 
 } // namespace app
+
 namespace Test {
 
+void ResetVersion()
+{
+    dataVersion = 0;
+}
+
 void BumpVersion()
 {
     dataVersion++;
@@ -407,5 +413,15 @@
     return attributeReport.EndOfAttributeReportIB();
 }
 
+void SetMockNodeConfig(const MockNodeConfig & config)
+{
+    mockConfig = &config;
+}
+
+void ResetMockNodeConfig()
+{
+    mockConfig = nullptr;
+}
+
 } // namespace Test
 } // namespace chip