Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit fcf64fc

Browse files
authored
Merge pull request #240 from onflow/feature/stable-cadence
Merge `feature/stable-cadence` into `master`
2 parents 8b45c5e + 6dabf29 commit fcf64fc

File tree

100 files changed

+4737
-2744
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+4737
-2744
lines changed

.changeset/big-crews-work.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@onflow/flow-js-testing": minor
3+
---
4+
5+
Allow loading service key from environment variables and files.
6+
7+
**BREAKING CHANGES**
8+
9+
- `getConfigValue` and `set` have been removed as these were just a confusing abstraction above the `@onflow/config` packages
10+
- They have been replaced by exporting they `config` instance directly from the package

.changeset/blue-pots-add.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@onflow/flow-js-testing": minor
3+
---
4+
5+
Add Cadence v1.0 support

.changeset/brave-feet-greet.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@onflow/flow-js-testing": patch
3+
---
4+
5+
Fix `stable-cadence` build

.changeset/late-trees-ring.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@onflow/flow-js-testing": patch
3+
---
4+
5+
Use `view` functions in FlowManager

.changeset/nasty-otters-chew.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@onflow/flow-js-testing": patch
3+
---
4+
5+
Add fallback for version checking CLI when JSON not supported

.changeset/pre.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"mode": "exit",
3+
"tag": "stable-cadence",
4+
"initialVersions": {
5+
"@onflow/flow-js-testing": "0.5.0"
6+
},
7+
"changesets": [
8+
"big-crews-work",
9+
"blue-pots-add",
10+
"brave-feet-greet",
11+
"late-trees-ring",
12+
"nasty-otters-chew",
13+
"tidy-coats-tickle",
14+
"two-news-change"
15+
]
16+
}

.changeset/tidy-coats-tickle.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@onflow/flow-js-testing": patch
3+
---
4+
5+
Fix shorthand imports

.changeset/two-news-change.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@onflow/flow-js-testing": patch
3+
---
4+
5+
Update @onflow/fcl to v1.10.1

.github/workflows/pull-request.yml renamed to .github/workflows/ci.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
name: Pull Request
1+
name: CI
22

33
on:
4+
push:
5+
branches:
6+
- master
7+
- feature/*
48
pull_request:
59
branches:
610
- master
11+
- feature/*
712

813
jobs:
914
test:
@@ -34,7 +39,7 @@ jobs:
3439
- name: Get Flow CLI version
3540
id: testbed
3641
run: |
37-
echo "flow-version=$(echo | flow version | grep 'Version' | sed 's/[^0-9\.]*//g')" >> $GITHUB_OUTPUT
42+
echo "flow-version=$(flow version --output=json | jq -r '.version')" >> $GITHUB_OUTPUT
3843
echo "package-version=$(grep version package.json | sed 's/.*"version": "\(.*\)".*/\1/')" >> $GITHUB_OUTPUT
3944
echo "fcl-version=$(grep 'fcl":' package.json | sed 's/.*"@onflow\/fcl": "\(.*\)".*/\1/')" >> $GITHUB_OUTPUT
4045

.github/workflows/release.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
push:
44
branches:
55
- master
6+
67
jobs:
78
release:
89
name: Release
@@ -21,7 +22,7 @@ jobs:
2122

2223
- name: Install Flow CLI
2324
# We will need Flow CLI in order to run tests, so we need to install it
24-
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)"
25+
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/refs/heads/master/install.sh)"
2526

2627
- name: Install Dependencies
2728
run: npm ci

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
node_modules
55
dist
66
.DS_Store
7+
coverage

.vscode/settings.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"editor.defaultFormatter": "esbenp.prettier-vscode",
3+
"editor.formatOnSave": true
4+
}

CHANGELOG.md

+41
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,46 @@
11
# flow-js-testing
22

3+
## 0.6.0-stable-cadence.4
4+
5+
### Minor Changes
6+
7+
- [#237](https://github.com/onflow/flow-js-testing/pull/237) [`eceb9d6`](https://github.com/onflow/flow-js-testing/commit/eceb9d6e4c3bd6160ccfe11b11040b2afc97498f) Thanks [@jribbink](https://github.com/jribbink)! - Allow loading service key from environment variables and files.
8+
9+
**BREAKING CHANGES**
10+
11+
- `getConfigValue` and `set` have been removed as these were just a confusing abstraction above the `@onflow/config` packages
12+
- They have been replaced by exporting they `config` instance directly from the package
13+
14+
### Patch Changes
15+
16+
- [#235](https://github.com/onflow/flow-js-testing/pull/235) [`1b630d2`](https://github.com/onflow/flow-js-testing/commit/1b630d2c9bdd97e30d0b302997ff6c9f2c800d98) Thanks [@Luze26](https://github.com/Luze26)! - Add fallback for version checking CLI when JSON not supported
17+
18+
## 0.6.0-stable-cadence.3
19+
20+
### Patch Changes
21+
22+
- [#231](https://github.com/onflow/flow-js-testing/pull/231) [`36824cf`](https://github.com/onflow/flow-js-testing/commit/36824cfcf210857b2a023e0c9900e95d72563b16) Thanks [@jribbink](https://github.com/jribbink)! - Update @onflow/fcl to v1.10.1
23+
24+
## 0.6.0-stable-cadence.2
25+
26+
### Patch Changes
27+
28+
- [#228](https://github.com/onflow/flow-js-testing/pull/228) [`1d66db1`](https://github.com/onflow/flow-js-testing/commit/1d66db1fadaca17624f28429edb7d76c428c6984) Thanks [@jribbink](https://github.com/jribbink)! - Use `view` functions in FlowManager
29+
30+
* [#229](https://github.com/onflow/flow-js-testing/pull/229) [`6a11947`](https://github.com/onflow/flow-js-testing/commit/6a11947171e7ba213624b5155dd8bb9c4ae49092) Thanks [@github-actions](https://github.com/apps/github-actions)! - Fix shorthand imports
31+
32+
## 0.6.0-stable-cadence.1
33+
34+
### Patch Changes
35+
36+
- [`ff545b0`](https://github.com/onflow/flow-js-testing/commit/ff545b0305baf67cad3b3e2cb1d0c8f17d32c820) Thanks [@jribbink](https://github.com/jribbink)! - Fix `stable-cadence` build
37+
38+
## 0.6.0-stable-cadence.0
39+
40+
### Minor Changes
41+
42+
- [#225](https://github.com/onflow/flow-js-testing/pull/225) [`f4780cd`](https://github.com/onflow/flow-js-testing/commit/f4780cd4597364d84c61d9c64257ba5ce81c543b) Thanks [@NtTestAlert](https://github.com/NtTestAlert)! - Add Cadence v1.0 support
43+
344
## 0.5.0
445

546
### Minor Changes

cadence/contracts/FlowManager.cdc

+43-37
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
pub contract FlowManager {
1+
access(all) contract FlowManager {
22

33
/// Account Manager
4-
pub event AccountAdded(address: Address)
4+
access(all) event AccountAdded(address: Address)
55

6-
pub struct Mapper {
7-
pub let accounts: {String: Address}
6+
access(all) struct Mapper {
7+
access(all) let accounts: {String: Address}
88

9-
pub fun getAddress(_ name: String): Address? {
9+
access(all) view fun getAddress(_ name: String): Address? {
1010
return self.accounts[name]
1111
}
1212

13-
pub fun setAddress(_ name: String, address: Address){
13+
access(all) fun setAddress(_ name: String, address: Address){
1414
self.accounts[name] = address
1515
emit FlowManager.AccountAdded(address: address)
1616
}
@@ -20,35 +20,34 @@ pub contract FlowManager {
2020
}
2121
}
2222

23-
pub fun getAccountAddress(_ name: String): Address?{
23+
access(all) view fun getAccountAddress(_ name: String): Address?{
2424
let accountManager = self.account
25-
.getCapability(self.accountManagerPath)
26-
.borrow<&FlowManager.Mapper>()!
25+
.capabilities.borrow<&FlowManager.Mapper>(self.accountManagerPath)!
2726

2827
return accountManager.getAddress(name)
2928
}
3029

31-
pub let defaultAccounts: {Address : String}
30+
access(all) let defaultAccounts: {Address : String}
3231

33-
pub fun resolveDefaultAccounts(_ address: Address): Address{
32+
access(all) fun resolveDefaultAccounts(_ address: Address): Address{
3433
let alias = self.defaultAccounts[address]!
3534
return self.getAccountAddress(alias)!
3635
}
3736

38-
pub let accountManagerStorage: StoragePath
39-
pub let contractManagerStorage: StoragePath
40-
pub let accountManagerPath: PublicPath
41-
pub let contractManagerPath: PublicPath
37+
access(all) let accountManagerStorage: StoragePath
38+
access(all) let contractManagerStorage: StoragePath
39+
access(all) let accountManagerPath: PublicPath
40+
access(all) let contractManagerPath: PublicPath
4241

4342
/// Environment Manager
44-
pub event BlockOffsetChanged(offset: UInt64)
45-
pub event TimestampOffsetChanged(offset: UFix64)
43+
access(all) event BlockOffsetChanged(offset: UInt64)
44+
access(all) event TimestampOffsetChanged(offset: UFix64)
4645

47-
pub struct MockBlock {
48-
pub let id: [UInt8; 32]
49-
pub let height: UInt64
50-
pub let view: UInt64
51-
pub let timestamp: UFix64
46+
access(all) struct MockBlock {
47+
access(all) let id: [UInt8; 32]
48+
access(all) let height: UInt64
49+
access(all) let view: UInt64
50+
access(all) let timestamp: UFix64
5251

5352
init(_ id: [UInt8; 32], _ height: UInt64, _ view: UInt64, _ timestamp: UFix64){
5453
self.id = id
@@ -58,34 +57,34 @@ pub contract FlowManager {
5857
}
5958
}
6059

61-
pub fun setBlockOffset(_ offset: UInt64){
60+
access(all) fun setBlockOffset(_ offset: UInt64){
6261
self.blockOffset = offset
6362
emit FlowManager.BlockOffsetChanged(offset: offset)
6463
}
6564

66-
pub fun setTimestampOffset(_ offset: UFix64){
65+
access(all) fun setTimestampOffset(_ offset: UFix64){
6766
self.timestampOffset = offset
6867
emit FlowManager.TimestampOffsetChanged(offset: offset)
6968
}
7069

71-
pub fun getBlockHeight(): UInt64 {
70+
access(all) view fun getBlockHeight(): UInt64 {
7271
var block = getCurrentBlock()
7372
return block.height + self.blockOffset
7473
}
7574

76-
pub fun getBlockTimestamp(): UFix64 {
75+
access(all) view fun getBlockTimestamp(): UFix64 {
7776
var block = getCurrentBlock()
7877
return block.timestamp + self.timestampOffset
7978
}
8079

81-
pub fun getBlock(): MockBlock {
80+
access(all) fun getBlock(): MockBlock {
8281
var block = getCurrentBlock()
8382
let mockBlock = MockBlock(block.id, block.height, block.view, block.timestamp);
8483
return mockBlock
8584
}
8685

87-
pub var blockOffset: UInt64;
88-
pub var timestampOffset: UFix64;
86+
access(all) var blockOffset: UInt64;
87+
access(all) var timestampOffset: UFix64;
8988

9089

9190
// Initialize contract
@@ -111,16 +110,23 @@ pub contract FlowManager {
111110

112111
self.accountManagerPath = /public/testSuiteAccountManager
113112
self.contractManagerPath = /public/testSuiteContractManager
114-
113+
115114
// Destroy previously stored values
116-
self.account.load<Mapper>(from: self.accountManagerStorage)
117-
self.account.load<Mapper>(from: self.contractManagerStorage)
115+
self.account.storage.load<Mapper>(from: self.accountManagerStorage)
116+
self.account.storage.load<Mapper>(from: self.contractManagerStorage)
117+
118+
self.account.storage.save(accountManager, to: self.accountManagerStorage)
119+
self.account.storage.save(contractManager, to: self.contractManagerStorage)
120+
118121

119-
self.account.save(accountManager, to: self.accountManagerStorage)
120-
self.account.save(contractManager, to: self.contractManagerStorage)
122+
self.account.capabilities.publish(
123+
self.account.capabilities.storage.issue<&Mapper>(
124+
self.accountManagerStorage
125+
), at: self.accountManagerPath)
121126

122-
self.account.link<&Mapper>(self.accountManagerPath, target: self.accountManagerStorage)
123-
self.account.link<&Mapper>(self.contractManagerPath, target: self.contractManagerStorage)
127+
self.account.capabilities.publish(
128+
self.account.capabilities.storage.issue<&Mapper>(
129+
self.contractManagerStorage
130+
), at: self.contractManagerPath)
124131
}
125132
}
126-

cadence/scripts/check-manager.cdc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import FlowManager from 0x01
22

3-
pub fun main(){
3+
access(all) fun main(){
44
// the body can be empty, cause script will throw error if FlowManager is not
55
// added to service address
66
}
+3-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import FlowManager from 0x01
22

3-
pub fun main(name: String, managerAccount: Address):Address? {
3+
access(all) fun main(name: String, managerAccount: Address):Address? {
44
let manager = getAccount(managerAccount)
55
let linkPath = FlowManager.accountManagerPath
6-
let accountManager = manager
7-
.getCapability(linkPath)
8-
.borrow<&FlowManager.Mapper>()!
6+
let accountManager = manager.capabilities.borrow<&FlowManager.Mapper>(linkPath)!
97

108
return accountManager.getAddress(name)
119

12-
}
10+
}

cadence/scripts/get-block-offset.cdc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import FlowManager from 0x01
22

3-
pub fun main():UInt64 {
3+
access(all) fun main():UInt64 {
44
return FlowManager.blockOffset
55
}
+3-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import FlowManager from 0x01
22

3-
pub fun main(name: String, managerAccount: Address):Address? {
3+
access(all) fun main(name: String, managerAccount: Address):Address? {
44
let manager = getAccount(managerAccount)
55
let linkPath = FlowManager.contractManagerPath
6-
let contractManager = manager
7-
.getCapability(linkPath)
8-
.borrow<&FlowManager.Mapper>()!
6+
let contractManager = manager.capabilities.borrow<&FlowManager.Mapper>(linkPath)!
97

108
return contractManager.getAddress(name)
119

12-
}
10+
}
+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
pub fun main(serviceAddress: Address): Address? {
1+
access(all) fun main(serviceAddress: Address): Address? {
22
let account = getAccount(serviceAddress)
3-
let ref = account
4-
.getCapability(/public/flowManagerAddress)
5-
.borrow<&[Address]>()!
3+
4+
let ref = account.capabilities.borrow<&[Address]>(/public/flowManagerAddress)!
65

76
return ref[0]
87
}
9-
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import FlowManager from 0x01
22

3-
pub fun main():UFix64 {
3+
access(all) fun main():UFix64 {
44
return FlowManager.timestampOffset
55
}

0 commit comments

Comments
 (0)