Say I have the following SimpleMath
solidity library
defined as follows:
library SimpleMath {
function add(uint a, uint b) internal pure returns(uint)
{
return a + b;
}
}
How do I import this library
using brownie in my python script and call the add
method? I would like to run unit tests of library
functions.
I don't seem to have an issue importing the library, however I can't access its functions even when changing the access modifier to public I get the following brownie error:
from brownie import SimpleMath
def test_add():
retVal = SimpleMath.add(10, 20)
assert retVal == 30
AttributeError: 'ContractContainer' object has no attribute 'add'
Edit: So apparently you have to deploy a library
the same way you would deploy a contract and then access it's methods, however I can't access the library's internal
methods only external
/public
:
simpleMath = SimpleMath.deploy({'from': account})
simpleMath = simpleMath.add() # since add is internal cannot access
AttributeError: Contract 'SimpleMath' object has no attribute 'add'
How then can I test a libraries functions that are internal in brownie?
hardhat-exposed
. Although I haven't tried it yet