Smart Contract Testing - Issue with option(string)

Hello all,
I have a smart contract entrypoint with signature given below:

stateful entrypoint transfer(from: address, to: address, token_id: int, data: option(string)) : unit =

However, while testing the contract using the Javascript aeSdk from my local machine, I am forced to give an input value for parameter [data] always.
example: “Sample”, “ABC” etc.

I have seen examples in aeternity tests where developers have mentioned, [{“None”;}] which is not working for me. In turn, I am getting an exception : “{“None”:”" is not a string.

Can someone please guide me in how to provide null value to an arguement which is is declared as option(string)/option(any datatype)?

Thanks in advance.

1 Like

Hello,

both {'None': []} and undefined should work as arguments. You can read more about JS to Sophia data types mapping here: GitHub - aeternity/aepp-calldata-js: Aeternity data serialization library

Not sure if the forum mis-formatted your example but it shows some weird symbol instead of [] (empty array).

3 Likes

Hi @dincho.chain,
Thanks for your reply.

  1. As you suggested to give {'None': []} (from javascript aesdk test )for the param which was defined as option(string) is still resulting in the following error. ValidationError: "Argument" at position 3 fails because [Value ""None":[]" at path: [3] not a string].

  2. giving undefined as input to the same param from aesdk works without any issue.

I am wondering why the former is still failing. Any thoughts.?

js中直接 data : " ‘’ "也不行吗?
双引号包裹着单引号
Option(string) 另外我不确定这里opt大小写是否有影响?

Try wrapping double quotes around single quotes?

Option(string) I’m not sure if I need to capitalize O here?

Hi @LiuShao ,
Thanks for the suggestions.

  1. Wrapping double quotes around single is not working out as javascript sdk is showing error.

  2. it should be option(small letter o) than the capital O. I tried compiling it anyway to double check. With capital O, the compiler is giving a parse error.

to add more context here for everyone.

I am trying to compile the AEX-141 standard and test its functionalities out.

Link to Project: aex141-examples/contracts at dev · aeternity/aex141-examples · GitHub

I am trying to test the base_nft.aes contract.
(The project already has pre-defined test cases which are failing for me).

1 Like

@Jkrish1011I can’t reproduce this issue using [email protected], here is a working example of all ways to pass absent of value to option argument:

const { Node, Universal, MemoryAccount } = require('@aeternity/aepp-sdk')

const contractSource = `
contract Test =
  stateful entrypoint transfer(from: address, to: address, token_id: int, data: option(string)) : unit =
    require(true, "Test")
`;

(async () => {
    const node = await Node({ url: 'https://testnet.aeternity.io' })
    const aeSdk = await Universal({
        nodes: [{ name: 'testnet', instance: node }],
        compilerUrl: 'https://compiler.aepps.com',
        accounts: [MemoryAccount({
            keypair: {
                publicKey: 'ak_2dATVcZ9KJU5a8hdsVtTv21pYiGWiPbmVcU1Pz72FFqpk9pSRR',
                secretKey: 'bf66e1c256931870908a649572ed0257876bb84e3cdf71efb12f56c7335fad54d5cf08400e988222f26eb4b02c8f89077457467211a6e6d955edb70749c6a33b'
            }
        })]
    })

    const contract = await aeSdk.getContractInstance({ source: contractSource })
    const deployInfo = await contract.deploy()
    console.log('Contract deployed at', deployInfo.address)
    const address = await aeSdk.address()
    await contract.methods.transfer.send(address, address, 42)
    await contract.methods.transfer.send(address, address, 42, undefined)
    await contract.methods.transfer.send(address, address, 42, null)
    await contract.methods.transfer.send(address, address, 42, { None: [] })
    console.log('Done')
})()
2 Likes

Hi @davidyuk,
Thanks for your update. Appologise for the late follow up. Was held up with some home duties.

I believe my sdk version is outdated. Let me update it to v11.0.1 and see how this functions.

Thanks,

1 Like

Hello All,

I did update my Aeproject to version 4.0.0 and the error is resolved.

1 Like

I am trying to compile the AEX-141 standard and test its functionalities out.

1 Like

thats good to know. What are you building/implementing using the NFTs?