예제 #1
0
        public void CanParseProposal()
        {
            var a = Proposal.Parse("1.0ABC=>2.0DEf");
            var b = Proposal.Parse("1.0ABC=>2.0DEF");
            var c = Proposal.Parse("1ABC=>2DEF");

            Assert.Equal("1.00ABC=>2.00DEF", a.ToString());
            Assert.Equal(a.ToString(), b.ToString());
            Assert.Equal(b.ToString(), c.ToString());
            a = Proposal.Parse("1.0ABC1=>2.0DEf2");
            Assert.Equal("1.00ABC1=>2.00DEF2", a.ToString());
            Assert.Throws <FormatException>(() => Proposal.Parse("ABC=>DEF"));
            Assert.Throws <FormatException>(() => Proposal.Parse("1.0=>1.0"));
        }
예제 #2
0
        public void Test1()
        {
            using (var tester = XSwapTester.Create())
            {
                var pubKey = tester.Bob.Facade.NewPubkey();

                var offer = tester.Alice.Facade.ProposeOffer(Proposal.Parse("1BTC1=>2BTC2"), pubKey).Result;

                var waitingOffer = tester.Alice.Facade.WaitOfferAsync(offer);
                tester.Alice.Facade.BroadcastOffer(offer, false).Wait();
                waitingOffer.Wait();

                tester.Bob.Facade.BroadcastOffer(offer.CreateCounterOffer(), true).Wait();

                var bobWait =
                    Task.WhenAll
                        (tester.Bob.Facade.WaitOfferConfirmationAsync(offer.CreateCounterOffer()),
                        tester.Bob.Facade.WaitOfferConfirmationAsync(offer));

                var aliceWait =
                    Task.WhenAll
                        (tester.Alice.Facade.WaitOfferConfirmationAsync(offer.CreateCounterOffer()),
                        tester.Alice.Facade.WaitOfferConfirmationAsync(offer));

                tester.Bob.Chain2.CreateRPCClient().Generate(1);
                tester.Alice.Chain1.CreateRPCClient().Generate(1);

                aliceWait.Wait();
                bobWait.Wait();

                var waitingTake = tester.Bob.Facade.WaitOfferTakenAsync(offer.CreateCounterOffer());

                tester.Alice.Facade.TakeOffer(offer.CreateCounterOffer()).Wait();

                waitingTake.Wait();
                tester.Bob.Facade.TakeOffer(offer).Wait();

                var bob   = tester.Bob.Chain1.CreateRPCClient().ListUnspent(0, 0);
                var alice = tester.Alice.Chain2.CreateRPCClient().ListUnspent(0, 0);
                Assert.Equal(1, bob.Length);
                Assert.Equal(1, alice.Length);
            }
        }