|
| 1 | +package events |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "github.com/stretchr/testify/require" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/onflow/cadence" |
| 9 | + jsoncdc "github.com/onflow/cadence/encoding/json" |
| 10 | + "github.com/onflow/cadence/runtime/tests/utils" |
| 11 | + "github.com/stretchr/testify/assert" |
| 12 | +) |
| 13 | + |
| 14 | +func TestCadenceEvents_Reveal(t *testing.T) { |
| 15 | + var ( |
| 16 | + packID = uint64(10) |
| 17 | + salt = "salt" |
| 18 | + |
| 19 | + momentID1 = uint64(1) |
| 20 | + momentID2 = uint64(2) |
| 21 | + momentID3 = uint64(3) |
| 22 | + momentIDs = fmt.Sprintf(`%d,%d,%d`, momentID1, momentID2, momentID3) |
| 23 | + ) |
| 24 | + |
| 25 | + revealedEventType := cadence.EventType{ |
| 26 | + Location: utils.TestLocation, |
| 27 | + QualifiedIdentifier: "PackNFT.Revealed", |
| 28 | + Fields: []cadence.Field{ |
| 29 | + { |
| 30 | + Identifier: "id", |
| 31 | + Type: cadence.UInt32Type{}, |
| 32 | + }, |
| 33 | + { |
| 34 | + Identifier: "salt", |
| 35 | + Type: cadence.StringType{}, |
| 36 | + }, |
| 37 | + { |
| 38 | + Identifier: "nfts", |
| 39 | + Type: cadence.StringType{}, |
| 40 | + }, |
| 41 | + }, |
| 42 | + } |
| 43 | + |
| 44 | + revealedEvent := cadence.NewEvent([]cadence.Value{ |
| 45 | + cadence.NewUInt64(packID), |
| 46 | + cadence.NewString(salt), |
| 47 | + cadence.NewString(momentIDs), |
| 48 | + }).WithType(&revealedEventType) |
| 49 | + |
| 50 | + revealedPayload, err := jsoncdc.Encode(revealedEvent) |
| 51 | + require.NoError(t, err, "failed to encode revealed cadence event") |
| 52 | + |
| 53 | + decodedRevealedEventType, err := DecodeRevealedEvent(revealedPayload) |
| 54 | + require.NoError(t, err, "failed to decode revealed cadence event") |
| 55 | + |
| 56 | + assert.Equal(t, packID, decodedRevealedEventType.Id()) |
| 57 | + assert.Equal(t, salt, decodedRevealedEventType.Salt()) |
| 58 | + assert.Equal(t, momentIDs, decodedRevealedEventType.NFTs()) |
| 59 | + |
| 60 | +} |
0 commit comments