Exemplo n.º 1
0
        public async Task MerklePathTest()
        {
            Init();
            var chainId = Mock.ChainId1;

            _contract = new SideChainContractShim(Mock, AddressHelpers.GetSystemContractAddress(chainId, SmartContractType.SideChainContract.ToString()));
            ulong pHeight = 1;
            ParentChainBlockRootInfo parentChainBlockRootInfo = new ParentChainBlockRootInfo
            {
                ChainId = chainId,
                Height  = pHeight,
                SideChainTransactionsRoot = Hash.Generate(),
                SideChainBlockHeadersRoot = Hash.Generate()
            };
            ParentChainBlockInfo parentChainBlockInfo = new ParentChainBlockInfo
            {
                Root = parentChainBlockRootInfo
            };

            parentChainBlockInfo.IndexedBlockInfo.Add(0, new MerklePath
            {
                Path = { Hash.FromString("Block1"), Hash.FromString("Block2"), Hash.FromString("Block3") }
            });
            await _contract.WriteParentChainBLockInfo(parentChainBlockInfo);

            ChainConfig.Instance.ChainId = chainId.DumpHex();
            var crossChainInfo = new CrossChainInfo(Mock.StateStore);
            var merklepath     = crossChainInfo.GetTxRootMerklePathInParentChain(0);

            Assert.NotNull(merklepath);
            Assert.Equal(parentChainBlockInfo.IndexedBlockInfo[0], merklepath);

            var parentHeight = crossChainInfo.GetParentChainCurrentHeight();

            Assert.Equal(pHeight, parentHeight);
            var boundHeight = crossChainInfo.GetBoundParentChainHeight(0);

            Assert.Equal(parentChainBlockRootInfo.Height, boundHeight);

            var boundBlockInfo = crossChainInfo.GetBoundParentChainBlockInfo(parentChainBlockRootInfo.Height);

            Assert.Equal(parentChainBlockInfo, boundBlockInfo);
        }