-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add events from nba api with unit tests (#128)
* validate event type * upgrade flow and cadence * add events from nba-api repo * add testify package * add unit tests * add event validation to momentDestroyed event * add unit test for moment destroyed * cleanup * use validate method and return error * clean up
- Loading branch information
Showing
20 changed files
with
1,019 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package events | ||
|
||
import ( | ||
"github.com/onflow/flow-go-sdk" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
|
||
"github.com/onflow/cadence" | ||
jsoncdc "github.com/onflow/cadence/encoding/json" | ||
"github.com/onflow/cadence/runtime/tests/utils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCadenceEvents_Deposit(t *testing.T) { | ||
id := uint64(1234) | ||
address := flow.HexToAddress("0x12345678") | ||
to := [8]byte(address) | ||
|
||
depositEventType := cadence.EventType{ | ||
Location: utils.TestLocation, | ||
QualifiedIdentifier: "TopShot.Deposit", | ||
Fields: []cadence.Field{ | ||
{ | ||
Identifier: "id", | ||
Type: cadence.UInt64Type{}, | ||
}, | ||
{ | ||
Identifier: "to", | ||
Type: cadence.OptionalType{}, | ||
}, | ||
}, | ||
Initializer: []cadence.Parameter{}, | ||
} | ||
|
||
depositEvent := cadence.NewEvent([]cadence.Value{ | ||
cadence.NewUInt64(id), | ||
cadence.NewOptional(cadence.NewAddress(to)), | ||
}).WithType(&depositEventType) | ||
|
||
payload, err := jsoncdc.Encode(depositEvent) | ||
require.NoError(t, err, "failed to encode deposit cadence event") | ||
|
||
decodedDepositEventType, err := DecodeDepositEvent(payload) | ||
require.NoError(t, err, "failed to decode deposit cadence event") | ||
|
||
assert.Equal(t, id, decodedDepositEventType.Id()) | ||
assert.Equal(t, address.String(), decodedDepositEventType.To()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package events | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
|
||
"github.com/onflow/cadence" | ||
jsoncdc "github.com/onflow/cadence/encoding/json" | ||
"github.com/onflow/cadence/runtime/tests/utils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCadenceEvents_MomentDestroyed(t *testing.T) { | ||
id := uint64(1234) | ||
|
||
momentDestroyedEventType := cadence.EventType{ | ||
Location: utils.TestLocation, | ||
QualifiedIdentifier: "TopShot.MomentDestroyed", | ||
Fields: []cadence.Field{ | ||
{ | ||
Identifier: "setID", | ||
Type: cadence.UInt64Type{}, | ||
}, | ||
}, | ||
} | ||
|
||
momentDestroyedEvent := cadence.NewEvent([]cadence.Value{ | ||
cadence.NewUInt64(id), | ||
}).WithType(&momentDestroyedEventType) | ||
|
||
payload, err := jsoncdc.Encode(momentDestroyedEvent) | ||
require.NoError(t, err, "failed to encode moment destroyed cadence event") | ||
|
||
decodeSetLockPurchasedEvent, err := DecodeMomentDestroyedEvent(payload) | ||
require.NoError(t, err, "failed to decode moment destroyed cadence event") | ||
|
||
assert.Equal(t, id, decodeSetLockPurchasedEvent.Id()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.