Пример #1
0
        public async Task can_get_commits_fails_if_any_index_invalid()
        {
            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            BaselineModule baselineModule = CreateBaselineModule(testRpc);

            await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether());

            Keccak txHash = (await baselineModule.baseline_deploy(TestItem.Addresses[0], "MerkleTreeSHA")).Data;
            await testRpc.AddBlock();

            ReceiptForRpc receipt = (await testRpc.EthModule.eth_getTransactionReceipt(txHash)).Data;

            await baselineModule.baseline_track(receipt.ContractAddress);

            await baselineModule.baseline_insertCommit(TestItem.Addresses[1], receipt.ContractAddress, TestItem.KeccakH);

            await testRpc.AddBlock();

            var result = await baselineModule.baseline_getCommits(
                receipt.ContractAddress, new UInt256[] { 0, (UInt256)uint.MaxValue + 1 });

            await testRpc.AddBlock();

            result.Result.ResultType.Should().Be(ResultType.Failure);
            result.ErrorCode.Should().Be(ErrorCodes.InvalidInput);
        }
        public async Task Suggesting_blocks_works_correctly_after_processor_restart(int suggestedBlocksAmount)
        {
            TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build();

            await testRpc.BlockchainProcessor.StopAsync();

            IBlockTree tree = testRpc.BlockTree;
            long       startingBlockNumber = tree.Head !.Number;

            SuggestNumberOfBlocks(tree, suggestedBlocksAmount);

            // simulating restarts - we stopped the old blockchain processor and create the new one
            BlockchainProcessor newBlockchainProcessor = new(tree, testRpc.BlockProcessor,
                                                             testRpc.BlockPreprocessorStep, testRpc.StateReader, LimboLogs.Instance, BlockchainProcessor.Options.Default);

            newBlockchainProcessor.Start();
            testRpc.BlockchainProcessor = newBlockchainProcessor;

            // fixing after restart
            StartupBlockTreeFixer fixer = new(new SyncConfig(), tree, testRpc.DbProvider.StateDb, LimboNoErrorLogger.Instance, 5);
            await tree.Accept(fixer, CancellationToken.None);

            // waiting for N new heads
            for (int i = 0; i < suggestedBlocksAmount; ++i)
            {
                await testRpc.WaitForNewHead();
            }

            // add a new block at the end
            await testRpc.AddBlock();

            Assert.AreEqual(startingBlockNumber + suggestedBlocksAmount + 1, tree.Head !.Number);
        }
        public async Task can_get_leaves_fails_if_any_index_invalid()
        {
            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            BaselineModule baselineModule = new BaselineModule(
                testRpc.TxPoolBridge,
                testRpc.LogFinder,
                testRpc.BlockTree,
                _abiEncoder,
                _fileSystem,
                new MemDb(),
                LimboLogs.Instance);

            await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether());

            Keccak txHash = (await baselineModule.baseline_deploy(TestItem.Addresses[0], "MerkleTreeSHA")).Data;
            await testRpc.AddBlock();

            ReceiptForRpc receipt = (await testRpc.EthModule.eth_getTransactionReceipt(txHash)).Data;

            await baselineModule.baseline_track(receipt.ContractAddress);

            await baselineModule.baseline_insertLeaf(TestItem.Addresses[1], receipt.ContractAddress, TestItem.KeccakH);

            await testRpc.AddBlock();

            var result = await baselineModule.baseline_getLeaves(receipt.ContractAddress, 0, (UInt256)uint.MaxValue + 1);

            await testRpc.AddBlock();

            result.Result.ResultType.Should().Be(ResultType.Failure);
            result.ErrorCode.Should().Be(ErrorCodes.InvalidInput);
        }
Пример #4
0
        public async Task can_return_tracked_list(uint trackedCount)
        {
            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            IStateReader   stateReader    = Substitute.For <IStateReader>();
            BaselineModule baselineModule = new BaselineModule(
                testRpc.TxSender,
                stateReader,
                testRpc.LogFinder,
                testRpc.BlockTree,
                _abiEncoder,
                _fileSystem,
                new MemDb(),
                LimboLogs.Instance);

            for (int i = 0; i < trackedCount; i++)
            {
                stateReader.GetCode(null, null).ReturnsForAnyArgs(new byte[] { 255 });
                await baselineModule.baseline_track(TestItem.Addresses[i]);
            }

            var result = (await baselineModule.baseline_getTracked());

            result.Data.Length.Should().Be((int)trackedCount);
        }
        public async Task can_restore_tracking_list_on_startup(uint trackedCount)
        {
            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            MemDb          memDb          = new MemDb();
            BaselineModule baselineModule = new BaselineModule(
                testRpc.TxPoolBridge,
                testRpc.LogFinder,
                testRpc.BlockTree,
                _abiEncoder,
                _fileSystem,
                memDb,
                LimboLogs.Instance);

            for (int i = 0; i < trackedCount; i++)
            {
                await baselineModule.baseline_track(TestItem.Addresses[i]); // any address (no need for tree there)
            }

            BaselineModule restored = new BaselineModule(
                testRpc.TxPoolBridge,
                testRpc.LogFinder,
                testRpc.BlockTree,
                _abiEncoder,
                _fileSystem,
                memDb,
                LimboLogs.Instance);

            var resultRestored = await restored.baseline_getTracked();

            resultRestored.Data.Length.Should().Be((int)trackedCount);
        }
Пример #6
0
        public async Task can_get_siblings_is_protected_against_overflow(long leafIndex)
        {
            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            BaselineModule baselineModule = new BaselineModule(
                testRpc.TxSender,
                testRpc.StateReader,
                testRpc.LogFinder,
                testRpc.BlockTree,
                _abiEncoder,
                _fileSystem,
                new MemDb(),
                LimboLogs.Instance);

            await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether());

            Keccak txHash = (await baselineModule.baseline_deploy(TestItem.Addresses[0], "MerkleTreeSHA")).Data;
            await testRpc.AddBlock();

            ReceiptForRpc receipt = (await testRpc.EthModule.eth_getTransactionReceipt(txHash)).Data;

            await baselineModule.baseline_insertLeaf(TestItem.Addresses[1], receipt.ContractAddress, TestItem.KeccakH);

            await testRpc.AddBlock();

            var result = await baselineModule.baseline_getSiblings(receipt.ContractAddress, leafIndex);

            await testRpc.AddBlock();

            result.Result.ResultType.Should().Be(ResultType.Failure);
            result.Result.Error.Should().NotBeNull();
            result.ErrorCode.Should().Be(ErrorCodes.InvalidInput);
            result.Data.Should().BeNull();
        }
Пример #7
0
        public async Task insert_commit_given_hash_is_emitting_an_event()
        {
            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            BaselineModule baselineModule = CreateBaselineModule(testRpc);
            BaselineTree   baselineTree   = new ShaBaselineTree(new MemDb(), new MemDb(), new byte[] { }, 0, LimboNoErrorLogger.Instance);
            await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether());

            await testRpc.AddFunds(TestItem.Addresses[1], 1.Ether());

            Keccak txHash = (await baselineModule.baseline_deploy(TestItem.Addresses[0], "MerkleTreeSHA")).Data;
            await testRpc.AddBlock();


            ReceiptForRpc receipt = (await testRpc.EthModule.eth_getTransactionReceipt(txHash)).Data;

            Keccak insertLeafTxHash = (
                await baselineModule.baseline_insertCommit(
                    TestItem.Addresses[1],
                    receipt.ContractAddress,
                    TestItem.KeccakH)).Data;
            await testRpc.AddBlock();

            ReceiptForRpc insertLeafReceipt = (await testRpc.EthModule.eth_getTransactionReceipt(insertLeafTxHash)).Data;

            insertLeafReceipt.Logs.Should().HaveCount(1);
        }
Пример #8
0
        public async Task deploy_deploys_the_contract()
        {
            var spec = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            testRpc.TestWallet.UnlockAccount(TestItem.Addresses[0], new SecureString());
            await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether());

            DepositModule depositModule = new DepositModule(
                testRpc.TxPoolBridge,
                testRpc.LogFinder,
                new DepositConfig()
            {
                DepositContractAddress = TestItem.AddressA.ToString()
            },
                LimboLogs.Instance);

            var result = await depositModule.deposit_deploy(TestItem.Addresses[0]);

            result.Data.Should().NotBe(null);
            result.ErrorCode.Should().Be(0);
            result.Result.Error.Should().BeNull();
            result.Result.ResultType.Should().Be(ResultType.Success);

            await testRpc.AddBlock();

            testRpc.BlockTree.Head.Number.Should().Be(5);
            testRpc.BlockTree.Head.Transactions.Should().Contain(tx => tx.IsContractCreation);

            var code = testRpc.StateReader
                       .GetCode(testRpc.BlockTree.Head.StateRoot, ContractAddress.From(TestItem.Addresses[0], 0));

            code.Should().NotBeEmpty();
        }
Пример #9
0
        public async Task deploy_deploys_the_contract()
        {
            var spec = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            testRpc.TestWallet.UnlockAccount(TestItem.Addresses[0], new SecureString());
            await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether());

            BaselineModule baselineModule = new BaselineModule(
                testRpc.TxSender,
                testRpc.StateReader,
                testRpc.LogFinder,
                testRpc.BlockTree,
                _abiEncoder,
                _fileSystem,
                new MemDb(),
                LimboLogs.Instance);

            var result = await baselineModule.baseline_deploy(TestItem.Addresses[0], "MerkleTreeSHA");

            result.Data.Should().NotBe(null);
            result.ErrorCode.Should().Be(0);
            result.Result.Error.Should().BeNull();
            result.Result.ResultType.Should().Be(ResultType.Success);

            await testRpc.AddBlock();

            testRpc.BlockTree.Head.Number.Should().Be(5);
            testRpc.BlockTree.Head.Transactions.Should().Contain(tx => tx.IsContractCreation);

            var code = testRpc.StateReader
                       .GetCode(testRpc.BlockTree.Head.StateRoot, ContractAddress.From(TestItem.Addresses[0], 0));

            code.Should().NotBeEmpty();
        }
Пример #10
0
        public async Task insert_leaf_given_hash_is_emitting_an_event()
        {
            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            BaselineModule baselineModule = new BaselineModule(
                testRpc.TxSender,
                testRpc.StateReader,
                testRpc.LogFinder,
                testRpc.BlockTree,
                _abiEncoder,
                _fileSystem,
                new MemDb(),
                LimboLogs.Instance);

            await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether());

            await testRpc.AddFunds(TestItem.Addresses[1], 1.Ether());

            Keccak txHash = (await baselineModule.baseline_deploy(TestItem.Addresses[0], "MerkleTreeSHA")).Data;
            await testRpc.AddBlock();

            ReceiptForRpc receipt = (await testRpc.EthModule.eth_getTransactionReceipt(txHash)).Data;

            Keccak insertLeafTxHash = (
                await baselineModule.baseline_insertLeaf(
                    TestItem.Addresses[1],
                    receipt.ContractAddress,
                    TestItem.KeccakH)).Data;
            await testRpc.AddBlock();

            ReceiptForRpc insertLeafReceipt = (await testRpc.EthModule.eth_getTransactionReceipt(insertLeafTxHash)).Data;

            insertLeafReceipt.Logs.Should().HaveCount(1);
        }
Пример #11
0
        public async Task concurrent_track_requests_will_succeed()
        {
            Random random = new Random(42);

            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            IStateReader   stateReader    = Substitute.For <IStateReader>();
            BaselineModule baselineModule = CreateBaselineModule(testRpc, stateReader);

            int    iterationsPerTask = 1000;
            Action trackAction       = () =>
            {
                for (int i = 0; i < iterationsPerTask; i++)
                {
                    byte[] bytes = new byte[20];
                    random.NextBytes(bytes);
                    Address address = new Address(bytes);

                    stateReader.GetCode(Arg.Any <Keccak>(), address).Returns(new byte[] { 255 });
                    var result = baselineModule.baseline_track(address).Result; // safe to invoke Result here
                    result.Result.ResultType.Should().Be(ResultType.Success);
                }
            };

            Task task1 = new Task(trackAction);
            Task task2 = new Task(trackAction);
            Task task3 = new Task(trackAction);

            task1.Start();
            task2.Start();
            task3.Start();

            await Task.WhenAll(task1, task2, task3);
        }
Пример #12
0
        public async Task track_untrack_track_works()
        {
            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            BaselineModule baselineModule = CreateBaselineModule(testRpc);

            await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether());

            Address treeAddress = await Deploy(testRpc, baselineModule);

            var result = await baselineModule.baseline_track(treeAddress);

            result.Result.ResultType.Should().Be(ResultType.Success);
            result = await baselineModule.baseline_untrack(treeAddress);

            result.Result.ResultType.Should().Be(ResultType.Success);
            result = await baselineModule.baseline_track(treeAddress);

            result.Result.ResultType.Should().Be(ResultType.Success);

            var countResult = await baselineModule.baseline_getCount(treeAddress);

            countResult.Result.ResultType.Should().Be(ResultType.Success);
        }
Пример #13
0
    public async Task Eth_create_access_list_calculates_proper_gas(bool optimize, long loads)
    {
        var test = await TestRpcBlockchain.ForTest(SealEngineType.NethDev)
                   .Build(new TestSpecProvider(Berlin.Instance));

        (byte[] code, AccessListItemForRpc[] accessList) = GetTestAccessList(loads);

        TransactionForRpc transaction =
            test.JsonSerializer.Deserialize <TransactionForRpc>(
                $"{{\"type\":\"0x1\", \"data\": \"{code.ToHexString(true)}\"}}");
        string serializedCreateAccessList = test.TestEthRpc("eth_createAccessList",
                                                            test.JsonSerializer.Serialize(transaction), "0x0", optimize.ToString().ToLower());

        if (optimize && loads <= AccessTxTracer.MaxStorageAccessToOptimize)
        {
            accessList = GetTestAccessList(loads, false).AccessList;
        }

        transaction.AccessList = accessList;
        string serializedEstimateGas =
            test.TestEthRpc("eth_estimateGas", test.JsonSerializer.Serialize(transaction), "0x0");

        var gasUsedEstimateGas      = JToken.Parse(serializedEstimateGas).Value <string>("result");
        var gasUsedCreateAccessList =
            JToken.Parse(serializedCreateAccessList).SelectToken("result.gasUsed")?.Value <string>();

        gasUsedCreateAccessList.Should().Be(gasUsedEstimateGas);
    }
Пример #14
0
        public async Task second_track_request_will_fail()
        {
            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            BaselineModule baselineModule = new BaselineModule(
                testRpc.TxSender,
                testRpc.StateReader,
                testRpc.LogFinder,
                testRpc.BlockTree,
                _abiEncoder,
                _fileSystem,
                new MemDb(),
                LimboLogs.Instance);

            await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether());

            await baselineModule.baseline_track(TestItem.AddressC);

            var result = await baselineModule.baseline_track(TestItem.AddressC);

            result.Result.ResultType.Should().Be(ResultType.Failure);
            result.Result.Error.Should().NotBeNull();
            result.ErrorCode.Should().Be(ErrorCodes.InvalidInput);
        }
Пример #15
0
        public async Task insert_commits_given_hash_is_emitting_an_event(int leafCount)
        {
            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            BaselineModule baselineModule = CreateBaselineModule(testRpc);

            await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether());

            await testRpc.AddFunds(TestItem.Addresses[1], 1.Ether());

            Keccak txHash = (await baselineModule.baseline_deploy(TestItem.Addresses[0], "MerkleTreeSHA")).Data;
            await testRpc.AddBlock();

            ReceiptForRpc receipt = (await testRpc.EthModule.eth_getTransactionReceipt(txHash)).Data;

            Keccak[] leaves             = Enumerable.Repeat(TestItem.KeccakH, leafCount).ToArray();
            Keccak   insertLeavesTxHash = (await baselineModule.baseline_insertCommits(
                                               TestItem.Addresses[1],
                                               receipt.ContractAddress,
                                               leaves)).Data;
            await testRpc.AddBlock();

            ReceiptForRpc insertLeafReceipt = (await testRpc.EthModule.eth_getTransactionReceipt(
                                                   insertLeavesTxHash)).Data;

            insertLeafReceipt.Logs.Should().HaveCount(1);
            insertLeafReceipt.Logs[0].Data.Length.Should().Be(128 + leafCount * 32);
        }
Пример #16
0
        public async Task can_get_commits_after_commit_is_added()
        {
            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            BaselineModule baselineModule = CreateBaselineModule(testRpc);

            await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether());

            await testRpc.AddFunds(TestItem.Addresses[1], 1.Ether());

            Keccak txHash = (await baselineModule.baseline_deploy(TestItem.Addresses[0], "MerkleTreeSHA")).Data;
            await testRpc.AddBlock();

            ReceiptForRpc receipt = (await testRpc.EthModule.eth_getTransactionReceipt(txHash)).Data;

            await baselineModule.baseline_insertCommit(TestItem.Addresses[1], receipt.ContractAddress, TestItem.KeccakH);

            await testRpc.AddBlock();

            await baselineModule.baseline_track(receipt.ContractAddress);

            var result = await baselineModule.baseline_getCommits(receipt.ContractAddress, new UInt256[] { 0, 1 });

            await testRpc.AddBlock();

            result.Result.ResultType.Should().Be(ResultType.Success);
            result.Result.Error.Should().Be(null);
            result.ErrorCode.Should().Be(0);
            result.Data[0].Hash.Should().Be(TestItem.KeccakH);
            result.Data[1].Hash.Should().Be(Keccak.Zero);
        }
Пример #17
0
        public async Task deploy_returns_an_error_when_file_is_missing()
        {
            var spec = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            testRpc.TestWallet.UnlockAccount(TestItem.Addresses[0], new SecureString());
            await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether());

            BaselineModule baselineModule = new BaselineModule(
                testRpc.TxSender,
                testRpc.StateReader,
                testRpc.LogFinder,
                testRpc.BlockTree,
                _abiEncoder,
                _fileSystem,
                new MemDb(),
                LimboLogs.Instance);

            var result = await baselineModule.baseline_deploy(TestItem.Addresses[0], "MissingContract");

            result.Data.Should().Be(null);
            result.ErrorCode.Should().Be(ErrorCodes.ResourceNotFound);
            result.Result.Error.Should().NotBeEmpty();
            result.Result.ResultType.Should().Be(ResultType.Failure);
        }
Пример #18
0
        public async Task deploy_bytecode_validates_input(string bytecode)
        {
            var spec = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            testRpc.TestWallet.UnlockAccount(TestItem.Addresses[0], new SecureString());
            await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether());

            BaselineModule baselineModule = CreateBaselineModule(testRpc);

            var result = await baselineModule.baseline_deployBytecode(
                TestItem.Addresses[0],
                bytecode); // invalid input

            result.Data.Should().Be(null);
            result.ErrorCode.Should().Be(ErrorCodes.InvalidInput);
            result.Result.Error.Should().NotBeNull();
            result.Result.ResultType.Should().Be(ResultType.Failure);
            await testRpc.AddBlock();

            testRpc.BlockTree.Head.Number.Should().Be(5);
            testRpc.BlockTree.Head.Transactions.Should().NotContain(tx => tx.IsContractCreation);

            var code = testRpc.StateReader
                       .GetCode(testRpc.BlockTree.Head.StateRoot, ContractAddress.From(TestItem.Addresses[0], 0));

            code.Should().BeEmpty();
        }
        private async Task <(TestRpcBlockchain TestRpc, BaselineModule BaselineModule)> InitializeTestRpc(Address address)
        {
            var spec         = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            var blockBuilder = Core.Test.Builders.Build.A.Block.Genesis.WithGasLimit(10000000000);
            var testRpc      = await TestRpcBlockchain.ForTest(SealEngineType.NethDev)
                               .WithGenesisBlockBuilder(blockBuilder)
                               .Build(spec);

            testRpc.TestWallet.UnlockAccount(address, new SecureString());
            await testRpc.AddFunds(address, 1.Ether());

            BaselineModule baselineModule = new BaselineModule(
                testRpc.TxSender,
                testRpc.StateReader,
                testRpc.LogFinder,
                testRpc.BlockTree,
                new AbiEncoder(),
                _fileSystem,
                _baselineDb,
                _metadataBaselineDb,
                LimboLogs.Instance,
                testRpc.BlockProcessor,
                new DisposableStack());
            Keccak txHash = (await baselineModule.baseline_deploy(address, "MerkleTreeSHA")).Data;
            await testRpc.AddBlock();

            return(testRpc, baselineModule);
        }
        public async Task Process_long_running_branch(int blocksAmount)
        {
            var address = TestItem.Addresses[0];
            var spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            var testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev)
                          .Build(spec);

            testRpc.TestWallet.UnlockAccount(address, new SecureString());
            await testRpc.AddFunds(address, 1.Ether());

            await testRpc.AddBlock();

            var suggestedBlockResetEvent = new SemaphoreSlim(0);

            testRpc.BlockTree.NewHeadBlock += (s, e) =>
            {
                suggestedBlockResetEvent.Release(1);
            };

            var branchLength = blocksAmount + (int)testRpc.BlockTree.BestKnownNumber + 1;

            ((BlockTree)testRpc.BlockTree).AddBranch(branchLength, (int)testRpc.BlockTree.BestKnownNumber);
            (await suggestedBlockResetEvent.WaitAsync(TestBlockchain.DefaultTimeout * 10)).Should().BeTrue();
            Assert.AreEqual(branchLength - 1, (int)testRpc.BlockTree.BestKnownNumber);
        }
        public static Task <TestMevRpcBlockchain> CreateChain(int maxMergedBundles, IReleaseSpec?releaseSpec = null, UInt256?initialBaseFeePerGas = null, Address[]?relayAddresses = null)
        {
            TestMevRpcBlockchain testMevRpcBlockchain = new(maxMergedBundles, initialBaseFeePerGas, relayAddresses);
            TestSpecProvider     testSpecProvider     = releaseSpec is not null ? new TestSpecProvider(releaseSpec) : new TestSpecProvider(Berlin.Instance);

            testSpecProvider.ChainId = 1;
            return(TestRpcBlockchain.ForTest(testMevRpcBlockchain).Build(testSpecProvider));
        }
Пример #22
0
        public static Task <TestAccountAbstractionRpcBlockchain> CreateChain(IReleaseSpec?releaseSpec = null, UInt256?initialBaseFeePerGas = null)
        {
            TestAccountAbstractionRpcBlockchain testMevRpcBlockchain = new(initialBaseFeePerGas);
            TestSpecProvider testSpecProvider = releaseSpec is not null ? new TestSpecProvider(releaseSpec) : new TestSpecProvider(London.Instance);

            testSpecProvider.ChainId = 1;
            return(TestRpcBlockchain.ForTest(testMevRpcBlockchain).Build(testSpecProvider));
        }
Пример #23
0
        public async Task Parallel_calls()
        {
            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(
                SealEngineType.NethDev).Build(spec, 100000.Ether());

            BaselineModule baselineModule = new BaselineModule(
                testRpc.TxSender,
                testRpc.StateReader,
                testRpc.LogFinder,
                testRpc.BlockTree,
                _abiEncoder,
                _fileSystem,
                new MemDb(),
                LimboLogs.Instance);

            for (int i = 0; i < 255; i++)
            {
                testRpc.TestWallet.UnlockAccount(TestItem.Addresses[i], new SecureString());
                await testRpc.AddFunds(TestItem.Addresses[i], 100.Ether());
            }

            // Keccak txHash = (await baselineModule.baseline_deploy(TestItem.Addresses[0], "MerkleTreeSHA")).Data;
            // await testRpc.AddBlock();
            // ReceiptForRpc receipt = (await testRpc.EthModule.eth_getTransactionReceipt(txHash)).Data;

            List <Task> tasks = new List <Task>();

            for (int i = 0; i < 16; i++)
            {
                Task task = RunAll(testRpc, baselineModule, i);
                tasks.Add(task);
            }

            await Task.WhenAny(Task.Delay(30000), Task.WhenAny(tasks)).ContinueWith(t =>
            {
                foreach (Task task in tasks)
                {
                    if (task.IsFaulted)
                    {
                        ExceptionHelper.Rethrow(task.Exception !.InnerException);
                    }
                }
            });

            await Task.WhenAny(Task.Delay(30000), Task.WhenAll(tasks)).ContinueWith(t =>
            {
                foreach (Task task in tasks)
                {
                    if (task.IsFaulted)
                    {
                        ExceptionHelper.Rethrow(task.Exception !.InnerException);
                    }
                }
            });
        }
Пример #24
0
        private async Task <TestRpcBlockchain> CreateTestRpc()
        {
            Address address = TestItem.Addresses[0];
            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev)
                                                .Build(spec);

            testRpc.TestWallet.UnlockAccount(address, new SecureString());
            await testRpc.AddFunds(address, 1.Ether());

            return(testRpc);
        }
Пример #25
0
        public async Task untrack_fails_when_not_tracked()
        {
            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            BaselineModule baselineModule = CreateBaselineModule(testRpc);

            await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether());

            var result = await baselineModule.baseline_untrack(TestItem.AddressC);

            result.Result.ResultType.Should().Be(ResultType.Failure);
        }
Пример #26
0
        public async Task can_get_siblings_after_leaf_is_added()
        {
            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            BaselineModule baselineModule = new BaselineModule(
                testRpc.TxSender,
                testRpc.StateReader,
                testRpc.LogFinder,
                testRpc.BlockTree,
                _abiEncoder,
                _fileSystem,
                new MemDb(),
                LimboLogs.Instance);

            await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether());

            await testRpc.AddFunds(TestItem.Addresses[1], 1.Ether());

            Keccak txHash = (await baselineModule.baseline_deploy(TestItem.Addresses[0], "MerkleTreeSHA")).Data;
            await testRpc.AddBlock();

            ReceiptForRpc receipt = (await testRpc.EthModule.eth_getTransactionReceipt(txHash)).Data;

            await baselineModule.baseline_insertLeaf(
                TestItem.Addresses[1], receipt.ContractAddress, TestItem.KeccakH);

            await testRpc.AddBlock();

            await baselineModule.baseline_track(receipt.ContractAddress);

            var result = await baselineModule.baseline_getSiblings(receipt.ContractAddress, 0);

            await testRpc.AddBlock();

            result.Result.ResultType.Should().Be(ResultType.Success);
            result.Result.Error.Should().Be(null);
            result.ErrorCode.Should().Be(0);
            result.Data.Should().HaveCount(32);

            Keccak root = (await baselineModule.baseline_getRoot(receipt.ContractAddress)).Data;
            bool   verificationResult =
                (await baselineModule.baseline_verify(
                     receipt.ContractAddress,
                     root,
                     TestItem.KeccakH,
                     result.Data))
                .Data;

            verificationResult.Should().Be(true);
        }
Пример #27
0
        public async Task track_request_will_succeed()
        {
            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            IStateReader   stateReader    = Substitute.For <IStateReader>();
            BaselineModule baselineModule = CreateBaselineModule(testRpc, stateReader);

            await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether());

            stateReader.GetCode(Arg.Any <Keccak>(), TestItem.AddressC).Returns(new byte[] { 255 });
            var result = await baselineModule.baseline_track(TestItem.AddressC);

            result.Result.ResultType.Should().Be(ResultType.Success);
        }
Пример #28
0
        public async Task Eth_gasPrice_BlocksAvailableLessThanBlocksToCheckWith1559Tx_ShouldGiveCorrectResult(bool eip1559Enabled, string expected)
        {
            using Context ctx = await Context.Create();

            Block[]        blocks         = GetThreeTestBlocksWith1559Tx();
            BlockTree      blockTree      = Build.A.BlockTree(blocks[0]).WithBlocks(blocks).TestObject;
            GasPriceOracle gasPriceOracle = new(blockTree, GetSpecProviderWithEip1559EnabledAs(eip1559Enabled));

            ctx._test = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).WithBlockFinder(blockTree).WithGasPriceOracle(gasPriceOracle)
                        .Build();

            string serialized = ctx._test.TestEthRpc("eth_gasPrice");

            Assert.AreEqual($"{{\"jsonrpc\":\"2.0\",\"result\":\"{expected}\",\"id\":67}}", serialized);
        }
Пример #29
0
        public async Task track_on_an_empty_code_account_will_fail()
        {
            SingleReleaseSpecProvider spec    = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1);
            TestRpcBlockchain         testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec);

            BaselineModule baselineModule = CreateBaselineModule(testRpc);

            await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether());

            var result = await baselineModule.baseline_track(TestItem.AddressC);

            result.Result.ResultType.Should().Be(ResultType.Failure);
            result.Result.Error.Should().NotBeNull();
            result.ErrorCode.Should().Be(ErrorCodes.InvalidInput);
        }
        public async Task Eth_call_with_accessList()
        {
            var test = await TestRpcBlockchain.ForTest(SealEngineType.NethDev)
                       .Build(new TestSpecProvider(Berlin.Instance));

            (byte[] code, AccessListItemForRpc[] accessList) = GetTestAccessList();

            TransactionForRpc transaction =
                test.JsonSerializer.Deserialize <TransactionForRpc>(
                    $"{{\"type\":\"0x1\", \"data\": \"{code.ToHexString(true)}\"}}");

            transaction.AccessList = accessList;
            string serialized = test.TestEthRpc("eth_call", test.JsonSerializer.Serialize(transaction), "0x0");

            Assert.AreEqual("{\"jsonrpc\":\"2.0\",\"result\":\"0x010203\",\"id\":67}", serialized);
        }