Example #1
0
        public void ShouldGenerateNoActionsOnSameState()
        {
            MockConfigProvider cp = new MockConfigProvider {
                CurrentState = new NodeState
                {
                    IsSigning             = true,
                    DockerImage           = "parity/parity:v2.3.4",
                    DockerChecksum        = "9f0142e1ae1641fbcf6116c49b5c73d5a4b48340e07f9ecb4da8d2d9847a76e6",
                    ChainspecUrl          = "https://foo.bar",
                    ChainspecChecksum     = "b76377f4f130134f352e81c8929fb0c8ffca94da722f704d16d0873fc9e030ea",
                    UpdateIntroducedBlock = 1234567
                }
            };

            // Recreate the same state so state object references are different
            NodeState newState = new NodeState
            {
                IsSigning             = true,
                DockerImage           = "parity/parity:v2.3.4",
                DockerChecksum        = "9f0142e1ae1641fbcf6116c49b5c73d5a4b48340e07f9ecb4da8d2d9847a76e6",
                ChainspecUrl          = "https://foo.bar",
                ChainspecChecksum     = "b76377f4f130134f352e81c8929fb0c8ffca94da722f704d16d0873fc9e030ea",
                UpdateIntroducedBlock = 1234567
            };

            StateCompare             sc      = new StateCompare(cp);
            List <StateChangeAction> actions = sc.ComputeActionsFromState(newState);

            // Assert
            actions.Should().BeEmpty();
        }
Example #2
0
        public void ShouldGenerateSigningAction()
        {
            MockConfigProvider cp = new MockConfigProvider {
                CurrentState = new NodeState
                {
                    IsSigning             = true,
                    DockerImage           = "parity/parity:v2.3.4",
                    DockerChecksum        = "9f0142e1ae1641fbcf6116c49b5c73d5a4b48340e07f9ecb4da8d2d9847a76e6",
                    ChainspecUrl          = "https://www.example.com/chainspec-20190210.json",
                    ChainspecChecksum     = "b76377f4f130134f352e81c8929fb0c8ffca94da722f704d16d0873fc9e030ea",
                    UpdateIntroducedBlock = 1234567
                }
            };

            // Recreate the same state so state object references are different
            NodeState newState = new NodeState
            {
                IsSigning             = false,
                DockerImage           = "parity/parity:v2.3.4",
                DockerChecksum        = "9f0142e1ae1641fbcf6116c49b5c73d5a4b48340e07f9ecb4da8d2d9847a76e6",
                ChainspecUrl          = "https://www.example.com/chainspec-20190210.json",
                ChainspecChecksum     = "b76377f4f130134f352e81c8929fb0c8ffca94da722f704d16d0873fc9e030ea",
                UpdateIntroducedBlock = 1234567
            };

            StateCompare             sc      = new StateCompare(cp);
            List <StateChangeAction> actions = sc.ComputeActionsFromState(newState);

            // Assert
            actions.Should().HaveCount(1);
            actions.Should().ContainSingle(action =>
                                           action.Mode == UpdateMode.ToggleSigning &&
                                           action.Payload == false.ToString() &&
                                           action.PayloadHash == string.Empty);
        }
Example #3
0
 public void ShouldNotInstantiateWithoutConfigProvider()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         _ = new StateCompare(null);
     });
 }
Example #4
0
        public void ShouldGenerateDockerAction()
        {
            MockConfigProvider cp = new MockConfigProvider {
                CurrentState = new NodeState
                {
                    IsSigning             = true,
                    DockerImage           = "parity/parity:v2.3.4",
                    DockerChecksum        = "9f0142e1ae1641fbcf6116c49b5c73d5a4b48340e07f9ecb4da8d2d9847a76e6",
                    ChainspecUrl          = "https://foo.bar",
                    ChainspecChecksum     = "b76377f4f130134f352e81c8929fb0c8ffca94da722f704d16d0873fc9e030ea",
                    UpdateIntroducedBlock = 1234567
                }
            };

            // Recreate the same state so state object references are different
            NodeState newState = new NodeState
            {
                IsSigning             = true,
                DockerImage           = "parity/parity:v2.4.4",
                DockerChecksum        = "c30bcff5580cb5d9c4edb0a0c8794210e85a134c2f12ffd166735e7c26079211",
                ChainspecUrl          = "https://foo.bar",
                ChainspecChecksum     = "b76377f4f130134f352e81c8929fb0c8ffca94da722f704d16d0873fc9e030ea",
                UpdateIntroducedBlock = 1234567
            };

            StateCompare             sc      = new StateCompare(cp);
            List <StateChangeAction> actions = sc.ComputeActionsFromState(newState);

            // Assert
            actions.Should().HaveCount(1);
            actions.Should().ContainSingle(action =>
                                           action.Mode == UpdateMode.Docker &&
                                           action.Payload == "parity/parity:v2.4.4" &&
                                           action.PayloadHash == "c30bcff5580cb5d9c4edb0a0c8794210e85a134c2f12ffd166735e7c26079211");
        }
Example #5
0
        public void ShouldThrowWhenComparingNullState()
        {
            MockConfigProvider cp = new MockConfigProvider();
            StateCompare       sc = new StateCompare(cp);

            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => { sc.ComputeActionsFromState(null); });

            Assert.Equal("newState", ex.ParamName);
        }
Example #6
0
        public void ShouldThrowWhenNullStateFromConfigProvider()
        {
            MockConfigProvider cp = new MockConfigProvider {
                CurrentState = null
            };
            StateCompare sc = new StateCompare(cp);

            StateCompareException ex = Assert.Throws <StateCompareException>(() =>
            {
                sc.ComputeActionsFromState(new NodeState());
            });

            Assert.Equal("Received state from configuration provider is null. Can't compare", ex.Message);
        }
Example #7
0
        public void ShouldGenerateActionCombinations(NodeState currentState, NodeState newState, List <StateChangeAction> expectedActions)
        {
            MockConfigProvider cp = new MockConfigProvider {
                CurrentState = currentState
            };

            StateCompare             sc      = new StateCompare(cp);
            List <StateChangeAction> actions = sc.ComputeActionsFromState(newState);

            // Assert
            actions.Should().HaveCount(expectedActions.Count);

            foreach (StateChangeAction expAction in expectedActions)
            {
                actions.Should().ContainEquivalentOf(expAction);
            }
        }
Example #8
0
        public void TestStateCompare1()
        {
            Assert.False(StateCompare.WasModified(1, 1));
            Assert.True(StateCompare.WasModified(1, 2));

            Assert.False(StateCompare.WasModified("1", "1"));
            Assert.True(StateCompare.WasModified("1", "2"));

            Assert.False(StateCompare.WasModified(null, (object)null));
            Assert.True(StateCompare.WasModified(null, new object()));

            var o1 = new object();
            var o2 = new object();

            Assert.False(StateCompare.WasModified(o1, o1));
            Assert.True(StateCompare.WasModified(o1, o2)); // Not same ref/pointer
        }
Example #9
0
        public void TestStateCompareEnumerable()
        {
            var a = new MyClass()
            {
                s = "a"
            };
            var b1 = new MyClass()
            {
                s = "b"
            };
            var b2 = new MyClass()
            {
                s = "b"
            };

            var l1 = new List <MyClass>()
            {
                a, b1
            };
            var l2_1 = new List <MyClass>()
            {
                a, b1
            };
            var l2_2 = new List <MyClass>()
            {
                a, b2
            };

            Assert.False(StateCompare.WasModified(l1, l1));
            Assert.True(StateCompare.WasModified(l1, l2_1));
            // 2 different arrays are created from the same source list:
            Assert.True(StateCompare.WasModified(l1.ToArray(), l1.ToArray()));

            // Same object references in both arrays (but arrays dont have same ref):
            Assert.True(l1.ToArray().SequenceEqual(l1.ToArray()));
            Assert.True(l1.ToArray().SequenceEqual(l2_1.ToArray()));
            // Because MyClass implements equals these are also equal:
            Assert.True(l1.ToArray().SequenceEqual(l2_2.ToArray()));
            Assert.False(l1.ToArray().Equals(l2_2.ToArray())); // Array ref not the same

            Assert.True(l1.ToArray().SequenceReferencesEqual(l2_1.ToArray()));
            Assert.False(l1.ToArray().SequenceReferencesEqual(l2_2.ToArray()));
            Assert.False(l1.ToArray().SequenceReferencesEqual(new MyClass[0]));
            Assert.False(new MyClass[0].SequenceReferencesEqual(l2_2.ToArray()));
        }
Example #10
0
        public void TestStateCompareNullable()
        {
            int?o1 = null;
            int?o2 = null;

            Assert.False(StateCompare.WasModified(o1, o2));
            o1 = 1;
            o2 = 1;
            Assert.False(StateCompare.WasModified(o1, o2));
            o1 = null;
            o2 = 1;
            Assert.True(StateCompare.WasModified(o1, o2));
            o1 = 1;
            o2 = null;
            Assert.True(StateCompare.WasModified(o1, o2));
            o1 = 1;
            o2 = 2;
            Assert.True(StateCompare.WasModified(o1, o2));
        }