-
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 remix to contracts * add remix to transactions * add remix to lib * fix misprints * add function to get moment's subedition * fix tests * fix tests * refactor subEdition contract * add subEdition tests * add new function to create subEdition resource * add documentation * refactor SubeditionAdmin * add comments/transactions/tests * add events * Revert spacings * Fix comments * use test abstractions in subedition_test.go * fix comments * fix comments * add comment to SubeditionAdminStoragePath() * add subeditionId to MomentMinted event * change SubeditionCreated event/add length check to MintMoment event * change subeditionID to subeditionId
- Loading branch information
1 parent
6c05097
commit 5801b39
Showing
21 changed files
with
1,762 additions
and
14 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,52 @@ | ||
package events | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/onflow/cadence" | ||
jsoncdc "github.com/onflow/cadence/encoding/json" | ||
) | ||
|
||
var ( | ||
EventSubeditionCreated = "TopShot.SubeditionCreated" | ||
) | ||
|
||
type SubeditionCreatedEvent interface { | ||
SubeditionId() uint32 | ||
Name() string | ||
MetaData() map[interface{}]interface{} | ||
} | ||
|
||
type subeditionCreatedEvent cadence.Event | ||
|
||
func (evt subeditionCreatedEvent) SubeditionId() uint32 { | ||
return evt.Fields[0].(cadence.UInt32).ToGoValue().(uint32) | ||
} | ||
|
||
func (evt subeditionCreatedEvent) Name() string { | ||
return evt.Fields[1].(cadence.String).ToGoValue().(string) | ||
} | ||
|
||
func (evt subeditionCreatedEvent) MetaData() map[interface{}]interface{} { | ||
return evt.Fields[2].(cadence.Dictionary).ToGoValue().(map[interface{}]interface{}) | ||
} | ||
|
||
func (evt subeditionCreatedEvent) validate() error { | ||
if evt.EventType.QualifiedIdentifier != EventSubeditionCreated { | ||
return fmt.Errorf("error validating event: event is not a valid subedition created event, expected type %s, got %s", | ||
EventSubeditionCreated, evt.EventType.QualifiedIdentifier) | ||
} | ||
return nil | ||
} | ||
|
||
func DecodeSubeditionCreatedEvent(b []byte) (SubeditionCreatedEvent, error) { | ||
value, err := jsoncdc.Decode(nil, b) | ||
if err != nil { | ||
return nil, err | ||
} | ||
event := subeditionCreatedEvent(value.(cadence.Event)) | ||
if err := event.validate(); err != nil { | ||
return nil, fmt.Errorf("error decoding event: %w", err) | ||
} | ||
return event, nil | ||
} |
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,47 @@ | ||
package events | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/onflow/cadence" | ||
jsoncdc "github.com/onflow/cadence/encoding/json" | ||
) | ||
|
||
var ( | ||
EventSubeditionAddedToMoment = "TopShot.SubeditionAddedToMoment" | ||
) | ||
|
||
type SubeditionAddedToMomentEvent interface { | ||
MomentID() uint64 | ||
SubeditionID() uint32 | ||
} | ||
|
||
type subeditionAddedToMomentEvent cadence.Event | ||
|
||
func (evt subeditionAddedToMomentEvent) MomentID() uint64 { | ||
return evt.Fields[0].(cadence.UInt64).ToGoValue().(uint64) | ||
} | ||
|
||
func (evt subeditionAddedToMomentEvent) SubeditionID() uint32 { | ||
return evt.Fields[1].(cadence.UInt32).ToGoValue().(uint32) | ||
} | ||
|
||
func (evt subeditionAddedToMomentEvent) validate() error { | ||
if evt.EventType.QualifiedIdentifier != EventSubeditionAddedToMoment { | ||
return fmt.Errorf("error validating event: event is not a valid subedition added to moment event, expected type %s, got %s", | ||
EventSubeditionAddedToMoment, evt.EventType.QualifiedIdentifier) | ||
} | ||
return nil | ||
} | ||
|
||
func DecodeSubeditionAddedToMomentEvent(b []byte) (SubeditionAddedToMomentEvent, error) { | ||
value, err := jsoncdc.Decode(nil, b) | ||
if err != nil { | ||
return nil, err | ||
} | ||
event := subeditionAddedToMomentEvent(value.(cadence.Event)) | ||
if err := event.validate(); err != nil { | ||
return nil, fmt.Errorf("error decoding event: %w", err) | ||
} | ||
return event, nil | ||
} |
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,49 @@ | ||
package events | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"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_SubeditionAddedToMoment(t *testing.T) { | ||
var ( | ||
subeditionID = uint32(1234) | ||
momentID = uint64(1234) | ||
) | ||
|
||
playCreatedEventType := cadence.EventType{ | ||
Location: utils.TestLocation, | ||
QualifiedIdentifier: "TopShot.SubeditionAddedToMoment", | ||
Fields: []cadence.Field{ | ||
{ | ||
Identifier: "momentID", | ||
Type: cadence.UInt64Type{}, | ||
}, | ||
{ | ||
Identifier: "subeditionID", | ||
Type: cadence.UInt32Type{}, | ||
}, | ||
}, | ||
Initializer: []cadence.Parameter{}, | ||
} | ||
|
||
subeditionAddedToMomentEvent := cadence.NewEvent([]cadence.Value{ | ||
cadence.NewUInt64(momentID), | ||
cadence.NewUInt32(subeditionID), | ||
}).WithType(&playCreatedEventType) | ||
|
||
payload, err := jsoncdc.Encode(subeditionAddedToMomentEvent) | ||
require.NoError(t, err, "failed to encode subedition added to moment cadence event") | ||
|
||
decodedPlayCreatedEventType, err := DecodeSubeditionAddedToMomentEvent(payload) | ||
require.NoError(t, err, "failed to decode subedition added to moment cadence event") | ||
|
||
assert.Equal(t, momentID, decodedPlayCreatedEventType.MomentID()) | ||
assert.Equal(t, subeditionID, decodedPlayCreatedEventType.SubeditionID()) | ||
} |
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,65 @@ | ||
package events | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"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_SubeditionCreated(t *testing.T) { | ||
var ( | ||
id = uint32(1234) | ||
name = "Subedition #1" | ||
setKey = "setID" | ||
setValue = "1234" | ||
playKey = "playID" | ||
playValue = "1234" | ||
) | ||
|
||
playCreatedEventType := cadence.EventType{ | ||
Location: utils.TestLocation, | ||
QualifiedIdentifier: "TopShot.SubeditionCreated", | ||
Fields: []cadence.Field{ | ||
{ | ||
Identifier: "subeditionId", | ||
Type: cadence.UInt32Type{}, | ||
}, | ||
{ | ||
Identifier: "name", | ||
Type: cadence.StringType{}, | ||
}, | ||
{ | ||
Identifier: "metadata", | ||
Type: cadence.DictionaryType{}, | ||
}, | ||
}, | ||
Initializer: []cadence.Parameter{}, | ||
} | ||
|
||
subeditionCreatedEvent := cadence.NewEvent([]cadence.Value{ | ||
cadence.NewUInt32(id), | ||
NewCadenceString(name), | ||
cadence.NewDictionary([]cadence.KeyValuePair{ | ||
{Key: NewCadenceString(setKey), Value: NewCadenceString(setValue)}, | ||
{Key: NewCadenceString(playKey), Value: NewCadenceString(playValue)}, | ||
}), | ||
}).WithType(&playCreatedEventType) | ||
|
||
payload, err := jsoncdc.Encode(subeditionCreatedEvent) | ||
require.NoError(t, err, "failed to encode play created cadence event") | ||
|
||
decodedSubeditionCreatedEventType, err := DecodeSubeditionCreatedEvent(payload) | ||
require.NoError(t, err, "failed to decode play created cadence event") | ||
|
||
assert.Equal(t, id, decodedSubeditionCreatedEventType.SubeditionId()) | ||
assert.Equal(t, name, decodedSubeditionCreatedEventType.Name()) | ||
assert.Equal(t, map[interface{}]interface{}{ | ||
setKey: setValue, | ||
playKey: playValue, | ||
}, decodedSubeditionCreatedEventType.MetaData()) | ||
} |
Oops, something went wrong.