public void UsingFindElement_TheCorrectCallIsMadeFromTheDriver(
            [Values] LocatorType rootLocatorType,
            [Values] LocatorType childLocatorType)
        {
            // Arrange
            bool      expectedAtomicCall = rootLocatorType.IsSubAtomic() && childLocatorType.IsSubAtomic();
            TestBlock block = GetBlockDefinedByLocatorType(rootLocatorType);

            this.findElementMethodLookup.TryGetValue(childLocatorType, out Func <TestBlock, IWebElement> method);

            // Act
            _ = method(block);

            // Log
            var driverCalls = Fake.GetCalls(this.driver).Where(c => c.Method.Name.StartsWith("FindElement")).ToList();

            TestContext.WriteLine($"There were {driverCalls.Count} call(s) to the IWebDriver.");
            foreach (var call in driverCalls)
            {
                TestContext.WriteLine($"The method called on the IWebDriver was {call.Method.Name}({call.ArgumentsAfterCall[0]})");
            }

            // Assert
            using (new AssertionScope())
            {
                driverCalls.Count.Should().Be(1);
                if (expectedAtomicCall)
                {
                    driverCalls[0].ArgumentsAfterCall[0].ToString().Should().StartWith("By.CssSelector");
                }
            }
        }
        public void UsingFindElement_NoCallIsMadeFromTheDriverWithAFoundRootElement(
            [Values] LocatorType childLocatorType)
        {
            // Arrange
            TestBlock block = new TestBlock(this.rootElement);

            this.findElementMethodLookup.TryGetValue(childLocatorType, out Func <TestBlock, IWebElement> method);

            // Act
            IWebElement element = method(block);

            // Log
            TestContext.WriteLine(element.Text);
            var driverCalls = Fake.GetCalls(this.driver).Where(c => c.Method.Name.StartsWith("FindElement")).ToList();

            TestContext.WriteLine($"There were {driverCalls.Count} call(s) to the IWebDriver.");
            foreach (var call in driverCalls)
            {
                TestContext.WriteLine($"The method called on the IWebDriver was {call.Method.Name}({call.ArgumentsAfterCall[0]})");
            }

            // Assert
            using (new AssertionScope())
            {
                driverCalls.Count.Should().Be(0);
            }
        }
Example #3
0
        public async Task ChainNoAttestations()
        {
            // Arrange
            IServiceProvider testServiceProvider = TestSystem.BuildTestServiceProvider(useStore: true);
            BeaconState      state = TestState.PrepareTestState(testServiceProvider);

            MiscellaneousParameters miscellaneousParameters = testServiceProvider.GetService <IOptions <MiscellaneousParameters> >().Value;
            MaxOperationsPerBlock   maxOperationsPerBlock   = testServiceProvider.GetService <IOptions <MaxOperationsPerBlock> >().Value;

            // Initialization
            ICryptographyService cryptographyService = testServiceProvider.GetService <ICryptographyService>();
            ForkChoice           forkChoice          = testServiceProvider.GetService <ForkChoice>();
            IStore store = forkChoice.GetGenesisStore(state);

            // On receiving a block of `GENESIS_SLOT + 1` slot
            BeaconBlock block1 = TestBlock.BuildEmptyBlockForNextSlot(testServiceProvider, state, signed: true);

            TestState.StateTransitionAndSignBlock(testServiceProvider, state, block1);
            await AddBlockToStore(testServiceProvider, store, block1);

            // On receiving a block of next epoch
            BeaconBlock block2 = TestBlock.BuildEmptyBlockForNextSlot(testServiceProvider, state, signed: true);

            TestState.StateTransitionAndSignBlock(testServiceProvider, state, block2);
            await AddBlockToStore(testServiceProvider, store, block2);

            // Act
            Hash32 headRoot = await forkChoice.GetHeadAsync(store);

            // Assert
            Hash32 expectedRoot = cryptographyService.SigningRoot(block2);

            headRoot.ShouldBe(expectedRoot);
        }
Example #4
0
        public async Task ChainNoAttestations()
        {
            // Arrange
            IServiceProvider testServiceProvider = TestSystem.BuildTestServiceProvider(useStore: true);
            BeaconState      state = TestState.PrepareTestState(testServiceProvider);

            // Initialization
            ICryptographyService cryptographyService = testServiceProvider.GetService <ICryptographyService>();
            IForkChoice          forkChoice          = testServiceProvider.GetService <IForkChoice>();
            IStore store = testServiceProvider.GetService <IStore>();
            await forkChoice.InitializeForkChoiceStoreAsync(store, state);

            // On receiving a block of `GENESIS_SLOT + 1` slot
            BeaconBlock       block1       = TestBlock.BuildEmptyBlockForNextSlot(testServiceProvider, state, BlsSignature.Zero);
            SignedBeaconBlock signedBlock1 = TestState.StateTransitionAndSignBlock(testServiceProvider, state, block1);

            await AddBlockToStore(testServiceProvider, store, signedBlock1);

            // On receiving a block of next epoch
            BeaconBlock       block2       = TestBlock.BuildEmptyBlockForNextSlot(testServiceProvider, state, BlsSignature.Zero);
            SignedBeaconBlock signedBlock2 = TestState.StateTransitionAndSignBlock(testServiceProvider, state, block2);

            await AddBlockToStore(testServiceProvider, store, signedBlock2);

            // Act
            Root headRoot = await forkChoice.GetHeadAsync(store);

            // Assert
            Root expectedRoot = cryptographyService.HashTreeRoot(block2);

            headRoot.ShouldBe(expectedRoot);
        }
Example #5
0
 public static void TestCode(TestBlock testBlock)
 {
     if (Util_Test.TestMode)
     {
         testBlock(PureAppli.syuturyoku1);
     }
 }
Example #6
0
        public async Task ChainNoAttestations()
        {
            // Arrange
            var testServiceProvider = TestSystem.BuildTestServiceProvider(useStore: true);
            var state = TestState.PrepareTestState(testServiceProvider);

            var miscellaneousParameters = testServiceProvider.GetService <IOptions <MiscellaneousParameters> >().Value;
            var maxOperationsPerBlock   = testServiceProvider.GetService <IOptions <MaxOperationsPerBlock> >().Value;

            // Initialization
            var forkChoice = testServiceProvider.GetService <ForkChoice>();
            var store      = forkChoice.GetGenesisStore(state);

            // On receiving a block of `GENESIS_SLOT + 1` slot
            var block1 = TestBlock.BuildEmptyBlockForNextSlot(testServiceProvider, state, signed: true);

            TestState.StateTransitionAndSignBlock(testServiceProvider, state, block1);
            AddBlockToStore(testServiceProvider, store, block1);

            // On receiving a block of next epoch
            var block2 = TestBlock.BuildEmptyBlockForNextSlot(testServiceProvider, state, signed: true);

            TestState.StateTransitionAndSignBlock(testServiceProvider, state, block2);
            AddBlockToStore(testServiceProvider, store, block2);

            // Act
            var headRoot = await forkChoice.GetHeadAsync(store);

            // Assert
            var expectedRoot = block2.SigningRoot(miscellaneousParameters, maxOperationsPerBlock);

            headRoot.ShouldBe(expectedRoot);
        }
Example #7
0
        public void UsingFindElements_AnAtomicCallIsMadeWhenBothLocatorsAreSubAtomic(
            [Values] LocatorType rootLocatorType,
            [Values] LocatorType childLocatorType)
        {
            // Arrange
            bool      expectedAtomicCall = rootLocatorType.IsSubAtomic() && childLocatorType.IsSubAtomic();
            TestBlock block = GetBlockDefinedByLocatorType(rootLocatorType);

            this.findElementsMethodLookup.TryGetValue(childLocatorType, out Func <TestBlock, ReadOnlyCollection <IWebElement> > method);

            // Act
            ReadOnlyCollection <IWebElement> elements = method(block);

            // Log
            TestContext.WriteLine(elements[0]?.Text);

            // Assert
            using (new AssertionScope())
            {
                elements.Count.Should().Be(1);
                elements[0].Should().Be(expectedAtomicCall ?
                                        this.elementInElementsReturnedByDriver :
                                        this.elementInElementsReturnedByFoundElement,
                                        "the wrong IWebElement was returned.");
            }
        }
        public void OnAttestationPreviousEpoch()
        {
            // Arrange
            var testServiceProvider = TestSystem.BuildTestServiceProvider(useStore: true);
            var state = TestState.PrepareTestState(testServiceProvider);

            var initialValues  = testServiceProvider.GetService <IOptions <InitialValues> >().Value;
            var timeParameters = testServiceProvider.GetService <IOptions <TimeParameters> >().Value;
            var forkChoice     = testServiceProvider.GetService <ForkChoice>();

            // Initialization
            var store = forkChoice.GetGenesisStore(state);
            var time  = store.Time + timeParameters.SecondsPerSlot * (ulong)timeParameters.SlotsPerEpoch;

            forkChoice.OnTick(store, time);

            var block = TestBlock.BuildEmptyBlockForNextSlot(testServiceProvider, state, signed: true);

            TestState.StateTransitionAndSignBlock(testServiceProvider, state, block);

            // Store block in store
            forkChoice.OnBlock(store, block);

            var attestation = TestAttestation.GetValidAttestation(testServiceProvider, state, block.Slot, CommitteeIndex.None, signed: true);

            attestation.Data.Target.Epoch.ShouldBe(initialValues.GenesisEpoch);

            var beaconChainUtility = testServiceProvider.GetService <BeaconChainUtility>();
            var currentSlot        = forkChoice.GetCurrentSlot(store);
            var currentEpoch       = beaconChainUtility.ComputeEpochAtSlot(currentSlot);

            currentEpoch.ShouldBe(initialValues.GenesisEpoch + new Epoch(1));

            RunOnAttestation(testServiceProvider, state, store, attestation, expectValid: true);
        }
        public SweepStakeTests()
        {
            var block = new TestBlock
            {
                Coinbase = contractOwnerAddress,
                Number   = 2
            };

            var message = new TestMessage
            {
                ContractAddress = contractAddress,
                GasLimit        = (Gas)(ulong)10000,
                Sender          = punter1Address,
                Value           = 0
            };

            this.transactionExecutor = Substitute.For <IInternalTransactionExecutor>();

            this.smartContractState = new TestSmartContractState(
                block,
                message,
                new InMemoryState(),
                null,
                transactionExecutor,
                () => (ulong)0,
                new TestInternalHashHelper()
                );
        }
Example #10
0
    public (Vector3, Vector3Int) RegisterBlock(TestBlock block)
    {
        Vector3Int gridPos = WorldToGrid(block.transform.position);

        Blocks[gridPos.x, gridPos.y, gridPos.z] = block;
        return(GridToWorld(gridPos), gridPos);
    }
    /// <summary>
    /// When using the TestLoader scene to setup an experiment, this function fetches some parameters of importance from the block that was generated.
    /// </summary>
    /// <param name="testBlock"> </param>
    public void LoadTestData(TestBlock testBlock)
    {
        /*Eyes = new List<Camera>();
         * switch (testBlock.SelectedVRHMD)
         * {
         *  case TestBlock.VRHMD.VIVE:
         *      Eyes.Add(VRCamera);
         *      break;
         *  case TestBlock.VRHMD.FOVE:
         *      Eyes.Add(_foveInterface.GetEyeCamera(EFVR_Eye.Left));
         *      Eyes.Add(_foveInterface.GetEyeCamera(EFVR_Eye.Right));
         *      break;
         * }*/
        GazeCursor.Instance.SetColor(testBlock.CursorColor);

        CurrentControlMethod      = testBlock.SelectedControlMethod;
        CurrentConfirmationMethod = testBlock.SelectedConfirmationMethod;

        GazeCursor.Instance.TargetHovered   += OnCursorHover;
        GazeCursor.Instance.TargetStayed    += OnCursorStay;
        GazeCursor.Instance.TargetUnhovered += OnCursorUnhover;

        if (CurrentConfirmationMethod == TestBlock.ConfirmationMethod.Click)
        {
            HasClickedDown += OnClickDown;
            HasClickedUp   += OnClickUp;
        }
        _eyeRayCache = new Ray[Mathf.Clamp(testBlock.EyeSmoothFactor, 1, int.MaxValue)];
    }
Example #12
0
        public void TestCorrectIntialReadyOperationsParallelDFG()
        {
            TestBlock operation1 = new TestBlock(new List <FluidBlock> {
            }, null, new TestModule());
            TestBlock operation2 = new TestBlock(new List <FluidBlock> {
            }, null, new TestModule());
            TestBlock operation3 = new TestBlock(new List <FluidBlock> {
            }, null, new TestModule());
            TestBlock operation4 = new TestBlock(new List <FluidBlock> {
            }, null, new TestModule());

            DFG <Block> dfg = new DFG <Block>();

            dfg.AddNode(operation1);
            dfg.AddNode(operation2);
            dfg.AddNode(operation3);
            dfg.AddNode(operation4);
            dfg.FinishDFG();

            Assay assay = new Assay(dfg);

            Assert.AreEqual(assay.GetReadyOperations().Count, dfg.Nodes.Count);
            foreach (var node in dfg.Nodes)
            {
                //Even the pointers should be the same.
                Assert.IsTrue(assay.GetReadyOperations().Contains(node.value));
            }
        }
Example #13
0
 public static void TestCode(TestBlock testBlock)
 {
     if (Util_Test.TestMode)
     {
         testBlock(Util_Machine.Syuturyoku);
     }
 }
Example #14
0
        public async Task OnAttestationCurrentEpoch()
        {
            // Arrange
            IServiceProvider testServiceProvider = TestSystem.BuildTestServiceProvider(useStore: true);
            BeaconState      state = TestState.PrepareTestState(testServiceProvider);

            InitialValues  initialValues  = testServiceProvider.GetService <IOptions <InitialValues> >().Value;
            TimeParameters timeParameters = testServiceProvider.GetService <IOptions <TimeParameters> >().Value;
            ForkChoice     forkChoice     = testServiceProvider.GetService <ForkChoice>();

            // Initialization
            IStore store = forkChoice.GetGenesisStore(state);
            ulong  time  = store.Time + timeParameters.SecondsPerSlot * 2;
            await forkChoice.OnTickAsync(store, time);

            BeaconBlock block = TestBlock.BuildEmptyBlockForNextSlot(testServiceProvider, state, signed: true);

            TestState.StateTransitionAndSignBlock(testServiceProvider, state, block);

            // Store block in store
            await forkChoice.OnBlockAsync(store, block);

            Attestation attestation = TestAttestation.GetValidAttestation(testServiceProvider, state, block.Slot, CommitteeIndex.None, signed: true);

            attestation.Data.Target.Epoch.ShouldBe(initialValues.GenesisEpoch);

            BeaconChainUtility beaconChainUtility = testServiceProvider.GetService <BeaconChainUtility>();
            Slot  currentSlot  = forkChoice.GetCurrentSlot(store);
            Epoch currentEpoch = beaconChainUtility.ComputeEpochAtSlot(currentSlot);

            currentEpoch.ShouldBe(initialValues.GenesisEpoch);

            await RunOnAttestation(testServiceProvider, state, store, attestation, expectValid : true);
        }
Example #15
0
        public AuctionTests()
        {
            var block = new TestBlock
            {
                Coinbase = ContractOwnerAddress,
                Number   = 1
            };

            var message = new TestMessage
            {
                ContractAddress = ContractOwnerAddress,
                GasLimit        = (Gas)GasLimit,
                Sender          = ContractOwnerAddress,
                Value           = Value
            };

            this.transactionExecutor = Substitute.For <IInternalTransactionExecutor>();

            this.smartContractState = new TestSmartContractState(
                block,
                message,
                new InMemoryState(),
                null,
                transactionExecutor,
                () => Balance,
                new TestInternalHashHelper()
                );
        }
        public void UsingFindElement_ACallIsMadeFromTheReturnedElementOnlyOnNonAtomicCalls(
            [Values] LocatorType rootLocatorType,
            [Values] LocatorType childLocatorType
            )
        {
            // Arrange
            bool      expectedAtomicCall = rootLocatorType.IsSubAtomic() && childLocatorType.IsSubAtomic();
            TestBlock block = GetBlockDefinedByLocatorType(rootLocatorType);

            this.findElementMethodLookup.TryGetValue(childLocatorType, out Func <TestBlock, IWebElement> method);

            // Act
            _ = method(block);

            // Log
            var returnedElementCalls = Fake.GetCalls(this.elementReturnedByDriver).Where(c => c.Method.Name.StartsWith("FindElement")).ToList();

            TestContext.WriteLine($"There were {returnedElementCalls.Count} call(s) to the returned Element.");
            foreach (var call in returnedElementCalls)
            {
                TestContext.WriteLine($"The Call made to the returnedElement was {call.Method.Name}({call.ArgumentsAfterCall[0]})");
            }

            // Assert
            returnedElementCalls.Count.Should().Be(expectedAtomicCall ? 0 : 1);
        }
Example #17
0
        // [DataRow(42uL, "0xab48aa2cc6f4a0bb63b5d67be54ac3aed10326dda304c5aeb9e942b40d6e7610478377680ab90e092ef1895e62786008", 0uL, 5uL, 1uL, null)]
        // [DataRow(42uL, "0x8aea7d8eb22063bcfe882e2b7efc0b3713e1a48dd8343bed523b1ab4546114be84d00f896d33c605d1f67456e8e2ed93", 0uL, 5uL, 1uL, null)]
        // [DataRow(42uL, "0x89db41a6183c2fe47cf54d1e00c3cfaae53df634a32cccd5cf0c0a73e95ee0450fc3d060bb6878780fbf5f30d9e29aac", 0uL, 5uL, 1uL, null)]
        // [DataRow(42uL, "0xb783a70a1cf9f53e7d2ddf386bea81a947e5360c5f1e0bf004fceedb2073e4dd180ef3d2d91bee7b1c5a88d1afd11c49", 0uL, 5uL, 1uL, null)]
        // [DataRow(42uL, "0x8fe55d12257709ae842f8594f9a0a40de3d38dabdf82b21a60baac927e52ed00c5fd42f4c905410eacdaf8f8a9952490", 0uL, 5uL, 1uL, null)]
        // [DataRow(42uL, "0x95906ec0660892c205634e21ad540cbe0b6f7729d101d5c4639b864dea09be7f42a4252c675d46dd90a2661b3a94e8ca", 0uL, 5uL, 1uL, null)]
        public async Task ValidatorDutyAtSpecificTimeDuplicateProposal(ulong targetTime, string publicKey, ulong epoch, ulong attestationSlot, ulong attestationShard, ulong?blockProposalSlot)
        {
            // NOTE: Current algorithm for GetBeaconProposerIndex() someimtes allocates multiple proposal slots in an epoch, e.g. above index 23 gets slot 2 and 6
            // It could be an error in the algorithm (need to check; domain type could be wrong), or due to the pre-shard algorithm.
            // The algorithm before shards were removed was different, so maybe ignore for now, implement phase 1 (with shards), and worry about it then.
            // This test for now will simply detect if things unintentionally change.

            // Arrange
            IServiceCollection testServiceCollection = TestSystem.BuildTestServiceCollection(useStore: true);

            testServiceCollection.AddSingleton <IHostEnvironment>(Substitute.For <IHostEnvironment>());
            ServiceProvider testServiceProvider = testServiceCollection.BuildServiceProvider();
            BeaconState     state      = TestState.PrepareTestState(testServiceProvider);
            IForkChoice     forkChoice = testServiceProvider.GetService <IForkChoice>();
            // Get genesis store initialise MemoryStoreProvider with the state
            IStore store = testServiceProvider.GetService <IStore>();
            await forkChoice.InitializeForkChoiceStoreAsync(store, state);

            // Move forward time
            TimeParameters timeParameters = testServiceProvider.GetService <IOptions <TimeParameters> >().Value;

            for (ulong timeSinceGenesis = 1; timeSinceGenesis <= targetTime; timeSinceGenesis++)
            {
                ulong time = state.GenesisTime + timeSinceGenesis;
                await forkChoice.OnTickAsync(store, time);

                if (timeSinceGenesis % timeParameters.SecondsPerSlot == 0)
                {
                    BeaconBlock       block       = TestBlock.BuildEmptyBlockForNextSlot(testServiceProvider, state, BlsSignature.Zero);
                    SignedBeaconBlock signedBlock = TestState.StateTransitionAndSignBlock(testServiceProvider, state, block);
                    await forkChoice.OnBlockAsync(store, signedBlock);
                }
            }

            Console.WriteLine("");
            Console.WriteLine("***** State advanced to slot {0}, time {1}, ready to start tests *****", state.Slot, store.Time);
            Console.WriteLine("");

            // Act
            ValidatorAssignments validatorAssignments = testServiceProvider.GetService <ValidatorAssignments>();
            BlsPublicKey         validatorPublicKey   = new BlsPublicKey(publicKey);
            Epoch targetEpoch = new Epoch(epoch);

            ValidatorDuty validatorDuty = await validatorAssignments.GetValidatorDutyAsync(validatorPublicKey, targetEpoch);

            Console.WriteLine("Validator {0}, epoch {1}: attestation slot {2}, shard {3}, proposal slot {4}",
                              validatorPublicKey, targetEpoch, validatorDuty.AttestationSlot, (ulong)validatorDuty.AttestationShard, validatorDuty.BlockProposalSlot);

            // Assert
            validatorDuty.ValidatorPublicKey.ShouldBe(validatorPublicKey);

            Slot  expectedBlockProposalSlot = blockProposalSlot.HasValue ? new Slot(blockProposalSlot.Value) : Slot.None;
            Slot  expectedAttestationSlot   = new Slot(attestationSlot);
            Shard expectedAttestationShard  = new Shard(attestationShard);

            validatorDuty.BlockProposalSlot.ShouldBe(expectedBlockProposalSlot);
            validatorDuty.AttestationSlot.ShouldBe(expectedAttestationSlot);
            validatorDuty.AttestationShard.ShouldBe(expectedAttestationShard);
        }
Example #18
0
        public void ProposerIndexForFirstTwoEpochsMustBeValid()
        {
            // Arrange
            IServiceCollection testServiceCollection = TestSystem.BuildTestServiceCollection(useStore: true);

            testServiceCollection.AddSingleton <IHostEnvironment>(Substitute.For <IHostEnvironment>());
            ServiceProvider testServiceProvider = testServiceCollection.BuildServiceProvider();
            BeaconState     state      = TestState.PrepareTestState(testServiceProvider);
            ForkChoice      forkChoice = testServiceProvider.GetService <ForkChoice>();
            // Get genesis store initialise MemoryStoreProvider with the state
            IStore store = forkChoice.GetGenesisStore(state);

            // Move forward time
            BeaconStateAccessor beaconStateAccessor = testServiceProvider.GetService <BeaconStateAccessor>();
            TimeParameters      timeParameters      = testServiceProvider.GetService <IOptions <TimeParameters> >().Value;
            ulong          time                  = state.GenesisTime + 1;
            ulong          nextSlotTime          = state.GenesisTime;
            ValidatorIndex maximumValidatorIndex = new ValidatorIndex((ulong)state.Validators.Count - 1);

            ValidatorIndex validatorIndex0 = beaconStateAccessor.GetBeaconProposerIndex(state);

            Console.WriteLine("Slot {0}, time {1} = proposer index {2}", state.Slot, time, validatorIndex0);
            validatorIndex0.ShouldBeLessThanOrEqualTo(maximumValidatorIndex);

            List <ValidatorIndex> proposerIndexes = new List <ValidatorIndex>();

            proposerIndexes.Add(validatorIndex0);

            for (int slotIndex = 1; slotIndex <= 16; slotIndex++)
            {
                // Slot 1
                nextSlotTime = nextSlotTime + timeParameters.SecondsPerSlot;
                while (time < nextSlotTime)
                {
                    forkChoice.OnTick(store, time);
                    time++;
                }

                forkChoice.OnTick(store, time);
                time++;
                BeaconBlock block = TestBlock.BuildEmptyBlockForNextSlot(testServiceProvider, state, signed: true);
                TestState.StateTransitionAndSignBlock(testServiceProvider, state, block);
                forkChoice.OnBlock(store, block);
                forkChoice.OnTick(store, time);
                time++;

                ValidatorIndex validatorIndex = beaconStateAccessor.GetBeaconProposerIndex(state);
                Console.WriteLine("Slot {0}, time {1} = proposer index {2}", state.Slot, time, validatorIndex);
                validatorIndex.ShouldBeLessThanOrEqualTo(maximumValidatorIndex);
                proposerIndexes.Add(validatorIndex);
            }

            for (var slotIndex = 0; slotIndex < proposerIndexes.Count; slotIndex++)
            {
                ValidatorIndex proposerIndex = proposerIndexes[slotIndex];
                Validator      proposer      = state.Validators[(int)(ulong)proposerIndex];
                Console.WriteLine("Slot {0} = proposer index {1}, public key {2}", slotIndex, proposerIndex, proposer.PublicKey);
            }
        }
        public void ProgramPoint_Equivalence()
        {
            var block = new TestBlock();
            var pp1   = new ProgramPoint(block, 1);
            var pp2   = new ProgramPoint(block, 1);

            pp2.Should().Be(pp1);
            pp2.GetHashCode().Should().Be(pp1.GetHashCode());
        }
        public void ProgramPoint_Equivalence()
        {
            var block = new TestBlock();
            var pp1 = new ProgramPoint(block, 1);
            var pp2 = new ProgramPoint(block, 1);

            Assert.AreEqual(pp1, pp2);
            Assert.AreEqual(pp1.GetHashCode(), pp2.GetHashCode());
        }
        public void ProgramPoint_Diff_Offset()
        {
            var block = new TestBlock();
            var pp1 = new ProgramPoint(block, 1);
            var pp2 = new ProgramPoint(block, 2);

            Assert.AreNotEqual(pp1, pp2);
            Assert.AreNotEqual(pp1.GetHashCode(), pp2.GetHashCode());
        }
Example #22
0
        public void ProgramPoint_Diff_Offset()
        {
            var block = new TestBlock();
            var pp1   = new ProgramPoint(block, 1);
            var pp2   = new ProgramPoint(block, 2);

            Assert.AreNotEqual(pp1, pp2);
            Assert.AreNotEqual(pp1.GetHashCode(), pp2.GetHashCode());
        }
Example #23
0
        public void ProgramPoint_Equivalence()
        {
            var block = new TestBlock();
            var pp1   = new ProgramPoint(block, 1);
            var pp2   = new ProgramPoint(block, 1);

            Assert.AreEqual(pp1, pp2);
            Assert.AreEqual(pp1.GetHashCode(), pp2.GetHashCode());
        }
        public void ProgramPoint_Diff_Offset()
        {
            var block = new TestBlock();
            var pp1   = new ProgramPoint(block, 1);
            var pp2   = new ProgramPoint(block, 2);

            pp2.Should().NotBe(pp1);
            pp2.GetHashCode().Should().NotBe(pp1.GetHashCode());
        }
Example #25
0
        public void TestUpdateReadyOperationsMultiDependecy()
        {
            TestBlock operation1 = new TestBlock(new List <FluidBlock> {
            }, "op1", new TestModule());
            TestBlock operation3 = new TestBlock(new List <FluidBlock> {
            }, "op3", new TestModule());
            TestBlock operation2 = new TestBlock(new List <FluidBlock> {
                operation1, operation3
            }, "op2", new TestModule());
            TestBlock operation4 = new TestBlock(new List <FluidBlock> {
            }, "op4", new TestModule());

            DFG <Block> dfg = new DFG <Block>();

            dfg.AddNode(operation1);
            dfg.AddNode(operation3);
            dfg.AddNode(operation2);
            dfg.AddNode(operation4);
            dfg.FinishDFG();

            //Now the operations associated with node 1,
            //should wait for the operation assocaited with node 0 and 2.

            Assay assay = new Assay(dfg);

            //Remove first dependecy

            assay.UpdateReadyOperations(dfg.Nodes[2].value);

            Assert.AreEqual(assay.GetReadyOperations().Count, dfg.Nodes.Count - 2);

            Assert.IsTrue(assay.GetReadyOperations().Contains(dfg.Nodes[0].value));
            Assert.IsTrue(assay.GetReadyOperations().Contains(dfg.Nodes[3].value));
            Assert.IsFalse(assay.GetReadyOperations().Contains(dfg.Nodes[1].value));
            Assert.IsFalse(assay.GetReadyOperations().Contains(dfg.Nodes[2].value));

            Assert.IsFalse(dfg.Nodes[0].value.IsDone);
            Assert.IsFalse(dfg.Nodes[1].value.IsDone);
            Assert.IsTrue(dfg.Nodes[2].value.IsDone);
            Assert.IsFalse(dfg.Nodes[3].value.IsDone);

            //remove last dependecy
            assay.UpdateReadyOperations(dfg.Nodes[0].value);

            Assert.AreEqual(assay.GetReadyOperations().Count, dfg.Nodes.Count - 2);

            Assert.IsTrue(assay.GetReadyOperations().Contains(dfg.Nodes[1].value));
            Assert.IsTrue(assay.GetReadyOperations().Contains(dfg.Nodes[3].value));
            Assert.IsFalse(assay.GetReadyOperations().Contains(dfg.Nodes[0].value));
            Assert.IsFalse(assay.GetReadyOperations().Contains(dfg.Nodes[2].value));

            Assert.IsTrue(dfg.Nodes[0].value.IsDone);
            Assert.IsFalse(dfg.Nodes[1].value.IsDone);
            Assert.IsTrue(dfg.Nodes[2].value.IsDone);
            Assert.IsFalse(dfg.Nodes[3].value.IsDone);
        }
        public void It_renders_its_child_parts_only_once_if_name_evaluates_to_a_collection()
        {
            var a = new TestBlock("a", new LiteralText("b"));
            var writer = new StringWriter();
            var context = new RenderContext(null, new { a = new[] { 1, 2, 3 } }, writer, null);

            a.Render(context);

            Assert.AreEqual("b", writer.GetStringBuilder().ToString());
        }
Example #27
0
        public void InvalidSignatureBlockHeader()
        {
            // Arrange
            var testServiceProvider = TestSystem.BuildTestServiceProvider();
            var state = TestState.PrepareTestState(testServiceProvider);

            var block = TestBlock.BuildEmptyBlockForNextSlot(testServiceProvider, state, signed: false);

            RunBlockHeaderProcessing(testServiceProvider, state, block, expectValid: false);
        }
        public void SuccessBlockHeader()
        {
            // Arrange
            IServiceProvider testServiceProvider = TestSystem.BuildTestServiceProvider();
            BeaconState      state = TestState.PrepareTestState(testServiceProvider);

            BeaconBlock block = TestBlock.BuildEmptyBlockForNextSlot(testServiceProvider, state, BlsSignature.Zero);

            RunBlockHeaderProcessing(testServiceProvider, state, block, expectValid: true);
        }
Example #29
0
    public static List <TestTrial> GetStepsFromBlock(TestBlock block)
    {
        List <TestTrial> steps = new List <TestTrial>();

        foreach (TestSequence trial in block.Sequences)
        {
            steps.AddRange(trial.Trials);
        }
        return(steps);
    }
        public void InvalidSlotBlockHeader()
        {
            // Arrange
            IServiceProvider testServiceProvider = TestSystem.BuildTestServiceProvider();
            BeaconState      state = TestState.PrepareTestState(testServiceProvider);

            BeaconBlock block = TestBlock.BuildEmptyBlock(testServiceProvider, state, state.Slot + new Slot(2), BlsSignature.Zero);

            RunBlockHeaderProcessing(testServiceProvider, state, block, expectValid: false);
        }
        public void It_supports_accessing_members_of_child_objects()
        {
            var a = new TestBlock("a.b", new LiteralText("c"));
            var writer = new StringWriter();
            var context = new RenderContext(null, new { a = new { b = new[] { 1, 2, 3 } } }, writer, null);

            a.Render(context);

            Assert.AreEqual("c", writer.GetStringBuilder().ToString());
        }
        public void It_does_not_render_its_child_parts_if_name_evaluates_to_empty_string()
        {
            var a = new TestBlock("a", new LiteralText("b"));
            var writer = new StringWriter();
            var context = new RenderContext(null, new { a = "" }, writer, null);

            a.Render(context);

            Assert.AreEqual("", writer.GetStringBuilder().ToString());
        }
Example #33
0
        public void Block_CreateAndGetFace_ShouldFindFace()
        {
            // 1. Prepare
            SphericalVector faceOrientation = new SphericalVector(Math.PI, Math.PI);

            // 2. Execute
            Block     b = new TestBlock(new BlockFace("test", faceOrientation));
            BlockFace f = b.GetBlockFace(faceOrientation);

            // 3. Verify
            Assert.NotNull(f);
        }
Example #34
0
        public void Block_CreateAndGetFaceWithBadOrientation_ReturnNull()
        {
            // 1. Prepare
            SphericalVector faceOrientation = new SphericalVector(Math.PI, Math.PI);
            Block           b = new TestBlock(new BlockFace("test", faceOrientation));

            // 2. Execute
            BlockFace f = b.GetBlockFace(new SphericalVector(100, 100));

            // 3. Verify
            Assert.Null(f);
        }
Example #35
0
        public async Task ShorterChainButHeavierWeight()
        {
            // Arrange
            IServiceProvider testServiceProvider = TestSystem.BuildTestServiceProvider(useStore: true);
            BeaconState      state = TestState.PrepareTestState(testServiceProvider);

            // Initialization
            ICryptographyService cryptographyService = testServiceProvider.GetService <ICryptographyService>();
            IForkChoice          forkChoice          = testServiceProvider.GetService <IForkChoice>();
            IStore store = testServiceProvider.GetService <IStore>();
            await forkChoice.InitializeForkChoiceStoreAsync(store, state);

            BeaconState genesisState = BeaconState.Clone(state);

            // build longer tree
            Root        longRoot  = Root.Zero;
            BeaconState longState = BeaconState.Clone(genesisState);

            for (int i = 0; i < 3; i++)
            {
                BeaconBlock       longBlock       = TestBlock.BuildEmptyBlockForNextSlot(testServiceProvider, longState, BlsSignature.Zero);
                SignedBeaconBlock signedLongBlock = TestState.StateTransitionAndSignBlock(testServiceProvider, longState, longBlock);
                await AddBlockToStore(testServiceProvider, store, signedLongBlock);

                if (i == 2)
                {
                    longRoot = cryptographyService.HashTreeRoot(longBlock);
                }
            }

            // build short tree
            BeaconState shortState = BeaconState.Clone(genesisState);
            BeaconBlock shortBlock = TestBlock.BuildEmptyBlockForNextSlot(testServiceProvider, shortState, BlsSignature.Zero);

            shortBlock.Body.SetGraffiti(new Bytes32(Enumerable.Repeat((byte)0x42, 32).ToArray()));
            TestBlock.SignBlock(testServiceProvider, shortState, shortBlock, ValidatorIndex.None);
            SignedBeaconBlock signedShortBlock = TestState.StateTransitionAndSignBlock(testServiceProvider, shortState, shortBlock);

            await AddBlockToStore(testServiceProvider, store, signedShortBlock);

            Attestation shortAttestation = TestAttestation.GetValidAttestation(testServiceProvider, shortState, shortBlock.Slot, CommitteeIndex.None, signed: true);

            await AddAttestationToStore(testServiceProvider, store, shortAttestation);

            // Act
            Root headRoot = await forkChoice.GetHeadAsync(store);

            // Assert
            Root expectedRoot = cryptographyService.HashTreeRoot(shortBlock);

            headRoot.ShouldBe(expectedRoot);
            headRoot.ShouldNotBe(longRoot);
        }
        public void It_has_a_useful_ToString_method()
        {
            var a = new TestBlock("a");

            Assert.AreEqual("TestBlock(\"a\")", a.ToString());
        }