Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita committed Sep 1, 2020
1 parent d0ca495 commit eab09a8
Show file tree
Hide file tree
Showing 30 changed files with 370 additions and 185 deletions.
2 changes: 1 addition & 1 deletion packages/config/src/configDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const getInitialConfig = ({
ipfsProtocol: "https",
ipfsPort: "5001",
registry: {
address: "0xD230Dd91A049284a236f6ccba4412F647BDAAD9e",
address: "0x0bd0200357D26A0bB5d1D1c1Fd56C317B68d15d5",
network: "ropsten"
},
version: "3"
Expand Down
1 change: 1 addition & 0 deletions packages/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
create: require("./lib/commands/create/helpers"),
console: require("./lib/repl"),
contracts: require("@truffle/workflow-compile"),
package: require("@truffle/ethpm-v3"),
test: require("./lib/test"),
version: pkg.version,
ganache: require("ganache-core/public-exports")
Expand Down
6 changes: 4 additions & 2 deletions packages/core/lib/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const command = {
},
{
option: "--alias",
description: "A different name under which to install this package."
description: "An alternate name under which to install this package."
}
]
},
Expand All @@ -31,7 +31,9 @@ const command = {
}
if (options._ && options._.length > 1) {
done(
new Error(`Only one package identifier can be installed at a time.`)
new Error(
`Multiple package identifiers detected. Only one package can be installed at a time.`
)
);
}
options.packageIdentifier = options._[0];
Expand Down
9 changes: 9 additions & 0 deletions packages/ethpm-v1/lib/ethpm-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const OS = require("os");

const PackageV1 = {
packages: async options => {
options.logger.log(
`ethpmV1 is deprecated. Please consider updating your packages to ethpmV3.`
);
try {
expect.options(options, [
"ethpm",
Expand Down Expand Up @@ -65,6 +68,9 @@ const PackageV1 = {
},

install: async function (options, callback) {
options.logger.log(
`ethpmV1 is deprecated. Please consider updating your packages to ethpmV3.`
);
const callbackPassed = typeof callback === "function";
expect.options(options, ["working_directory", "ethpm"]);

Expand Down Expand Up @@ -167,6 +173,9 @@ const PackageV1 = {
},

publish: async function (options, callback) {
options.logger.log(
`ethpmV1 is deprecated. Please consider updating your packages to ethpmV3.`
);
const callbackPassed = typeof callback === "function";
var self = this;

Expand Down
6 changes: 4 additions & 2 deletions packages/ethpm-v1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
],
"homepage": "http://www.ethpm.com",
"license": "MIT",
"main": "lib/ethpm-v1.js",
"main": "./lib/ethpm-v1.js",
"dependencies": {
"ethpm-registry": "0.1.0-next.3"
"@truffle/error": "^0.0.9",
"ethpm": "0.0.19",
"ethpm-registry": "0.1.0-next.3"
},
"directories": {
"lib": "lib",
Expand Down
40 changes: 15 additions & 25 deletions packages/ethpm-v1/tests/ethpm-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var fs = require("fs-extra");
var glob = require("glob");
var path = require("path");
var Contracts = require("@truffle/workflow-compile");
var PackageV1 = require("../lib/package.js");
var PackageV1 = require("../lib/ethpm-v1.js");
var GithubExamples = require("ethpm/lib/indexes/github-examples");
var Blockchain = require("@truffle/blockchain-utils");
var Ganache = require("ganache-core");
var Resolver = require("@truffle/resolver");
Expand All @@ -29,35 +30,24 @@ describe.skip("EthPM integration", function () {
);
}

beforeEach("Create a Ganache provider and get a blockchain uri", function (
done
) {
beforeEach("Create a Ganache provider and get a blockchain uri", async () => {
provider = Ganache.provider();

Blockchain.asURI(provider, function (err, uri) {
if (err) return done(err);
blockchain_uri = uri;
done();
});
blockchain_uri = await Blockchain.asURI(provider);
});

// Super slow doing these in a beforeEach, but it ensures nothing conflicts.
beforeEach("Create a sandbox", function (done) {
beforeEach("Create a sandbox", async () => {
this.timeout(20000);
Box.sandbox(function (err, result) {
if (err) return done(err);
config = result;
config.resolver = new Resolver(config);
config.artifactor = new Artifactor(config.contracts_build_directory);
config.networks = {
development: {
network_id: blockchain_uri,
provider: provider
}
};
config.network = "development";
done();
});
config = await Box.sandbox("default");
config.resolver = new Resolver(config);
config.artifactor = new Artifactor(config.contracts_build_directory);
config.networks = {
development: {
network_id: blockchain_uri,
provider: provider
}
};
config.network = "development";
});

beforeEach("Create a fake EthPM host and memory registry", function (done) {
Expand Down
25 changes: 16 additions & 9 deletions packages/ethpm-v3/lib/ethpm-v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const PackageV3 = {
);
}

var provider = utils.pluckProviderFromConfig(options);

let targetRegistry;
if (!isAddress(options.ethpm.registry.address)) {
targetRegistry = await utils.resolveEnsName(
Expand All @@ -49,8 +51,6 @@ const PackageV3 = {
targetRegistry = options.ethpm.registry.address;
}

var provider = utils.pluckProviderFromConfig(options);

// Create an ethpm instance
let ethpm;
try {
Expand All @@ -74,11 +74,16 @@ const PackageV3 = {
options.logger.log(
`Searching for packages published on registry located at: ${targetRegistry}`
);
const owner = await ethpm.registries.registry.methods.owner().call();
options.logger.log(`Registry controlled by account: ${owner}`);

// display owner / warning about unauthorized registries
await utils.displayRegistryPermissions(options, ethpm);

// Display all packages from connected registry
const allPackages = await ethpm.registries.packages();
if (allPackages.length == 0) {
options.logger.log(`0 packages found on this registry.`);
}

for (var i = 0; i < allPackages.length; i++) {
const packageName = allPackages[i];
const allReleases = await ethpm.registries
Expand Down Expand Up @@ -123,6 +128,7 @@ const PackageV3 = {
options.logger.log(
`! Please use caution when interacting with installed packages.\n! Only use packages that are published on trusted registries, or whose assets you've verified directly.`
);

options.logger.log("Fetching package manifest...");
var targetNetwork = options.ethpm.registry.network;
var targetNetworkId = options.networks[targetNetwork].network_id;
Expand Down Expand Up @@ -160,6 +166,9 @@ const PackageV3 = {
throw new TruffleError(`Unable to configure ethpm: ${err.message}`);
}

// display owner / warning about unauthorized registries
await utils.displayRegistryPermissions(options, ethpm);

let manifestUri;
let targetPackageName;
let targetVersion;
Expand Down Expand Up @@ -242,11 +251,10 @@ const PackageV3 = {
const allReleases = await ethpm.registries
.package(targetPackageName)
.releases();
try {
targetVersion = semver.maxSatisfying(Object.keys(allReleases), "*");
} catch (err) {
targetVersion = semver.maxSatisfying(Object.keys(allReleases), "*");
if (!targetVersion) {
throw new TruffleError(
`Releases on active version do not look like semver. Please specify a version of the package you want to install.`
`Releases for specified package (${targetPackageName}) do not look like semver. Please specify the version of the package you want to install.`
);
}
}
Expand Down Expand Up @@ -308,7 +316,6 @@ const PackageV3 = {
if (deployment.contractType === contractType) {
contractDeployments[networkId] = {
address: deployment.address
// links && events
};
}
}
Expand Down
67 changes: 43 additions & 24 deletions packages/ethpm-v3/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,39 +54,46 @@ async function getPublishableArtifacts(options, ethpm) {
});
}

const requiredNetworkIds = Object.keys(detectedNetworkIdsToBlockchainUris);
const availableNetworkIds = Object.keys(options.networks).map(n =>
options.networks[n].network_id.toString()
);
for (let networkId of requiredNetworkIds) {
if (!availableNetworkIds.includes(networkId)) {
throw new TruffleError(
`Detected a deployment for network id: ${networkId}, but missing a provider for this network. Please make sure there is an available provider for this network id in your truffle-config.`
);
}
}

// generate blockchainURI for each detected networkId
for (let networkId of Object.keys(detectedNetworkIdsToBlockchainUris)) {
for (let networkId of requiredNetworkIds) {
let targetProvider;
for (let provider of Object.keys(options.networks)) {
if (
options.networks[provider].network_id == networkId &&
options.networks[provider].provider
) {
targetProvider = pluckProviderFromConfig(options);
if (options.networks[provider].network_id == networkId) {
// handle ganache provider from tests
if (
options.networks[provider].provider.constructor.name == "Function"
) {
targetProvider = options.networks[provider].provider();
} else {
targetProvider = options.networks[provider].provider;
}
}
}

if (!targetProvider) {
throw new TruffleError(
`Missing provider for network id: ${networkId}. Please make sure there is an available provider in your truffle-config`
);
}

const blockchainUri = await getBlockchainUriForProvider(targetProvider);
detectedNetworkIdsToBlockchainUris[networkId] = blockchainUri;
}

// replace network ids with blockchain uri in detected artifacts
for (let artifactPath of Object.keys(detectedArtifacts)) {
var artifactDeployments = detectedArtifacts[artifactPath].networks;
if (Object.keys(artifactDeployments).length > 0) {
Object.keys(artifactDeployments).forEach(id => {
var matchingUri = detectedNetworkIdsToBlockchainUris[id];
artifactDeployments[matchingUri] = artifactDeployments[id];
delete artifactDeployments[id];
});
detectedArtifacts[artifactPath].networks = artifactDeployments;
}
var updatedDeployments = {};
Object.keys(artifactDeployments).forEach(id => {
var matchingUri = detectedNetworkIdsToBlockchainUris[id];
updatedDeployments[matchingUri] = artifactDeployments[id];
});
detectedArtifacts[artifactPath].networks = updatedDeployments;
}

const normalizedArtifacts = Object.keys(detectedArtifacts).map(
Expand Down Expand Up @@ -270,13 +277,25 @@ function pluckProviderFromConfig(config) {
}
}

async function displayRegistryPermissions(options, ethpm) {
try {
const owner = await ethpm.registries.registry.methods.owner().call();
options.logger.log(`Registry controlled by account: ${owner}`);
} catch (err) {
options.logger.log(
`This registry does not appear to have permissioned releases. This means that anybody can publish a package to this registry. Please be very careful before installing and interacting with packages on this registry.`
);
}
}

module.exports = {
getPublishableArtifacts,
resolveEthpmUri,
resolveEnsName,
convertContractTypeToContractSchema,
displayRegistryPermissions,
getPublishableArtifacts,
fetchInstalledBuildDependencies,
pluckProviderFromConfig,
resolveEthpmUri,
resolveEnsName,
SUPPORTED_CHAIN_IDS,
SUPPORTED_GENESIS_BLOCKS
};
13 changes: 7 additions & 6 deletions packages/ethpm-v3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
],
"homepage": "http://www.ethpm.com",
"license": "MIT",
"main": "lib/ethpm-v3.js",
"main": "./lib/ethpm-v3.js",
"scripts": {
"test": "mocha ./tests/* --timeout 10000 --exit"
},
"dependencies": {
"ethpm": "0.1.0-next.26",
"ethpm-spec": "3.0.0",
"ethereum-ens": "0.8.0",
"semver": "7.3.2"
"@truffle/error": "^0.0.10",
"ethpm": "0.1.0-next.30",
"ethpm-spec": "^3.0.0",
"ethereum-ens": "^0.8.0",
"semver": "^7.3.2"
},
"devDependencies": {
"mocha": "8.0.1"
"mocha": "^8.0.1"
},
"directories": {
"lib": "lib",
Expand Down
Loading

0 comments on commit eab09a8

Please sign in to comment.