public void GivenNoPeers_WhenSyncSelf_ThenGetSameMoney(float money) { MyAccount.Self.Money = (Money)money; MyActor.SyncAll(); Assert.Equal(money, MyAccount.Self.Money); }
public void AfterIConnectWithAgent_IAmConnectedToAgent() { MyActor.Connect(OtherId); Assert.NotNull(MyAccount.GetPeer(OtherId)); Assert.True(MyAccount.IsConnectedTo(OtherId)); }
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)); }
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)); }
public void AfterCreateArtefact_MyPeersKnowIHaveIt() { Interconnect(MyActor, OtherActor); var artefact = MyActor.CreateArtefact(Artefact.Name); Assert.True(OtherAccount.GetPeer(MyId).HasArtefact(artefact.Id)); }
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)); }
/// <summary> /// Peforms the state action. /// </summary> public override void Tick() { MyActor.MoveNextDirection(); if (MyActor.Directions.Count == 0) { Finished = true; } }
public void WhenUpdatedWithInvalidSignature_ThrowsInvalidOperationException() { MyActor.Connect(OtherId); var otherAgent = _network.FindAgent(OtherId); Assert.Throws <InvalidOperationException>( () => _network.SendAction(MyId, OtherId, _cryptography.Sign(new NoAction()))); }
public void CanSetAndGetTrustOfPeer(float trustValue) { var trust = (SignedWeight)trustValue; MyActor.Connect(OtherId); MyAccount.SetTrust(OtherId, trust); Assert.Equal(trust, MyAccount.GetTrust(OtherId)); }
private MyActor AddActor(int id, string name) { MyActor Actor = new MyActor(); Actor.MyActorID = id; Actor.ActorName = name; return(Actor); }
internal override void OnRemove(MyActor owner) { m_lodStrategy.Destroy(); m_cpuCulledEntity.Unregister(); MyObjectPoolManager.Deallocate(m_instanceMaterials); MyObjectPoolManager.Deallocate(m_cpuCulledEntity); MyManagers.Instances.RemoveInternal(this); }
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 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); }
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)); }
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)); }
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)); }
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)); }
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(); }
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); }
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)); }
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 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); }
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 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 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); }
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)); }
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()); }
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); }
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); }