Accessing private members
Titanoboa allows access to private members of a contract. This is useful for testing internal functions or variables without having to expose them to the outside world.
Given a vyper module foo.vy in the same folder as your python code:
x: uint256
y: immutable(uint256)
def __init__(y_initial: uint256):
self.x = 42
self.y = y_initial
@internal
@pure
def _bar() -> uint256:
return 111
We can notice that x, y and _bar are all private members of the contract that wouldn't be easily accessible in a normal context. Boa allows access to all of these members, let's see how.
Accessing internal functions
internal functions can be accessed by calling the function from the internal attribute of the contract.
Accessing private storage variables
Private storage variables can be accessed by calling the variable from the _storage attribute of the contract:
Accessing private immutable variables
Similarly private immutable variables can be accessed by calling the variable from the _immutable attribute of the contract:
Accessing internal module variables
Since vyper 0.4.0 it is possible to modularize contracts.
Boa doesn't yet support accessing private module variables. However this can easily be done using eval.
Given a module bar.vy:
If another contract foo.vy imports bar:
It is possible to access bar.x from foo using eval: