forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutils_test.go
119 lines (114 loc) · 5.45 KB
/
utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package withdrawals
import (
"encoding/json"
"math/big"
"os"
"path"
"testing"
"github.com/ethereum-optimism/optimism/op-node/bindings"
"github.com/ethereum-optimism/optimism/op-service/testutils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
)
func TestParseMessagePassed(t *testing.T) {
tests := []struct {
name string
file string
expected *bindings.L2ToL1MessagePasserMessagePassed
}{
{
"withdrawal through bridge",
"bridge-withdrawal.json",
&bindings.L2ToL1MessagePasserMessagePassed{
Nonce: new(big.Int),
Sender: common.HexToAddress("0x4200000000000000000000000000000000000007"),
Target: common.HexToAddress("0x6900000000000000000000000000000000000002"),
Value: new(big.Int),
GasLimit: big.NewInt(203648),
Data: hexutil.MustDecode(
"0xd764ad0b00010000000000000000000000000000000000000000000000000000" +
"00000000000000000000000000000000420000000000000000000000000000000000" +
"00100000000000000000000000006900000000000000000000000000000000000003" +
"00000000000000000000000000000000000000000000000000000000000000000000" +
"00000000000000000000000000000000000000000000000000000000000000000000" +
"000000000000000000000000000000000000000000000000000000c0000000000000" +
"00000000000000000000000000000000000000000000000000e40166a07a00000000" +
"000000000000000089d51be807d98fc974a0f41b2e67a8228d7846ef000000000000" +
"0000000000007c6b91d9be155a6db01f749217d76ff02a7227f20000000000000000" +
"00000000c20c5ec92fda6e611a08485123cdc0d5b84bd3a200000000000000000000" +
"0000c20c5ec92fda6e611a08485123cdc0d5b84bd3a2000000000000000000000000" +
"00000000000000000000000000000000000001f40000000000000000000000000000" +
"0000000000000000000000000000000000c000000000000000000000000000000000" +
"00000000000000000000000000000000000000000000000000000000000000000000" +
"00000000000000000000",
),
WithdrawalHash: common.HexToHash("0x0d827f8148288e3a2466018f71b968ece4ea9f9e2a81c30da9bd46cce2868285"),
Raw: types.Log{
Address: common.HexToAddress("0x4200000000000000000000000000000000000016"),
Topics: []common.Hash{
common.HexToHash("0x02a52367d10742d8032712c1bb8e0144ff1ec5ffda1ed7d70bb05a2744955054"),
common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
common.HexToHash("0x0000000000000000000000004200000000000000000000000000000000000007"),
common.HexToHash("0x0000000000000000000000006900000000000000000000000000000000000002"),
},
Data: hexutil.MustDecode(
"0x00000000000000000000000000000000000000000000000000000000000000" +
"000000000000000000000000000000000000000000000000000000000000031b80" +
"00000000000000000000000000000000000000000000000000000000000000800d" +
"827f8148288e3a2466018f71b968ece4ea9f9e2a81c30da9bd46cce28682850000" +
"0000000000000000000000000000000000000000000000000000000001e4d764ad" +
"0b0001000000000000000000000000000000000000000000000000000000000000" +
"000000000000000000000000420000000000000000000000000000000000001000" +
"000000000000000000000069000000000000000000000000000000000000030000" +
"000000000000000000000000000000000000000000000000000000000000000000" +
"000000000000000000000000000000000000000000000000000000000000000000" +
"000000000000000000000000000000000000000000000000000000c00000000000" +
"0000000000000000000000000000000000000000000000000000e40166a07a0000" +
"0000000000000000000089d51be807d98fc974a0f41b2e67a8228d7846ef000000" +
"0000000000000000007c6b91d9be155a6db01f749217d76ff02a7227f200000000" +
"0000000000000000c20c5ec92fda6e611a08485123cdc0d5b84bd3a20000000000" +
"00000000000000c20c5ec92fda6e611a08485123cdc0d5b84bd3a2000000000000" +
"00000000000000000000000000000000000000000000000001f400000000000000" +
"000000000000000000000000000000000000000000000000c00000000000000000" +
"000000000000000000000000000000000000000000000000000000000000000000" +
"000000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000",
),
BlockNumber: 0x36,
TxHash: common.HexToHash("0x9346381068b59d2098495baa72ed2f773c1e09458610a7a208984859dff73add"),
TxIndex: 1,
BlockHash: common.HexToHash("0xfdd4ad8a984b45687aca0463db491cbd0e85273d970019a3f8bf618b614938df"),
Index: 2,
Removed: false,
},
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
f, err := os.Open(path.Join("testdata", test.file))
require.NoError(t, err)
dec := json.NewDecoder(f)
receipt := new(types.Receipt)
require.NoError(t, dec.Decode(receipt))
parsed, err := ParseMessagePassed(receipt)
require.NoError(t, err)
// Have to do this weird thing to compare zero bigints.
// When they're deserialized from JSON, the internal byte
// array is an empty array whereas it is nil in the expectation.
parsedNonce := parsed.Nonce
parsedValue := parsed.Value
expNonce := test.expected.Nonce
expValue := test.expected.Value
testutils.RequireBigEqual(t, expNonce, parsedNonce)
testutils.RequireBigEqual(t, expValue, parsedValue)
parsed.Nonce = nil
parsed.Value = nil
test.expected.Nonce = nil
test.expected.Value = nil
require.EqualValues(t, test.expected, parsed)
})
}
}