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