private async Task RunAll(TestRpcBlockchain testRpc, BaselineModule baselineModule, int taskId) { Keccak txHash = (await baselineModule.baseline_deploy(TestItem.Addresses[0], "MerkleTreeSHA")).Data; await testRpc.AddBlock(); ReceiptForRpc receipt; int tries = 100; do { receipt = (await testRpc.EthModule.eth_getTransactionReceipt(txHash)).Data; await Task.Delay(10); tries--; } while (receipt != null && tries > 0); if (receipt == null) { throw new InvalidOperationException($"Receipt is null in task {taskId}"); } Address contract = receipt.ContractAddress; Console.WriteLine($"Task {taskId} operating on contract {contract}"); await baselineModule.baseline_track(contract); for (int i = 0; i < 16; i++) { Stopwatch stopwatch = Stopwatch.StartNew(); await baselineModule.baseline_insertLeaf(TestItem.Addresses[taskId], contract, TestItem.Keccaks[i % TestItem.Keccaks.Length]); await testRpc.AddBlock(); Block headBlock = testRpc.BlockTree.Head; BaselineTreeNode[] siblings = (await baselineModule.baseline_getSiblings( contract, 0, new BlockParameter(headBlock.Number))).Data; Keccak root = (await baselineModule.baseline_getRoot( contract, new BlockParameter(headBlock.Number))).Data; bool result = (await baselineModule.baseline_verify( contract, root, TestItem.Keccaks[0], siblings, new BlockParameter(headBlock.Number))).Data; if (!result) { throw new InvalidOperationException($"Failed to verify at {contract}, task {taskId}, iteration {i}, root {root}"); } else { Console.WriteLine($"Verified at {contract}, task {taskId}, iteration {i}, root {root}"); } } Console.WriteLine($"Finishing task {taskId}"); }
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); }
public async Task can_get_siblings_after_commit_is_added() { SingleReleaseSpecProvider spec = new(ConstantinopleFix.Instance, 1); using TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest <BaseLineRpcBlockchain>(SealEngineType.NethDev).Build(spec); BaselineModule baselineModule = CreateBaselineModule(testRpc); Keccak txHash = (await baselineModule.baseline_deploy(TestItem.Addresses[0], "MerkleTreeSHA")).Data; await testRpc.AddBlock(); ReceiptForRpc receipt = (await testRpc.EthRpcModule.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_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); }