Skip to content
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

Feat: update to use upload to pinnata #47

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions packages/contracts/deploy/20_new_version/23_publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
isLocal,
pluginEnsDomain,
} from '../../utils/helpers';
import {PLUGIN_REPO_PERMISSIONS, uploadToIPFS} from '@aragon/osx-commons-sdk';
import {PLUGIN_REPO_PERMISSIONS, uploadToPinata} from '@aragon/osx-commons-sdk';
import {writeFile} from 'fs/promises';
import {ethers} from 'hardhat';
import {DeployFunction} from 'hardhat-deploy/types';
Expand All @@ -31,14 +31,21 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {deployments} = hre;
const [deployer] = await hre.ethers.getSigners();

// Upload the metadata to IPFS
const releaseMetadataURI = `ipfs://${await uploadToIPFS(
JSON.stringify(METADATA.release, null, 2)
)}`;
const buildMetadataURI = `ipfs://${await uploadToIPFS(
JSON.stringify(METADATA.build, null, 2)
)}`;
// metadata will be empty if running locally
let releaseMetadataURI = '';
let buildMetadataURI = '';

if (!isLocal(hre)) {
// Upload the metadata to IPFS
releaseMetadataURI = await uploadToPinata(
JSON.stringify(METADATA.release, null, 2),
`${PLUGIN_REPO_ENS_SUBDOMAIN_NAME}-release-metadata`
);
buildMetadataURI = await uploadToPinata(
JSON.stringify(METADATA.build, null, 2),
`${PLUGIN_REPO_ENS_SUBDOMAIN_NAME}-build-metadata`
);
}
console.log(`Uploaded release metadata: ${releaseMetadataURI}`);
console.log(`Uploaded build metadata: ${buildMetadataURI}`);

Expand Down
22 changes: 0 additions & 22 deletions packages/contracts/deploy/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,6 @@ export const DAO_PERMISSIONS = [
'REGISTER_STANDARD_CALLBACK_PERMISSION',
];

export async function uploadToIPFS(
metadata: string,
networkName: string
): Promise<string> {
const client = IPFS.create({
url: 'https://prod.ipfs.aragon.network/api/v0',
headers: {
'X-API-KEY': 'b477RhECf8s8sdM7XrkLBs2wHc4kCMwpbcFC55Kt',
},
});

if (networkName === 'hardhat' || networkName === 'localhost') {
// return a dummy path
return 'QmNnobxuyCjtYgsStCPhXKEiQR5cjsc3GtG9ZMTKFTTEFJ';
}

const res = await client.add(metadata);
await client.pin.add(res.cid);
console.log(`Uploaded to IPFS with cid ${res.cid.toString()}`);
return res.cid.toString();
}

export async function getContractAddress(
contractName: string,
hre: HardhatRuntimeEnvironment
Expand Down
27 changes: 16 additions & 11 deletions packages/contracts/test/20_integration-testing/21_deployment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {METADATA, VERSION} from '../../plugin-settings';
import { VERSION, PLUGIN_SETUP_CONTRACT_NAME} from '../../plugin-settings';
import {getProductionNetworkName, findPluginRepo} from '../../utils/helpers';
import {
getLatestNetworkDeployment,
Expand All @@ -9,7 +9,6 @@ import {
PERMISSION_MANAGER_FLAGS,
PLUGIN_REPO_PERMISSIONS,
UnsupportedNetworkError,
uploadToIPFS,
} from '@aragon/osx-commons-sdk';
import {
DAO,
Expand Down Expand Up @@ -65,20 +64,16 @@ describe(`Deployment on network '${productionNetworkName}'`, function () {

context('PluginSetup Publication', async () => {
it('registers the setup', async () => {
const {pluginRepo} = await loadFixture(fixture);
const {pluginRepo, pluginSetupAddr} = await loadFixture(fixture);

const results = await pluginRepo['getVersion((uint8,uint16))']({
release: VERSION.release,
build: VERSION.build,
});

const buildMetadataURI = `ipfs://${await uploadToIPFS(
JSON.stringify(METADATA.build, null, 2)
)}`;

expect(results.buildMetadata).to.equal(
ethers.utils.hexlify(ethers.utils.toUtf8Bytes(buildMetadataURI))
);
expect(results.pluginSetup).to.equal(pluginSetupAddr);
expect(results.tag.build).to.equal(VERSION.build);
expect(results.tag.release).to.equal(VERSION.release);
});
});
});
Expand All @@ -88,6 +83,7 @@ type FixtureResult = {
pluginRepo: PluginRepo;
pluginRepoRegistry: PluginRepoRegistry;
managementDaoProxy: DAO;
pluginSetupAddr: string;
};

async function fixture(): Promise<FixtureResult> {
Expand Down Expand Up @@ -124,5 +120,14 @@ async function fixture(): Promise<FixtureResult> {
deployer
);

return {deployer, pluginRepo, pluginRepoRegistry, managementDaoProxy};
const pluginSetupAddr = (await deployments.get(PLUGIN_SETUP_CONTRACT_NAME))
.address;

return {
deployer,
pluginRepo,
pluginRepoRegistry,
managementDaoProxy,
pluginSetupAddr,
};
}
Loading