onflow/flow-js-testing

thrown: undefined

jjz opened this issue · 28 comments

jjz commented

Instructions

This error occurred when I ran the test:
https://github.com/onflow/kitty-items/tree/master/cadence/tests

Problem

NFT Storefront › should deploy NFTStorefront contract

    thrown: undefined

      30 |
      31 | describe("NFT Storefront", () => {
    > 32 |      beforeEach(async () => {
         |      ^
      33 |              const basePath = path.resolve(__dirname, "../../");
      34 |              const port = 7003;
      35 |              await init(basePath, {port});

      at test/nft-storefront.test.js:32:2
      at Object.<anonymous> (test/nft-storefront.test.js:31:1)

@jjz can you tell me Flow CLI and flow-js-testing versions you are using?

jjz commented
flow version
Version: v0.31.1

"flow-js-testing": "^0.2.2"
maggo commented

Seeing the same error with flow-cli@0.31.1 and flow-js-testing@0.2.2 when deploying a contract.

Upgrading to flow-js-testing@0.2.3-alpha.2 returns a result with this error:

[ null, 'undefined is not supported' ]

This seems to only happen when deploying a contract with arguments, when I deploy another contract without it all works fine.

My args: args: ["lorem", 10000, "123"]

Seeing the same error with flow-cli@0.31.1 and flow-js-testing@0.2.2 when deploying a contract.

Upgrading to flow-js-testing@0.2.3-alpha.2 returns a result with this error:

[ null, 'undefined is not supported' ]

This seems to only happen when deploying a contract with arguments, when I deploy another contract without it all works fine.

My args: args: ["lorem", 10000, "123"]

Can you put here your contract init method? (with exactly the same formatting)

maggo commented

@MaxStalker
Here you go, it's the default example NFT init function with some added config parameters (description, supply, IPFS CID)

    init(description: String, maximumSupply: UInt64, metadataCID: String) {
        // Initialize the total supply
        self.totalSupply = 0

        // Initialize the maximum supply
        self.maximumSupply = maximumSupply

        // Initialize the metadata CID
        self.metadataCID = metadataCID

        // Initialize the description
        self.description = description

        // Initialize the revealed flag
        self.revealed = false

        // Set the named paths
        self.CollectionStoragePath = /storage/TokenCollection
        self.CollectionPublicPath = /public/TokenCollection
        self.AdminStoragePath = /storage/TokenAdmin

        // Create a Collection resource and save it to storage
        let collection <- create Collection()
        self.account.save(<-collection, to: self.CollectionStoragePath)

        // create a public capability for the collection
        self.account.link<&Token.Collection{NonFungibleToken.CollectionPublic, Token.TokenCollectionPublic}>(
            self.CollectionPublicPath,
            target: self.CollectionStoragePath
        )

        // Create a Admin resource and save it to storage
        let admin <- create Admin()
        self.account.save(<-admin, to: self.AdminStoragePath)

        emit ContractInitialized()
    }
jjz commented

Here you go, it's the default example NFT init function with some added config parameters (description, supply, IPFS CID)

I'm using the example [kitty-items] in there and I'm not changing the code

@jjz can you try 0.2.3-alpha.3

jjz commented

@jjz can you try 0.2.3-alpha.3

How? Has it been released?

@jjz can you try 0.2.3-alpha.3

How? Has it been released?

It's on npm, yeah. Simply bump version in package.json and run npm/yarn install

@MaxStalker bumping to 0.2.3-alpha.3 from 0.1.13 causes alot of problems. Emulator does not stop Aftereach test, and expect changes from a value to an array of [result, error]

jjz commented

Part of it worked, but there was a new error。

 Kitty Items › supply should be 0 after contract is deployed

    TypeError: e is not iterable

      51 |              await shallPass(setupKittyItemsOnAccount(KittyAdmin));
      52 |
    > 53 |              await shallResolve(async () => {
         |              ^
      54 |                      const supply = await getKittyItemSupply();
      55 |                      expect(supply).toBe(0);
      56 |              });

      at node_modules/flow-js-testing/src/jest-asserts.js:66:26
          at runMicrotasks (<anonymous>)
      at Object.<anonymous> (test/kitty-items.test.js:53:3)

Hi Everyone
Is there any update for this issue. I also get stuck on the same issue.

@jjz shallResolve expect that async callback will return tupple [result, err]
you can rewrite your code like this:

const [supply] = await shallResolve(getKittyItemsSupply())
expect(supply).toBe(0)

Hi Everyone Is there any update for this issue. I also get stuck on the same issue.

@bevis-lin Bump your js-testing-version to 0.2.3-alpha.3

@MaxStalker bumping to 0.2.3-alpha.3 from 0.1.13 causes alot of problems. Emulator does not stop Aftereach test, and expect changes from a value to an array of [result, error]

@timongll yes, this is a major release, which requires code to be refactored 🤷
I'm looking why afterEach not stopping emulator. But I can't reproduce it here yet. Are you sure it's not running alongside - in VSCode maybe?

For everyone here still having troubles, please try 0.2.3-alpha.4 version of flow-js-testing together with 0.31.1 of CLI

This is still broken for me using 0.2.3-alpha.4 with version 0.31.1 of the CLI. I get a long string of

console.log node_modules/flow-js-testing/dist/index.js:1
    DEBUG: 🎁  GetLatestBlock called

when running a test. Test hangs until timeout

I had some weird cadence errors that don't appear when using the flow emulator but now with 0.2.3-alpha.4 alongside 0.31.1 version all my issues have flown away.

Hmm, still nothing. Getting the same issue. I'm running on Ubuntu 20.04, in case that's relevant

Please see: #94 (comment)

yep, i had this error too.
when i try to test, the error said "undefined is not support"

but we found maybe the panic fields is too long🐱‍🐉? the js-testing it will throw error✔
i change it and make sense ✔

@s1119858711 @onkel-skrue @seddik11 @adhurjaty @bevis-lin @jjz @timongll @maggo can you try to fetch 0.2.3-alpha.5 version and try to run your tests again?..

0.2.3-alpha.5

flow cli version: v0.33.0
flow-js-testing version: 0.2.3-alpha.5

No problems or any errors with my tests ✔️

@MaxStalker changing to alpha.5 fixed my issue. Thanks!

Probably a duplicated report, but since with Secure Cadence we're using CLI v0.36.0 - with this flow-cli version alpha.5 still has the same error.

Are we expected to get a stable version of flow-js-testing that's working fine with latest cli?

Still issue with flow-cli v0.37.2 and v0.2.3-alpha.7 :(

Hi @PeterBenc the package has been moved to @onflow/flow-js-testing - can you confirm you still have this issue with @onflow/flow-js-testing@0.3.0-alpha.8

Closing, please re-open if this happens again.