Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
0
        public void WhenSync_LearnAboutUnknownArtefactsPossessedByPeers()
        {
            Interconnect(OtherActor, ThirdActor);
            var artefact = ThirdActor.CreateArtefact(Artefact.Name);

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

            MyActor.SyncAll();

            Assert.True(MyAccount.KnowsArtefact(artefact.Id));
        }
Exemplo n.º 5
0
        public void GivenMinorityOfPeersBelieveKnownArtefactHasDifferentOwner_WhenSync_ArtefactOwnerIsNotChanged(float otherTrust, float thirdTrust)
        {
            Interconnect(MyActor, OtherActor, ThirdActor);
            var artefact = ThirdActor.CreateArtefact(Artefact.Name);

            MyAccount.SetTrust(OtherId, (SignedWeight)otherTrust);
            MyAccount.SetTrust(ThirdId, (SignedWeight)thirdTrust);
            MyAccount.MoveArtefact(artefact, MyId);

            MyActor.SyncAll();

            Assert.True(MyAccount.Self.HasArtefact(artefact.Id));
            Assert.Equal(MyId, MyAccount.GetArtefact(artefact.Id).OwnerId);
        }
Exemplo n.º 6
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));
        }
Exemplo 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));
        }
Exemplo n.º 8
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));
        }