Skip to content
This repository was archived by the owner on Dec 2, 2021. It is now read-only.

Commit ce68e0b

Browse files
abrinckmswetharepakula
authored andcommitted
Added integration test; Modified the examples to reflect changes
Signed-off-by: Adam Brinckman <[email protected]>
1 parent a9d103e commit ce68e0b

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

Fab3_Instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ curl http://127.0.0.1:5000 -X POST -H "Content-Type:application/json" -d '{
294294
"gasUsed": 0,
295295
"cumulativeGasUsed": 0,
296296
"to": "",
297-
"logs": null,
297+
"logs": [],
298298
"status": "0x1",
299299
"from": "0xa6e427512d418a9f8f1277dff45a1942236005d3"
300300
},

fab3/types/types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,17 @@ type Log struct {
200200
Index string `json:"logIndex"`
201201
}
202202

203+
// MarshalJSON will json marshal the transaction receipt and set Logs to an empty []Log if none returned
204+
func (txReceipt *TxReceipt) MarshalJSON() ([]byte, error) {
205+
receipt := *txReceipt
206+
207+
if receipt.Logs == nil {
208+
receipt.Logs = []Log{}
209+
}
210+
211+
return json.Marshal(receipt)
212+
}
213+
203214
// Transaction represents an ethereum evm transaction.
204215
//
205216
// https://github.com/ethereum/wiki/wiki/JSON-RPC#returns-28

fab3/types/types_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,35 @@ var _ = Describe("Types JSON Marshaling and Unmarshaling", func() {
213213
[]byte(`{"blockHash":"0x1234567", "blockNumber":"", "to":"", "input":"","transactionIndex":"", "hash":"", "gasPrice":"0x0", "value":"0x0"}`)),
214214
)
215215

216+
DescribeTable("TxReceipt MarshalJSON",
217+
func(txReceipt TxReceipt, bytes []byte) {
218+
marshalledData, err := txReceipt.MarshalJSON()
219+
Expect(err).ToNot(HaveOccurred())
220+
221+
var target TxReceipt
222+
err = json.Unmarshal(marshalledData, &target)
223+
Expect(err).ToNot(HaveOccurred())
224+
225+
var expectedReceipt TxReceipt
226+
err = json.Unmarshal(bytes, &expectedReceipt)
227+
Expect(err).ToNot(HaveOccurred())
228+
229+
Expect(target).To(Equal(expectedReceipt))
230+
},
231+
232+
Entry("empty receipt object",
233+
TxReceipt{},
234+
[]byte(`{"transactionHash":"","transactionIndex":"","blockHash":"","blockNumber":"","gasUsed":0,"cumulativeGasUsed":0,"to":"","logs":[],"status":"","from":""}`)),
235+
236+
Entry("non-empty receipt object",
237+
TxReceipt{Status: "0x1", TransactionHash: "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b", CumulativeGasUsed: 314159, GasUsed: 30234},
238+
[]byte(`{"transactionHash":"0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b","transactionIndex":"","blockHash":"","blockNumber":"","gasUsed":30234,"cumulativeGasUsed":314159,"to":"","logs":[],"status":"0x1","from":""}`)),
239+
240+
Entry("non-empty logs field",
241+
TxReceipt{Logs: make([]Log, 1), Status: "0x1", TransactionHash: "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b", CumulativeGasUsed: 314159, GasUsed: 30234},
242+
[]byte(`{"transactionHash":"0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b","transactionIndex":"","blockHash":"","blockNumber":"","gasUsed":30234,"cumulativeGasUsed":314159,"to":"","contractAddress":"","gasUsed":30234,"cumulativeGasUsed":314159,"to":"","logs":[{"address":"","topics":null,"blockNumber":"","transactionHash":"","transactionIndex":"","blockHash":"","logIndex":""}],"status":"0x1","from":""}`)),
243+
)
244+
216245
DescribeTable("Block MarshalJSON",
217246
func(blk Block, bytes []byte) {
218247
By("copying the original struct")

integration/fab3/fab3_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ var _ = Describe("Fab3", func() {
131131

132132
receipt := rpcResp.Result
133133

134+
Expect(receipt.Logs).ToNot(BeNil())
134135
checkHexEncoded(receipt.ContractAddress)
135136
Expect(receipt.TransactionHash).To(Equal("0x" + txHash))
136137
checkHexEncoded(receipt.BlockNumber)

0 commit comments

Comments
 (0)