예제 #1
0
        public async Task mingas_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.AddressB, FnSignature2, 1, TxPriorityContract.DestinationSource.Local),
                new TxPriorityContract.Destination(TestItem.AddressC, FnSignature,  1, TxPriorityContract.DestinationSource.Local),
            };

            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.MinGasPrices.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 minGasPrices = chain.MinGasPrices.GetItemsFromContractAtBlock(chain.BlockTree.Head.Header);

            minGasPrices.Should().BeEquivalentTo(expected, o => o.ComparingByMembers <TxPriorityContract.Destination>());
        }
예제 #2
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);
 }