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(); }
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); }
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); }
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 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); }
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); }
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); }
public async Task can_get_siblings_is_protected_against_overflow(long leafIndex) { 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_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(); }
private static async Task <Address> Deploy(TestRpcBlockchain testRpc, BaselineModule baselineModule) { Keccak txHash = (await baselineModule.baseline_deploy(TestItem.Addresses[0], "MerkleTreeSHA")).Data; await testRpc.AddBlock(); ReceiptForRpc receipt = (await testRpc.EthModule.eth_getTransactionReceipt(txHash)).Data; return(receipt.ContractAddress); }
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 ResultWrapper <ReceiptForRpc> eth_getTransactionReceipt(Keccak txHash) { var receipt = _blockchainBridge.GetReceipt(txHash); if (receipt == null) { return(ResultWrapper <ReceiptForRpc> .Success(null)); } var receiptModel = new ReceiptForRpc(txHash, receipt); if (_logger.IsTrace) { _logger.Trace($"eth_getTransactionReceipt request {txHash}, result: {txHash}"); } return(ResultWrapper <ReceiptForRpc> .Success(receiptModel)); }
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 string Deploy(string address) { TransactionForRpc tx = new TransactionForRpc(); tx.Value = 0; tx.Data = Bytes.FromHexString(ContractData.GetInitCode(new Address(address))); tx.Gas = 3000000; tx.GasPrice = (UInt256)(Engine.JintEngine.GetValue("gasPrice").AsNumber()); tx.From = new Address(address); Keccak keccak = NodeManager.Post <Keccak>("eth_sendTransaction", tx).Result; ReceiptForRpc receipt = null; while (receipt == null) { Console.WriteLine("Awaiting receipt..."); receipt = NodeManager.Post <ReceiptForRpc>("eth_getTransactionReceipt", keccak).Result; Thread.Sleep(1000); } return(receipt.ContractAddress.ToString()); }
public ResultWrapper <ReceiptForRpc> eth_getTransactionReceipt(Keccak txHash) { try { _readerWriterLockSlim.EnterReadLock(); var transactionReceipt = _blockchainBridge.GetTransactionReceipt(txHash); if (transactionReceipt == null) { return(ResultWrapper <ReceiptForRpc> .Success(null)); } var transactionReceiptModel = new ReceiptForRpc(txHash, transactionReceipt); if (Logger.IsTrace) { Logger.Trace($"eth_getTransactionReceipt request {txHash}, result: {txHash}"); } return(ResultWrapper <ReceiptForRpc> .Success(transactionReceiptModel)); } finally { _readerWriterLockSlim.ExitReadLock(); } }
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); }