public void Can_do_roundtrip_storage([Values(true, false)] bool encodeWithTxHash, [Values(RlpBehaviors.Storage | RlpBehaviors.Eip658Receipts, RlpBehaviors.Storage)] RlpBehaviors encodeBehaviors, [Values(true, false)] bool withError, [Values(true, false)] bool valueDecoder) { TxReceipt GetExpected() { ReceiptBuilder receiptBuilder = Build.A.Receipt.WithAllFieldsFilled; if ((encodeBehaviors & RlpBehaviors.Eip658Receipts) != 0) { receiptBuilder.WithState(null); } else { receiptBuilder.WithStatusCode(0); } if (!encodeWithTxHash) { receiptBuilder.WithTransactionHash(null); } if (!withError) { receiptBuilder.WithError(string.Empty); } return(receiptBuilder.TestObject); } TxReceipt BuildReceipt() { ReceiptBuilder receiptBuilder = Build.A.Receipt.WithAllFieldsFilled; if (!withError) { receiptBuilder.WithError(string.Empty); } return(receiptBuilder.TestObject); } TxReceipt txReceipt = BuildReceipt(); ReceiptStorageDecoder encoder = new ReceiptStorageDecoder(encodeWithTxHash); Rlp rlp = encoder.Encode(txReceipt, encodeBehaviors); ReceiptStorageDecoder decoder = new ReceiptStorageDecoder(); TxReceipt deserialized; if (valueDecoder) { Rlp.ValueDecoderContext valueContext = rlp.Bytes.AsRlpValueContext(); deserialized = decoder.Decode(ref valueContext, RlpBehaviors.Storage); } else { deserialized = decoder.Decode(rlp.Bytes.AsRlpStream(), RlpBehaviors.Storage); } deserialized.Should().BeEquivalentTo(GetExpected()); }
public void Can_do_roundtrip_root() { TxReceipt txReceipt = Build.A.Receipt.TestObject; txReceipt.BlockNumber = 1; txReceipt.BlockHash = TestItem.KeccakA; txReceipt.Bloom = new Bloom(); txReceipt.Bloom.Set(Keccak.EmptyTreeHash.Bytes); txReceipt.ContractAddress = TestItem.AddressA; txReceipt.Sender = TestItem.AddressB; txReceipt.Recipient = TestItem.AddressC; txReceipt.GasUsed = 100; txReceipt.GasUsedTotal = 1000; txReceipt.Index = 2; txReceipt.PostTransactionState = TestItem.KeccakH; ReceiptStorageDecoder decoder = new ReceiptStorageDecoder(); Rlp rlp = decoder.Encode(txReceipt); TxReceipt deserialized = decoder.Decode(rlp.Bytes.AsRlpStream()); Assert.AreEqual(null, deserialized.BlockHash, "block hash"); Assert.AreEqual(0L, deserialized.BlockNumber, "block number"); Assert.AreEqual(0, deserialized.Index, "index"); Assert.AreEqual(null, deserialized.ContractAddress, "contract"); Assert.AreEqual(null, deserialized.Sender, "sender"); Assert.AreEqual(0L, deserialized.GasUsed, "gas used"); Assert.AreEqual(1000L, deserialized.GasUsedTotal, "gas used total"); Assert.AreEqual(txReceipt.Bloom, deserialized.Bloom, "bloom"); Assert.AreEqual(txReceipt.PostTransactionState, deserialized.PostTransactionState, "post transaction state"); Assert.AreEqual(null, deserialized.Recipient, "recipient"); Assert.AreEqual(txReceipt.StatusCode, deserialized.StatusCode, "status"); }
public void Can_do_roundtrip_with_storage_receipt_and_tx_type_access_list() { TxReceipt txReceipt = Build.A.Receipt.TestObject; txReceipt.BlockNumber = 1; txReceipt.BlockHash = TestItem.KeccakA; txReceipt.Bloom = new Bloom(); txReceipt.Bloom.Set(Keccak.EmptyTreeHash.Bytes); txReceipt.ContractAddress = TestItem.AddressA; txReceipt.Sender = TestItem.AddressB; txReceipt.Recipient = TestItem.AddressC; txReceipt.GasUsed = 100; txReceipt.GasUsedTotal = 1000; txReceipt.Index = 2; txReceipt.PostTransactionState = TestItem.KeccakH; txReceipt.StatusCode = 1; txReceipt.TxType = TxType.AccessList; ReceiptStorageDecoder decoder = new ReceiptStorageDecoder(); Rlp rlp = decoder.Encode(txReceipt, RlpBehaviors.Storage | RlpBehaviors.Eip658Receipts); TxReceipt deserialized = decoder.Decode(rlp.Bytes.AsRlpStream(), RlpBehaviors.Storage | RlpBehaviors.Eip658Receipts); Assert.AreEqual(txReceipt.TxType, deserialized.TxType, "tx type"); Assert.AreEqual(txReceipt.BlockHash, deserialized.BlockHash, "block hash"); Assert.AreEqual(txReceipt.BlockNumber, deserialized.BlockNumber, "block number"); Assert.AreEqual(txReceipt.Index, deserialized.Index, "index"); Assert.AreEqual(txReceipt.ContractAddress, deserialized.ContractAddress, "contract"); Assert.AreEqual(txReceipt.Sender, deserialized.Sender, "sender"); Assert.AreEqual(txReceipt.GasUsed, deserialized.GasUsed, "gas used"); Assert.AreEqual(txReceipt.GasUsedTotal, deserialized.GasUsedTotal, "gas used total"); Assert.AreEqual(txReceipt.Bloom, deserialized.Bloom, "bloom"); Assert.AreEqual(txReceipt.Recipient, deserialized.Recipient, "recipient"); Assert.AreEqual(txReceipt.StatusCode, deserialized.StatusCode, "status"); }
private static TxReceipt DeserializeReceiptObsolete(Keccak hash, Span <byte> receiptData) { if (!receiptData.IsNullOrEmpty()) { var context = new Rlp.ValueDecoderContext(receiptData); try { var receipt = StorageDecoder.Decode(ref context, RlpBehaviors.Storage); receipt.TxHash = hash; return(receipt); } catch (RlpException) { context.Position = 0; var receipt = StorageDecoder.Decode(ref context); receipt.TxHash = hash; return(receipt); } } return(null); }
public void Can_do_roundtrip_storage_eip() { TxReceipt txReceipt = Build.A.Receipt.TestObject; txReceipt.BlockNumber = 1; txReceipt.BlockHash = TestItem.KeccakA; txReceipt.Bloom = new Bloom(); txReceipt.Bloom.Set(Keccak.EmptyTreeHash.Bytes); txReceipt.ContractAddress = TestItem.AddressA; txReceipt.Sender = TestItem.AddressB; txReceipt.Recipient = TestItem.AddressC; txReceipt.GasUsed = 100; txReceipt.GasUsedTotal = 1000; txReceipt.Index = 2; txReceipt.PostTransactionState = TestItem.KeccakH; txReceipt.StatusCode = 1; ReceiptStorageDecoder decoder = new ReceiptStorageDecoder(); Rlp rlp = decoder.Encode(txReceipt, RlpBehaviors.Storage | RlpBehaviors.Eip658Receipts); TxReceipt deserialized = decoder.Decode(rlp.Bytes.AsRlpStream(), RlpBehaviors.Storage | RlpBehaviors.Eip658Receipts); AssertStorageReceipt(txReceipt, deserialized); }