public async Task RecordSideChainData() { var parentChainId = 123; var lockedToken = 10L; long parentChainHeightOfCreation = 10; var sideChainId = await InitAndCreateSideChainAsync(parentChainHeightOfCreation, parentChainId, lockedToken); var fakeSideChainBlockHash = Hash.FromString("sideChainBlockHash"); var fakeTxMerkleTreeRoot = Hash.FromString("txMerkleTreeRoot"); var sideChainBlockData = CreateSideChainBlockData(fakeSideChainBlockHash, 1, sideChainId, fakeTxMerkleTreeRoot); var crossChainBlockData = new CrossChainBlockData { SideChainBlockData = {sideChainBlockData} }; var indexingTx = await CrossChainContractStub.RecordCrossChainData.SendAsync(crossChainBlockData); Assert.True(indexingTx.TransactionResult.Status == TransactionResultStatus.Mined); var balance = await CrossChainContractStub.GetSideChainBalance.CallAsync(new SInt32Value {Value = sideChainId}); Assert.Equal(lockedToken - 1, balance.Value); var blockHeader = await BlockchainService.GetBestChainLastBlockHeaderAsync(); var indexedCrossChainBlockData = await CrossChainContractStub.GetIndexedCrossChainBlockDataByHeight.CallAsync(new SInt64Value {Value = blockHeader.Height}); Assert.Equal(crossChainBlockData, indexedCrossChainBlockData); }
public async Task RecordSideChainData_WithChainNotExist() { int parentChainId = 123; long lockedToken = 10; long parentChainHeightOfCreation = 10; var sideChainId1 = await InitAndCreateSideChainAsync(parentChainHeightOfCreation, parentChainId, lockedToken); // create second side chain long lockedTokenAmount = 10; await ApproveBalanceAsync(lockedTokenAmount); var sideChainCreationRequest = CreateSideChainCreationRequest(1, lockedTokenAmount, ByteString.Empty); var sideChainId2 = ChainHelper.GetChainId(2); await BlockMiningService.MineBlockAsync(new List<Transaction> { CrossChainContractStub.CreateSideChain.GetTransaction(sideChainCreationRequest) }, true); var fakeSideChainBlockHash = Hash.FromString("sideChainBlockHash"); var fakeTxMerkleTreeRoot = Hash.FromString("txMerkleTreeRoot"); var sideChainBlockData1 = CreateSideChainBlockData(fakeSideChainBlockHash, 1, sideChainId1, fakeTxMerkleTreeRoot); var sideChainBlockData2 = CreateSideChainBlockData(fakeSideChainBlockHash, 2, sideChainId2, fakeTxMerkleTreeRoot); int fakeChainId = 124; var sideChainBlockData3 = CreateSideChainBlockData(fakeSideChainBlockHash, 1, fakeChainId, fakeTxMerkleTreeRoot); var crossChainBlockData = new CrossChainBlockData { SideChainBlockData = {sideChainBlockData1, sideChainBlockData2, sideChainBlockData3} }; await BlockMiningService.MineBlockAsync(new List<Transaction> { CrossChainContractStub.RecordCrossChainData.GetTransaction(crossChainBlockData) }); var balance = await CrossChainContractStub.GetSideChainBalance.CallAsync(new SInt32Value {Value = sideChainId1}); Assert.Equal(lockedToken - 1, balance.Value); var blockHeader = await BlockchainService.GetBestChainLastBlockHeaderAsync(); var indexedCrossChainBlockData = await CrossChainContractStub.GetIndexedCrossChainBlockDataByHeight.CallAsync(new SInt64Value {Value = blockHeader.Height}); var expectedCrossChainBlocData = new CrossChainBlockData(); expectedCrossChainBlocData.SideChainBlockData.Add(sideChainBlockData1); Assert.Equal(expectedCrossChainBlocData, indexedCrossChainBlockData); }