Skip to content

Commit b1b43c0

Browse files
committed
contracts: release candidate 5: 0d9061f229da73edae890e6fdd1fbf753028df6d
Call event op hashes are now indexed.
1 parent 0d4704e commit b1b43c0

File tree

2 files changed

+54
-35
lines changed

2 files changed

+54
-35
lines changed

receipts.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ func V3DecodeCallSucceededEvent(log *types.Log) (common.Hash, *big.Int, error) {
213213

214214
switch len(log.Topics) {
215215
case 1:
216-
args, err := event.Inputs.Unpack(log.Data)
216+
legacyInputs := make(abi.Arguments, len(event.Inputs))
217+
copy(legacyInputs, event.Inputs)
218+
legacyInputs[0].Indexed = false
219+
220+
args, err := legacyInputs.Unpack(log.Data)
217221
if err != nil {
218222
return common.Hash{}, nil, fmt.Errorf("unable to decode CallSucceeded: %w", err)
219223
}
@@ -265,7 +269,11 @@ func V3DecodeCallFailedEvent(log *types.Log) (common.Hash, *big.Int, error, erro
265269

266270
switch len(log.Topics) {
267271
case 1:
268-
args, err := event.Inputs.Unpack(log.Data)
272+
legacyInputs := make(abi.Arguments, len(event.Inputs))
273+
copy(legacyInputs, event.Inputs)
274+
legacyInputs[0].Indexed = false
275+
276+
args, err := legacyInputs.Unpack(log.Data)
269277
if err != nil {
270278
return common.Hash{}, nil, nil, fmt.Errorf("unable to decode CallFailed: %w", err)
271279
}
@@ -341,7 +349,11 @@ func V3DecodeCallAbortedEvent(log *types.Log) (common.Hash, *big.Int, error, err
341349

342350
switch len(log.Topics) {
343351
case 1:
344-
args, err := event.Inputs.Unpack(log.Data)
352+
legacyInputs := make(abi.Arguments, len(event.Inputs))
353+
copy(legacyInputs, event.Inputs)
354+
legacyInputs[0].Indexed = false
355+
356+
args, err := legacyInputs.Unpack(log.Data)
345357
if err != nil {
346358
return common.Hash{}, nil, nil, fmt.Errorf("unable to decode CallAborted: %w", err)
347359
}
@@ -417,7 +429,11 @@ func V3DecodeCallSkippedEvent(log *types.Log) (common.Hash, *big.Int, error) {
417429

418430
switch len(log.Topics) {
419431
case 1:
420-
args, err := event.Inputs.Unpack(log.Data)
432+
legacyInputs := make(abi.Arguments, len(event.Inputs))
433+
copy(legacyInputs, event.Inputs)
434+
legacyInputs[0].Indexed = false
435+
436+
args, err := legacyInputs.Unpack(log.Data)
421437
if err != nil {
422438
return common.Hash{}, nil, fmt.Errorf("unable to decode CallSkipped: %w", err)
423439
}

receipts/receipts_test.go

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/0xsequence/ethkit/ethrpc"
1111
"github.com/0xsequence/ethkit/go-ethereum/common"
12+
"github.com/0xsequence/ethkit/go-ethereum/common/hexutil"
1213
"github.com/0xsequence/ethkit/go-ethereum/core/types"
1314
"github.com/0xsequence/go-sequence/receipts"
1415
"github.com/stretchr/testify/assert"
@@ -130,11 +131,11 @@ func test(t *testing.T, test Test) {
130131
assert.Len(t, receipts.Receipts, len(test.Receipts))
131132

132133
for i, receipt_ := range receipts.Receipts {
133-
assert.True(t, isEqual(receipt.Logs, receipt_, test.Receipts[i]))
134+
assert.NoError(t, isEqual(receipt.Logs, receipt_, test.Receipts[i]))
134135
}
135136
}
136137

137-
func isEqual(logs []*types.Log, actual receipts.Receipt, expected Receipt) bool {
138+
func isEqual(logs []*types.Log, actual receipts.Receipt, expected Receipt) error {
138139
if expected.LogStart < 0 {
139140
panic(fmt.Sprintf("log start %v < 0", expected.LogStart))
140141
}
@@ -143,62 +144,64 @@ func isEqual(logs []*types.Log, actual receipts.Receipt, expected Receipt) bool
143144
}
144145

145146
if actual.Status != expected.Status {
146-
return false
147+
return fmt.Errorf("receipt status %v, expected %v", actual.Status, expected.Status)
147148
}
148149

149150
if expected.Error == "" {
150151
if actual.Error != nil {
151-
return false
152+
return fmt.Errorf("receipt error %v, expected nil", actual.Error)
152153
}
153154
} else {
154-
if actual.Error == nil || actual.Error.Error() != expected.Error {
155-
return false
155+
if actual.Error == nil {
156+
return fmt.Errorf("receipt error nil, expected %v", expected.Error)
157+
} else if actual.Error.Error() != expected.Error {
158+
return fmt.Errorf("receipt error %v, expected %v", actual.Error, expected.Error)
156159
}
157160
}
158161

159162
if expected.LogEnd > len(logs) {
160-
return false
163+
return fmt.Errorf("%v transaction logs, expected at least %v", len(logs), expected.LogEnd)
161164
}
162165
if len(actual.Logs) != expected.LogEnd-expected.LogStart {
163-
return false
166+
return fmt.Errorf("%v receipt logs, expected %v", actual.Logs, expected.LogEnd-expected.LogStart)
164167
}
165168

166169
for i, log := range actual.Logs {
167-
if !isEqualLog(log, logs[expected.LogStart+i]) {
168-
return false
170+
if err := isEqualLog(log, logs[expected.LogStart+i]); err != nil {
171+
return fmt.Errorf("log %v: %w", i, err)
169172
}
170173
}
171174

172-
return true
175+
return nil
173176
}
174177

175-
func isEqualLog(a, b *types.Log) bool {
176-
if a == b {
177-
return true
178+
func isEqualLog(actual, expected *types.Log) error {
179+
if actual == expected {
180+
return nil
178181
}
179-
if a.Address != b.Address {
180-
return false
182+
if actual.Address != expected.Address {
183+
return fmt.Errorf("log address %v, expected %v", actual.Address, expected.Address)
181184
}
182-
if !slices.Equal(a.Topics, b.Topics) {
183-
return false
185+
if !slices.Equal(actual.Topics, expected.Topics) {
186+
return fmt.Errorf("log topics %v, expected %v", actual.Topics, expected.Topics)
184187
}
185-
if !bytes.Equal(a.Data, b.Data) {
186-
return false
188+
if !bytes.Equal(actual.Data, expected.Data) {
189+
return fmt.Errorf("log data %v, expected %v", hexutil.Encode(actual.Data), hexutil.Encode(expected.Data))
187190
}
188-
if a.BlockNumber != b.BlockNumber {
189-
return false
191+
if actual.BlockNumber != expected.BlockNumber {
192+
return fmt.Errorf("log block number %v, expected %v", actual.BlockNumber, expected.BlockNumber)
190193
}
191-
if a.TxHash != b.TxHash {
192-
return false
194+
if actual.TxHash != expected.TxHash {
195+
return fmt.Errorf("log transaction hash %v, expected %v", actual.TxHash, expected.TxHash)
193196
}
194-
if a.TxIndex != b.TxIndex {
195-
return false
197+
if actual.TxIndex != expected.TxIndex {
198+
return fmt.Errorf("log transaction index %v, expected %v", actual.TxIndex, expected.TxIndex)
196199
}
197-
if a.BlockHash != b.BlockHash {
198-
return false
200+
if actual.BlockHash != expected.BlockHash {
201+
return fmt.Errorf("log block hash %v, expected %v", actual.BlockHash, expected.BlockHash)
199202
}
200-
if a.Index != b.Index {
201-
return false
203+
if actual.Index != expected.Index {
204+
return fmt.Errorf("log index %v, expected %v", actual.Index, expected.Index)
202205
}
203-
return true
206+
return nil
204207
}

0 commit comments

Comments
 (0)