-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fork test tooling #419
Merged
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
df1e6f4
Add fork test tooling
shahthepro aaae7d6
Update tooling to record script executions
shahthepro d3f4806
Merge branch 'DanielVF/DeployFiles' into shah/fork-test-tooling
shahthepro 28e29a7
Add a bit of tests
shahthepro cc01b28
Fix brownie tests
shahthepro 516937b
Add fork tests
shahthepro 383f2df
Print safe tx data
shahthepro e5582e1
Print tx data only on mainnet
shahthepro 8526d1d
Add Migrator tests
shahthepro 9728d78
Fix CI
shahthepro 5a7e530
Brownie remap
shahthepro efd24a5
Cherry pick CR comments
shahthepro 14d1073
Deploy 010 - OGN Rewards Source and xOGN (#420)
shahthepro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ out/ | |
.vscode | ||
brownie-deploy/ | ||
.idea | ||
deployments-fork.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"1": { | ||
"executions": {}, | ||
"contracts": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ remappings = [ | |
"OpenZeppelin/[email protected]/=./lib/openzeppelin-contracts-upgradeable", | ||
"paulrberg/[email protected]/=./lib/prb-math" | ||
] | ||
fs_permissions = [{ access = "read-write", path = "./build"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
// SPDX-License-Identifier: Unlicense | ||
pragma solidity 0.8.10; | ||
|
||
import "forge-std/Script.sol"; | ||
import "OpenZeppelin/[email protected]/contracts/utils/Strings.sol"; | ||
|
||
import {BaseMainnetScript} from "./mainnet/BaseMainnetScript.sol"; | ||
|
||
import {XOGNSetupScript} from "./mainnet/010_xOGNSetupScript.sol"; | ||
import {OgnOgvMigrationScript} from "./mainnet/011_OgnOgvMigrationScript.sol"; | ||
import {XOGNGovernanceScript} from "./mainnet/012_xOGNGovernanceScript.sol"; | ||
|
||
contract DeployManager is Script { | ||
mapping(string => address) public deployedContracts; | ||
mapping(string => bool) public scriptsExecuted; | ||
|
||
function isForked() public view returns (bool) { | ||
return vm.isContext(VmSafe.ForgeContext.ScriptDryRun) || vm.isContext(VmSafe.ForgeContext.Test) | ||
|| vm.isContext(VmSafe.ForgeContext.TestGroup); | ||
} | ||
|
||
function getDeploymentFilePath() public view returns (string memory) { | ||
return isForked() ? getForkDeploymentFilePath() : getMainnetDeploymentFilePath(); | ||
} | ||
|
||
function getMainnetDeploymentFilePath() public view returns (string memory) { | ||
return string(abi.encodePacked(vm.projectRoot(), "/build/deployments.json")); | ||
} | ||
|
||
function getForkDeploymentFilePath() public view returns (string memory) { | ||
return string(abi.encodePacked(vm.projectRoot(), "/build/deployments-fork.json")); | ||
} | ||
|
||
function setUp() external { | ||
string memory chainIdStr = Strings.toString(block.chainid); | ||
string memory chainIdKey = string(abi.encodePacked(".", chainIdStr)); | ||
|
||
string memory mainnetFilePath = getMainnetDeploymentFilePath(); | ||
if (!vm.isFile(mainnetFilePath)) { | ||
// Create mainnet deployment file if it doesn't exist | ||
vm.writeFile( | ||
mainnetFilePath, | ||
string(abi.encodePacked('{ "', chainIdStr, '": { "executions": {}, "contracts": {} } }')) | ||
); | ||
} else if (!vm.keyExistsJson(vm.readFile(mainnetFilePath), chainIdKey)) { | ||
// Create network entry if it doesn't exist | ||
vm.writeJson( | ||
vm.serializeJson(chainIdStr, '{ "executions": {}, "contracts": {} }'), mainnetFilePath, chainIdKey | ||
); | ||
} | ||
|
||
if (isForked()) { | ||
// Duplicate Mainnet File | ||
vm.writeFile(getForkDeploymentFilePath(), vm.readFile(mainnetFilePath)); | ||
} | ||
} | ||
|
||
function run() external { | ||
// TODO: Use vm.readDir to recursively build this? | ||
_runDeployFile(new XOGNSetupScript()); | ||
_runDeployFile(new OgnOgvMigrationScript()); | ||
_runDeployFile(new XOGNGovernanceScript()); | ||
} | ||
|
||
function _runDeployFile(BaseMainnetScript deployScript) internal { | ||
string memory chainIdStr = Strings.toString(block.chainid); | ||
string memory chainIdKey = string(abi.encodePacked(".", chainIdStr)); | ||
|
||
string memory contractsKey = string(abi.encodePacked(chainIdKey, ".contracts")); | ||
string memory executionsKey = string(abi.encodePacked(chainIdKey, ".executions")); | ||
|
||
string memory deploymentsFilePath = getDeploymentFilePath(); | ||
string memory fileContents = vm.readFile(deploymentsFilePath); | ||
|
||
/** | ||
* Execution History | ||
*/ | ||
string memory currentExecutions = ""; | ||
string[] memory executionKeys = vm.parseJsonKeys(fileContents, executionsKey); | ||
|
||
for (uint256 i = 0; i < executionKeys.length; ++i) { | ||
uint256 deployedTimestamp = | ||
vm.parseJsonUint(fileContents, string(abi.encodePacked(executionsKey, ".", executionKeys[i]))); | ||
|
||
currentExecutions = vm.serializeUint(executionsKey, executionKeys[i], deployedTimestamp); | ||
scriptsExecuted[executionKeys[i]] = true; | ||
} | ||
|
||
if (scriptsExecuted[deployScript.DEPLOY_NAME()]) { | ||
// TODO: Handle any active governance proposal | ||
console.log("Skipping already deployed script"); | ||
return; | ||
} | ||
|
||
/** | ||
* Pre-deployment | ||
*/ | ||
BaseMainnetScript.DeployRecord[] memory deploys; | ||
string memory networkDeployments = ""; | ||
string[] memory existingContracts = vm.parseJsonKeys(fileContents, contractsKey); | ||
for (uint256 i = 0; i < existingContracts.length; ++i) { | ||
address deployedAddr = | ||
vm.parseJsonAddress(fileContents, string(abi.encodePacked(contractsKey, ".", existingContracts[i]))); | ||
|
||
networkDeployments = vm.serializeAddress(contractsKey, existingContracts[i], deployedAddr); | ||
|
||
deployedContracts[existingContracts[i]] = deployedAddr; | ||
|
||
deployScript.preloadDeployedContract(existingContracts[i], deployedAddr); | ||
} | ||
|
||
// Deployment | ||
deployScript.setUp(); | ||
deployScript.run(); | ||
|
||
/** | ||
* Post-deployment | ||
*/ | ||
BaseMainnetScript.DeployRecord[] memory records = deployScript.getAllDeployRecords(); | ||
|
||
for (uint256 i = 0; i < records.length; ++i) { | ||
string memory name = records[i].name; | ||
address addr = records[i].addr; | ||
|
||
console.log(string(abi.encodePacked("> Recorded Deploy of ", name, " at")), addr); | ||
networkDeployments = vm.serializeAddress(contractsKey, name, addr); | ||
deployedContracts[name] = addr; | ||
} | ||
|
||
vm.writeJson(networkDeployments, deploymentsFilePath, contractsKey); | ||
|
||
/** | ||
* Write Execution History | ||
*/ | ||
currentExecutions = vm.serializeUint(executionsKey, deployScript.DEPLOY_NAME(), block.timestamp); | ||
|
||
vm.writeJson(currentExecutions, deploymentsFilePath, executionsKey); | ||
} | ||
|
||
function getDeployment(string calldata contractName) external view returns (address) { | ||
return deployedContracts[contractName]; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still getting a lot of random failure on these writeJson's (about 2/3 of the 50% of tests fail, about 1/6 of the time, all tests succeed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. It's mostly about writing twice to the same file back to back. Thats why I added a small delay. Will work on a clean fix to do a single write instead