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 track_on_an_empty_code_account_will_fail() { SingleReleaseSpecProvider spec = new(ConstantinopleFix.Instance, 1); using TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest <BaseLineRpcBlockchain>(SealEngineType.NethDev).Build(spec); BaselineModule baselineModule = CreateBaselineModule(testRpc); 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 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); }
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.TxPoolBridge, testRpc.LogFinder, testRpc.BlockTree, _abiEncoder, _fileSystem, new MemDb(), LimboLogs.Instance); await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether()); await baselineModule.baseline_track(TestItem.AddressC); // any address (no need for tree there) var result = await baselineModule.baseline_track(TestItem.AddressC); // any address (no need for tree there) result.Result.ResultType.Should().Be(ResultType.Failure); result.Result.Error.Should().NotBeNull(); result.ErrorCode.Should().Be(ErrorCodes.InvalidInput); }
public async Task track_untrack_track_works() { SingleReleaseSpecProvider spec = new(ConstantinopleFix.Instance, 1); using TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest <BaseLineRpcBlockchain>(SealEngineType.NethDev).Build(spec); BaselineModule baselineModule = CreateBaselineModule(testRpc); 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); }
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(); MemDb baselineMetaDataDb = new MemDb(); IStateReader stateReader = Substitute.For <IStateReader>(); BaselineModule baselineModule = new BaselineModule( testRpc.TxSender, stateReader, testRpc.LogFinder, testRpc.BlockTree, _abiEncoder, _fileSystem, memDb, baselineMetaDataDb, LimboLogs.Instance, testRpc.BlockProcessor, new DisposableStack()); for (int i = 0; i < trackedCount; i++) { stateReader.GetCode(null, null).ReturnsForAnyArgs(new byte[] { 255 }); await baselineModule.baseline_track(TestItem.Addresses[i]); // any address (no need for tree there) } BaselineModule restored = new BaselineModule( testRpc.TxSender, stateReader, testRpc.LogFinder, testRpc.BlockTree, _abiEncoder, _fileSystem, memDb, baselineMetaDataDb, LimboLogs.Instance, testRpc.BlockProcessor, new DisposableStack()); var resultRestored = await restored.baseline_getTracked(); resultRestored.Data.Length.Should().Be((int)trackedCount); }
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 = CreateBaselineModule(testRpc, stateReader); 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 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 = new BaselineModule( testRpc.TxSender, stateReader, testRpc.LogFinder, testRpc.BlockTree, _abiEncoder, _fileSystem, new MemDb(), LimboLogs.Instance); 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); }
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); }
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 = new BaselineModule( testRpc.TxSender, testRpc.StateReader, testRpc.LogFinder, testRpc.BlockTree, _abiEncoder, _fileSystem, new MemDb(), LimboLogs.Instance); 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 can_return_tracked_list(uint trackedCount) { 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); for (int i = 0; i < trackedCount; i++) { await baselineModule.baseline_track(TestItem.Addresses[i]); // any address (no need for tree there) } var result = (await baselineModule.baseline_getTracked()); result.Data.Length.Should().Be((int)trackedCount); }
public async Task track_untrack_will_cause_tracking_checks_to_start_failing() { SingleReleaseSpecProvider spec = new(ConstantinopleFix.Instance, 1); using TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest <BaseLineRpcBlockchain>(SealEngineType.NethDev).Build(spec); BaselineModule baselineModule = CreateBaselineModule(testRpc); 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); var keccakResult = await baselineModule.baseline_insertCommit(TestItem.Addresses[0], TestItem.AddressC, Keccak.Zero); keccakResult.Result.ResultType.Should().Be(ResultType.Failure); keccakResult = await baselineModule.baseline_insertCommits(TestItem.Addresses[0], TestItem.AddressC, Keccak.Zero); keccakResult.Result.ResultType.Should().Be(ResultType.Failure); }
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.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_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, 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 can_work_with_many_trees() { 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; Keccak txHash2 = (await baselineModule.baseline_deploy(TestItem.Addresses[0], "MerkleTreeSHA")).Data; Keccak txHash3 = (await baselineModule.baseline_deploy(TestItem.Addresses[0], "MerkleTreeSHA")).Data; await testRpc.AddBlock(); await testRpc.AddBlock(); await testRpc.AddBlock(); ReceiptForRpc receipt = (await testRpc.EthModule.eth_getTransactionReceipt(txHash)).Data; ReceiptForRpc receipt2 = (await testRpc.EthModule.eth_getTransactionReceipt(txHash2)).Data; ReceiptForRpc receipt3 = (await testRpc.EthModule.eth_getTransactionReceipt(txHash3)).Data; receipt.Status.Should().Be(1); receipt2.Status.Should().Be(1); receipt3.Status.Should().Be(1); await baselineModule.baseline_insertLeaves( TestItem.Addresses[1], receipt.ContractAddress, TestItem.KeccakG, TestItem.KeccakH); await baselineModule.baseline_insertLeaves( TestItem.Addresses[1], receipt2.ContractAddress, TestItem.KeccakE, TestItem.KeccakF); await baselineModule.baseline_insertLeaf( TestItem.Addresses[1], receipt3.ContractAddress, TestItem.KeccakG); await baselineModule.baseline_insertLeaf( TestItem.Addresses[1], receipt3.ContractAddress, TestItem.KeccakH); await testRpc.AddBlock(); await testRpc.AddBlock(); await baselineModule.baseline_track(receipt.ContractAddress); await baselineModule.baseline_track(receipt2.ContractAddress); await baselineModule.baseline_track(receipt3.ContractAddress); var result = await baselineModule.baseline_getSiblings(receipt.ContractAddress, 1); var result2 = await baselineModule.baseline_getSiblings(receipt2.ContractAddress, 1); var result3 = await baselineModule.baseline_getSiblings(receipt3.ContractAddress, 1); await testRpc.AddBlock(); result.Result.ResultType.Should().Be(ResultType.Success); result.Data.Should().HaveCount(32); result2.Result.ResultType.Should().Be(ResultType.Success); result2.Data.Should().HaveCount(32); result3.Result.ResultType.Should().Be(ResultType.Success); result3.Data.Should().HaveCount(32); for (int i = 1; i < 32; i++) { result.Data[i].Hash.Should().Be(Keccak.Zero); result2.Data[i].Hash.Should().Be(Keccak.Zero); result3.Data[i].Hash.Should().Be(Keccak.Zero); } result.Data[0].Hash.Should().NotBe(Keccak.Zero); result2.Data[0].Hash.Should().NotBe(Keccak.Zero); result3.Data[0].Hash.Should().NotBe(Keccak.Zero); result.Data[0].Hash.Should().NotBe(result2.Data[0].Hash); result.Data[0].Hash.Should().Be(result3.Data[0].Hash); }
public async Task can_work_with_many_trees() { 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; Keccak txHash2 = (await baselineModule.baseline_deploy(TestItem.Addresses[0], "MerkleTreeSHA")).Data; Keccak txHash3 = (await baselineModule.baseline_deploy(TestItem.Addresses[0], "MerkleTreeSHA")).Data; await testRpc.AddBlock(); await testRpc.AddBlock(); await testRpc.AddBlock(); ReceiptForRpc receipt = (await testRpc.EthRpcModule.eth_getTransactionReceipt(txHash)).Data; ReceiptForRpc receipt2 = (await testRpc.EthRpcModule.eth_getTransactionReceipt(txHash2)).Data; ReceiptForRpc receipt3 = (await testRpc.EthRpcModule.eth_getTransactionReceipt(txHash3)).Data; receipt.Status.Should().Be(1); receipt2.Status.Should().Be(1); receipt3.Status.Should().Be(1); await baselineModule.baseline_insertCommits( TestItem.Addresses[1], receipt.ContractAddress, TestItem.KeccakG, TestItem.KeccakH); await baselineModule.baseline_insertCommits( TestItem.Addresses[1], receipt2.ContractAddress, TestItem.KeccakE, TestItem.KeccakF); await baselineModule.baseline_insertCommit( TestItem.Addresses[1], receipt3.ContractAddress, TestItem.KeccakG); await baselineModule.baseline_insertCommit( TestItem.Addresses[1], receipt3.ContractAddress, TestItem.KeccakH); await testRpc.AddBlock(); await testRpc.AddBlock(); await baselineModule.baseline_track(receipt.ContractAddress); await baselineModule.baseline_track(receipt2.ContractAddress); await baselineModule.baseline_track(receipt3.ContractAddress); var result = await baselineModule.baseline_getSiblings(receipt.ContractAddress, 1); var result2 = await baselineModule.baseline_getSiblings(receipt2.ContractAddress, 1); var result3 = await baselineModule.baseline_getSiblings(receipt3.ContractAddress, 1); await testRpc.AddBlock(); result.Result.ResultType.Should().Be(ResultType.Success); result.Data.Should().HaveCount(32); result2.Result.ResultType.Should().Be(ResultType.Success); result2.Data.Should().HaveCount(32); result3.Result.ResultType.Should().Be(ResultType.Success); result3.Data.Should().HaveCount(32); for (int i = 1; i < 32; i++) { result.Data[i].Hash.Should().Be(Keccak.Zero); result2.Data[i].Hash.Should().Be(Keccak.Zero); result3.Data[i].Hash.Should().Be(Keccak.Zero); } result.Data[0].Hash.Should().NotBe(Keccak.Zero); result2.Data[0].Hash.Should().NotBe(Keccak.Zero); result3.Data[0].Hash.Should().NotBe(Keccak.Zero); result.Data[0].Hash.Should().NotBe(result2.Data[0].Hash); result.Data[0].Hash.Should().Be(result3.Data[0].Hash); }