foundry-defi-stablecoin-f23 TransferOwnership Failed #1790
-
After adding arguments to constructor like this: code snippet of DeployDSC vm.startBroadcast();
DecentralizedStableCoin dsc = new DecentralizedStableCoin(address(this), "DecentralizedStableCoin", "DSC");
DSCEngine engine = new DSCEngine(tokenAddresses, priceFeedAddresses, address(dsc));
dsc.transferOwnership(address(engine));
vm.stopBroadcast(); The error is below:
any suggestions for resolution? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Hello @badar-chachar, Below is what my // SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.23;
import {Script, console2} from "forge-std/Script.sol";
import {HelperConfig} from "./HelperConfig.s.sol";
import {DecentralizedStableCoin} from "../src/DecentralizedStableCoin.sol";
import {DSCEngine} from "../src/DSCEngine.sol";
contract DeployDSCEngine is Script {
DecentralizedStableCoin decentralized_stable_coin;
DSCEngine dsc_engine;
address[] private address_of_collateral_tokens;
address[] private address_of_collateral_token_price_feeds;
function run() external returns (DecentralizedStableCoin, DSCEngine, HelperConfig) {
decentralized_stable_coin = new DecentralizedStableCoin();
HelperConfig helper_config = new HelperConfig();
(
address wETH_token_address,
address wBTC_token_address,
address wETH_token_addres_price_feed,
address wBTC_token_addres_price_feed,
uint256 deployer_key
) = helper_config.active_network_config();
address_of_collateral_tokens = [wETH_token_address, wBTC_token_address];
address_of_collateral_token_price_feeds = [wETH_token_addres_price_feed, wBTC_token_addres_price_feed];
vm.startBroadcast(deployer_key);
dsc_engine = new DSCEngine(
address_of_collateral_tokens, address_of_collateral_token_price_feeds, address(decentralized_stable_coin)
);
vm.stopBroadcast();
decentralized_stable_coin.transferOwnership(address(dsc_engine));
return (decentralized_stable_coin, dsc_engine, helper_config);
}
} Can you please show me yours? |
Beta Was this translation helpful? Give feedback.
-
I was also getting error in this **Ran 1 test for test/unit/DSCEngineTest.t.sol:DSCEngineTest
[FAIL. Reason: setup failed: OwnableInvalidOwner(0x0000000000000000000000000000000000000000)] setUp() (gas: 0)
Traces:
[7669204] DSCEngineTest::setUp()
├─ [4038904] → new DeployDSC@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
│ └─ ← [Return] 20061 bytes of code
├─ [3587913] DeployDSC::run()
│ ├─ [3339508] → new HelperConfig@0x104fBc016F4bb334D775a19E8A6510109AC63E00
│ │ ├─ [0] VM::startBroadcast()
│ │ │ └─ ← [Return]
│ │ ├─ [372255] → new MockV3Aggregator@0x90193C961A926261B756D1E5bb255e67ff9498A1
│ │ │ └─ ← [Return] 1082 bytes of code
│ │ ├─ [516505] → new ERC20Mock@0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496
│ │ │ ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: DeployDSC: [0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f], value: 100000000000 [1e11])
│ │ │ └─ ← [Return] 2117 bytes of code
│ │ ├─ [372255] → new MockV3Aggregator@0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3
│ │ │ └─ ← [Return] 1082 bytes of code
│ │ ├─ [516505] → new ERC20Mock@0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76
│ │ │ ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: DeployDSC: [0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f], value: 100000000000 [1e11])
│ │ │ └─ ← [Return] 2117 bytes of code
│ │ ├─ [0] VM::stopBroadcast()
│ │ │ └─ ← [Return]
│ │ └─ ← [Return] 6360 bytes of code
│ ├─ [912] HelperConfig::activeNetworkConfig() [staticcall]
│ │ └─ ← [Return] MockV3Aggregator: [0x90193C961A926261B756D1E5bb255e67ff9498A1], MockV3Aggregator: [0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3], ERC20Mock: [0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496], ERC20Mock: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76], 77814517325470205911140941194401928579557062014761831930645393041380819009408 [7.781e76]
│ ├─ [0] VM::startBroadcast(<pk>)
│ │ └─ ← [Return]
│ ├─ [45275] → new <unknown>@0x5FbDB2315678afecb367f032d93F642f64180aa3
│ │ └─ ← [Revert] OwnableInvalidOwner(0x0000000000000000000000000000000000000000)
│ └─ ← [Revert] OwnableInvalidOwner(0x0000000000000000000000000000000000000000)
└─ ← [Revert] OwnableInvalidOwner(0x0000000000000000000000000000000000000000)
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 4.57ms (0.00ns CPU time)
Ran 1 test suite in 1.52s (4.57ms CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests)
Failing tests:
Encountered 1 failing test in test/unit/DSCEngineTest.t.sol:DSCEngineTest
[FAIL. Reason: setup failed: OwnableInvalidOwner(0x0000000000000000000000000000000000000000)] setUp() (gas: 0)** But my issue has been resolved by making the change in //change here 0x0 to msg.sender ///
// constructor() ERC20("DecentralizedStableCoin", "DSC") Ownable(address(0)) {}
constructor() ERC20("DecentralizedStableCoin", "DSC") Ownable(msg.sender) {} wtihout making any changes in |
Beta Was this translation helpful? Give feedback.
Remove this line of code
dsc.transferOwnership(address(engine));
from inside thevm.startBroadcast()
andvm.stopBroadcast()
and let's see if the test would still error.