src/Stratis.FederatedPeg.Tests/CrossChainTransferStoreTests.cs
/// <summary>
/// Check that partial transactions present in the store cause partial transaction requests made to peers.
/// </summary>
Check that partial transactions present in the store cause partial transaction requests made to peers.
Check that partial transactions present in the store cause partial transaction requests made to peers .
[Fact]
        public void StoredPartialTransactionsTriggerSignatureRequest()
        {
            var dataFolder = new DataFolder(CreateTestDir(this));
            this.Init(dataFolder);
            this.AddFunding();
            this.AppendBlocks(this.federationGatewaySettings.MinCoinMaturity);
            MultiSigAddress multiSigAddress = this.wallet.MultiSigAddress;
            using (ICrossChainTransferStore crossChainTransferStore = this.CreateStore())
            {
                crossChainTransferStore.Initialize();
                crossChainTransferStore.Start();
                Assert.Equal(this.chain.Tip.HashBlock, crossChainTransferStore.TipHashAndHeight.HashBlock);
                Assert.Equal(this.chain.Tip.Height, crossChainTransferStore.TipHashAndHeight.Height);
                BitcoinAddress address1 = (new Key()).PubKey.Hash.GetAddress(this.network);
                BitcoinAddress address2 = (new Key()).PubKey.Hash.GetAddress(this.network);
                var deposit1 = new Deposit(0, new Money(160m, MoneyUnit.BTC), address1.ToString(), crossChainTransferStore.NextMatureDepositHeight, 1);
                var deposit2 = new Deposit(1, new Money(60m, MoneyUnit.BTC), address2.ToString(), crossChainTransferStore.NextMatureDepositHeight, 1);
                MaturedBlockDepositsModel[] blockDeposits = new[] { new MaturedBlockDepositsModel(
                    new MaturedBlockInfoModel() {
                        BlockHash = 1,
                        BlockHeight = crossChainTransferStore.NextMatureDepositHeight },
                    new[] { deposit1, deposit2 })
                };
                crossChainTransferStore.RecordLatestMatureDepositsAsync(blockDeposits).GetAwaiter().GetResult();
                Dictionary<uint256, Transaction> transactions = crossChainTransferStore.GetTransactionsByStatusAsync(
                    CrossChainTransferStatus.Partial).GetAwaiter().GetResult();
                var requester = new PartialTransactionRequester(this.loggerFactory, crossChainTransferStore, this.asyncLoopFactory,
                    this.nodeLifetime, this.connectionManager, this.federationGatewaySettings);
                var peerEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("1.2.3.4"), 5);
                var peer = Substitute.For<INetworkPeer>();
                peer.RemoteSocketAddress.Returns(peerEndPoint.Address);
                peer.RemoteSocketPort.Returns(peerEndPoint.Port);
                peer.PeerEndPoint.Returns(peerEndPoint);
                peer.IsConnected.Returns(true);
                var peers = new NetworkPeerCollection();
                peers.Add(peer);
                this.federationGatewaySettings.FederationNodeIpEndPoints.Returns(new[] { peerEndPoint });
                this.connectionManager.ConnectedPeers.Returns(peers);
                requester.Start();
                Thread.Sleep(100);
                peer.Received().SendMessageAsync(Arg.Is<RequestPartialTransactionPayload>(o =>
                    o.DepositId == 0 && o.PartialTransaction.GetHash() == transactions[0].GetHash())).GetAwaiter().GetResult();
                peer.DidNotReceive().SendMessageAsync(Arg.Is<RequestPartialTransactionPayload>(o =>
                    o.DepositId == 1 && o.PartialTransaction.GetHash() == transactions[1].GetHash())).GetAwaiter().GetResult();
            }
        }
[ Fact ] public void StoredPartialTransactionsTriggerSignatureRequest ( ) { var dataFolder = new DataFolder ( CreateTestDir ( this ) ) ; this . Init ( dataFolder ) ; this . AddFunding ( ) ; this . AppendBlocks ( this . federationGatewaySettings . MinCoinMaturity ) ; MultiSigAddress multiSigAddress = this . wallet . MultiSigAddress ; using ( ICrossChainTransferStore crossChainTransferStore = this . CreateStore ( ) ) { crossChainTransferStore . Initialize ( ) ; crossChainTransferStore . Start ( ) ; Assert . Equal ( this . chain . Tip . HashBlock , crossChainTransferStore . TipHashAndHeight . HashBlock ) ; Assert . Equal ( this . chain . Tip . Height , crossChainTransferStore . TipHashAndHeight . Height ) ; BitcoinAddress address1 = ( new Key ( ) ) . PubKey . Hash . GetAddress ( this . network ) ; BitcoinAddress address2 = ( new Key ( ) ) . PubKey . Hash . GetAddress ( this . network ) ; var deposit1 = new Deposit ( 0 , new Money ( 160m , MoneyUnit . BTC ) , address1 . ToString ( ) , crossChainTransferStore . NextMatureDepositHeight , 1 ) ; var deposit2 = new Deposit ( 1 , new Money ( 60m , MoneyUnit . BTC ) , address2 . ToString ( ) , crossChainTransferStore . NextMatureDepositHeight , 1 ) ; MaturedBlockDepositsModel [ ] blockDeposits = new [ ] { new MaturedBlockDepositsModel ( new MaturedBlockInfoModel ( ) { BlockHash = 1 , BlockHeight = crossChainTransferStore . NextMatureDepositHeight } , new [ ] { deposit1 , deposit2 } ) } ; crossChainTransferStore . RecordLatestMatureDepositsAsync ( blockDeposits ) . GetAwaiter ( ) . GetResult ( ) ; Dictionary < uint256 , Transaction > transactions = crossChainTransferStore . GetTransactionsByStatusAsync ( CrossChainTransferStatus . Partial ) . GetAwaiter ( ) . GetResult ( ) ; var requester = new PartialTransactionRequester ( this . loggerFactory , crossChainTransferStore , this . asyncLoopFactory , this . nodeLifetime , this . connectionManager , this . federationGatewaySettings ) ; var peerEndPoint = new System . Net . IPEndPoint ( System . Net . IPAddress . Parse ( " " ) , 5 ) ; var peer = Substitute . For < INetworkPeer > ( ) ; peer . RemoteSocketAddress . Returns ( peerEndPoint . Address ) ; peer . RemoteSocketPort . Returns ( peerEndPoint . Port ) ; peer . PeerEndPoint . Returns ( peerEndPoint ) ; peer . IsConnected . Returns ( true ) ; var peers = new NetworkPeerCollection ( ) ; peers . Add ( peer ) ; this . federationGatewaySettings . FederationNodeIpEndPoints . Returns ( new [ ] { peerEndPoint } ) ; this . connectionManager . ConnectedPeers . Returns ( peers ) ; requester . Start ( ) ; Thread . Sleep ( 100 ) ; peer . Received ( ) . SendMessageAsync ( Arg . Is < RequestPartialTransactionPayload > ( o => o . DepositId == 0 && o . PartialTransaction . GetHash ( ) == transactions [ 0 ] . GetHash ( ) ) ) . GetAwaiter ( ) . GetResult ( ) ; peer . DidNotReceive ( ) . SendMessageAsync ( Arg . Is < RequestPartialTransactionPayload > ( o => o . DepositId == 1 && o . PartialTransaction . GetHash ( ) == transactions [ 1 ] . GetHash ( ) ) ) . GetAwaiter ( ) . GetResult ( ) ; } }
Check that partial transactions present in the store cause partial transaction requests made to peers.
Check that partial transactions present in the store cause partial transaction requests made to peers .