Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync Stable Cadence feature branch #2755

Merged
merged 65 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
19dbd0e
Introduce filter in VariableSizedArray type
darkdrag00nv2 Jul 24, 2023
ae5936a
Also support fixed sized array types
darkdrag00nv2 Jul 29, 2023
ff1207f
Address review comments
darkdrag00nv2 Jul 31, 2023
4cac1eb
fix lint
darkdrag00nv2 Jul 31, 2023
ae0b246
get rid of useless variable i
darkdrag00nv2 Jul 31, 2023
f9d584c
Address review comments
darkdrag00nv2 Aug 3, 2023
e940e2d
Update Blockchain.reset() function to require a block height
m-Peter Aug 4, 2023
c5a7641
Add the Test.assertError() helper function
m-Peter Aug 4, 2023
ff06b1d
Improve docstring wordings for Test contract
m-Peter Aug 7, 2023
fcb488b
Merge pull request #2696 from m-Peter/cadence-testing-framework-impro…
SupunS Aug 8, 2023
b1ca6fa
update runtime interface method for randomness
Aug 9, 2023
a64c735
remove slice allocation
Aug 9, 2023
70f0ddf
Hex enc user input in error to avoid invalid UTF-8
fxamacker Aug 9, 2023
016525d
Merge pull request #2704 from onflow/fxamacker/fix-potential-invalid-…
fxamacker Aug 9, 2023
d68565d
minor change
Aug 9, 2023
9c2eb9d
Reuse type slice and reorganize tests
darkdrag00nv2 Aug 12, 2023
af119ed
Merge pull request #2678 from darkdrag00nv2/filter_array
SupunS Aug 14, 2023
5051efd
Give CompositeTypeHandler higher precedence over getUserCompositeType
m-Peter Aug 15, 2023
e287ab0
Merge pull request #2706 from onflow/tarak/new-unsafeRandom-signature
tarakby Aug 16, 2023
2a4fe65
add capability field to capabilitity controllers
turbolent Aug 16, 2023
2a39a39
Add a utility method to the Test.Blockchain struct for moving the blo…
m-Peter Aug 17, 2023
853a510
Merge pull request #2729 from m-Peter/testing-framework-move-time-uti…
SupunS Aug 17, 2023
128aea5
Merge pull request #2724 from onflow/bastian/2711-controller-capabili…
turbolent Aug 17, 2023
dd65cc4
add test for attachment on built-in composite
turbolent Aug 17, 2023
c8e3f03
Add test for inner container mutation while iterating outer
SupunS Aug 17, 2023
893aea8
Merge pull request #2732 from onflow/bastian/test-builtin-composite-a…
turbolent Aug 18, 2023
a8e229a
Allow moveTime function to accept negative time deltas for going back…
m-Peter Aug 18, 2023
b775cda
Add more tests
SupunS Aug 18, 2023
75714d7
Merge pull request #2734 from m-Peter/testing-framework-move-time-bac…
turbolent Aug 18, 2023
510df95
Merge pull request #2733 from onflow/supun/container-mutation-test
SupunS Aug 18, 2023
7355acf
Introduce map in Array type
darkdrag00nv2 Aug 18, 2023
a8519ad
Merge pull request #2717 from m-Peter/composite-type-handler-precedence
SupunS Aug 18, 2023
4dc39ff
Update runtime/interpreter/value.go
darkdrag00nv2 Aug 19, 2023
b8a7fe3
address review comments
darkdrag00nv2 Aug 19, 2023
4013dcb
issues-520 fixed
PratikDhanave Aug 20, 2023
3c1b177
issues-520 fixed
PratikDhanave Aug 20, 2023
3d521f7
Update runtime/interpreter/value.go
darkdrag00nv2 Aug 20, 2023
a09ea5f
add meeting notes for 2023-08-15
turbolent Aug 22, 2023
519407f
Review suggestions
darkdrag00nv2 Aug 23, 2023
8cd7819
Merge pull request #2737 from darkdrag00nv2/map_function_array
SupunS Aug 23, 2023
d81ee60
Add cadence-tools/test as a dependency to language server
SupunS Aug 23, 2023
f63f38e
Merge pull request #2742 from onflow/supun/fix-update-tool
SupunS Aug 24, 2023
f1db11c
Merge pull request #2740 from onflow/bastian/meeting-notes-2023-08-15
turbolent Aug 24, 2023
0f67e2f
introduce and use name constants for type constructor functions
turbolent Aug 25, 2023
2f45b8c
add type ID getter function to static type
turbolent Aug 25, 2023
8da91c2
improve Type.identifier, remove unnecessary conversion of static to s…
turbolent Aug 25, 2023
16c349d
improve TypeValue.HashInput, remove unnecessary conversion of static …
turbolent Aug 25, 2023
1208bc4
clean up composite and interface static types
turbolent Aug 25, 2023
53b2e6e
use existing NewTypeIDFromQualifiedName helper
turbolent Aug 25, 2023
bee5dad
replace remaining uses of composite literals with constructor functio…
turbolent Aug 25, 2023
5c4cb7a
add more tests for restricted type equality
turbolent Aug 26, 2023
e982587
test added
PratikDhanave Aug 28, 2023
07255c1
Redeclaration Error for initializerParameters
PratikDhanave Aug 28, 2023
9132dfa
code review resolved
PratikDhanave Aug 28, 2023
1bbc078
Merge pull request #2738 from PratikDhanave/issues-520
turbolent Aug 28, 2023
b607d00
Add the NewEmulatorBackend method on TestFramework interface
m-Peter Aug 25, 2023
3d752c8
Move creation of mockedTestFramework struct in newEmulatorBackend fun…
m-Peter Aug 28, 2023
6862627
Extract Blockchain interface out of TestFramework interface
m-Peter Aug 29, 2023
4e587ce
Merge pull request #2744 from m-Peter/testing-framework-new-emulator-…
SupunS Aug 29, 2023
bd3056f
Merge pull request #2751 from onflow/bastian/clean-up-composite-and-i…
turbolent Aug 29, 2023
c29c99e
Merge branch 'master' into bastian/2748-statictype-typeid
turbolent Aug 29, 2023
c5ea847
Merge pull request #2750 from onflow/bastian/2748-statictype-typeid
turbolent Aug 29, 2023
2931c18
Merge branch 'master' into bastian/sync-stable-cadence-6
turbolent Aug 29, 2023
3773020
remove TODO
turbolent Aug 29, 2023
6307564
remove unused field
turbolent Aug 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion encoding/json/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (d *Decoder) decodeAddress(valueJSON any) cadence.Address {
actualPrefix := v[:prefixLength]
if actualPrefix != addressPrefix {
panic(errors.NewDefaultUserError(
"invalid address prefix: expected `%s`, got `%s`",
"invalid address prefix: (shown as hex) expected %x, got %x", // hex encoding user input (actualPrefix) avoids invalid UTF-8.
addressPrefix,
actualPrefix,
))
Expand Down
24 changes: 8 additions & 16 deletions encoding/json/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,55 +849,55 @@ func prepareType(typ cadence.Type, results typePreparationResults) jsonValue {
return jsonNominalType{
Kind: "Struct",
Type: "",
TypeID: typeId(typ.Location, typ.QualifiedIdentifier),
TypeID: string(common.NewTypeIDFromQualifiedName(nil, typ.Location, typ.QualifiedIdentifier)),
Fields: prepareFields(typ.Fields, results),
Initializers: prepareInitializers(typ.Initializers, results),
}
case *cadence.ResourceType:
return jsonNominalType{
Kind: "Resource",
Type: "",
TypeID: typeId(typ.Location, typ.QualifiedIdentifier),
TypeID: string(common.NewTypeIDFromQualifiedName(nil, typ.Location, typ.QualifiedIdentifier)),
Fields: prepareFields(typ.Fields, results),
Initializers: prepareInitializers(typ.Initializers, results),
}
case *cadence.EventType:
return jsonNominalType{
Kind: "Event",
Type: "",
TypeID: typeId(typ.Location, typ.QualifiedIdentifier),
TypeID: string(common.NewTypeIDFromQualifiedName(nil, typ.Location, typ.QualifiedIdentifier)),
Fields: prepareFields(typ.Fields, results),
Initializers: [][]jsonParameterType{prepareParameters(typ.Initializer, results)},
}
case *cadence.ContractType:
return jsonNominalType{
Kind: "Contract",
Type: "",
TypeID: typeId(typ.Location, typ.QualifiedIdentifier),
TypeID: string(common.NewTypeIDFromQualifiedName(nil, typ.Location, typ.QualifiedIdentifier)),
Fields: prepareFields(typ.Fields, results),
Initializers: prepareInitializers(typ.Initializers, results),
}
case *cadence.StructInterfaceType:
return jsonNominalType{
Kind: "StructInterface",
Type: "",
TypeID: typeId(typ.Location, typ.QualifiedIdentifier),
TypeID: string(common.NewTypeIDFromQualifiedName(nil, typ.Location, typ.QualifiedIdentifier)),
Fields: prepareFields(typ.Fields, results),
Initializers: prepareInitializers(typ.Initializers, results),
}
case *cadence.ResourceInterfaceType:
return jsonNominalType{
Kind: "ResourceInterface",
Type: "",
TypeID: typeId(typ.Location, typ.QualifiedIdentifier),
TypeID: string(common.NewTypeIDFromQualifiedName(nil, typ.Location, typ.QualifiedIdentifier)),
Fields: prepareFields(typ.Fields, results),
Initializers: prepareInitializers(typ.Initializers, results),
}
case *cadence.ContractInterfaceType:
return jsonNominalType{
Kind: "ContractInterface",
Type: "",
TypeID: typeId(typ.Location, typ.QualifiedIdentifier),
TypeID: string(common.NewTypeIDFromQualifiedName(nil, typ.Location, typ.QualifiedIdentifier)),
Fields: prepareFields(typ.Fields, results),
Initializers: prepareInitializers(typ.Initializers, results),
}
Expand Down Expand Up @@ -937,7 +937,7 @@ func prepareType(typ cadence.Type, results typePreparationResults) jsonValue {
case *cadence.EnumType:
return jsonNominalType{
Kind: "Enum",
TypeID: typeId(typ.Location, typ.QualifiedIdentifier),
TypeID: string(common.NewTypeIDFromQualifiedName(nil, typ.Location, typ.QualifiedIdentifier)),
Fields: prepareFields(typ.Fields, results),
Initializers: prepareInitializers(typ.Initializers, results),
Type: prepareType(typ.RawType, results),
Expand Down Expand Up @@ -1030,11 +1030,3 @@ func encodeUFix64(v uint64) string {
fraction,
)
}

func typeId(location common.Location, identifier string) string {
if location == nil {
return identifier
}

return string(location.TypeID(nil, identifier))
}
10 changes: 10 additions & 0 deletions encoding/json/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ func TestEncodeAddress(t *testing.T) {
)
}

func TestDecodeInvalidAddress(t *testing.T) {

t.Parallel()

msg := `{"type":"Address","value":"000000000102030405"}`

_, err := json.Decode(nil, []byte(msg))
require.ErrorContains(t, err, "invalid address prefix: (shown as hex) expected 3078, got 3030")
}

func TestEncodeInt(t *testing.T) {

t.Parallel()
Expand Down
167 changes: 167 additions & 0 deletions meetings/2023-08-15.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Aug 14th, 2023

## Ways to contribute

* Participate in [FLIP (Flow Improvement Proposal) discussions](https://github.com/onflow/flips)
* Contribute to Cadence implementation: ➡️[GitHub issues](https://github.com/onflow/cadence/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22Good+First+Issue%22)
* Contribute Cadence tools: ➡️[GitHub issues](https://github.com/onflow/cadence-tools/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22Good+First+Issue%22)

## FLIPs

### Interface Conformance Improvements

* FLIP: [https://github.com/onflow/flips/pull/83](https://github.com/onflow/flips/pull/83)
* Status:
* FLIP approved and merged 🎉

### Remove pub, pub(set) and priv

* FLIP: [https://github.com/onflow/flips/pull/84](https://github.com/onflow/flips/pull/84)
* Status:
* FLIP approved and merged 🎉

### Emit events from function conditions, allow concrete events in interfaces

* FLIP: [https://github.com/onflow/flips/pull/111](https://github.com/onflow/flips/pull/111)
* Status:
* FLIP approved and merged 🎉

### Remove restricted types, interface set types

* FLIP: [https://github.com/onflow/flips/pull/85](https://github.com/onflow/flips/pull/85)
* Status:
* FLIP approved and merged 🎉

### Add Range type

* FLIP: [https://github.com/onflow/flips/pull/96](https://github.com/onflow/flips/pull/96)
* Status:
* FLIP approved and merged 🎉

### External Mutability

* Vision: [https://github.com/onflow/flips/pull/97](https://github.com/onflow/flips/pull/97)
* FLIPs:
* **Change member access semantic**
* FLIP: [https://github.com/onflow/flips/pull/89](https://github.com/onflow/flips/pull/89)
* Status:
* FLIP approved and merged 🎉
* **Improve entitlement mappings**
* FLIP: [https://github.com/onflow/flips/pull/94](https://github.com/onflow/flips/pull/94)
* Status:
* FLIP approved and merged 🎉
* **Introduce built-in mutability entitlements**
* FLIP: [https://github.com/onflow/flips/pull/86](https://github.com/onflow/flips/pull/86)
* Status:
* Positive sentiment
* No new feedback in last few weeks
* Implementation and documentation ready
* Last conversation was about naming convention for entitlements
* Open problems:
* None
* Next steps:
* **Approved**

### Account Type

* FLIP: [https://github.com/onflow/flips/pull/92](https://github.com/onflow/flips/pull/92)
* Status:
* Positive sentiment
* No new feedback in last few weeks
* Implementation ready
* Open problems:
* None
* Next steps:
* **Approved**

### Remove nested type requirements

* FLIP: [https://github.com/onflow/flips/pull/118](https://github.com/onflow/flips/pull/118)
* Overview:
* Remove nested type requirements
* Allow declaration of events in interfaces as concrete types (used in core contracts)
* Status:
* Positive sentiment
* No new feedback in last few weeks
* Implementation ready (2 PRs)
* Open problems:
* None
* Next steps:
* **Approved**

### Random function

* FLIP: [https://github.com/onflow/flips/pull/118](https://github.com/onflow/flips/pull/118)
* Overview:
* Rename unsafeRandom to random, underlying implementation has been secured using Flow protocol native random beacon
* Update the interface to a safer and more convenient one (generalized types and a modulo parameter)
* Rollout: add random, deprecate unsafeRandom, finally remove in SC release
* Status:
* Positive sentiment for random
* Open problems:
* Behavior in scripts
* Should not panic
* Several options
* Naming:
* Potential for misuse by developers. Unsafe → safe renaming might be confusing
* Maybe addressed by commit-reveal scheme FLIP: [https://github.com/onflow/flips/pull/123](https://github.com/onflow/flips/pull/123)
* Next steps:
* Determine script behavior, maybe propose in separate FLIP
* Schedule breakout session
* Deniz
* You? Leave a comment!
* Feedback:
* Just switch unsafeRandom to safe random generator for now
* Different name/indicator to prevent misuse?
* Trigger developers to check documentation, see/use commit-reveal scheme design pattern to use returned safe random properly
* `random(iReadTheDocs: Bool)`
* Our bar is very high, other systems isn't

### Commit-reveal scheme for non-reverted randomness

* FLIP: [https://github.com/onflow/flips/pull/123](https://github.com/onflow/flips/pull/123)
* Overview:
* Provide a safe pattern to address transaction abortion after a random is revealed
* Commit to block
* In the future, query history of past randoms
* Use past, committed seed for new random
* Status:
* Positive sentiment
* Waiting for feedback
* Open problems:
* None
* Next steps:
* Gather more feedback

### Remove custom destructors

* FLIP: [https://github.com/onflow/flips/pull/131](https://github.com/onflow/flips/pull/131)
* Overview:
* Proposal to address inability for users to destroy resources they own
* One of the discussed options (others: try/catch, etc.)
* Originated from attachments feature (attachment might prevent destruction of whole resource)
* Remove destroy
* Allows users to always destroy resources
* Status:
* New
* Very much an RFC!
* Open problems:
* Philosophical question (sending to "burner account")
* Existing code / applications
* "Migration" path for use-cases like FT total supply
* Next steps:
* Discuss
* Breakout session
* You? Leave a comment!
* Publish resource destruction options document, add to FLIP
* Feedback:
* Provide details on impact on applications, e.g. core contracts like FT/NFT
* Chicken-and-egg problem: need more data on how feature is used, can then figure out if/what alternative is
* Even if exploit vector isn’t used today, it should be addressed/prevented
* If important use-case exists, also not worth it to remove
* Emitting events could maybe be allowed
* Given impact, reach out to more developers / gather more feedback

## Related FLIPs / forum discussions

* [https://forum.onflow.org/t/storage-fees-improvements-and-few-random-ideas-on-the-way/5104](https://forum.onflow.org/t/storage-fees-improvements-and-few-random-ideas-on-the-way/5104)
70 changes: 70 additions & 0 deletions runtime/capabilitycontrollers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,43 @@ func TestRuntimeCapabilityControllers(t *testing.T) {

t.Parallel()

t.Run("capability", func(t *testing.T) {
t.Parallel()

err, _ := test(
// language=cadence
`
import Test from 0x1

transaction {
prepare(signer: AuthAccount) {
let storagePath = /storage/r
let resourceID = 42

// Arrange
Test.createAndSaveR(id: resourceID, storagePath: storagePath)

let issuedCap: Capability<&Test.R> =
signer.capabilities.storage.issue<&Test.R>(storagePath)
let controller1: &StorageCapabilityController =
signer.capabilities.storage.getController(byCapabilityID: issuedCap.id)!
let controller2: &StorageCapabilityController =
signer.capabilities.storage.getController(byCapabilityID: issuedCap.id)!

// Act
let controller1Cap = controller1.capability
let controller2Cap = controller2.capability

// Assert
assert(controller1Cap.borrow<&Test.R>() != nil)
assert(controller2Cap.borrow<&Test.R>() != nil)
}
}
`,
)
require.NoError(t, err)
})

t.Run("tag", func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -2379,6 +2416,39 @@ func TestRuntimeCapabilityControllers(t *testing.T) {

t.Parallel()

t.Run("capability", func(t *testing.T) {
t.Parallel()

err, _ := test(
// language=cadence
`
import Test from 0x1

transaction {
prepare(signer: AuthAccount) {

// Arrange
let issuedCap: Capability<&AuthAccount> =
signer.capabilities.account.issue<&AuthAccount>()
let controller1: &AccountCapabilityController =
signer.capabilities.account.getController(byCapabilityID: issuedCap.id)!
let controller2: &AccountCapabilityController =
signer.capabilities.account.getController(byCapabilityID: issuedCap.id)!

// Act
let controller1Cap = controller1.capability
let controller2Cap = controller2.capability

// Assert
assert(controller1Cap.borrow<&AuthAccount>() != nil)
assert(controller2Cap.borrow<&AuthAccount>() != nil)
}
}
`,
)
require.NoError(t, err)
})

t.Run("tag", func(t *testing.T) {
t.Parallel()

Expand Down
5 changes: 3 additions & 2 deletions runtime/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,12 @@ func (*StandardLibraryHandler) ProgramLog(message string, locationRange interpre
return nil
}

func (h *StandardLibraryHandler) UnsafeRandom() (uint64, error) {
func (h *StandardLibraryHandler) ReadRandom(p []byte) error {
if h.rand == nil {
h.rand = rand.New(rand.NewSource(time.Now().UnixNano()))
}
return h.rand.Uint64(), nil
h.rand.Read(p)
return nil
}

func (*StandardLibraryHandler) GetBlockAtHeight(_ uint64) (block stdlib.Block, exists bool, err error) {
Expand Down
5 changes: 2 additions & 3 deletions runtime/convertTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,19 +547,18 @@ func exportCapabilityType(
}

func importInterfaceType(memoryGauge common.MemoryGauge, t cadence.InterfaceType) interpreter.InterfaceStaticType {
return interpreter.NewInterfaceStaticType(
return interpreter.NewInterfaceStaticTypeComputeTypeID(
memoryGauge,
t.InterfaceTypeLocation(),
t.InterfaceTypeQualifiedIdentifier(),
)
}

func importCompositeType(memoryGauge common.MemoryGauge, t cadence.CompositeType) interpreter.CompositeStaticType {
return interpreter.NewCompositeStaticType(
return interpreter.NewCompositeStaticTypeComputeTypeID(
memoryGauge,
t.CompositeTypeLocation(),
t.CompositeTypeQualifiedIdentifier(),
"", // intentionally empty
)
}

Expand Down
Loading
Loading