multiversx / mx-sdk-py-cli

Python Command Line Tools and SDK for interacting with the MultiversX blockchain and dApps.
Other
35 stars 36 forks source link

mandos: decoding error when dumping the state after sending esdt #101

Open jacobleygonie opened 2 years ago

jacobleygonie commented 2 years ago

I am having decoding errors in mandos tests when dumping the state after sending an ESDT token to a contract. Currently using elrond-wasm v0.27.2. The error is not triggered when sending EGLD to the contract.

Below is an example of contract+test triggering the error:

The Smart Contract

#![no_std]
elrond_wasm::imports!();
elrond_wasm::derive_imports!();

#[elrond_wasm::contract]
pub trait Test {

  #[init]
  fn init(&self) {}

  #[payable(“*”)]
  #[endpoint(AcceptPayment)]
  fn accept_payment(&self) {}
}

The Test (dumpState at the end)

{
  "name": "bug dumpState",
  "steps": [
    {
      "step": "setState",
      "accounts": {
        "address:user": {
          "balance": "1,000",
          "esdt": {
            "str:TOKENA-abcdef": "100"
          }
        },
        "sc:contract": {
          "code": "file:../sc-test/output/arda-test.wasm",
          "owner": "address:user"
        }
      }
    },
    {
      "step": "scCall",
      "txId": "SendTokenToContract",
      "tx": {
        "from": "address:user",
        "to": "sc:contract",
        "esdtValue": {
          "tokenIdentifier": "str:TOKENA-abcdef",
          "value": "100"
        },
        "function": "AcceptPayment",
        "gasLimit": "1,000,000,000",
        "gasPrice": "0"
      }
    },
    { "step": "dumpState" }
  ]
}

The Error

INFO:myprocess:run_process: ['/Users/jacobleygonie/elrondsdk/vmtools/mandos-test', '/Users/jacobleygonie/Dropbox/Mon Mac (pse-senik)/Desktop/arda-sc/test/mandos'], in folder: None
Traceback (most recent call last):
  File "/Users/jacobleygonie/elrondsdk/erdpy", line 8, in <module>
    sys.exit(main())
  File "/Users/jacobleygonie/elrondsdk/erdpy-venv/lib/python3.9/site-packages/erdpy/cli.py", line 32, in main
    _do_main()
  File "/Users/jacobleygonie/elrondsdk/erdpy-venv/lib/python3.9/site-packages/erdpy/cli.py", line 58, in _do_main
    args.func(args)
  File "/Users/jacobleygonie/elrondsdk/erdpy-venv/lib/python3.9/site-packages/erdpy/cli_contracts.py", line 186, in run_tests
    projects.run_tests(args)
  File "/Users/jacobleygonie/elrondsdk/erdpy-venv/lib/python3.9/site-packages/erdpy/projects/core.py", line 65, in run_tests
    project.run_tests(directory, wildcard)
  File "/Users/jacobleygonie/elrondsdk/erdpy-venv/lib/python3.9/site-packages/erdpy/projects/project_base.py", line 105, in run_tests
    myprocess.run_process(args, env=tool_env)
  File "/Users/jacobleygonie/elrondsdk/erdpy-venv/lib/python3.9/site-packages/erdpy/myprocess.py", line 19, in run_process
    output = subprocess.check_output(args, shell=False, universal_newlines=True, stderr=subprocess.STDOUT, env=env, cwd=cwd)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 424, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 507, in run
    stdout, stderr = process.communicate(input, timeout=timeout)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 1121, in communicate
    stdout = self.stdout.read()
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 651: invalid start byte
Alex1304 commented 2 years ago

I get the same error but it is not specific to dumpState, sometimes checkState does it too. It's really annoying.

andreibancioiu commented 2 years ago

@jacobleygonie, @Alex1304, thank you for reporting the issue :pray:

Mandos is writing non-printable characters in the stdout, in this case. E.g.

Scenario: adder.scen.json ... world state dump: 
{
    "address:user": {
        "nonce": "1",
        "balance": "1000",
        "esdt": {
            "str:TOKENA-abcdef": {
                "instances": [
                    {
                        "nonce": "0",
                        "balance": "100"
                    }
                ],
                "lastNonce": "0"
            }
        }
    },
    "sc:contract": {
        "nonce": "0",
        "balance": "0",
        "owner": "address:user"
    },     
    "address:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff#ff": {
        "nonce": "0",
        "balance": "0"
    }
}

We are working on a fix.

mingles commented 2 years ago

Any updates on this? It's pretty grizzly writing these tests without this functionality.