Skip to content

Commit

Permalink
core: more test for goat txs
Browse files Browse the repository at this point in the history
  • Loading branch information
ericlee42 committed Dec 19, 2024
1 parent 9ac1449 commit c4781fc
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 0 deletions.
57 changes: 57 additions & 0 deletions core/types/receipt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"math"
"math/big"
"os"
"reflect"
"testing"

Expand Down Expand Up @@ -527,3 +528,59 @@ func clearComputedFieldsOnLogs(logs []*Log) []*Log {
}
return l
}

func TestGoatTxReceipt(t *testing.T) {
rawData, err := os.ReadFile("testdata/goat-receipts.json")
if err != nil {
t.Fatal(err)
}

var receipts []*Receipt
if err := json.Unmarshal(rawData, &receipts); err != nil {
t.Fatal(err)
}

for idx, receipt := range receipts {
raw, err := receipt.MarshalBinary()
if err != nil {
t.Fatal(err)
}

var expect Receipt
if err := expect.UnmarshalBinary(raw); err != nil {
t.Fatal(err)
}

if receipt.Status != expect.Status {
t.Errorf("receipt %d: status mismatch, got %d want %d", idx, expect.Status, receipt.Status)
}

if receipt.CumulativeGasUsed != expect.CumulativeGasUsed {
t.Errorf("receipt %d: cumulative gas used mismatch, got %d want %d", idx, expect.CumulativeGasUsed, receipt.CumulativeGasUsed)
}

if receipt.Bloom != expect.Bloom {
t.Errorf("receipt %d: bloom mismatch, got %x want %x", idx, expect.Bloom, receipt.Bloom)
}

for i := 0; i < len(receipt.Logs); i++ {
if receipt.Logs[i].Address != expect.Logs[i].Address {
t.Errorf("receipt %d log %d: address mismatch, got %x want %x", idx, i, expect.Logs[i].Address, receipt.Logs[i].Address)
}

if !bytes.Equal(receipt.Logs[i].Data, expect.Logs[i].Data) {
t.Errorf("receipt %d log %d: data mismatch, got %x want %x", idx, i, expect.Logs[i].Data, receipt.Logs[i].Data)
}

if !reflect.DeepEqual(receipt.Logs[i].Topics, expect.Logs[i].Topics) {
t.Errorf("receipt %d log %d: topics mismatch, got %x want %x", idx, i, expect.Logs[i].Topics, receipt.Logs[i].Topics)
}
}

buf := new(bytes.Buffer)
Receipts([]*Receipt{receipt}).EncodeIndex(0, buf)
if want := buf.Bytes(); !bytes.Equal(raw, want) || len(want) == 0 {
t.Errorf("receipt %d: binary encoding mismatch", idx)
}
}
}
121 changes: 121 additions & 0 deletions core/types/testdata/goat-receipts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
[
{
"blockHash": "0x74825a896430bbd0bd2d1e77909cfea44ccf8e6150d8c41a1df3ff4445cbf76f",
"blockNumber": "0xd5b46",
"contractAddress": null,
"cumulativeGasUsed": "0x0",
"effectiveGasPrice": "0x0",
"from": "0xbc10000000000000000000000000000000001000",
"gasUsed": "0x0",
"logs": [
{
"address": "0xbc10000000000000000000000000000000000002",
"topics": [
"0x0553260a2e46b0577270d8992db02d30856ca880144c72d6e9503760946aef13"
],
"data": "0x000000000000000000000000bc10000000000000000000000000000000000003000000000000000000000000000000000000000000000000000001d1a94a2000",
"blockNumber": "0xd5b46",
"transactionHash": "0x65d6429cde7f656bc632175dedf6ece3b7f725d15d604a61063f3d5f815f827c",
"transactionIndex": "0x0",
"blockHash": "0x74825a896430bbd0bd2d1e77909cfea44ccf8e6150d8c41a1df3ff4445cbf76f",
"logIndex": "0x0",
"removed": false
},
{
"address": "0xbc10000000000000000000000000000000000003",
"topics": [
"0xb74f5dbf34aabe02f20ff775b898acf1a9f70e4fbd48ad50548acae86e1ccd78",
"0x0000000000000000000000000000000000000000000000000000000000000022"
],
"data": "0xbbfec0c7fb83cd5aeee97420f8a6875a91ecf7af8bd4c20bc2f5a733848ef3b80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001db1cd62496c00",
"blockNumber": "0xd5b46",
"transactionHash": "0x65d6429cde7f656bc632175dedf6ece3b7f725d15d604a61063f3d5f815f827c",
"transactionIndex": "0x0",
"blockHash": "0x74825a896430bbd0bd2d1e77909cfea44ccf8e6150d8c41a1df3ff4445cbf76f",
"logIndex": "0x1",
"removed": false
}
],
"logsBloom": "0x00000000000000004000000000000000000000000000000000000000000000000000002000000000000104000000000000000000000000000000010000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000004000000000800000000000000000080008000000000000000000200000000000000000000000000001000000000000000040000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000",
"status": "0x1",
"to": "0xbc10000000000000000000000000000000000003",
"transactionHash": "0x65d6429cde7f656bc632175dedf6ece3b7f725d15d604a61063f3d5f815f827c",
"transactionIndex": "0x0",
"type": "0x60"
},
{
"blockHash": "0x74825a896430bbd0bd2d1e77909cfea44ccf8e6150d8c41a1df3ff4445cbf76f",
"blockNumber": "0xd5b46",
"contractAddress": null,
"cumulativeGasUsed": "0x0",
"effectiveGasPrice": "0x0",
"from": "0xbc10000000000000000000000000000000001000",
"gasUsed": "0x0",
"logs": [
{
"address": "0xbc10000000000000000000000000000000000002",
"topics": [
"0x0553260a2e46b0577270d8992db02d30856ca880144c72d6e9503760946aef13"
],
"data": "0x000000000000000000000000bc10000000000000000000000000000000000003000000000000000000000000000000000000000000000000000001d1a94a2000",
"blockNumber": "0xd5b46",
"transactionHash": "0x65d6429cde7f656bc632175dedf6ece3b7f725d15d604a61063f3d5f815f827c",
"transactionIndex": "0x0",
"blockHash": "0x74825a896430bbd0bd2d1e77909cfea44ccf8e6150d8c41a1df3ff4445cbf76f",
"logIndex": "0x0",
"removed": false
},
{
"address": "0xbc10000000000000000000000000000000000003",
"topics": [
"0xb74f5dbf34aabe02f20ff775b898acf1a9f70e4fbd48ad50548acae86e1ccd78",
"0x0000000000000000000000000000000000000000000000000000000000000022"
],
"data": "0xbbfec0c7fb83cd5aeee97420f8a6875a91ecf7af8bd4c20bc2f5a733848ef3b80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001db1cd62496c00",
"blockNumber": "0xd5b46",
"transactionHash": "0x65d6429cde7f656bc632175dedf6ece3b7f725d15d604a61063f3d5f815f827c",
"transactionIndex": "0x0",
"blockHash": "0x74825a896430bbd0bd2d1e77909cfea44ccf8e6150d8c41a1df3ff4445cbf76f",
"logIndex": "0x1",
"removed": false
}
],
"logsBloom": "0x00000000000000004000000000000000000000000000000000000000000000000000002000000000000104000000000000000000000000000000010000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000004000000000800000000000000000080008000000000000000000200000000000000000000000000001000000000000000040000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000",
"status": "0x1",
"to": "0xbc10000000000000000000000000000000000003",
"transactionHash": "0x65d6429cde7f656bc632175dedf6ece3b7f725d15d604a61063f3d5f815f827c",
"transactionIndex": "0x0",
"type": "0x60"
},
{
"blockHash": "0xb3b6cbdc38196b20cd485784d8bbf2650031c15590df19dea12a8e74c87be45e",
"blockNumber": "0xacd17",
"contractAddress": null,
"cumulativeGasUsed": "0x0",
"effectiveGasPrice": "0x0",
"from": "0xbc10000000000000000000000000000000001000",
"gasUsed": "0x0",
"logs": [
{
"address": "0xbc10000000000000000000000000000000000003",
"topics": [
"0x829a8683c544ad289ce92d3ce06e9ebad69b18a6916e60ec766c2c217461d8e9",
"0x0000000000000000000000000000000000000000000000000000000000000032"
],
"data": "0x",
"blockNumber": "0xacd17",
"transactionHash": "0x85f74291e80823ec903552f61f598f04878a0eb4b4dcb345c970775ca79b453a",
"transactionIndex": "0x0",
"blockHash": "0xb3b6cbdc38196b20cd485784d8bbf2650031c15590df19dea12a8e74c87be45e",
"logIndex": "0x0",
"removed": false
}
],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000002000000000000000104000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000200000000000000000000000000000800000000000000000000000000000000000000000000000000800000000000000000000000080000000000000000000000000000000000000000000",
"status": "0x1",
"to": "0xbc10000000000000000000000000000000000003",
"transactionHash": "0x85f74291e80823ec903552f61f598f04878a0eb4b4dcb345c970775ca79b453a",
"transactionIndex": "0x0",
"type": "0x60"
}
]

0 comments on commit c4781fc

Please sign in to comment.