From 2c075b5d61783f6e2d8544fa86ca9a94eaebc1ee Mon Sep 17 00:00:00 2001 From: Piper Merriam Date: Fri, 3 Feb 2017 14:18:09 -0700 Subject: [PATCH] Dogfood the package index --- .gitignore | 1 + contracts/IndexedOrderedSetLib.sol | 91 ------ contracts/PackageDB.sol | 9 +- contracts/PackageIndex.sol | 17 +- contracts/PackageIndexInterface.sol | 7 +- contracts/ReleaseDB.sol | 11 +- contracts/SemVersionLib.sol | 292 ------------------- ethpm.json | 6 + populus.json | 203 ++++++++++++- scripts/deploy.py | 60 ++-- tests/conftest.py | 30 +- tests/package-index/test_getting_releases.py | 3 +- 12 files changed, 269 insertions(+), 461 deletions(-) delete mode 100644 contracts/IndexedOrderedSetLib.sol delete mode 100644 contracts/SemVersionLib.sol create mode 100644 ethpm.json diff --git a/.gitignore b/.gitignore index d25def0..ea925a0 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ chains/ *.sqlite .env public/ +installed_packages/ diff --git a/contracts/IndexedOrderedSetLib.sol b/contracts/IndexedOrderedSetLib.sol deleted file mode 100644 index b0219ed..0000000 --- a/contracts/IndexedOrderedSetLib.sol +++ /dev/null @@ -1,91 +0,0 @@ -pragma solidity ^0.4.0; - -/// @title Library implementing an array type which allows O(1) lookups on values. -/// @author Piper Merriam -library IndexedOrderedSetLib { - struct IndexedOrderedSet { - bytes32[] _values; - mapping (bytes32 => uint) _valueIndices; - mapping (bytes32 => bool) _exists; - } - - modifier requireValue(IndexedOrderedSet storage self, bytes32 value) { - if (contains(self, value)) { - _; - } else { - throw; - } - } - - /// @dev Returns the size of the set - /// @param self The set - function size(IndexedOrderedSet storage self) constant returns (uint) { - return self._values.length; - } - - /// @dev Returns boolean if the key is in the set - /// @param self The set - /// @param value The value to check - function contains(IndexedOrderedSet storage self, bytes32 value) constant returns (bool) { - return self._exists[value]; - } - - /// @dev Returns the index of the value in the set. - /// @param self The set - /// @param value The value to look up the index for. - function indexOf(IndexedOrderedSet storage self, bytes32 value) requireValue(self, value) - constant - returns (uint) { - return self._valueIndices[value]; - } - - /// @dev Removes the element at index idx from the set and returns it. - /// @param self The set - /// @param idx The index to remove and return. - function pop(IndexedOrderedSet storage self, uint idx) public returns (bytes32) { - bytes32 value = get(self, idx); - - if (idx != self._values.length - 1) { - bytes32 movedValue = self._values[self._values.length - 1]; - self._values[idx] = movedValue; - self._valueIndices[movedValue] = idx; - } - self._values.length -= 1; - - delete self._valueIndices[value]; - delete self._exists[value]; - - return value; - } - - /// @dev Removes the element at index idx from the set - /// @param self The set - /// @param value The value to remove from the set. - function remove(IndexedOrderedSet storage self, bytes32 value) requireValue(self, value) - public - returns (bool) { - uint idx = indexOf(self, value); - pop(self, idx); - return true; - } - - /// @dev Retrieves the element at the provided index. - /// @param self The set - /// @param idx The index to retrieve. - function get(IndexedOrderedSet storage self, uint idx) public returns (bytes32) { - return self._values[idx]; - } - - /// @dev Pushes the new value onto the set - /// @param self The set - /// @param value The value to push. - function add(IndexedOrderedSet storage self, bytes32 value) public returns (bool) { - if (contains(self, value)) return true; - - self._valueIndices[value] = self._values.length; - self._values.push(value); - self._exists[value] = true; - - return true; - } -} diff --git a/contracts/PackageDB.sol b/contracts/PackageDB.sol index e923fb8..ef5f28a 100644 --- a/contracts/PackageDB.sol +++ b/contracts/PackageDB.sol @@ -1,15 +1,14 @@ pragma solidity ^0.4.0; -import {SemVersionLib} from "./SemVersionLib.sol"; -import {IndexedOrderedSetLib} from "./IndexedOrderedSetLib.sol"; +import {IndexedEnumerableSetLib} from "indexed-enumerable-set-lib/contracts/IndexedEnumerableSetLib.sol"; + import {Authorized} from "./Authority.sol"; /// @title Database contract for a package index package data. /// @author Tim Coulter , Piper Merriam contract PackageDB is Authorized { - using SemVersionLib for SemVersionLib.SemVersion; - using IndexedOrderedSetLib for IndexedOrderedSetLib.IndexedOrderedSet; + using IndexedEnumerableSetLib for IndexedEnumerableSetLib.IndexedEnumerableSet; struct Package { bool exists; @@ -21,7 +20,7 @@ contract PackageDB is Authorized { // Package Data: (nameHash => value) mapping (bytes32 => Package) _recordedPackages; - IndexedOrderedSetLib.IndexedOrderedSet _allPackageNameHashes; + IndexedEnumerableSetLib.IndexedEnumerableSet _allPackageNameHashes; // Events event PackageReleaseAdd(bytes32 indexed nameHash, bytes32 indexed releaseHash); diff --git a/contracts/PackageIndex.sol b/contracts/PackageIndex.sol index d9c06ee..eac804f 100644 --- a/contracts/PackageIndex.sol +++ b/contracts/PackageIndex.sol @@ -207,21 +207,24 @@ contract PackageIndex is Authorized, PackageIndexInterface { /// @dev Returns the release data for the release associated with the given release hash. /// @param releaseHash The release hash. - function getReleaseData(bytes32 releaseHash) constant returns (uint32 major, - uint32 minor, - uint32 patch, + function getReleaseData(bytes32 releaseHash) constant returns (string packageName, + uint32, + uint32, + uint32, string preRelease, string build, string releaseLockfileURI, uint createdAt, uint updatedAt) { - bytes32 versionHash; - (,versionHash, createdAt, updatedAt) = releaseDb.getReleaseData(releaseHash); - (major, minor, patch) = releaseDb.getMajorMinorPatch(versionHash); + bytes32[2] memory hashes; + uint32[3] memory versionNumbers; + (hashes[0] ,hashes[1], createdAt, updatedAt) = releaseDb.getReleaseData(releaseHash); + (versionNumbers[0], versionNumbers[1], versionNumbers[2]) = releaseDb.getMajorMinorPatch(hashes[1]); + packageName = getPackageName(hashes[0]); preRelease = getPreRelease(releaseHash); build = getBuild(releaseHash); releaseLockfileURI = getReleaseLockfileURI(releaseHash); - return (major, minor, patch, preRelease, build, releaseLockfileURI, createdAt, updatedAt); + return (packageName, versionNumbers[0], versionNumbers[1], versionNumbers[2], preRelease, build, releaseLockfileURI, createdAt, updatedAt); } /// @dev Returns the release hash at the provide index in the array of all release hashes. diff --git a/contracts/PackageIndexInterface.sol b/contracts/PackageIndexInterface.sol index 80f83b3..865e7ae 100644 --- a/contracts/PackageIndexInterface.sol +++ b/contracts/PackageIndexInterface.sol @@ -107,9 +107,10 @@ contract PackageIndexInterface is AuthorizedInterface { /// @dev Returns the release data for the release associated with the given release hash. /// @param releaseHash The release hash. - function getReleaseData(bytes32 releaseHash) constant returns (uint32 major, - uint32 minor, - uint32 patch, + function getReleaseData(bytes32 releaseHash) constant returns (string packageName, + uint32, + uint32, + uint32, string preRelease, string build, string releaseLockfileURI, diff --git a/contracts/ReleaseDB.sol b/contracts/ReleaseDB.sol index 203cb10..73b8259 100644 --- a/contracts/ReleaseDB.sol +++ b/contracts/ReleaseDB.sol @@ -1,7 +1,8 @@ pragma solidity ^0.4.0; -import {SemVersionLib} from "./SemVersionLib.sol"; -import {IndexedOrderedSetLib} from "./IndexedOrderedSetLib.sol"; +import {SemVersionLib} from "sem-version-lib/contracts/SemVersionLib.sol"; +import {IndexedEnumerableSetLib} from "indexed-enumerable-set-lib/contracts/IndexedEnumerableSetLib.sol"; + import {Authorized} from "./Authority.sol"; @@ -9,7 +10,7 @@ import {Authorized} from "./Authority.sol"; /// @author Tim Coulter , Piper Merriam contract ReleaseDB is Authorized { using SemVersionLib for SemVersionLib.SemVersion; - using IndexedOrderedSetLib for IndexedOrderedSetLib.IndexedOrderedSet; + using IndexedEnumerableSetLib for IndexedEnumerableSetLib.IndexedEnumerableSet; struct Release { bool exists; @@ -22,8 +23,8 @@ contract ReleaseDB is Authorized { // Release Data: (releaseHash => value) mapping (bytes32 => Release) _recordedReleases; - IndexedOrderedSetLib.IndexedOrderedSet _allReleaseHashes; - mapping (bytes32 => IndexedOrderedSetLib.IndexedOrderedSet) _releaseHashesByNameHash; + IndexedEnumerableSetLib.IndexedEnumerableSet _allReleaseHashes; + mapping (bytes32 => IndexedEnumerableSetLib.IndexedEnumerableSet) _releaseHashesByNameHash; // Version Data: (versionHash => value) mapping (bytes32 => SemVersionLib.SemVersion) _recordedVersions; diff --git a/contracts/SemVersionLib.sol b/contracts/SemVersionLib.sol deleted file mode 100644 index 5c4c267..0000000 --- a/contracts/SemVersionLib.sol +++ /dev/null @@ -1,292 +0,0 @@ -pragma solidity ^0.4.0; - -/// @title Library which implements a semver datatype and comparisons. -/// @author Piper Merriam -library SemVersionLib { - struct SemVersion { - bytes32 hash; - uint32 major; - uint32 minor; - uint32 patch; - string preRelease; - string build; - string[] preReleaseIdentifiers; - } - - enum Comparison { - Before, - Same, - After - } - - /// @dev Initialize a SemVersion struct - /// @param self The SemVersion object to initialize. - /// @param major The major portion of the semver version string. - /// @param minor The minor portion of the semver version string. - /// @param patch The patch portion of the semver version string. - /// @param preRelease The pre-release portion of the semver version string. Use empty string if the version string has no pre-release portion. - /// @param build The build portion of the semver version string. Use empty string if the version string has no build portion. - function init(SemVersion storage self, - uint32 major, - uint32 minor, - uint32 patch, - string preRelease, - string build) public returns (bool) { - self.major = major; - self.minor = minor; - self.patch = patch; - self.preRelease = preRelease; - self.preReleaseIdentifiers = splitIdentifiers(preRelease); - self.build = build; - self.hash = sha3(major, minor, patch, preRelease); - return true; - } - - // - // Storage Operations - // - /// @dev Return boolean indicating if the two SemVersion objects are considered equal - /// @param self The first SemVersion - /// @param other The second SemVersion - function isEqual(SemVersion storage self, SemVersion storage other) public returns (bool) { - return self.hash == other.hash; - } - - /// @dev Return boolean indicating if the first SemVersion object is considered strictly greater than the second. - /// @param self The first SemVersion - /// @param other The second SemVersion - function isGreater(SemVersion storage self, SemVersion storage other) public returns (bool) { - if (self.hash == other.hash) { - return false; - } else if (self.major > other.major) { - return true; - } else if (self.major < other.major) { - return false; - } else if (self.minor > other.minor) { - return true; - } else if (self.minor < other.minor) { - return false; - } else if (self.patch > other.patch) { - return true; - } else if (self.patch < other.patch) { - return false; - } else if (!isPreRelease(self) && isPreRelease(other)) { - return true; - } else if (isPreRelease(self) && !isPreRelease(other)) { - return false; - } else if (isPreReleaseGreater(self, other)) { - return true; - } else { - return false; - } - } - - /// @dev Return boolean indicating if the first SemVersion object is considered greater than or equal to the second. - /// @param self The first SemVersion - /// @param other The second SemVersion - function isGreaterOrEqual(SemVersion storage self, SemVersion storage other) public returns (bool) { - return isEqual(self, other) || isGreater(self, other); - } - - /* - * PreRelease comparisons - */ - /// @dev Return boolean indicating if the pre-release string from the first SemVersion object is considered greater than the pre-release string from the second SemVersion object. - /// @param left The first SemVersion - /// @param right The second SemVersion - function isPreReleaseGreater(SemVersion storage left, SemVersion storage right) internal returns (bool) { - return comparePreReleases(left, right) == Comparison.After; - } - - /// @dev Return boolean indicating if the provided SemVersion is a pre-release. - /// @param self The SemVersion - function isPreRelease(SemVersion storage self) internal returns (bool) { - return self.preReleaseIdentifiers.length > 0; - } - - /// @dev Return a comparison of the pre-release strings for the two provided SemVersion objects. - /// @param left The first SemVersion - /// @param right The second SemVersion - function comparePreReleases(SemVersion storage left, SemVersion storage right) internal returns (Comparison comparisonResult) { - uint minLength = min(left.preReleaseIdentifiers.length, - right.preReleaseIdentifiers.length); - for (uint i = 0; i < minLength; i++) { - if (isNumericString(left.preReleaseIdentifiers[i]) && isNumericString(right.preReleaseIdentifiers[i])) { - comparisonResult = compareNumericStrings(left.preReleaseIdentifiers[i], right.preReleaseIdentifiers[i]); - } else { - comparisonResult = compareStrings(left.preReleaseIdentifiers[i], right.preReleaseIdentifiers[i]); - } - - if (comparisonResult != Comparison.Same) { - return comparisonResult; - } - continue; - } - - if (left.preReleaseIdentifiers.length < right.preReleaseIdentifiers.length) { - return Comparison.Before; - } else if (left.preReleaseIdentifiers.length > right.preReleaseIdentifiers.length) { - return Comparison.After; - } else { - return Comparison.Same; - } - } - - // - // PreRelease String Utils - // - /// @dev Return a comparison based on the ASCII ordering of the two strings - /// @param left The first string - /// @param right The second string - function compareStrings(string left, string right) internal returns (Comparison) { - for (uint i = 0; i < min(bytes(left).length, bytes(right).length); i++) { - if (bytes(left)[i] == bytes(right)[i]) { - continue; - } else if (uint(bytes(left)[i]) < uint(bytes(right)[i])) { - return Comparison.Before; - } else { - return Comparison.After; - } - } - - if (bytes(left).length < bytes(right).length) { - return Comparison.Before; - } else if (bytes(left).length > bytes(right).length) { - return Comparison.After; - } else { - return Comparison.Same; - } - } - - /// @dev Return a comparison based on the integer representation of the two string. - /// @param left The first string - /// @param right The second string - function compareNumericStrings(string left, string right) internal returns (Comparison) { - uint leftAsNumber = castStringToUInt(left); - uint rightAsNumber = castStringToUInt(right); - - if (leftAsNumber < rightAsNumber) { - return Comparison.Before; - } else if (leftAsNumber > rightAsNumber) { - return Comparison.After; - } else { - return Comparison.Same; - } - } - - /// @dev Splits a string on periods. - /// @param preRelease The string to split. - function splitIdentifiers(string preRelease) internal returns (string[]) { - if (bytes(preRelease).length == 0) { - return new string[](0); - } - - uint i; - uint leftBound = 0; - uint numIdentifiers = 1; - - for (i = 0; i < bytes(preRelease).length; i++) { - if (bytes(preRelease)[i] == PERIOD) { - numIdentifiers += 1; - } - } - - string[] memory preReleaseIdentifiers = new string[](numIdentifiers); - - numIdentifiers = 0; - - for (i = 0; i <= bytes(preRelease).length; i++) { - if (i == bytes(preRelease).length || bytes(preRelease)[i] == PERIOD) { - uint identifierLength = i - leftBound; - - bytes memory buffer = new bytes(identifierLength); - for (uint j = 0; j < identifierLength; j++) { - buffer[j] = bytes(preRelease)[j + leftBound]; - } - preReleaseIdentifiers[numIdentifiers] = string(buffer); - leftBound = i + 1; - numIdentifiers += 1; - } - } - return preReleaseIdentifiers; - } - - // - // Math utils - // - /// @dev Returns the minimum of two unsigned integers - /// @param a The first unsigned integer - /// @param b The first unsigned integer - function min(uint a, uint b) internal returns (uint) { - if (a <= b) { - return a; - } else { - return b; - } - } - - // - // Char Utils - // - uint constant DIGIT_0 = uint(bytes1('0')); - uint constant DIGIT_9 = uint(bytes1('9')); - bytes1 constant PERIOD = bytes1('.'); - - /// @dev Returns boolean indicating if the provided character is a numeric digit. - /// @param v The character to check. - function isDigit(bytes1 v) internal returns (bool) { - return (uint(v) >= DIGIT_0 && uint(v) <= DIGIT_9); - } - - // - // String Utils - // - /// @dev Returns boolean indicating if the provided string is all numeric. - /// @param value The string to check. - function isNumericString(string value) internal returns (bool) { - for (uint i = 0; i < bytes(value).length; i++) { - if (!isDigit(bytes(value)[i])) { - return false; - } - } - - return bytes(value).length > 0; - } - - /// @dev Returns the integer representation of a numeric string. - /// @param numericString The string to convert. - function castStringToUInt(string numericString) internal returns (uint) { - uint value = 0; - - for (uint i = 0; i < bytes(numericString).length; i++) { - value *= 10; - value += uint(bytes(numericString)[i]) - 48; - } - - return value; - } - - /// @dev Concatenates the two strings together. - /// @param _head The first string - /// @param tail The second string - function concat(string storage _head, string tail) returns (bool) { - bytes head = bytes(_head); - - for (uint i = 0; i < bytes(tail).length; i++) { - head.push(bytes(tail)[i]); - } - - _head = string(head); - - return true; - } - - /// @dev Concatenates the provided byte to the end of the provided string. - /// @param value The string to append the byte to. - /// @param b The byte. - function concatByte(string storage value, bytes1 b) returns (bool) { - bytes memory _b = new bytes(1); - _b[0] = b; - return concat(value, string(_b)); - } -} diff --git a/ethpm.json b/ethpm.json new file mode 100644 index 0000000..ac5917e --- /dev/null +++ b/ethpm.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "indexed-enumerable-set-lib": "1.0.0", + "sem-version-lib": ">=1.1.0" + } +} \ No newline at end of file diff --git a/populus.json b/populus.json index d21e17d..8c60802 100644 --- a/populus.json +++ b/populus.json @@ -1,24 +1,213 @@ { - "compiler": { + "chains": { + "mainnet-foo": { + "chain": { + "class": "populus.chain.external.ExternalChain" + }, + "contracts": { + "backends": { + "InstalledPackages": { + "$ref": "contracts.backends.InstalledPackages" + }, + "JSONFile": { + "$ref": "contracts.backends.JSONFile" + } + } + }, + "web3": { + "$ref": "web3.Mainnet" + } + }, + "ropsten": { + "chain": { + "class": "populus.chain.external.ExternalChain" + }, + "contracts": { + "backends": { + "InstalledPackages": { + "$ref": "contracts.backends.InstalledPackages" + }, + "JSONFile": { + "$ref": "contracts.backends.JSONFile" + } + } + }, + "web3": { + "$ref": "web3.Ropsten" + } + }, + "temp": { + "chain": { + "class": "populus.chain.geth.TemporaryGethChain" + }, + "contracts": { + "backends": { + "InstalledPackages": { + "$ref": "contracts.backends.InstalledPackages" + }, + "Memory": { + "$ref": "contracts.backends.Memory" + } + } + }, + "web3": { + "$ref": "web3.GethIPC" + } + }, + "tester": { + "chain": { + "class": "populus.chain.tester.TesterChain" + }, + "contracts": { + "backends": { + "InstalledPackages": { + "$ref": "contracts.backends.InstalledPackages" + }, + "Memory": { + "$ref": "contracts.backends.Memory" + } + } + }, + "web3": { + "$ref": "web3.Tester" + } + }, + "testrpc": { + "chain": { + "class": "populus.chain.testrpc.TestRPCChain" + }, + "contracts": { + "backends": { + "InstalledPackages": { + "$ref": "contracts.backends.InstalledPackages" + }, + "Memory": { + "$ref": "contracts.backends.Memory" + } + } + }, + "web3": { + "$ref": "web3.TestRPC" + } + } + }, + "compilation": { + "contracts_dir": "./contracts", "settings": { "optimize": true } }, - "chains": { - "ropsten": { - "chain": { - "class": "populus.chain.ExternalChain" + "contracts": { + "backends": { + "InstalledPackages": { + "class": "populus.contracts.backends.installed_packages.InstalledPackagesBackend", + "priority": 20 + }, + "JSONFile": { + "class": "populus.contracts.backends.filesystem.JSONFileBackend", + "priority": 10, + "settings": { + "file_path": "./registrar.json" + } }, - "web3": {"$ref": "web3.Ropsten"} + "Memory": { + "class": "populus.contracts.backends.memory.MemoryBackend", + "priority": 40 + } } }, + "packaging": { + "backends": { + "IPFSBackend": { + "class": "populus.packages.backends.ipfs.IPFSPackageBackend", + "priority": 30, + "settings": { + "host": "https://ipfs.infura.io", + "port": 5001 + } + }, + "LocalFilesystemLockfileBackend": { + "class": "populus.packages.backends.lockfile.LocalFilesystemLockfileBackend", + "priority": 20 + }, + "LocalManifestBackend": { + "class": "populus.packages.backends.manifest.LocalManifestBackend", + "priority": 10 + }, + "RopstenPackageIndexBackend": { + "class": "populus.packages.backends.index.PackageIndexBackend", + "priority": 40, + "settings": { + "package_index_address": "0x8011df4830b4f696cd81393997e5371b93338878", + "web3-for-install": { + "$ref": "web3.InfuraRopsten" + }, + "web3-for-publish": { + "$ref": "web3.Ropsten" + } + } + } + } + }, + "version": "1", "web3": { + "GethIPC": { + "provider": { + "class": "web3.providers.ipc.IPCProvider" + } + }, + "Mainnet": { + "provider": { + "class": "web3.providers.ipc.IPCProvider", + "settings": { + "ipc_path": "/Users/piper/Library/Ethereum/geth.ipc" + } + }, + "eth": { + "default_account": "0xd3cda913deb6f67967b99d67acdfa1712c293601" + } + }, "Ropsten": { "provider": { "class": "web3.providers.ipc.IPCProvider", "settings": { - "ipc_path": "/Users/piper/Library/Ethereum/ropsten/geth.ipc" + "ipc_path": "/Users/piper/Library/Ethereum/testnet/geth.ipc" } + }, + "eth": { + "default_account": "0xaffa9e11a8deac514b93169c764aa042b4fe316f" + } + }, + "InfuraMainnet": { + "eth": { + "default_account": "0x0000000000000000000000000000000000000001" + }, + "provider": { + "class": "web3.providers.rpc.HTTPProvider", + "settings": { + "endpoint_uri": "https://mainnet.infura.io" + } + } + }, + "InfuraRopsten": { + "eth": { + "default_account": "0x0000000000000000000000000000000000000001" + }, + "provider": { + "class": "web3.providers.rpc.HTTPProvider", + "settings": { + "endpoint_uri": "https://ropsten.infura.io" + } + } + }, + "TestRPC": { + "provider": { + "class": "web3.providers.tester.TestRPCProvider" + } + }, + "Tester": { + "provider": { + "class": "web3.providers.tester.EthereumTesterProvider" } } } diff --git a/scripts/deploy.py b/scripts/deploy.py index a805de4..2da9b1e 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -31,9 +31,9 @@ def verify_bytecode(web3, ContractFactory, contract_address): raise click.ClickException("Error deploying contract") -def deploy_contract(chain, contract_name, **kwargs): +def deploy_contract(chain, contract_name): click.echo("Loading {0} contract... ".format(contract_name), nl=False) - ContractFactory = chain.get_contract_factory(contract_name, **kwargs) + ContractFactory = chain.store.provider.get_contract_factory(contract_name) click.echo("LOADED") click.echo("Sending deploy transaction for {0} contract... ".format(contract_name), nl=False) @@ -244,58 +244,40 @@ def set_release_validator_address_on_package_index(chain, package_index, release 'authority_address', '--authority', '-a', - default='0x06658b994d95d1e8432192b9e3c0b2dbce6fe66f', -) -@click.option( - 'sem_version_lib_address', - '--sem-version-lib', - '-s', - default='0xd49cce0631b148a61e562f32ef53605cebd593cb', -) -@click.option( - 'indexed_ordered_set_lib_address', - '--indexed-ordered-set-lib', - '-o', - default='0x0a038b2b9b1be306aee706aabd9d402cb66eb02f', + #default='0x06658b994d95d1e8432192b9e3c0b2dbce6fe66f', ) @click.option( 'package_db_address', '--package-db', '-d', - default='0x489d3a2c3b0f392fa780ab76a17f1586fd19e77c', + #default='0x489d3a2c3b0f392fa780ab76a17f1586fd19e77c', ) @click.option( 'release_db_address', '--release-db', '-r', - default='0x666495528e96a6fc3bb809151d3a73f1cf2585f9', + #default='0x666495528e96a6fc3bb809151d3a73f1cf2585f9', ) @click.option( 'release_validator_address', '--release-validator', '-v', - default='0x5b745832e56ab7b97990890161b43db4ce0aa6cc', + #default='0x5b745832e56ab7b97990890161b43db4ce0aa6cc', ) @click.option( 'package_index_address', '--package-index', '-i', - default='0x8011df4830b4f696cd81393997e5371b93338878', + #default='0x8011df4830b4f696cd81393997e5371b93338878', ) def deploy(chain_name, authority_address, - indexed_ordered_set_lib_address, - sem_version_lib_address, package_db_address, release_db_address, release_validator_address, package_index_address): """ #. Deploy WhitelistAuthority - #. Deploy Libraries: - - EnumerableMappingLib - - SemVersionLib - - IndexedOrderedSetLib #. Deploy PackageDB - set Authority #. Deploy ReleaseDB @@ -335,38 +317,30 @@ def deploy(chain_name, else: release_validator = deploy_contract(chain, 'ReleaseValidator') - if sem_version_lib_address: - sem_version_lib = chain.contract_factories.SemVersionLib( - address=sem_version_lib_address, + if not chain.store.provider.is_contract_available('SemVersionLib'): + raise ValueError( + "SemVersionLib not available and it should be. Have project " + "packages been installed?" ) - else: - sem_version_lib = deploy_contract(chain, 'SemVersionLib') - - if indexed_ordered_set_lib_address: - indexed_ordered_set_lib = chain.contract_factories.IndexedOrderedSetLib( - address=indexed_ordered_set_lib_address, + if not chain.store.provider.is_contract_available('IndexedEnumerableSetLib'): + raise ValueError( + "IndexedEnumerableSetLib not available and it should be. Have project " + "packages been installed?" ) - else: - indexed_ordered_set_lib = deploy_contract(chain, 'IndexedOrderedSetLib') - - link_dependencies = { - 'SemVersionLib': sem_version_lib.address, - 'IndexedOrderedSetLib': indexed_ordered_set_lib.address, - } if package_db_address: package_db = chain.contract_factories.PackageDB( address=package_db_address, ) else: - package_db = deploy_contract(chain, 'PackageDB', link_dependencies=link_dependencies) + package_db = deploy_contract(chain, 'PackageDB') if release_db_address: release_db = chain.contract_factories.ReleaseDB( address=release_db_address, ) else: - release_db = deploy_contract(chain, 'ReleaseDB', link_dependencies=link_dependencies) + release_db = deploy_contract(chain, 'ReleaseDB') if package_index_address: package_index = chain.contract_factories.PackageIndex(address=package_index_address) diff --git a/tests/conftest.py b/tests/conftest.py index 427ea62..7f4ad05 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,7 +9,7 @@ @pytest.fixture() def authority(chain, accounts): authority_owner = accounts[5] - _authority = chain.get_contract( + _authority, _ = chain.store.provider.get_or_deploy_contract( 'WhitelistAuthority', deploy_transaction={'from': authority_owner}, ) @@ -56,9 +56,25 @@ def _whitelist_call(code_address, function_signature, can_call): return _whitelist_call +@pytest.fixture() +def sem_version_lib(chain): + _sem_version_lib, _ = chain.store.provider.get_or_deploy_contract( + 'SemVersionLib', + ) + return _sem_version_lib + + +@pytest.fixture() +def indexed_enumerable_set_lib(chain): + _indexed_enumerable_set_lib, _ = chain.store.provider.get_or_deploy_contract( + 'IndexedEnumerableSetLib', + ) + return _indexed_enumerable_set_lib + + @pytest.fixture() def package_db(chain, authority): - _package_db = chain.get_contract( + _package_db, _ = chain.store.provider.get_or_deploy_contract( 'PackageDB', deploy_transaction={'from': authority.call().owner()}, ) @@ -70,8 +86,8 @@ def package_db(chain, authority): @pytest.fixture() -def release_db(chain, authority): - _release_db = chain.get_contract( +def release_db(chain, authority, sem_version_lib, indexed_enumerable_set_lib): + _release_db, _ = chain.store.provider.get_or_deploy_contract( 'ReleaseDB', deploy_transaction={'from': authority.call().owner()}, ) @@ -84,7 +100,7 @@ def release_db(chain, authority): @pytest.fixture() def release_validator(chain, authority): - _release_validator = chain.get_contract( + _release_validator, _ = chain.store.provider.get_or_deploy_contract( 'ReleaseValidator', deploy_transaction={'from': authority.call().owner()}, ) @@ -99,7 +115,7 @@ def package_index(chain, release_validator, authorize_call, whitelist_call): - _package_index = chain.get_contract( + _package_index, _ = chain.store.provider.get_or_deploy_contract( 'PackageIndex', deploy_transaction={'from': authority.call().owner()}, ) @@ -203,7 +219,7 @@ def topics_to_abi(project): event_abi_to_log_topic, ) all_events_abi = filter_by_type('event', itertools.chain.from_iterable( - contract['abi'] for contract in project.compiled_contracts.values() + contract['abi'] for contract in project.compiled_contract_data.values() )) _topic_to_abi = { event_abi_to_log_topic(abi): abi diff --git a/tests/package-index/test_getting_releases.py b/tests/package-index/test_getting_releases.py index c52c3ea..994ffc7 100644 --- a/tests/package-index/test_getting_releases.py +++ b/tests/package-index/test_getting_releases.py @@ -17,12 +17,13 @@ def _assert_release(web3, release_data): timestamp = web3.eth.getBlock(release_receipt['blockHash'])['timestamp'] name_hash = package_db.call().hashName(name) + package_name = package_db.call().getPackageName(name_hash) version_hash = release_db.call().hashVersion(major, minor, patch, pre_release, build) release_hash = release_db.call().hashRelease(name_hash, version_hash) assert package_index.call().releaseExists(name, major, minor, patch, pre_release, build) assert release_hash in package_index.call().getAllPackageReleaseHashes(name) - assert release_data == [major, minor, patch, pre_release, build, lockfile_uri, timestamp, timestamp] + assert release_data == [package_name, major, minor, patch, pre_release, build, lockfile_uri, timestamp, timestamp] @pytest.fixture