DeployTransparentProxy Not Working
Hi folks. Quite blocked here simply trying to deploy transparent proxy.
Trying to deploy a very straightforward erc20 not sure why this is breaking for me.
My contract is
contract NativeTokenV1 is
Initializable,
ERC20Upgradeable,
ERC20BurnableUpgradeable,
ERC20PausableUpgradeable,
ERC20PermitUpgradeable
{
function initialize(
uint256 _burnRate,
uint256 _txFeeRate
) public initializer {
__ERC20_init("Interchain Token", "ITS");
__ERC20Burnable_init();
__ERC20Pausable_init();
__ERC20Permit_init("Interchain Token");
s_burnRate = _burnRate;
s_txFeeRate = _txFeeRate;
}
}
My test is
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.20;
import "forge-std/Test.sol";
import "forge-std/console2.sol";
import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol";
import {NativeTokenV1} from "../../src/NativeTokenV1.sol";
import {AccessControl} from "../../src/AccessControl.sol";
contract Setup is Test {
NativeTokenV1 public token;
constructor() {
address tokenInstance = Upgrades.deployTransparentProxy(
"NativeTokenV1.sol",
vm.addr(1),
abi.encodeCall(NativeTokenV1.initialize, (20000, 10000))
);
}
}
Getting this error
[FAIL. Reason: EvmError: Revert] setUp() (gas: 0)
Traces:
[71365] → new <Unknown>@0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496
├─ [0] VM::addr(<pk>) [staticcall]
│ └─ ← 0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf
├─ [0] VM::envOr(FOUNDRY_OUT, out) [staticcall]
│ └─ ← <env var value>
├─ [0] VM::projectRoot() [staticcall]
│ └─ ← /Desktop/Work/Content/Token
├─ [0] VM::readFile(/Desktop/Work/Content/Token/my-output-dir/NativeTokenV1.sol/NativeTokenV1.json) [staticcall]
│ └─ ← "The path "/Desktop/Work/Content/Token/my-output-dir/NativeTokenV1.sol/NativeTokenV1.json" is not allowed to be accessed for read operations."
└─ ← 0 bytes of code
Test result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 553.67µs
Ran 1 test suites: 0 tests passed, 1 failed, 0 skipped (1 total tests)
Failing tests:
Encountered 1 failing test in test/NativeTokenToken.t.sol:Initialization
[FAIL. Reason: EvmError: Revert] setUp() (gas: 0)
Encountered a total of 1 failing tests, 0 tests succeeded
No idea what's wrong here been trying for hours. I have following the instructions found here.
I have tried both by passing "NativeTokenV1.sol", and "NativeTokenV1" as first arg. Help is greatly appreciated
It looks like you may have out = "my-output-dir" in foundry.toml according to our example in the documentation, but Foundry does not allow read permissions by default for custom output directories.
You could do one of the following:
- Change the output directory setting in foundry.toml to the default setting:
out = "out" - or add read permissions to the custom directory in foundry.toml:
fs_permissions = [{ access = "read", path = "my-output-dir" }]
this is my toml file
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
ffi = true
ast = true
build_info = true
extra_output = ["storageLayout"]
dont have my-output-dir set anywhere
~~Can you try clearing the FOUNDRY_OUT environment variable by setting it to empty string?~~
^ Don't do this. See below.
Sorry I think I'm misunderstanding you here lol. Where should I set this empty string if not in the .env?
I put this in the FOUNDRY_OUT .env file and ran forge clean and forge build cannot see any code now (gitlog is gone too) is there a way i can backtrack this? thanks
Sorry, it should be FOUNDRY_OUT="out"
Foundry deletes the entire project if it is empty string! I'll report this issue to Foundry.
Is there anyway to recover? I can't find my code, not in gitlog, not even in vs code file history
If not, that's okay not the end of the world I was not super super deep in this project, though this is still quite a setback. I have restarted in a new repo from the tabs I had opened in my editor. This bug still persists in new repo though
I've opened https://github.com/foundry-rs/foundry/issues/7811 for the above. I'm not aware of whether it can be recovered, but have asked in that issue.
For your new repo, did you set FOUNDRY_OUT="out" in .env? Can you share the exact error that you are getting?
Okay fixed this by simply upgrading my foundry version as instructed here https://github.com/foundry-rs/foundry/issues/7615 @ericglau if you or anyone on the team has any solution for how I can recover my code from the the FOUNDRY_OUT issue from a few hours ago that would be amazing as I am really at a loss for this. Having said that the initial question I had regarding the upgrade command working is now resolved. thanks
@benjamin852 Sorry, I don't know how it can be recovered; you may need to use some file recovery method for your OS if needed.
I had the weirdest behaviour. When testing locally everything would work, including the proxy unit tests I created. But when I tried to deploy it either on a testnet or by manually setting up anvil, it would give me EvmError: Revert or some other custom error I can't replicate anymore. All to say this issue fixed it, it was simply needed to update foundry. Thanks!