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 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 = CreateBaselineModule(testRpc); 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); }
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 can_get_commit_fails_on_not_tracked() { 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(); var result = await baselineModule.baseline_getCommit(receipt.ContractAddress, 0); result.Result.ResultType.Should().Be(ResultType.Failure); result.ErrorCode.Should().Be(ErrorCodes.InvalidInput); }
public async Task insert_leaves_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 = 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[] leaves = Enumerable.Repeat(TestItem.KeccakH, leafCount).ToArray(); Keccak insertLeavesTxHash = (await baselineModule.baseline_insertLeaves( 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); }
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); }