flow-js-testing icon indicating copy to clipboard operation
flow-js-testing copied to clipboard

Unable to execute scripts with parameters having the keyword `access(all)` instead of `pub`

Open SnowyField1906 opened this issue 2 years ago • 5 comments

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 avatar Jul 27 '23 17:07 SnowyField1906

@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?

MaxStalker avatar Jul 28 '23 08:07 MaxStalker

@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?

https://github.com/onflow/cadence/pull/2540 I think pub is being removed in favour of access(all)

jribbink avatar Jul 28 '23 13:07 jribbink

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 avatar Jul 28 '23 17:07 MaxStalker

@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)
})
    ```

SnowyField1906 avatar Jul 28 '23 18:07 SnowyField1906

https://github.com/onflow/flow-cadut/pull/136 https://github.com/onflow/flow-js-testing/pull/225

NtTestAlert avatar Mar 22 '24 07:03 NtTestAlert

resolved

jribbink avatar May 23 '24 18:05 jribbink