Skip to content

Sale Deed Registry Unit Tests

Ranjan Dailata edited this page Dec 16, 2019 · 1 revision

The SaleDeedRegistry smart contract functionalities are unit tested using xunit and moq libraries.

alt text

The Unit Test consists of a Test Class - "SaleDeedContractTest" having a collection of Facts that's responsible for performing the contract operation and verifies or validates the results.

        public SaleDeedContractTest()
        {
            transferResult = new Mock<ITransferResult>();
            mockContractLogger = new Mock<IContractLogger>();
            mockPersistentState = new Mock<IPersistentState>();
            mockContractState = new Mock<ISmartContractState>();
            mockInternalExecutor = new Mock<IInternalTransactionExecutor>();

            this.mockContractState.Setup(s => s.PersistentState).Returns(this.mockPersistentState.Object);
            this.mockContractState.Setup(s => s.ContractLogger).Returns(this.mockContractLogger.Object);
            this.mockContractState.Setup(x => x.InternalTransactionExecutor).Returns(mockInternalExecutor.Object);

            assetId = UniqueIdHelper.GenerateId(); 
            this.sender = "0x0000000000000000000000000000000000000001".HexToAddress();
            this.buyer = "0x0000000000000000000000000000000000000002".HexToAddress();
            this.propertyOwner = "0x0000000000000000000000000000000000000003".HexToAddress();
            this.payee = "0x0000000000000000000000000000000000000004".HexToAddress();
        }

Below is the code snippet that demonstrates how one can handle the contract Init operation.

        [Fact]
        public void SaleDeed_Init_Application()
        {
            this.mockContractState.Setup(s => s.PersistentState).Returns(this.mockPersistentState.Object);
            SaleDeedRegistryContract saleDeedRegistry =
                new SaleDeedRegistryContract(mockContractState.Object, payee);

            Address address = "0x0000000000000000000000000000000000000002".HexToAddress();
            this.mockPersistentState.Setup(s => s.GetUInt32($"PropertyState[" + assetId + "]"))
             .Returns((uint)PropertyStateType.InProgress);

            saleDeedRegistry.InitApplication(propertyOwner, buyer, assetId);

            // Get the Property State and validate
            uint state = saleDeedRegistry.GetPropertyState(assetId);
            Assert.True(state == (uint)PropertyStateType.InProgress);
        }
Clone this wiki locally