Esempio n. 1
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));
        }
Esempio n. 2
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);
        }
Esempio n. 3
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));
        }
Esempio n. 4
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);
        }
Esempio n. 5
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));
        }
Esempio n. 6
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);
        }
Esempio n. 7
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));
        }
Esempio n. 8
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));
        }
Esempio n. 9
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);
        }
Esempio n. 10
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);
        }