Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

oz call doesn't support reading from public mappings #1209

Closed
abcoathup opened this issue Aug 28, 2019 · 3 comments · Fixed by #1224
Closed

oz call doesn't support reading from public mappings #1209

abcoathup opened this issue Aug 28, 2019 · 3 comments · Fixed by #1224
Assignees
Labels
kind:bug topic:dx Issue that affects developer experience

Comments

@abcoathup
Copy link
Contributor

oz call doesn't support reading from public mappings

Reported in the forum: https://forum.openzeppelin.com/t/how-to-check-the-mapping-value-via-openzeppelin-cli/1253/2

Test.sol

pragma solidity ^0.5.0;

contract Test {
  mapping(uint256 => string) public _storage;

  function setStorage() public {
    _storage[1] = "test";
  }
}

Set a value in the mapping

$ npx oz send-tx
? Pick a network development
? Pick an instance Test at 0xA94B7f0465E98609391C623d0560C5720a3f2D33
? Select which function setStorage()
✓ Transaction successful. Transaction hash: 0x73ea3701929d73e6e0174479ae56f61c98e82109151eda451dff750865795208

Attempt to read the value

Fails as the parameter is not named.

$ npx oz call
? Pick a network development
? Pick an instance Test at 0xA94B7f0465E98609391C623d0560C5720a3f2D33
? Select which function _storage(: uint256)
You must provide a `name` parameter

Read the value specifying method name

We can read the value when we specify a method name and argument.

$ npx oz call --method "_storage(uint256)" --args 1
? Pick a network development
? Pick an instance Test at 0xA94B7f0465E98609391C623d0560C5720a3f2D33
✓ Method '_storage(uint256)' returned: test
test
@nventuro
Copy link
Contributor

Hmm, this probably comes from storage variable getters not requiring a name to their key, since they use it implicitly. Could you check if you can reproduce this issue with the following function?

function getStorage(uint256) public view returns (string memory) {
  return _storage[1];
}

(note that it receives an unnamed parameter)

@abcoathup
Copy link
Contributor Author

Added

  function getStorage(uint256) public view returns (string memory) {
    return _storage[1];
  }

Calling the function with a parameter with no name via the interactive commands results in the same error:

$ npx oz call
? Pick a network development
? Pick an instance Test at 0x6f84742680311CEF5ba42bc10A71a4708b4561d1
? Select which function getStorage(: uint256)
You must provide a `name` parameter

The call can be used specifying the method and arguments in the command line.

$ npx oz call --method "getStorage(uint256)" --args 1
? Pick a network development
? Pick an instance Test at 0x6f84742680311CEF5ba42bc10A71a4708b4561d1
✓ Method 'getStorage(uint256)' returned: test
test

@jbcarpanelli
Copy link
Contributor

Good catch @abcoathup (as always!).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind:bug topic:dx Issue that affects developer experience
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants