Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
judezhu committed Aug 8, 2024
1 parent f3e14bd commit 0c3db89
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
1 change: 1 addition & 0 deletions lib/go/events/decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func DecodeCadenceValue(payload []byte) (cadence.Value, error) {
)
if err != nil {
// json decode failed, try ccf decode
fmt.Printf("json decode failed, try ccf decode, reason: %s\n", err.Error())
ccfValue, ccfErr := ccf.Decode(nil, payload)
if ccfErr != nil {
return cadence.Event{}, pkgerrors.Wrapf(
Expand Down
3 changes: 0 additions & 3 deletions lib/go/events/moment_destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,5 @@ func DecodeMomentDestroyedEvent(b []byte) (MomentDestroyedEvent, error) {
return nil, err
}
event := momentDestroyedEvent(eventMap)
if err := event.validate(); err != nil {
return nil, fmt.Errorf("error decoding event: %w", err)
}
return event, nil
}
22 changes: 11 additions & 11 deletions lib/go/events/moment_destroy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ import (

func TestCadenceEvents_MomentDestroyed(t *testing.T) {
id := uint64(1234)

momentDestroyedEventType := cadence.EventType{
Location: utils.TestLocation,
QualifiedIdentifier: "TopShot.MomentDestroyed",
Fields: []cadence.Field{
momentDestroyedEventType := cadence.NewEventType(
utils.TestLocation,
"TopShot.MomentDestroyed",
[]cadence.Field{
{
Identifier: "setID",
Type: cadence.UInt64Type{},
Identifier: "id",
Type: cadence.UInt64Type,
},
},
}
nil,
)

momentDestroyedEvent := cadence.NewEvent([]cadence.Value{
cadence.NewUInt64(id),
}).WithType(&momentDestroyedEventType)
}).WithType(momentDestroyedEventType)

payload, err := jsoncdc.Encode(momentDestroyedEvent)
require.NoError(t, err, "failed to encode moment destroyed cadence event")

decodeSetLockPurchasedEvent, err := DecodeMomentDestroyedEvent(payload)
decodeSetLockDestroyedEvent, err := DecodeMomentDestroyedEvent(payload)
require.NoError(t, err, "failed to decode moment destroyed cadence event")

assert.Equal(t, id, decodeSetLockPurchasedEvent.Id())
assert.Equal(t, id, decodeSetLockDestroyedEvent.Id())
}

0 comments on commit 0c3db89

Please sign in to comment.