Ejemplo n.º 1
0
        public void GivenNoPeers_WhenSyncSelf_ThenGetSameMoney(float money)
        {
            MyAccount.Self.Money = (Money)money;
            MyActor.SyncAll();

            Assert.Equal(money, MyAccount.Self.Money);
        }
Ejemplo n.º 2
0
        public void AfterIConnectWithAgent_IAmConnectedToAgent()
        {
            MyActor.Connect(OtherId);

            Assert.NotNull(MyAccount.GetPeer(OtherId));
            Assert.True(MyAccount.IsConnectedTo(OtherId));
        }
Ejemplo n.º 3
0
 public void WhenDecreaseTrustWithFactor_OutOfBounds_ThrowsOutOfBoundsException(
     float trustBefore, float factor)
 {
     MyActor.Connect(OtherId);
     MyAccount.SetTrust(OtherId, (SignedWeight)trustBefore);
     Assert.Throws <OutOfBounds <float> >(() => MyAccount.DecreaseTrust(OtherId, (Weight)factor));
 }
Ejemplo n.º 4
0
 public void CanIncreaseTrustWithFactor(float trustBefore, float factor, float trustAfter)
 {
     MyActor.Connect(OtherId);
     MyAccount.SetTrust(OtherId, (SignedWeight)trustBefore);
     MyAccount.IncreaseTrust(OtherId, (Weight)factor);
     Assert.Equal((SignedWeight)trustAfter, MyAccount.GetTrust(OtherId));
 }
Ejemplo n.º 5
0
        public void AfterCreateArtefact_MyPeersKnowIHaveIt()
        {
            Interconnect(MyActor, OtherActor);
            var artefact = MyActor.CreateArtefact(Artefact.Name);

            Assert.True(OtherAccount.GetPeer(MyId).HasArtefact(artefact.Id));
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Peforms the state action.
 /// </summary>
 public override void Tick()
 {
     MyActor.MoveNextDirection();
     if (MyActor.Directions.Count == 0)
     {
         Finished = true;
     }
 }
Ejemplo n.º 8
0
        public void WhenUpdatedWithInvalidSignature_ThrowsInvalidOperationException()
        {
            MyActor.Connect(OtherId);
            var otherAgent = _network.FindAgent(OtherId);

            Assert.Throws <InvalidOperationException>(
                () => _network.SendAction(MyId, OtherId, _cryptography.Sign(new NoAction())));
        }
Ejemplo n.º 9
0
        public void CanSetAndGetTrustOfPeer(float trustValue)
        {
            var trust = (SignedWeight)trustValue;

            MyActor.Connect(OtherId);
            MyAccount.SetTrust(OtherId, trust);
            Assert.Equal(trust, MyAccount.GetTrust(OtherId));
        }
Ejemplo n.º 10
0
        private MyActor AddActor(int id, string name)
        {
            MyActor Actor = new MyActor();

            Actor.MyActorID = id;
            Actor.ActorName = name;
            return(Actor);
        }
Ejemplo n.º 11
0
        internal override void OnRemove(MyActor owner)
        {
            m_lodStrategy.Destroy();
            m_cpuCulledEntity.Unregister();
            MyObjectPoolManager.Deallocate(m_instanceMaterials);
            MyObjectPoolManager.Deallocate(m_cpuCulledEntity);

            MyManagers.Instances.RemoveInternal(this);
        }
Ejemplo n.º 12
0
        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));
        }
Ejemplo n.º 13
0
        public void WhenCreatingManyTransientArtefacts_IdsAreReused()
        {
            var first = MyActor.CreateArtefact("abc");

            ((Account)MyAccount)._transientArtefactCount = int.MaxValue - 1;
            MyActor.CreateArtefact("abc");
            var last = MyActor.CreateArtefact("abc");

            Assert.Equal(first.Id.Number, last.Id.Number);
        }
Ejemplo n.º 14
0
        public void CanCreateTwoDifferentArtefacts()
        {
            Interconnect(MyActor, OtherActor);

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

            Assert.True(OtherAccount.GetPeer(MyId).HasArtefact(a1.Id));
            Assert.True(OtherAccount.GetPeer(MyId).HasArtefact(a2.Id));
        }
Ejemplo n.º 15
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));
        }
Ejemplo n.º 16
0
        public void AfterICreatedChild_MeAndChildAreInterconnected()
        {
            const string childName = "child";

            Interconnect(MyActor, OtherActor);

            var newAccount = MyActor.CreateAccount(childName);

            Assert.True(newAccount.IsConnectedTo(MyId));
            Assert.True(MyAccount.IsConnectedTo(newAccount.Id));
        }
Ejemplo n.º 17
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));
        }
        public void AfterIEndorcedPeer_TrustOfPeerIncreaseWithEndorcementFactor(float trustValueBefore)
        {
            var trustBefore = (SignedWeight)trustValueBefore;

            MyActor.Connect(OtherId);
            MyAccount.SetTrust(OtherId, trustBefore);

            MyActor.Endorce(OtherId);

            Assert.Equal(trustBefore.Increase(EndorcementTrustFactor), MyAccount.GetTrust(OtherId));
        }
Ejemplo n.º 19
0
        public void ShardedDaemonProcess_must_not_run_if_the_role_does_not_match_node_role()
        {
            Cluster.Get(Sys).Join(Cluster.Get(Sys).SelfAddress);

            var probe    = CreateTestProbe();
            var settings = ShardedDaemonProcessSettings.Create(Sys).WithRole("workers");

            ShardedDaemonProcess.Get(Sys).Init("roles", 3, id => MyActor.Props(id, probe.Ref), settings);

            probe.ExpectNoMsg();
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
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));
        }
Ejemplo n.º 22
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);
        }
Ejemplo n.º 23
0
        public void ShardedDaemonProcess_must_start_N_actors_with_unique_ids()
        {
            Cluster.Get(Sys).Join(Cluster.Get(Sys).SelfAddress);

            var probe = CreateTestProbe();

            ShardedDaemonProcess.Get(Sys).Init("a", 5, id => MyActor.Props(id, probe.Ref));

            var started = probe.ReceiveN(5);

            started.Count.ShouldBe(5);
        }
Ejemplo n.º 24
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));
        }
Ejemplo n.º 25
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);
        }
Ejemplo n.º 26
0
        public void Given_1_PeerWithFullTrustAndConnectivity_WhenSyncSelf_ThenGetMeanPeerMoney(
            float myMoneyBefore, float peerAssessment, float myMoneyAfter)
        {
            Interconnect(MyActor, OtherActor);
            OtherAccount.SetMoney(MyId, (Money)peerAssessment);
            MyAccount.Self.Money = (Money)myMoneyBefore;
            MyAccount.SetTrust(OtherId, (SignedWeight)1);

            MyActor.SyncAll();

            Assert.Equal(myMoneyAfter, MyAccount.Self.Money);
        }
Ejemplo n.º 27
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));
        }
Ejemplo n.º 28
0
        public void CreateActorAndChildActor()
        {
            Actor       actor  = new MyActor();
            ActorSystem system = new ActorSystem();

            var actorref      = system.ActorOf(actor, "myactor");
            var childactorref = actor.Context.ActorOf(typeof(MyActor), "mychildactor");

            Assert.IsNotNull(actorref);
            Assert.IsNotNull(childactorref);
            Assert.AreEqual("/myactor", actorref.Path.ToString());
            Assert.AreEqual("/myactor/mychildactor", childactorref.Path.ToString());
        }
Ejemplo n.º 29
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);
        }
Ejemplo n.º 30
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);
        }