コード例 #1
0
        public void ComputeTotal_Fails_Sender_Not_Manufacturer()
        {
            this.mockPersistentState.Setup(s => s.GetAddress(nameof(DefectiveComponentCounter.Manufacturer))).Returns(ManufacturerAddress);
            this.mockContractState.Setup(s => s.Message.Sender).Returns(ManufacturerAddress);

            var defectiveComponentsCounter = new DefectiveComponentCounter(this.mockContractState.Object, new byte[] { });

            this.mockContractState.Setup(s => s.Message.Sender).Returns(Address.Zero);

            Assert.Throws <SmartContractAssertException>(() => defectiveComponentsCounter.ComputeTotal());
        }
コード例 #2
0
        [InlineData(new uint[] { 1, uint.MaxValue })] // 1, uint.MaxValue
        public void ComputeTotal_Overflow_Throws_Exception(uint[] components)
        {
            components = ToFixedWidthArray(components);

            this.mockPersistentState.Setup(s => s.GetAddress(nameof(DefectiveComponentCounter.Manufacturer))).Returns(ManufacturerAddress);
            this.mockContractState.Setup(s => s.Message.Sender).Returns(ManufacturerAddress);

            var defectiveComponentsCounter = new DefectiveComponentCounter(this.mockContractState.Object, new byte[] { });

            this.mockPersistentState.Setup(s => s.GetArray <uint>("DefectiveComponentsCount")).Returns(components);

            Assert.Throws <OverflowException>(() => defectiveComponentsCounter.ComputeTotal());
        }
コード例 #3
0
        public void ComputeTotal_Computes_Correctly(uint[] components, uint expectedTotal)
        {
            components = ToFixedWidthArray(components);

            this.mockPersistentState.Setup(s => s.GetAddress(nameof(DefectiveComponentCounter.Manufacturer))).Returns(ManufacturerAddress);
            this.mockContractState.Setup(s => s.Message.Sender).Returns(ManufacturerAddress);

            var defectiveComponentsCounter = new DefectiveComponentCounter(this.mockContractState.Object, ToByteArray(components));

            this.mockPersistentState.Setup(s => s.GetArray <uint>("DefectiveComponentsCount")).Returns(components);

            defectiveComponentsCounter.ComputeTotal();

            this.mockPersistentState.Verify(s => s.SetUInt32(nameof(DefectiveComponentCounter.Total), expectedTotal));
        }