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

Merge feature/stable-cadence into master #240

Merged
merged 20 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions .changeset/big-crews-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@onflow/flow-js-testing": minor
---

Allow loading service key from environment variables and files.

**BREAKING CHANGES**

- `getConfigValue` and `set` have been removed as these were just a confusing abstraction above the `@onflow/config` packages
- They have been replaced by exporting they `config` instance directly from the package
5 changes: 5 additions & 0 deletions .changeset/blue-pots-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/flow-js-testing": minor
---

Add Cadence v1.0 support
5 changes: 5 additions & 0 deletions .changeset/brave-feet-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/flow-js-testing": patch
---

Fix `stable-cadence` build
5 changes: 5 additions & 0 deletions .changeset/late-trees-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/flow-js-testing": patch
---

Use `view` functions in FlowManager
5 changes: 5 additions & 0 deletions .changeset/nasty-otters-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/flow-js-testing": patch
---

Add fallback for version checking CLI when JSON not supported
16 changes: 16 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"mode": "exit",
"tag": "stable-cadence",
"initialVersions": {
"@onflow/flow-js-testing": "0.5.0"
},
"changesets": [
"big-crews-work",
"blue-pots-add",
"brave-feet-greet",
"late-trees-ring",
"nasty-otters-chew",
"tidy-coats-tickle",
"two-news-change"
]
}
5 changes: 5 additions & 0 deletions .changeset/tidy-coats-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/flow-js-testing": patch
---

Fix shorthand imports
5 changes: 5 additions & 0 deletions .changeset/two-news-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/flow-js-testing": patch
---

Update @onflow/fcl to v1.10.1
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
name: Pull Request
name: CI

on:
push:
branches:
- master
- feature/*
pull_request:
branches:
- master
- feature/*

jobs:
test:
Expand Down Expand Up @@ -34,7 +39,7 @@ jobs:
- name: Get Flow CLI version
id: testbed
run: |
echo "flow-version=$(echo | flow version | grep 'Version' | sed 's/[^0-9\.]*//g')" >> $GITHUB_OUTPUT
echo "flow-version=$(flow version --output=json | jq -r '.version')" >> $GITHUB_OUTPUT
echo "package-version=$(grep version package.json | sed 's/.*"version": "\(.*\)".*/\1/')" >> $GITHUB_OUTPUT
echo "fcl-version=$(grep 'fcl":' package.json | sed 's/.*"@onflow\/fcl": "\(.*\)".*/\1/')" >> $GITHUB_OUTPUT

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- master

jobs:
release:
name: Release
Expand All @@ -21,7 +22,7 @@ jobs:

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

- name: Install Dependencies
run: npm ci
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
node_modules
dist
.DS_Store
coverage
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
41 changes: 41 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
# flow-js-testing

## 0.6.0-stable-cadence.4

### Minor Changes

- [#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.

**BREAKING CHANGES**

- `getConfigValue` and `set` have been removed as these were just a confusing abstraction above the `@onflow/config` packages
- They have been replaced by exporting they `config` instance directly from the package

### Patch Changes

- [#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

## 0.6.0-stable-cadence.3

### Patch Changes

- [#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

## 0.6.0-stable-cadence.2

### Patch Changes

- [#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

* [#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

## 0.6.0-stable-cadence.1

### Patch Changes

- [`ff545b0`](https://github.com/onflow/flow-js-testing/commit/ff545b0305baf67cad3b3e2cb1d0c8f17d32c820) Thanks [@jribbink](https://github.com/jribbink)! - Fix `stable-cadence` build

## 0.6.0-stable-cadence.0

### Minor Changes

- [#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

## 0.5.0

### Minor Changes
Expand Down
80 changes: 43 additions & 37 deletions cadence/contracts/FlowManager.cdc
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
pub contract FlowManager {
access(all) contract FlowManager {

/// Account Manager
pub event AccountAdded(address: Address)
access(all) event AccountAdded(address: Address)

pub struct Mapper {
pub let accounts: {String: Address}
access(all) struct Mapper {
access(all) let accounts: {String: Address}

pub fun getAddress(_ name: String): Address? {
access(all) view fun getAddress(_ name: String): Address? {
return self.accounts[name]
}

pub fun setAddress(_ name: String, address: Address){
access(all) fun setAddress(_ name: String, address: Address){
self.accounts[name] = address
emit FlowManager.AccountAdded(address: address)
}
Expand All @@ -20,35 +20,34 @@ pub contract FlowManager {
}
}

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

return accountManager.getAddress(name)
}

pub let defaultAccounts: {Address : String}
access(all) let defaultAccounts: {Address : String}

pub fun resolveDefaultAccounts(_ address: Address): Address{
access(all) fun resolveDefaultAccounts(_ address: Address): Address{
let alias = self.defaultAccounts[address]!
return self.getAccountAddress(alias)!
}

pub let accountManagerStorage: StoragePath
pub let contractManagerStorage: StoragePath
pub let accountManagerPath: PublicPath
pub let contractManagerPath: PublicPath
access(all) let accountManagerStorage: StoragePath
access(all) let contractManagerStorage: StoragePath
access(all) let accountManagerPath: PublicPath
access(all) let contractManagerPath: PublicPath

/// Environment Manager
pub event BlockOffsetChanged(offset: UInt64)
pub event TimestampOffsetChanged(offset: UFix64)
access(all) event BlockOffsetChanged(offset: UInt64)
access(all) event TimestampOffsetChanged(offset: UFix64)

pub struct MockBlock {
pub let id: [UInt8; 32]
pub let height: UInt64
pub let view: UInt64
pub let timestamp: UFix64
access(all) struct MockBlock {
access(all) let id: [UInt8; 32]
access(all) let height: UInt64
access(all) let view: UInt64
access(all) let timestamp: UFix64

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

pub fun setBlockOffset(_ offset: UInt64){
access(all) fun setBlockOffset(_ offset: UInt64){
self.blockOffset = offset
emit FlowManager.BlockOffsetChanged(offset: offset)
}

pub fun setTimestampOffset(_ offset: UFix64){
access(all) fun setTimestampOffset(_ offset: UFix64){
self.timestampOffset = offset
emit FlowManager.TimestampOffsetChanged(offset: offset)
}

pub fun getBlockHeight(): UInt64 {
access(all) view fun getBlockHeight(): UInt64 {
var block = getCurrentBlock()
return block.height + self.blockOffset
}

pub fun getBlockTimestamp(): UFix64 {
access(all) view fun getBlockTimestamp(): UFix64 {
var block = getCurrentBlock()
return block.timestamp + self.timestampOffset
}

pub fun getBlock(): MockBlock {
access(all) fun getBlock(): MockBlock {
var block = getCurrentBlock()
let mockBlock = MockBlock(block.id, block.height, block.view, block.timestamp);
return mockBlock
}

pub var blockOffset: UInt64;
pub var timestampOffset: UFix64;
access(all) var blockOffset: UInt64;
access(all) var timestampOffset: UFix64;


// Initialize contract
Expand All @@ -111,16 +110,23 @@ pub contract FlowManager {

self.accountManagerPath = /public/testSuiteAccountManager
self.contractManagerPath = /public/testSuiteContractManager

// Destroy previously stored values
self.account.load<Mapper>(from: self.accountManagerStorage)
self.account.load<Mapper>(from: self.contractManagerStorage)
self.account.storage.load<Mapper>(from: self.accountManagerStorage)
self.account.storage.load<Mapper>(from: self.contractManagerStorage)

self.account.storage.save(accountManager, to: self.accountManagerStorage)
self.account.storage.save(contractManager, to: self.contractManagerStorage)


self.account.save(accountManager, to: self.accountManagerStorage)
self.account.save(contractManager, to: self.contractManagerStorage)
self.account.capabilities.publish(
self.account.capabilities.storage.issue<&Mapper>(
self.accountManagerStorage
), at: self.accountManagerPath)

self.account.link<&Mapper>(self.accountManagerPath, target: self.accountManagerStorage)
self.account.link<&Mapper>(self.contractManagerPath, target: self.contractManagerStorage)
self.account.capabilities.publish(
self.account.capabilities.storage.issue<&Mapper>(
self.contractManagerStorage
), at: self.contractManagerPath)
}
}

2 changes: 1 addition & 1 deletion cadence/scripts/check-manager.cdc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import FlowManager from 0x01

pub fun main(){
access(all) fun main(){
// the body can be empty, cause script will throw error if FlowManager is not
// added to service address
}
8 changes: 3 additions & 5 deletions cadence/scripts/get-account-address.cdc
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import FlowManager from 0x01

pub fun main(name: String, managerAccount: Address):Address? {
access(all) fun main(name: String, managerAccount: Address):Address? {
let manager = getAccount(managerAccount)
let linkPath = FlowManager.accountManagerPath
let accountManager = manager
.getCapability(linkPath)
.borrow<&FlowManager.Mapper>()!
let accountManager = manager.capabilities.borrow<&FlowManager.Mapper>(linkPath)!

return accountManager.getAddress(name)

}
}
2 changes: 1 addition & 1 deletion cadence/scripts/get-block-offset.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FlowManager from 0x01

pub fun main():UInt64 {
access(all) fun main():UInt64 {
return FlowManager.blockOffset
}
8 changes: 3 additions & 5 deletions cadence/scripts/get-contract-address.cdc
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import FlowManager from 0x01

pub fun main(name: String, managerAccount: Address):Address? {
access(all) fun main(name: String, managerAccount: Address):Address? {
let manager = getAccount(managerAccount)
let linkPath = FlowManager.contractManagerPath
let contractManager = manager
.getCapability(linkPath)
.borrow<&FlowManager.Mapper>()!
let contractManager = manager.capabilities.borrow<&FlowManager.Mapper>(linkPath)!

return contractManager.getAddress(name)

}
}
8 changes: 3 additions & 5 deletions cadence/scripts/get-manager-address.cdc
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
pub fun main(serviceAddress: Address): Address? {
access(all) fun main(serviceAddress: Address): Address? {
let account = getAccount(serviceAddress)
let ref = account
.getCapability(/public/flowManagerAddress)
.borrow<&[Address]>()!

let ref = account.capabilities.borrow<&[Address]>(/public/flowManagerAddress)!

return ref[0]
}

2 changes: 1 addition & 1 deletion cadence/scripts/get-timestamp-offset.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FlowManager from 0x01

pub fun main():UFix64 {
access(all) fun main():UFix64 {
return FlowManager.timestampOffset
}
Loading
Loading