Example #1
0
        private SerializedCallGraph SerializeCallingGraph(CallGraph graph)
        {
            var serializedCallGraph = new SerializedCallGraph();

            serializedCallGraph.Edges.AddRange(graph.Edges.Select(edge =>
                                                                  new GraphEdge {
                Source = edge.Source, Target = edge.Target
            }));
            serializedCallGraph.Vertices.AddRange(graph.Vertices);
            return(serializedCallGraph);
        }
Example #2
0
        /// <summary>
        /// calling graph is prepared for update contract code (check for DAG at that time)
        /// </summary>
        /// <param name="edges"></param>
        /// <returns></returns>
        /// <exception cref="FunctionMetadataException"></exception>
        private CallGraph BuildCallingGraph(SerializedCallGraph callGraph)
        {
            CallGraph graph = new CallGraph();

            graph.AddVertexRange(callGraph.Vertices);
            graph.AddEdgeRange(callGraph.Edges.Select(serializedEdge =>
                                                      new Edge <string>(serializedEdge.Source, serializedEdge.Target)));
            try
            {
                graph.TopologicalSort();
            }
            catch (NonAcyclicGraphException)
            {
                throw new FunctionMetadataException(
                          "The calling graph ISNOT DAG when restoring the calling graph according to the ContractMetadataTemplateMap from the database");
            }

            return(graph);
        }
Example #3
0
        public void IEquatable_SerializedCallGraph_Equals_Null_False()
        {
            IEquatable <SerializedCallGraph> serializedCallGraph = new SerializedCallGraph
            {
                Edges =
                {
                    new GraphEdge {
                        Source = "Source1", Target = "Target1"
                    },
                    new GraphEdge {
                        Source = "Source2", Target = "Target2"
                    },
                    new GraphEdge {
                        Source = "Source3", Target = "Target3"
                    }
                },
                Vertices = { "Vertices" }
            };

            serializedCallGraph.Equals(null).ShouldBeFalse();
        }
Example #4
0
        public void IEquatable_SerializedCallGraph_Equals_Other_True()
        {
            IEquatable <SerializedCallGraph> serializedCallGraph = new SerializedCallGraph
            {
                Edges =
                {
                    new GraphEdge {
                        Source = "Source1", Target = "Target1"
                    },
                    new GraphEdge {
                        Source = "Source2", Target = "Target2"
                    },
                    new GraphEdge {
                        Source = "Source3", Target = "Target3"
                    }
                },
                Vertices = { "Vertices" }
            };

            var otherSerializedCallGraph = new SerializedCallGraph
            {
                Edges =
                {
                    new GraphEdge {
                        Source = "Source1", Target = "Target1"
                    },
                    new GraphEdge {
                        Source = "Source2", Target = "Target2"
                    },
                    new GraphEdge {
                        Source = "Source3", Target = "Target3"
                    }
                },
                Vertices = { "Vertices" }
            };

            serializedCallGraph.Equals(otherSerializedCallGraph).ShouldBeTrue();
        }
Example #5
0
        bool IEquatable <SerializedCallGraph> .Equals(SerializedCallGraph other)
        {
            if (other == null)
            {
                return(false);
            }

            var edges = new RepeatedField <GraphEdge>();

            edges.AddRange(Edges.OrderBy(e => e.Source).ThenBy(e => e.Target));
            var otherEdges = new RepeatedField <GraphEdge>();

            otherEdges.AddRange(other.Edges.OrderBy(e => e.Source).ThenBy(e => e.Target));

            var vertices = new RepeatedField <string>();

            vertices.AddRange(Vertices.OrderBy(v => v));
            var otherVertices = new RepeatedField <string>();

            otherVertices.AddRange(other.Vertices.OrderBy(v => v));


            return(edges.Equals(otherEdges) && vertices.Equals(otherVertices));
        }
Example #6
0
        public void IEquatable_SerializedCallGraph_Equals_Other_False()
        {
            IEquatable <SerializedCallGraph> serializedCallGraph = new SerializedCallGraph
            {
                Edges =
                {
                    new GraphEdge {
                        Source = "Source1", Target = "Target1"
                    },
                    new GraphEdge {
                        Source = "Source2", Target = "Target2"
                    },
                    new GraphEdge {
                        Source = "Source3", Target = "Target3"
                    }
                },
                Vertices = { "Vertices" }
            };

            serializedCallGraph.Equals(new SerializedCallGraph()).ShouldBeFalse();

            var otherSerializedCallGraph1 = new SerializedCallGraph
            {
                Edges =
                {
                    new GraphEdge {
                        Source = "Source1", Target = "Target1"
                    },
                    new GraphEdge {
                        Source = "Source2", Target = "Target2"
                    },
                    new GraphEdge {
                        Source = "Source3", Target = "Target4"
                    }
                },
                Vertices = { "Vertices" }
            };

            serializedCallGraph.Equals(otherSerializedCallGraph1).ShouldBeFalse();

            var otherSerializedCallGraph2 = new SerializedCallGraph
            {
                Edges =
                {
                    new GraphEdge {
                        Source = "Source1", Target = "Target1"
                    },
                    new GraphEdge {
                        Source = "Source2", Target = "Target2"
                    },
                    new GraphEdge {
                        Source = "Source3", Target = "Target3"
                    }
                },
                Vertices = { "OtherVertices" }
            };

            serializedCallGraph.Equals(otherSerializedCallGraph2).ShouldBeFalse();

            var otherSerializedCallGraph3 = new SerializedCallGraph
            {
                Edges =
                {
                    new GraphEdge {
                        Source = "Source1", Target = "Target1"
                    },
                    new GraphEdge {
                        Source = "Source2", Target = "Target2"
                    },
                    new GraphEdge {
                        Source = "Source3", Target = "Target4"
                    }
                },
                Vertices = { "OtherVertices" }
            };

            serializedCallGraph.Equals(otherSerializedCallGraph3).ShouldBeFalse();
        }