I am testing on mainnet-fork
and it always fails when particular contracts like (Uniswap) are called more than once.
Is there any fix for this or is this problem outside the scope of brownie? Thanks
Here is the error
FAILED tests/test_uniswap.py::test_uniswap - brownie.exceptions.VirtualMachineError: revert: UniswapV2: LOCKED
Here is the code. It swaps DAI for USDC
contract TestUniswap {
address constant private usdc = address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
address constant private dai = address(0x6B175474E89094C44Da98b954EedeAC495271d0F);
address constant private uniswap = address(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
address constant private weth = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
function swap() external {
uint daiBal = IERC20(dai).balanceOf(address(this));
IERC20(dai).approve(uniswap, daiBal);
address[] memory path = new address[](3);
path[0] = dai;
path[1] = weth;
path[2] = usdc;
Uni(uniswap).swapExactTokensForTokens(
daiBal, uint(0), path, address(this), now + 1800
);
}
}
Here is the test
def test_uniswap(accounts, testUniswap, dai, stable_coin_holder):
dai_amount = 10 * 10 ** 18
# check dai balance
stable_coin_holder_bal = dai.balanceOf(stable_coin_holder)
assert stable_coin_holder_bal >= dai_amount
# transfer DAI to testUniswap
dai.transfer(testUniswap, dai_amount, {'from': stable_coin_holder})
assert dai.balanceOf(testUniswap) == dai_amount
testUniswap.swap()
testUniswap.swap()