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);
 }
        public void WhenMyPeerCreateChild_IConnectWithChild()
        {
            const string childName = "child";

            Interconnect(MyActor, OtherActor);

            var newAccount = OtherActor.CreateAccount(childName);

            Assert.True(MyAccount.IsConnectedTo(newAccount.Id));
        }
示例#3
0
        public void AfterOtherAccountCreateAndDestroyArtefact_ICanCreateSameArtefact()
        {
            Interconnect(MyActor, OtherActor, ThirdActor);
            var a1 = OtherActor.CreateArtefact(Artefact.Name);

            OtherActor.DestroyArtefact(a1.Id);

            var a2 = MyActor.CreateArtefact(Artefact.Name);

            Assert.True(ThirdAccount.GetPeer(MyId).HasArtefact(a2.Id));
        }
示例#4
0
        public void AfterPeerTransferArtefactToMe_AllPeersPeersKnowIHaveIt()
        {
            Interconnect(MyActor, OtherActor);
            Interconnect(OtherActor, ThirdActor);

            var artefact = OtherActor.CreateArtefact(Artefact.Name);

            MakeTransaction(OtherActor, MyActor, artefact);

            Assert.Equal(MyId, ThirdAccount.GetArtefact(artefact.Id).OwnerId);
        }
        public void AfterEndorcedUnconnectedAgent_RelationIsIncreaseWithEndorcementFactor()
        {
            Interconnect(MyActor, OtherActor);

            OtherActor.Endorce(ThirdId);

            var expectedRelationWeight = Weight.Min.Increase(EndorcementTrustFactor);
            var actualRelationWeight   = MyAccount.GetPeer(OtherId).GetRelation(ThirdId).Strength;

            Assert.Equal(expectedRelationWeight, actualRelationWeight);
        }
示例#6
0
        public void IfBuyerDontBelieveSellerHasArtefact_TransactionIsNotAccepted()
        {
            Interconnect(MyActor, OtherActor);
            var artefact = MyActor.CreateArtefact(Artefact.Name);

            OtherActor.CounterfeitArtefact(artefact);
            var key = StartTransaction(MyActor, OtherActor, artefact);

            Assert.NotNull(key);
            Assert.NotEmpty(key);
            Assert.False(OtherActor.AcceptTransaction(key));
        }
        public void AfterEndorcedConnectedAgent_RelationIsIncreaseWithEndorcementFactor(float initialRelation)
        {
            Interconnect(MyActor, OtherActor, ThirdActor);
            MyAccount.SetRelationWeight(OtherId, ThirdId, (Weight)initialRelation);

            OtherActor.Endorce(ThirdId);

            var expectedRelationWeight = ((Weight)initialRelation).Increase(EndorcementTrustFactor);
            var actualRelationWeight   = MyAccount.GetRelationWeight(OtherId, ThirdId);

            Assert.Equal(expectedRelationWeight, actualRelationWeight);
        }
示例#8
0
        public void WhenActorCreateArtefact_IdIsBasedOnAccountIdWithIncrementalNumber()
        {
            var a1 = MyActor.CreateArtefact("abc");
            var a2 = MyActor.CreateArtefact("abc");
            var b1 = OtherActor.CreateArtefact("abc");
            var b2 = OtherActor.CreateArtefact("abc");

            Assert.Equal(MyAccount.Id / 1, a1.Id);
            Assert.Equal(MyAccount.Id / 2, a2.Id);
            Assert.Equal(OtherAccount.Id / 1, b1.Id);
            Assert.Equal(OtherAccount.Id / 2, b2.Id);
        }
        public void AfterPeerEndorcedMe_MyMoneyIncrease(
            float trustForEndorcingPeer,
            float relationOfEndorcingPeerToEndorcedPeer,
            float expectedMoney)
        {
            Interconnect(MyActor, OtherActor);
            MyAccount.SetTrust(OtherId, (SignedWeight)trustForEndorcingPeer);
            MyAccount.SetRelationWeight(OtherId, MyId, (Weight)relationOfEndorcingPeerToEndorcedPeer);

            OtherActor.Endorce(MyId);
            Assert.Equal(expectedMoney, MyAccount.Self.Money);
        }
示例#10
0
        public void AfterEndorcedArtefact_OwnerGainsTrust()
        {
            Interconnect(MyActor, OtherActor);
            var artefact    = OtherActor.CreateArtefact(Artefact.Name);
            var trustBefore = MyAccount.GetTrust(OtherId);

            MyActor.EndorceArtefact(artefact);

            var expectedTrust = trustBefore.Increase(ArtefactEndorcementTrustFactor);

            Assert.Equal(expectedTrust, MyAccount.GetTrust(OtherId));
        }
示例#11
0
        public void IfPeerDontAgreeGiverHasArtefact_TransactionIsNotAcceptedByDisagreeingPeer()
        {
            Interconnect(MyActor, OtherActor);
            var artefact = OtherActor.CreateArtefact(Artefact.Name);

            ThirdActor.CounterfeitArtefact(artefact);
            Interconnect(MyActor, OtherActor, ThirdActor);
            MyAccount.SetTrust(OtherId, (SignedWeight)1);
            MyAccount.SetTrust(ThirdId, (SignedWeight)1);

            Assert.True(MakeTransaction(OtherActor, MyActor, artefact));
            Assert.True(ThirdAccount.Self.HasArtefact(artefact.Id));
        }
示例#12
0
        public void WhenPeerEndorceArtefact_PeerRelationWithOwnerIsStrengthened()
        {
            Interconnect(MyActor, OtherActor);
            var artefact       = OtherActor.CreateArtefact(Artefact.Name);
            var strengthBefore = MyAccount.Self.GetRelation(OtherId).Strength;

            MyActor.EndorceArtefact(artefact);

            var expectedStrength = strengthBefore.Increase(ArtefactEndorcementTrustFactor);
            var strengthAfter    = MyAccount.Self.GetRelation(OtherId).Strength;

            Assert.Equal(expectedStrength, strengthAfter);
        }
示例#13
0
        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));
        }
示例#14
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));
        }
示例#15
0
        public void WhenPeerDestroyArtefactThatPeerDoesntOwn_PeerLoosesTrust()
        {
            var artefact = MyActor.CreateArtefact(Artefact.Name);

            OtherActor.CounterfeitArtefact(artefact);
            Interconnect(MyActor, OtherActor);
            var trustBefore = MyAccount.GetTrust(OtherId);

            OtherActor.DestroyArtefact(artefact.Id);

            var expectedTrustAfter = trustBefore.Decrease(DestroyOthersArtefactDistrustFactor);

            Assert.Equal(expectedTrustAfter, MyAccount.GetTrust(OtherId));
        }
示例#16
0
        public void WhenPeerCreateArtefactThatOtherPeerAlreadyHas_PeerLoosesTrust()
        {
            Interconnect(MyActor, OtherActor, ThirdActor);
            var otherTrustBefore = MyAccount.GetTrust(OtherId);
            var thirdTrustBefore = MyAccount.GetTrust(ThirdId);

            var artefact = OtherActor.CreateArtefact(Artefact.Name);

            ThirdActor.CounterfeitArtefact(artefact);

            Assert.Equal(otherTrustBefore, MyAccount.GetTrust(OtherId));
            var expectedThirdTrust = thirdTrustBefore.Decrease(MakeCounterfeitArtefactDistrustFactor);

            Assert.Equal(expectedThirdTrust, MyAccount.GetTrust(ThirdId));
        }
示例#17
0
        public void GivenMinorityOfPeersBelieveKnownArtefactHasDifferentOwner_WhenSync_TheyLooseTrust(float trustValueBefore)
        {
            var trustBefore = (SignedWeight)trustValueBefore;

            Interconnect(MyActor, OtherActor);
            var artefact = OtherActor.CreateArtefact(Artefact.Name);

            MyAccount.SetTrust(OtherId, trustBefore);
            MyAccount.MoveArtefact(artefact, MyId);

            MyActor.SyncAll();

            var expectedTrust = trustBefore.Decrease(HoldCounterfeitArtefactDistrustFactor);

            Assert.Equal(expectedTrust, MyAccount.GetTrust(OtherId));
        }
示例#18
0
        public void WhenPeerEndorceArtefactWithWrongOwner_PeerLoosesTrust()
        {
            Interconnect(MyActor, OtherActor, ThirdActor);
            var artefact    = ThirdActor.CreateArtefact(Artefact.Name);
            var trustBefore = MyAccount.GetTrust(OtherId);

            OtherAccount.ForgetArtefact(artefact.Id);

            var fakeArtefact = new Artefact(artefact, OtherId);

            OtherActor.EndorceArtefact(fakeArtefact);

            var expectedTrust = trustBefore.Decrease(EndorceCounterfeitArtefactDistrustFactor);

            Assert.Equal(expectedTrust, MyAccount.GetTrust(OtherId));
        }
示例#19
0
        public void CanExchangeArtefactsForMoney()
        {
            var money = (Money)100;

            Interconnect(MyActor, OtherActor, ThirdActor);
            SetMutualTrust((SignedWeight)1, MyActor, OtherActor, ThirdActor);
            InitializeMoney(money, MyActor, OtherActor, ThirdActor);
            var a1 = OtherActor.CreateArtefact(Artefact.Name);
            var a2 = OtherActor.CreateArtefact(AnotherArtefact.Name);

            Assert.True(MakeTransaction(OtherActor, MyActor, money, a1, a2));

            Assert.Equal(Money.Min, ThirdAccount.GetMoney(MyId));
            Assert.Equal(2 * money, ThirdAccount.GetMoney(OtherId));
            Assert.Equal(MyId, ThirdAccount.GetArtefact(a1.Id).OwnerId);
            Assert.Equal(MyId, ThirdAccount.GetArtefact(a2.Id).OwnerId);
        }
示例#20
0
        public void WhenTransactionIsAccounted_InvolvedPeersGainTrust()
        {
            Interconnect(MyActor, OtherActor, ThirdActor);
            var artefact         = OtherActor.CreateArtefact(Artefact.Name);
            var otherTrustBefore = MyAccount.GetTrust(OtherId);
            var thirdTrustBefore = MyAccount.GetTrust(ThirdId);

            MakeTransaction(OtherActor, ThirdActor, artefact);

            var expectedOtherTrust = otherTrustBefore.Increase(AccountedTransactionTrustFactor);
            var expectedThirdTrust = thirdTrustBefore.Increase(AccountedTransactionTrustFactor);
            var actualOtherTrust   = MyAccount.GetTrust(OtherId);
            var actualThirdTrust   = MyAccount.GetTrust(ThirdId);

            Assert.Equal(expectedOtherTrust, actualOtherTrust);
            Assert.Equal(expectedThirdTrust, actualThirdTrust);
        }
 public void AfterMyPeerConnectWithMe_IAmUpdatedOfPeerConnection()
 {
     MyActor.Connect(OtherId);
     OtherActor.Connect(MyId);
     Assert.True(MyAccount.GetPeer(OtherId).IsConnectedTo(MyId));
 }
 public void AfterMyPeerConnectWithOtherAgent_IAmUpdatedOfPeerConnection()
 {
     Interconnect(MyActor, OtherActor);
     OtherActor.Connect(ThirdId);
     Assert.True(MyAccount.GetPeer(OtherId).IsConnectedTo(ThirdId));
 }