public async Task can_validate_gas_limit_incorrect()
        {
            using TestGasLimitContractBlockchain chain = await TestContractBlockchain.ForTest <TestGasLimitContractBlockchain, AuRaContractGasLimitOverrideTests>();

            bool isValid = ((AuRaContractGasLimitOverride)chain.GasLimitCalculator).IsGasLimitValid(chain.BlockTree.Head.Header, 100000001, out long?expectedGasLimit);

            isValid.Should().BeFalse();
            expectedGasLimit.Should().Be(CorrectHeadGasLimit);
        }
        public async Task caches_read_block_gas_limit()
        {
            using TestGasLimitContractBlockchain chain = await TestContractBlockchain.ForTest <TestGasLimitContractBlockchain, AuRaContractGasLimitOverrideTests>();

            chain.GasLimitCalculator.GetGasLimit(chain.BlockTree.Head.Header);
            long?gasLimit = chain.GasLimitOverrideCache.GasLimitCache.Get(chain.BlockTree.Head.Hash);

            gasLimit.Should().Be(CorrectHeadGasLimit);
        }
Esempio n. 3
0
        public async Task whitelist_should_return_correctly()
        {
            using var chain = await TestContractBlockchain.ForTest <TxPermissionContractBlockchainWithBlocks, TxPriorityContractTests>();

            var whiteList           = chain.TxPriorityContract.SendersWhitelist.GetAllItemsFromBlock(chain.BlockTree.Head.Header);
            var whiteListInContract = chain.SendersWhitelist.GetItemsFromContractAtBlock(chain.BlockTree.Head.Header);

            object[] expected = { TestItem.AddressA, TestItem.AddressC };
            whiteList.Should().BeEquivalentTo(expected);
            whiteListInContract.Should().BeEquivalentTo(expected);
        }
        public async Task mingas_should_return_correctly()
        {
            var chain = await TestContractBlockchain.ForTest <TxPermissionContractBlockchainWithBlocks, TxPriorityContractTests>();

            var minGasPrices           = chain.TxPriorityContract.MinGasPrices.GetAllItemsFromBlock(chain.BlockTree.Head.Header);
            var minGasPricesInContract = chain.MinGasPrices.GetItemsFromContractAtBlock(chain.BlockTree.Head.Header);

            object[] expected = { new TxPriorityContract.Destination(TestItem.AddressB, FnSignature, 4) };
            minGasPrices.Should().BeEquivalentTo(expected, o => o.ComparingByMembers <TxPriorityContract.Destination>());
            minGasPricesInContract.Should().BeEquivalentTo(expected, o => o.ComparingByMembers <TxPriorityContract.Destination>());
        }
        priority_should_return_correctly()
        {
            using TxPermissionContractBlockchainWithBlocks chain = await TestContractBlockchain.ForTest <TxPermissionContractBlockchainWithBlocks, TxPriorityContractTests>();

            IEnumerable <TxPriorityContract.Destination> priorities           = chain.TxPriorityContract.Priorities.GetAllItemsFromBlock(chain.BlockTree.Head.Header);
            IEnumerable <TxPriorityContract.Destination> prioritiesInContract = chain.Priorities.GetItemsFromContractAtBlock(chain.BlockTree.Head.Header);

            TxPriorityContract.Destination[] expected =
            {
                new(TestItem.AddressB, FnSignature,  3, TxPriorityContract.DestinationSource.Contract, 2),
                new(TestItem.AddressA, FnSignature2, 1, TxPriorityContract.DestinationSource.Contract, 1),
                new(TestItem.AddressB, FnSignature2, 4, TxPriorityContract.DestinationSource.Contract, 1),
            };
        public async Task priority_should_return_correctly()
        {
            var chain = await TestContractBlockchain.ForTest <TxPermissionContractBlockchainWithBlocks, TxPriorityContractTests>();

            var priorities           = chain.TxPriorityContract.Priorities.GetAllItemsFromBlock(chain.BlockTree.Head.Header);
            var prioritiesInContract = chain.Priorities.GetItemsFromContractAtBlock(chain.BlockTree.Head.Header);

            object[] expected =
            {
                new TxPriorityContract.Destination(TestItem.AddressB, FnSignature,                                               3),
                new TxPriorityContract.Destination(TestItem.AddressA, TxPriorityContract.Destination.FnSignatureEmpty, UInt256.One),
            };

            priorities.Should().BeEquivalentTo(expected, o => o.ComparingByMembers <TxPriorityContract.Destination>());
            prioritiesInContract.Should().BeEquivalentTo(expected, o => o.ComparingByMembers <TxPriorityContract.Destination>());
        }
Esempio n. 7
0
        public async Task mingas_should_return_correctly()
        {
            using var chain = await TestContractBlockchain.ForTest <TxPermissionContractBlockchainWithBlocks, TxPriorityContractTests>();

            var minGasPrices           = chain.TxPriorityContract.MinGasPrices.GetAllItemsFromBlock(chain.BlockTree.Head.Header);
            var minGasPricesInContract = chain.MinGasPrices.GetItemsFromContractAtBlock(chain.BlockTree.Head.Header);

            object[] expected =
            {
                new TxPriorityContract.Destination(TestItem.AddressB, FnSignature2, 4, TxPriorityContract.DestinationSource.Contract, 1),
                new TxPriorityContract.Destination(TestItem.AddressB, FnSignature,  2, TxPriorityContract.DestinationSource.Contract, 2),
            };
            minGasPrices.Should().BeEquivalentTo(expected, o => o.ComparingByMembers <TxPriorityContract.Destination>()
                                                 .Excluding(su => su.SelectedMemberPath.EndsWith("BlockNumber")));

            minGasPricesInContract.Should().BeEquivalentTo(expected, o => o.ComparingByMembers <TxPriorityContract.Destination>());
        }
Esempio n. 8
0
        public async Task priority_should_return_correctly_with_local_storage([Values(true, false)] bool fileFirst)
        {
            using var chain = fileFirst
                ? await TestContractBlockchain.ForTest <TxPermissionContractBlockchainWithBlocksAndLocalDataBeforeStart, TxPriorityContractTests>()
                : await TestContractBlockchain.ForTest <TxPermissionContractBlockchainWithBlocksAndLocalData, TxPriorityContractTests>();

            TxPriorityContract.Destination[] expected =
            {
                new TxPriorityContract.Destination(TestItem.AddressB, FnSignature,                                               5, TxPriorityContract.DestinationSource.Local),
                new TxPriorityContract.Destination(TestItem.AddressC, FnSignature,                                               1, TxPriorityContract.DestinationSource.Local),
                new TxPriorityContract.Destination(TestItem.AddressB, FnSignature2,                                              1, TxPriorityContract.DestinationSource.Local),
                new TxPriorityContract.Destination(TestItem.AddressA, TxPriorityContract.Destination.FnSignatureEmpty, UInt256.One, TxPriorityContract.DestinationSource.Contract, 1),
            };

            var semaphoreSlim = new SemaphoreSlim(chain.LocalDataSource.Data != null ? 1 : 0);

            chain.LocalDataSource.Changed += (sender, args) =>
            {
                var localData = chain.LocalDataSource.Data;
                if (localData != null)
                {
                    chain.LocalDataSource.Data.Priorities.Should().BeEquivalentTo(
                        expected.Where(e => e.Source == TxPriorityContract.DestinationSource.Local),
                        o => o.ComparingByMembers <TxPriorityContract.Destination>());
                    semaphoreSlim.Release();
                }
            };

            if (!await chain.FileSemaphore.WaitAsync(100))
            {
                Assert.Fail("File not written");
            }

            if (!await semaphoreSlim.WaitAsync(100))
            {
                if (chain.LocalDataSource.Data == null)
                {
                    Assert.Fail("Local file rule storage has not been loaded.");
                }
            }

            var priorities = chain.Priorities.GetItemsFromContractAtBlock(chain.BlockTree.Head.Header);

            priorities.Should().BeEquivalentTo(expected, o => o.ComparingByMembers <TxPriorityContract.Destination>());
        }
Esempio n. 9
0
        public async Task whitelist_should_return_correctly_with_local_storage([Values(true, false)] bool fileFirst)
        {
            using var chain = fileFirst
                ? await TestContractBlockchain.ForTest <TxPermissionContractBlockchainWithBlocksAndLocalDataBeforeStart, TxPriorityContractTests>()
                : await TestContractBlockchain.ForTest <TxPermissionContractBlockchainWithBlocksAndLocalData, TxPriorityContractTests>();

            var semaphoreSlim = new SemaphoreSlim(chain.LocalDataSource.Data != null ? 1 : 0);

            chain.LocalDataSource.Changed += (sender, args) =>
            {
                var localData = chain.LocalDataSource.Data;
                if (localData != null)
                {
                    localData.Whitelist.Should().BeEquivalentTo(new object[] { TestItem.AddressD, TestItem.AddressB });
                    semaphoreSlim.Release();
                }
            };

            if (!await chain.FileSemaphore.WaitAsync(100))
            {
                Assert.Fail("File not written");
            }

            if (!await semaphoreSlim.WaitAsync(100))
            {
                if (chain.LocalDataSource.Data == null)
                {
                    Assert.Fail("Local file rule storage has not been loaded.");
                }
            }

            object[] expected = { TestItem.AddressD, TestItem.AddressB, TestItem.AddressA, TestItem.AddressC };

            var whiteList = chain.SendersWhitelist.GetItemsFromContractAtBlock(chain.BlockTree.Head.Header);

            whiteList.Should().BeEquivalentTo(expected);
        }
 public async Task skip_validate_gas_limit_before_enabled()
 {
     using var chain = await TestContractBlockchain.ForTest<TestGasLimitContractBlockchainLateBlockGasLimit, AuRaContractGasLimitOverrideTests>();
     var isValid = ((AuRaContractGasLimitOverride) chain.GasLimitCalculator).IsGasLimitValid(chain.BlockTree.Genesis, 100000001, out _);
     isValid.Should().BeTrue();
 }
 public async Task can_validate_gas_limit_correct()
 {
     using var chain = await TestContractBlockchain.ForTest<TestGasLimitContractBlockchain, AuRaContractGasLimitOverrideTests>();
     var isValid = ((AuRaContractGasLimitOverride) chain.GasLimitCalculator).IsGasLimitValid(chain.BlockTree.Head.Header, CorrectHeadGasLimit, out _);
     isValid.Should().BeTrue();
 }
 public async Task can_read_block_gas_limit_from_contract()
 {
     using var chain = await TestContractBlockchain.ForTest<TestGasLimitContractBlockchain, AuRaContractGasLimitOverrideTests>();
     var gasLimit = chain.GasLimitCalculator.GetGasLimit(chain.BlockTree.Head.Header);
     gasLimit.Should().Be(CorrectHeadGasLimit);
 }