From 5a9ad7bbd71c93561d21621b444001e1ef1dc7de Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Tue, 19 Dec 2023 23:01:44 +0100 Subject: [PATCH] Small fixes in deployment scripts, added additional test for HubController, deployed contracts on Gnosis Mainnet --- .../v1/storage/assets/ContentAssetStorage.sol | 2 +- deploy/001_deploy_hub_v2.ts | 2 +- deploy/003_deploy_token.ts | 11 +- deploy/007_deploy_sha256.ts | 1 + deploy/009_deploy_log2pldsf.ts | 1 + deployments/gnosis_mainnet_contracts.json | 240 ++++++++++++++++++ test/v1/unit/HubController.test.ts | 148 ++++++++++- utils/helpers.ts | 8 +- 8 files changed, 398 insertions(+), 15 deletions(-) create mode 100644 deployments/gnosis_mainnet_contracts.json diff --git a/contracts/v1/storage/assets/ContentAssetStorage.sol b/contracts/v1/storage/assets/ContentAssetStorage.sol index 74d3219f..2518a35c 100644 --- a/contracts/v1/storage/assets/ContentAssetStorage.sol +++ b/contracts/v1/storage/assets/ContentAssetStorage.sol @@ -20,7 +20,7 @@ contract ContentAssetStorage is AbstractAsset, ERC721 { mapping(bytes32 => address) public issuers; // solhint-disable-next-line no-empty-blocks - constructor(address hubAddress) AbstractAsset(hubAddress) ERC721("ContentAssetStorage", "DKG") {} + constructor(address hubAddress) AbstractAsset(hubAddress) ERC721("KnowledgeAssetCollection", "DKG") {} function name() public view virtual override(Named, ERC721) returns (string memory) { return ERC721.name(); diff --git a/deploy/001_deploy_hub_v2.ts b/deploy/001_deploy_hub_v2.ts index 8b266ad7..0bfe78d7 100644 --- a/deploy/001_deploy_hub_v2.ts +++ b/deploy/001_deploy_hub_v2.ts @@ -42,7 +42,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { setContractInHub: false, }); - if (previousHubControllerAddress == null) { + if (previousHubControllerAddress === null) { const hubAddress = hre.helpers.contractDeployments.contracts['Hub'].evmAddress; const Hub = await hre.ethers.getContractAt('Hub', hubAddress, deployer); diff --git a/deploy/003_deploy_token.ts b/deploy/003_deploy_token.ts index a1613d96..12ace36c 100644 --- a/deploy/003_deploy_token.ts +++ b/deploy/003_deploy_token.ts @@ -13,14 +13,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const tokenInHub = await Hub['isContract(string)']('Token'); if (!tokenInHub) { - const hubControllerAddress = hre.helpers.contractDeployments.contracts['HubController'].evmAddress; - const HubController = await hre.ethers.getContractAt('HubController', hubControllerAddress, deployer); - - const tokenAddress = hre.helpers.contractDeployments.contracts['Token'].evmAddress; - - console.log(`Setting Token (${tokenAddress}) in the Hub (${Hub.address}).`); - const setTokenTx = await HubController.setContractAddress('Token', tokenAddress); - await setTokenTx.wait(); + hre.helpers.newContracts.push(['Token', hre.helpers.contractDeployments.contracts['Token'].evmAddress]); } } else if (!isDeployed && hre.network.config.environment === 'development') { const Token = await hre.helpers.deploy({ @@ -43,6 +36,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const mintTx = await Token.mint(acc.address, amountToMint, { from: deployer, gasLimit: 80_000 }); await mintTx.wait(); } + } else { + throw new Error('Missing Token address in the JSON config!'); } }; diff --git a/deploy/007_deploy_sha256.ts b/deploy/007_deploy_sha256.ts index a59113c4..3e95f069 100644 --- a/deploy/007_deploy_sha256.ts +++ b/deploy/007_deploy_sha256.ts @@ -7,6 +7,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const SHA256 = await hre.helpers.deploy({ newContractName: 'SHA256', passHubInConstructor: false, + setContractInHub: false, }); if (!isDeployed) { diff --git a/deploy/009_deploy_log2pldsf.ts b/deploy/009_deploy_log2pldsf.ts index 3be71f74..41e4895e 100644 --- a/deploy/009_deploy_log2pldsf.ts +++ b/deploy/009_deploy_log2pldsf.ts @@ -6,6 +6,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const Log2PLDSF = await hre.helpers.deploy({ newContractName: 'Log2PLDSF', + setContractInHub: false, }); if (!isDeployed) { diff --git a/deployments/gnosis_mainnet_contracts.json b/deployments/gnosis_mainnet_contracts.json new file mode 100644 index 00000000..32568479 --- /dev/null +++ b/deployments/gnosis_mainnet_contracts.json @@ -0,0 +1,240 @@ +{ + "contracts": { + "Assertion": { + "deployed": true, + "deploymentTimestamp": 1703023107033, + "evmAddress": "0xB86D4A6deB4e507DF21A29efa00b908d39f730B3", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.1" + }, + "AssertionStorage": { + "deployed": true, + "deploymentTimestamp": 1703022989141, + "evmAddress": "0xff1c0D62eAC3fE4Fd69e42e587107fb5EaBf6836", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.0" + }, + "CommitManagerV1": { + "deployed": true, + "deploymentTimestamp": 1703023158518, + "evmAddress": "0xa4809dFDD80DF5D79fE938d9e01E795A84E014CA", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.1" + }, + "CommitManagerV1U1": { + "deployed": true, + "deploymentTimestamp": 1703023188102, + "evmAddress": "0x40bb23901022b9b3B055bee49cCcd462c1756Db2", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.1" + }, + "ContentAsset": { + "deployed": true, + "deploymentTimestamp": 1703023247599, + "evmAddress": "0xa51BA17e7bE776ccf1FBe5177f7356b63486c54F", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.2" + }, + "ContentAssetStorage": { + "deployed": true, + "deploymentTimestamp": 1703023075721, + "evmAddress": "0x9157595f26F6069A7c29e988c4249bA98A53c697", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "2.0.1" + }, + "HashingProxy": { + "deployed": true, + "deploymentTimestamp": 1703022944891, + "evmAddress": "0xEAE9dE9AA95AFc43CAB20970f1883c4857bC4a16", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.1" + }, + "Hub": { + "deployed": true, + "deploymentTimestamp": 1703022869550, + "evmAddress": "0xbEF14fc04F870c2dD65c13Df4faB6ba01A9c746b", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "2.0.0" + }, + "HubController": { + "deployed": true, + "deploymentTimestamp": 1703022879509, + "evmAddress": "0x48EA24e5C817C13215B3121bd6Fcc6B93D3c0caC", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.2" + }, + "Identity": { + "deployed": true, + "deploymentTimestamp": 1703023115582, + "evmAddress": "0xd821411AA4347906CF3FB6B6F65391Ef3976ff2d", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.1" + }, + "IdentityStorage": { + "deployed": true, + "deploymentTimestamp": 1703022999913, + "evmAddress": "0x85f868877Ccd88e1cd7936443ceD093f7E67BA37", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "2.0.0" + }, + "Log2PLDSF": { + "deployed": true, + "deploymentTimestamp": 1703022975903, + "evmAddress": "0x7A1a6f2262da962E2f0c2117668C8b03976C43FF", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": null + }, + "ParametersStorage": { + "deployed": true, + "deploymentTimestamp": 1703022903732, + "evmAddress": "0x394e73722B13F162778d9F9Ad0ce49f02aB51210", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.1.0" + }, + "Profile": { + "deployed": true, + "deploymentTimestamp": 1703023151472, + "evmAddress": "0x3Bb0F09B3625eF43afe1e590e4C41F63db7fF0C1", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.2" + }, + "ProfileStorage": { + "deployed": true, + "deploymentTimestamp": 1703023027670, + "evmAddress": "0x8E24940cA87B23a742E70Ca93BD43a13211B2c4d", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.0" + }, + "ProofManagerV1": { + "deployed": true, + "deploymentTimestamp": 1703023171376, + "evmAddress": "0x3d2f4a8c4d33D21415bCC107cE65cEbC0108326b", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.2" + }, + "ProofManagerV1U1": { + "deployed": true, + "deploymentTimestamp": 1703023211461, + "evmAddress": "0xa606689669BABb9C0D48A9B9C5C37cb874ACda4D", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.2" + }, + "SHA256": { + "deployed": true, + "deploymentTimestamp": 1703022954842, + "evmAddress": "0xDD21D2607D3f7e0fe939D25200f0256Cb7C7C9F7", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": null + }, + "ScoringProxy": { + "deployed": true, + "deploymentTimestamp": 1703022965121, + "evmAddress": "0xC7C52e75bc43147779A2F4C065324C3A0f7AfbEe", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.1" + }, + "ServiceAgreementStorageProxy": { + "deployed": true, + "deploymentTimestamp": 1703023064603, + "evmAddress": "0x8f8430045Fc2CAbD37cc744633987e1dBFfA1A7C", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.0" + }, + "ServiceAgreementStorageV1": { + "deployed": true, + "deploymentTimestamp": 1703023042140, + "evmAddress": "0xb3db60d04D2Ea88c21C4A27960665e0e1eEE8c28", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.0" + }, + "ServiceAgreementStorageV1U1": { + "deployed": true, + "deploymentTimestamp": 1703023053866, + "evmAddress": "0xC2bf77D0A4C5B6EfE2D0A37cb45B9e31C3E49a58", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.0" + }, + "ServiceAgreementV1": { + "deployed": true, + "deploymentTimestamp": 1703023240311, + "evmAddress": "0xC20dC8df633b049e9C227f1161548C6FA99c1d02", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.1.1" + }, + "ShardingTable": { + "deployed": true, + "deploymentTimestamp": 1703023127708, + "evmAddress": "0xd8B622e5D98d358C0DC730e90d749B3371054655", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.1" + }, + "ShardingTableStorage": { + "deployed": true, + "deploymentTimestamp": 1703023010069, + "evmAddress": "0xFD9B5c2221f4c248761710020edb8b565A7f220a", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.0" + }, + "Staking": { + "deployed": true, + "deploymentTimestamp": 1703023140241, + "evmAddress": "0x0ea866cB43BF4088F5ECC94bd6eD588154e8b972", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.2" + }, + "StakingStorage": { + "deployed": true, + "deploymentTimestamp": 1703023020919, + "evmAddress": "0xBA854b8d7052fcE6ff58D04818D68B9dC0718Fdd", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.0" + }, + "Token": { + "deployed": true, + "evmAddress": "0xEddd81E0792E764501AaE206EB432399a0268DB5" + }, + "UnfinalizedStateStorage": { + "deployed": true, + "deploymentTimestamp": 1703023096226, + "evmAddress": "0x22617263B5a2cab82d7c6f2956867eb4CDd29F6a", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.0" + }, + "WhitelistStorage": { + "deployed": true, + "deploymentTimestamp": 1703022936712, + "evmAddress": "0xa1238eD2C1DCe4EA5c51038396404114ACA7DdBF", + "gitBranch": "main", + "gitCommitHash": "c993c8564d17e5b8fbab770b020d7c926608ea24", + "version": "1.0.0" + } + } +} diff --git a/test/v1/unit/HubController.test.ts b/test/v1/unit/HubController.test.ts index 97300760..4c3bdede 100644 --- a/test/v1/unit/HubController.test.ts +++ b/test/v1/unit/HubController.test.ts @@ -3,7 +3,7 @@ import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; import { expect } from 'chai'; import hre from 'hardhat'; -import { Hub, HubController, Profile } from '../../../typechain'; +import { Hub, HubController, Profile, Token } from '../../../typechain'; import { GeneralStructs } from '../../../typechain/contracts/v1/HubController'; type HubControllerFixture = { @@ -13,6 +13,8 @@ type HubControllerFixture = { }; describe('@v1 @unit HubController contract', function () { + this.timeout(1000000); + let accounts: SignerWithAddress[]; let HubController: HubController; let Profile: Profile; @@ -110,4 +112,148 @@ describe('@v1 @unit HubController contract', function () { .to.emit(ScoringProxy, 'NewScoringFunctionContract') .withArgs(1, Log2PLDSF.address); }); + + it('Deploy full set of contracts and set new contract in Hub using HubController; Expect to be successful', async () => { + await hre.deployments.fixture(['Hub', 'Token']); + + HubController = await hre.ethers.getContract('HubController'); + const Token = await hre.ethers.getContract('Token'); + + const ParametersStorage = await hre.helpers.deploy({ newContractName: 'ParametersStorage' }); + const WhitelistStorage = await hre.helpers.deploy({ newContractName: 'WhitelistStorage' }); + const HashingProxy = await hre.helpers.deploy({ newContractName: 'HashingProxy' }); + const SHA256 = await hre.helpers.deploy({ + newContractName: 'SHA256', + passHubInConstructor: false, + setContractInHub: false, + }); + const ScoringProxy = await hre.helpers.deploy({ newContractName: 'ScoringProxy' }); + const Log2PLDSF = await hre.helpers.deploy({ + newContractName: 'Log2PLDSF', + setContractInHub: false, + }); + const AssertionStorage = await hre.helpers.deploy({ newContractName: 'AssertionStorage' }); + const IdentityStorage = await hre.helpers.deploy({ newContractName: 'IdentityStorage' }); + const ShardingTableStorage = await hre.helpers.deploy({ newContractName: 'ShardingTableStorage' }); + const StakingStorage = await hre.helpers.deploy({ newContractName: 'StakingStorage' }); + const ProfileStorage = await hre.helpers.deploy({ newContractName: 'ProfileStorage' }); + const ServiceAgreementStorageV1 = await hre.helpers.deploy({ newContractName: 'ServiceAgreementStorageV1' }); + const ServiceAgreementStorageV1U1 = await hre.helpers.deploy({ newContractName: 'ServiceAgreementStorageV1U1' }); + const ServiceAgreementStorageProxy = await hre.helpers.deploy({ newContractName: 'ServiceAgreementStorageProxy' }); + const ContentAssetStorage = await hre.helpers.deploy({ + newContractName: 'ContentAssetStorage', + passHubInConstructor: true, + setContractInHub: false, + setAssetStorageInHub: true, + }); + const UnfinalizedStateStorage = await hre.helpers.deploy({ newContractName: 'UnfinalizedStateStorage' }); + const Assertion = await hre.helpers.deploy({ newContractName: 'Assertion' }); + const Identity = await hre.helpers.deploy({ newContractName: 'Identity' }); + const ShardingTable = await hre.helpers.deploy({ newContractName: 'ShardingTable' }); + const Staking = await hre.helpers.deploy({ newContractName: 'Staking' }); + const Profile = await hre.helpers.deploy({ newContractName: 'Profile' }); + const CommitManagerV1 = await hre.helpers.deploy({ newContractName: 'CommitManagerV1' }); + const ProofManagerV1 = await hre.helpers.deploy({ newContractName: 'ProofManagerV1' }); + const CommitManagerV1U1 = await hre.helpers.deploy({ newContractName: 'CommitManagerV1U1' }); + const ProofManagerV1U1 = await hre.helpers.deploy({ newContractName: 'ProofManagerV1U1' }); + const ServiceAgreementV1 = await hre.helpers.deploy({ newContractName: 'ServiceAgreementV1' }); + const ContentAsset = await hre.helpers.deploy({ newContractName: 'ContentAsset' }); + + const newContracts = [ + { name: 'Token', addr: Token.address }, + { name: 'ParametersStorage', addr: ParametersStorage.address }, + { name: 'WhitelistStorage', addr: WhitelistStorage.address }, + { name: 'HashingProxy', addr: HashingProxy.address }, + { name: 'ScoringProxy', addr: ScoringProxy.address }, + { name: 'AssertionStorage', addr: AssertionStorage.address }, + { name: 'IdentityStorage', addr: IdentityStorage.address }, + { name: 'ShardingTableStorage', addr: ShardingTableStorage.address }, + { name: 'StakingStorage', addr: StakingStorage.address }, + { name: 'ProfileStorage', addr: ProfileStorage.address }, + { name: 'ServiceAgreementStorageV1', addr: ServiceAgreementStorageV1.address }, + { name: 'ServiceAgreementStorageV1U1', addr: ServiceAgreementStorageV1U1.address }, + { name: 'ServiceAgreementStorageProxy', addr: ServiceAgreementStorageProxy.address }, + { name: 'UnfinalizedStateStorage', addr: UnfinalizedStateStorage.address }, + { name: 'Assertion', addr: Assertion.address }, + { name: 'Identity', addr: Identity.address }, + { name: 'ShardingTable', addr: ShardingTable.address }, + { name: 'Staking', addr: Staking.address }, + { name: 'Profile', addr: Profile.address }, + { name: 'CommitManagerV1', addr: CommitManagerV1.address }, + { name: 'ProofManagerV1', addr: ProofManagerV1.address }, + { name: 'CommitManagerV1U1', addr: CommitManagerV1U1.address }, + { name: 'ProofManagerV1U1', addr: ProofManagerV1U1.address }, + { name: 'ServiceAgreementV1', addr: ServiceAgreementV1.address }, + { name: 'ContentAsset', addr: ContentAsset.address }, + ]; + const newAssetStorageContracts = [{ name: 'ContentAssetStorage', addr: ContentAssetStorage.address }]; + const newHashFunctions = [SHA256.address]; + const newScoreFunctions = [Log2PLDSF.address]; + const contractsForReinitialization = [ + Log2PLDSF.address, + StakingStorage.address, + ProfileStorage.address, + ServiceAgreementStorageV1.address, + ServiceAgreementStorageV1U1.address, + ServiceAgreementStorageProxy.address, + Assertion.address, + Identity.address, + ShardingTable.address, + Staking.address, + Profile.address, + CommitManagerV1.address, + ProofManagerV1.address, + CommitManagerV1U1.address, + ProofManagerV1U1.address, + ServiceAgreementV1.address, + ContentAsset.address, + ]; + const setParametersEncodedData = [ + { + contractName: 'ParametersStorage', + encodedData: [ + '0x0d8d840b0000000000000000000000000000000000000000000000000000000000000e10', + '0x51ce6d3e0000000000000000000000000000000000000000000000000000000000000258', + ], + }, + { + contractName: 'CommitManagerV1', + encodedData: [ + '0x7ea63c6e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001', + ], + }, + { + contractName: 'ProogManagerV1', + encodedData: [ + '0x7ea63c6e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001', + '0x7ea63c6e00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001', + ], + }, + { + contractName: 'CommitManagerV1U1', + encodedData: [ + '0x7ea63c6e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001', + '0x7ea63c6e00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001', + ], + }, + { + contractName: 'ProofManagerV1U1', + encodedData: [ + '0x7ea63c6e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001', + '0x7ea63c6e00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001', + ], + }, + ]; + + const setAndReinitializeContractsTx = await HubController.setAndReinitializeContracts( + newContracts, + newAssetStorageContracts, + newHashFunctions, + newScoreFunctions, + contractsForReinitialization, + setParametersEncodedData, + ); + + await expect(setAndReinitializeContractsTx).to.not.be.reverted; + }); }); diff --git a/utils/helpers.ts b/utils/helpers.ts index da8ba3a8..c531cf48 100644 --- a/utils/helpers.ts +++ b/utils/helpers.ts @@ -283,12 +283,12 @@ export class Helpers { } else { throw Error(`Parameter '${getterName}' doesn't exist in the contract '${contractName}'.`); } - - if (encodedData[1].length !== 0) { - this.setParametersEncodedData.push(encodedData); - } } } + + if (encodedData[1].length !== 0) { + this.setParametersEncodedData.push(encodedData); + } } public inConfig(contractName: string): boolean {