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

Commit 36824cf

Browse files
authored
Update FCL to v1.10.1 & Fix CI (#231)
1 parent a51729a commit 36824cf

File tree

11 files changed

+3949
-2212
lines changed

11 files changed

+3949
-2212
lines changed

.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/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- name: Get Flow CLI version
4141
id: testbed
4242
run: |
43-
echo "flow-version=$(echo | flow-c1 version --output json | grep 'Version:' | grep -oEi '(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?')" >> $GITHUB_OUTPUT
43+
echo "flow-version=$(flow-c1 version --output=json | jq -r '.version')" >> $GITHUB_OUTPUT
4444
echo "package-version=$(grep version package.json | sed 's/.*"version": "\(.*\)".*/\1/')" >> $GITHUB_OUTPUT
4545
echo "fcl-version=$(grep 'fcl":' package.json | sed 's/.*"@onflow\/fcl": "\(.*\)".*/\1/')" >> $GITHUB_OUTPUT
4646

.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+
}

package-lock.json

+3,894-2,110
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"scripts": {
1313
"build": "microbundle --no-compress",
14-
"generate-code": "echo manually edited, do not run // node_modules/.bin/flow-generate -i ./cadence -o ./src/generated",
14+
"generate-code": "node_modules/.bin/flow-generate -i ./cadence -o ./src/generated",
1515
"lint": "eslint -c .eslintrc.js src",
1616
"check-headers": "sh ./check-headers.sh",
1717
"prettify": "prettier --write ./src",
@@ -55,24 +55,25 @@
5555
]
5656
},
5757
"dependencies": {
58-
"@onflow/fcl": "^1.3.2",
58+
"@onflow/fcl": "1.3.2",
5959
"@onflow/fcl-config": "^0.0.1",
60-
"@onflow/flow-cadut": "^0.3.0-stable-cadence.0",
61-
"@onflow/types": "^1.0.5",
60+
"@onflow/flow-cadut": "^0.3.0-stable-cadence.1",
6261
"elliptic": "^6.5.4",
6362
"esm": "^3.2.25",
6463
"jest-environment-uint8array": "^1.0.0",
6564
"js-sha256": "^0.9.0",
6665
"js-sha3": "^0.8.0",
6766
"rimraf": "^3.0.2",
6867
"rlp": "^2.2.6",
68+
"semver": "^7.6.2",
6969
"yargs": "^17.0.1"
7070
},
7171
"devDependencies": {
7272
"@babel/core": "^7.21.0",
7373
"@babel/preset-env": "^7.14.5",
7474
"@changesets/changelog-github": "^0.4.5",
7575
"@changesets/cli": "^2.23.0",
76+
"@onflow/flow-cadut-generator": "^0.1.1-stable-cadence.0",
7677
"babel-jest": "^27.0.2",
7778
"eslint": "^7.24.0",
7879
"eslint-config-prettier": "^8.5.0",

src/emulator/emulator.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919
import {send, build, getBlock, decode, config} from "@onflow/fcl"
2020
import {Logger, LOGGER_LEVELS} from "./logger"
2121
import {getAvailablePorts, getFlowVersion} from "../utils"
22+
import {satisfies} from "semver"
2223

2324
const {spawn} = require("child_process")
2425

26+
const SUPPORTED_FLOW_CLI_VERSIONS = ">=2.0.0"
27+
const SUPPORTED_PRE_RELEASE_MATCHER = "cadence-v1.0.0-preview"
28+
2529
const DEFAULT_HTTP_PORT = 8080
2630
const DEFAULT_GRPC_PORT = 3569
2731

@@ -79,11 +83,24 @@ export class Emulator {
7983
* @returns Promise<*>
8084
*/
8185
async start(options = {}) {
86+
const {flags, logging = false, signatureCheck = false, execName} = options
87+
if (execName) this.execName = execName
88+
8289
// Get version of CLI
83-
const flowVersion = await getFlowVersion()
84-
if (flowVersion.major < 1) {
90+
const flowVersion = await getFlowVersion(this.execName)
91+
const satisfiesVersion = satisfies(
92+
flowVersion.raw,
93+
SUPPORTED_FLOW_CLI_VERSIONS,
94+
{
95+
includePrerelease: true,
96+
}
97+
)
98+
const satisfiesPreRelease = flowVersion.raw.includes(
99+
SUPPORTED_PRE_RELEASE_MATCHER
100+
)
101+
if (!satisfiesVersion && !satisfiesPreRelease) {
85102
throw new Error(
86-
`Flow CLI version ${flowVersion.major}.${flowVersion.minor}.${flowVersion.patch} is not supported. Please install version 1.0.0 or higher.`
103+
`Unsupported Flow CLI version: ${flowVersion.raw}. Supported versions: ${SUPPORTED_FLOW_CLI_VERSIONS} or pre-releases tagged with ${SUPPORTED_PRE_RELEASE_MATCHER}`
87104
)
88105
}
89106

@@ -108,9 +125,6 @@ More info: https://github.com/onflow/flow-js-testing/blob/master/TRANSITIONS.md#
108125
this.grpcPort = DEFAULT_GRPC_PORT + offset
109126
}
110127

111-
const {flags, logging = false, signatureCheck = false, execName} = options
112-
if (execName) this.execName = execName
113-
114128
// config access node
115129
config().put("accessNode.api", `http://localhost:${this.restPort}`)
116130

src/generated/contracts/FlowManager.js

+2-68
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import {
44
getEnvironment,
55
replaceImportAddresses,
66
reportMissingImports,
7-
// deployContract, // TODO broken, using our own version
8-
sendTransaction,
7+
deployContract,
98
} from '@onflow/flow-cadut'
109

1110
export const CODE = `
@@ -161,78 +160,13 @@ export const FlowManagerTemplate = async (addressMap = {}) => {
161160
return replaceImportAddresses(CODE, fullMap);
162161
};
163162

164-
// TODO copied from cadut and patched for Cadence 1.0
165-
const deployContract = async props => {
166-
const {
167-
name,
168-
to,
169-
payer,
170-
proposer,
171-
code: contractCode,
172-
update = false,
173-
processed = false,
174-
addressMap = {},
175-
} = props
176-
177-
// Update imprort statement with addresses from addressMap
178-
const ixContractCode = processed
179-
? contractCode
180-
: replaceImportAddresses(contractCode, addressMap)
181-
182-
// TODO: Implement arguments for "init" method
183-
const template = update ? `
184-
transaction(name: String, code: String) {
185-
prepare(acct: auth(AddContract) &Account) {
186-
let decoded = code.decodeHex()
187-
188-
acct.contracts.add(
189-
name: name,
190-
code: decoded,
191-
)
192-
}
193-
}
194-
` : `
195-
transaction(name: String, code: String){
196-
prepare(acct: auth(AddContract, UpdateContract) &Account) {
197-
let decoded = code.decodeHex()
198-
199-
if acct.contracts.get(name: name) == nil {
200-
acct.contracts.add(name: name, code: decoded)
201-
} else {
202-
acct.contracts.update(name: name, code: decoded)
203-
}
204-
}
205-
}
206-
`
207-
208-
const hexedCode = Buffer.from(ixContractCode, "utf8").toString("hex")
209-
const args = [name, hexedCode]
210-
// Set roles
211-
let ixProposer = to
212-
let ixPayer = to
213-
let ixSigners = [to]
214-
215-
if (payer) {
216-
ixPayer = payer
217-
ixProposer = proposer || payer
218-
}
219-
220-
return await sendTransaction({
221-
payer: ixPayer,
222-
proposer: ixProposer,
223-
signers: ixSigners,
224-
code: template,
225-
args,
226-
});
227-
}
228-
229163
/**
230164
* Deploys FlowManager transaction to the network
231165
* @param {Object.<string, string>} addressMap - contract name as a key and address where it's deployed as value
232166
* @param Array<*> args - list of arguments
233167
* param Array<string> - list of signers
234168
*/
235-
export const deployFlowManager = async (props) => {
169+
export const deployFlowManager = async (props = {}) => {
236170
const { addressMap = {} } = props;
237171
const code = await FlowManagerTemplate(addressMap);
238172
const name = "FlowManager"

src/interaction.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,6 @@ export const sendTransaction = async (...props) => {
162162
return [result, err, logs]
163163
}
164164

165-
// TODO helper until flow-cadut is updated
166-
const replaceAccessAllInScript = code => {
167-
const scriptMatcher = /(pub|access\s*\(\s*all\s*\))\s+fun\s+main\s*/gimu
168-
if (scriptMatcher.test(code)) {
169-
return code.replace(scriptMatcher, "pub fun main")
170-
}
171-
return code
172-
}
173-
174165
/**
175166
* Sends script code for execution. Returns decoded value
176167
* @param {Object} props
@@ -188,12 +179,11 @@ export const executeScript = async (...props) => {
188179
try {
189180
const extractor = extractParameters("script")
190181
const {code, args, limit} = await extractor(_props)
191-
const patchedCode = replaceAccessAllInScript(code)
192182

193183
const ix = [fcl.script(code), fcl.limit(limit)]
194184
// add arguments if any
195185
if (args) {
196-
const resolvedArgs = await resolveArguments(args, patchedCode)
186+
const resolvedArgs = await resolveArguments(args, code)
197187
ix.push(fcl.args(resolvedArgs))
198188
}
199189
const response = await fcl.send(ix)

src/utils.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
import {config, withPrefix} from "@onflow/fcl"
2020
import {exec} from "child_process"
2121
import {createServer} from "net"
22-
23-
const FLOW_VERSION_REGEX = /v((\d+)\.(\d+)\.(\d+))/
22+
import * as semver from "semver"
2423

2524
export const isObject = arg => typeof arg === "object" && arg !== null
2625
export const isString = obj => typeof obj === "string" || obj instanceof String
@@ -40,20 +39,26 @@ export function getAvailablePorts(count = 1) {
4039
})
4140
}
4241

43-
export async function getFlowVersion() {
42+
/**
43+
* Get the Flow CLI version
44+
* @param {string} flowCommand - the Flow CLI command name
45+
* @returns {Promise<import("semver").SemVer>}
46+
*/
47+
export async function getFlowVersion(flowCommand = "flow") {
4448
return new Promise((resolve, reject) => {
45-
exec("flow version", (error, stdout) => {
49+
exec(`${flowCommand} version --output=json`, (error, stdout) => {
4650
if (error) {
4751
reject(
4852
"Could not determine Flow CLI version, please make sure it is installed and available in your PATH"
4953
)
5054
} else {
51-
const version = FLOW_VERSION_REGEX.exec(stdout).slice(2, 5)
52-
resolve({
53-
major: parseInt(version[0]),
54-
minor: parseInt(version[1]),
55-
patch: parseInt(version[2]),
56-
})
55+
const versionStr = JSON.parse(stdout).version
56+
const version = semver.parse(versionStr)
57+
if (!version) {
58+
reject(`Invalid Flow CLI version string: ${versionStr}`)
59+
}
60+
61+
resolve(version)
5762
}
5863
})
5964
})

test/integration/account.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ beforeEach(async () => {
2424
})
2525

2626
afterEach(async () => {
27-
emulator.stop()
27+
return emulator.stop()
2828
})
2929

3030
it("createAccount - should work with name and resolves to correct getAccountAddress", async () => {

test/integration/storage.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ beforeEach(async () => {
2626
})
2727

2828
afterEach(async () => {
29-
emulator.stop()
29+
await emulator.stop()
3030
})
3131

3232
describe("Storage Inspection", () => {

0 commit comments

Comments
 (0)