Beispiel #1
0
        public void WhenSyncPeer_ThenUpdateFromConnectedPeersAndWeighBySumOfTheirTrust(
            float peerMoneyBefore,
            float[] peerTrusts,
            int[] peerAssessments,
            float peerMoneyAfter)
        {
            var peers = peerTrusts
                        .Select((pt, i) => _network
                                .CreateRootAccount($"Peer{i}", (byte)(10 + i))
                                .GetActor(_network, new TransactionFactory()))
                        .ToArray();
            int i            = 0;
            var peerToUpdate = peers[0];

            foreach (var peer in peers)
            {
                Interconnect(MyActor, peer);
                MyAccount.SetTrust(peer.Account.Id, (SignedWeight)peerTrusts[i]);
                var peerAssessment = peerAssessments[i];
                if (peerAssessment >= 0)
                {
                    Interconnect(peer, peerToUpdate);
                    peer.Account.SetMoney(peerToUpdate.Account.Id, (Money)peerAssessments[i]);
                }
                i++;
            }
            MyAccount.SetMoney(peerToUpdate.Account.Id, (Money)peerMoneyBefore);

            MyActor.SyncAll();

            Assert.Equal(peerMoneyAfter, MyAccount.GetMoney(peerToUpdate.Account.Id));
        }
        public void AfterSetMoney_PeerHasMoney(float initialMoney, float setMoney, float hasMoney)
        {
            MyActor.Connect(OtherId);
            MyAccount.SetMoney(OtherId, (Money)initialMoney);

            MyAccount.SetMoney(OtherId, (Money)setMoney);

            Assert.Equal(hasMoney, MyAccount.GetMoney(OtherId));
        }
 public void WhenEndorcePeerManyTimes_MoneyIncreaseLessThanTwo()
 {
     Interconnect(MyActor, OtherActor, ThirdActor);
     MyAccount.SetTrust(OtherId, SignedWeight.Max);
     for (int i = 0; i < 100; i++)
     {
         OtherActor.Endorce(ThirdId);
     }
     Assert.InRange(MyAccount.GetMoney(ThirdId), 1f, 2f);
 }
Beispiel #4
0
        public void WhenConnectPeer_PeerIsSynced()
        {
            Interconnect(MyActor, OtherActor);
            Interconnect(ThirdActor, OtherActor);
            OtherAccount.SetMoney(ThirdId, (Money)100);
            MyAccount.SetTrust(OtherId, SignedWeight.Max);

            MyActor.Connect(ThirdId);

            Assert.Equal((Money)50, MyAccount.GetMoney(ThirdId));
        }
Beispiel #5
0
        public void WhenEndorceArtefactMayTimes_MoneyIncreaseWithLessThan_1()
        {
            Interconnect(MyActor, OtherActor, ThirdActor);
            MyAccount.SetTrust(OtherId, SignedWeight.Max);
            var artefact = ThirdActor.CreateArtefact(Artefact.Name);

            for (int i = 0; i < 100; i++)
            {
                MyActor.EndorceArtefact(artefact);
            }
            Assert.InRange(MyAccount.GetMoney(ThirdId), 0.5f, 1);
        }
Beispiel #6
0
        public void WhenEndorceDifferentArtefactsWithSameOwner_MoneyIncreaseWithLessThan_1()
        {
            Interconnect(MyActor, OtherActor, ThirdActor);
            MyAccount.SetTrust(OtherId, SignedWeight.Max);
            var artefacts = Enumerable.Range(1, 100).Select(i => ThirdActor.CreateArtefact(Artefact.Name + i));

            foreach (Artefact artefact in artefacts)
            {
                MyActor.EndorceArtefact(artefact);
            }
            Assert.InRange(MyAccount.GetMoney(ThirdId), 0.5f, 1);
        }
        public void AfterOnePeerEndorceAnotherPeer_EndorcedPeerIncreaseMoney(
            float trustForEndorcingPeer,
            float relationOfEndorcingPeerToEndorcedPeer,
            float expectedMoney)
        {
            Interconnect(MyActor, OtherActor, ThirdActor);
            MyAccount.SetTrust(OtherId, (SignedWeight)trustForEndorcingPeer);
            MyAccount.SetRelationWeight(OtherId, ThirdId, (Weight)relationOfEndorcingPeerToEndorcedPeer);

            OtherActor.Endorce(ThirdId);

            Assert.Equal(expectedMoney, MyAccount.GetMoney(ThirdId));
        }
Beispiel #8
0
        public void AfterPeerEndorceArtefact_ArtefactOwnerIncreaseMoney(
            float trustForEndorcingPeer,
            float relationOfEndorcingPeerToEndorcedPeer,
            float expectedIncrease)
        {
            Interconnect(MyActor, OtherActor, ThirdActor);
            MyAccount.SetTrust(OtherId, (SignedWeight)trustForEndorcingPeer);
            MyAccount.SetRelationWeight(OtherId, ThirdId, (Weight)relationOfEndorcingPeerToEndorcedPeer);
            var artefact = ThirdActor.CreateArtefact(Artefact.Name);

            OtherActor.EndorceArtefact(artefact);

            Assert.Equal(expectedIncrease, MyAccount.GetMoney(ThirdId));
        }
Beispiel #9
0
        public void Given_1_PeerWithFullTrustAndConnectivity_WhenSyncAll_ThenGetMeanPeerMoney(
            float mySelfMoneyBefore,
            float myPeerMoneyBefore,
            float peerMyMoneyBefore,
            float peerSelfMoneyBefore,
            float mySelfMoneyAfter,
            float myPeerMoneyAfter)
        {
            Interconnect(MyActor, OtherActor);
            MyAccount.Self.Money = (Money)mySelfMoneyBefore;
            MyAccount.SetMoney(OtherId, (Money)myPeerMoneyBefore);
            OtherAccount.Self.Money = (Money)peerSelfMoneyBefore;
            OtherAccount.SetMoney(MyId, (Money)peerMyMoneyBefore);
            MyAccount.SetTrust(OtherId, (SignedWeight)1);

            MyActor.SyncAll();

            Assert.Equal(mySelfMoneyAfter, MyAccount.Self.Money);
            Assert.Equal(myPeerMoneyAfter, MyAccount.GetMoney(OtherId));
        }