flow-js-testing
flow-js-testing copied to clipboard
Unable to execute scripts with parameters having the keyword `access(all)` instead of `pub`
Instructions
access(all) keyword is not supported for executeScript if that script goes with parameters
Problem
when using executeScript, if that script is defined by pub fun main(*/ params /*), it works normally
but if it is defined by access(all) fun main(*/ params /*), it will throw this error:
TypeError: Cannot read properties of undefined (reading 'map')
this seems a small bug but it is really annoying for people who do not want to use pub for their scripts
and without parameters, access(all) scripts work normally
@SnowyField1906 why you would want to avoid this? Both of them are equal in access rights and pub is even easier to write 😅
It should be easy to fix, but can you elaborate why?
@SnowyField1906 why you would want to avoid this? Both of them are equal in access rights and
pubis even easier to write 😅It should be easy to fix, but can you elaborate
why?
https://github.com/onflow/cadence/pull/2540 I think pub is being removed in favour of access(all)
Just checked. This test runs just fine:
test("executeScript - shall return with access(all) modifier", async ()=>{
const [result] = await executeScript({
code: `
access(all) fun main(): Int{
return 42
}
`
})
expect(result).toBe("42")
})
@SnowyField1906 Can you tell me the versions of CLI and flow-js-testing you are using?
@MaxStalker Oh I forgot to put the condition "with parameters"
Without parameters, access(all) works fine but if the parameters exist, it will throw error
Please run this test instead:
it("executeScript - shall return with access(all) modifier", async () => {
const num = "1"
const [pub] = await executeScript({
code: `
pub fun main(a: Int): Int{
return a
}
`,
args: [num]
})
expect(pub).toBe(num)
const [access] = await executeScript({
code: `
access(all) fun main(a: Int): Int {
return a
}`
,
args: [num]
})
expect(access).toBe(num)
})
```
https://github.com/onflow/flow-cadut/pull/136 https://github.com/onflow/flow-js-testing/pull/225
resolved