Skip to content

Commit 6ada120

Browse files
committed
renamed getSources to get, added contract version and name to the return parameters
1 parent fe0a547 commit 6ada120

17 files changed

+104
-58
lines changed

.changeset/eleven-falcons-study.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@peeramid-labs/eds": minor
3+
---
4+
5+
renamed getSources to get, added contract version and name to the return parameters

src/abstracts/CloneDistribution.sol

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import "../interfaces/IDistribution.sol";
66
import "./CodeIndexer.sol";
77

88
abstract contract CloneDistribution is IDistribution, CodeIndexer {
9-
function sources() internal view virtual returns (address[] memory);
9+
10+
11+
function sources() internal view virtual returns (address[] memory, bytes32 name, uint256 version);
1012

1113
function instantiate() public virtual returns (address[] memory instances) {
12-
address[] memory _sources = sources();
14+
(address[] memory _sources,,) = sources();
1315
instances = new address[](_sources.length);
1416
for (uint256 i = 0; i < _sources.length; i++) {
1517
address clone = Clones.clone(_sources[i]);
@@ -19,7 +21,7 @@ abstract contract CloneDistribution is IDistribution, CodeIndexer {
1921
return instances;
2022
}
2123

22-
function getSources() public view virtual returns (address[] memory) {
24+
function get() public view virtual returns (address[] memory src, bytes32 name, uint256 version) {
2325
return sources();
2426
}
2527

src/abstracts/Repository.sol

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import "../libraries/LibSemver.sol";
55
import "../interfaces/IRepository.sol";
66

77
abstract contract Repository is IRepository {
8+
9+
bytes32 immutable public repositoryName;
810
struct Uint64WithMetadata {
911
uint64 value;
1012
bytes metadata;
@@ -24,6 +26,9 @@ abstract contract Repository is IRepository {
2426
uint64 internal majorReleases;
2527
uint256 internal latestVersion;
2628

29+
constructor(bytes32 _repositoryName) {
30+
repositoryName = _repositoryName;
31+
}
2732
// error VersionHashDoesNotExist(uint256 version);
2833
// error ReleaseZeroNotAllowed();
2934
// error AlreadyInPreviousRelease(uint256 version, bytes32 source);

src/distributions/CodeHashDistribution.sol

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import "../abstracts/CloneDistribution.sol";
66
contract CodeHashDistribution is CloneDistribution {
77
bytes32 immutable metadata;
88
address immutable _reference;
9+
bytes32 immutable public distributionName;
10+
uint256 immutable public distributionVersion;
911

10-
constructor(bytes32 codeHash, bytes32 _metadata) {
12+
constructor(bytes32 codeHash, bytes32 _metadata, bytes32 name, uint256 version) {
13+
distributionName = name;
14+
distributionVersion = version;
1115
metadata = _metadata;
1216
ICodeIndex index = getContractsIndex();
1317
_reference = index.get(codeHash);
@@ -16,10 +20,10 @@ contract CodeHashDistribution is CloneDistribution {
1620
}
1721
}
1822

19-
function sources() internal view virtual override returns (address[] memory) {
23+
function sources() internal view virtual override returns (address[] memory, bytes32 name, uint256 version) {
2024
address[] memory _sources = new address[](1);
2125
_sources[0] = _reference;
22-
return _sources;
26+
return (_sources, distributionName, distributionVersion);
2327
}
2428

2529
function getMetadata() public view virtual override returns (string memory) {

src/distributions/LatestVersionDistribution.sol

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pragma solidity =0.8.20;
33

44
import "../abstracts/CloneDistribution.sol";
55
import "../interfaces/IRepository.sol";
6+
import "../libraries/LibSemver.sol";
67

78
contract LatestVersionDistribution is CloneDistribution {
89
bytes32 immutable metadata;
@@ -13,11 +14,11 @@ contract LatestVersionDistribution is CloneDistribution {
1314
repository = _repository;
1415
}
1516

16-
function sources() internal view virtual override returns (address[] memory) {
17+
function sources() internal view virtual override returns (address[] memory srcs, bytes32 name, uint256 version) {
1718
address[] memory _sources = new address[](1);
18-
19-
_sources[0] = getContractsIndex().get(repository.getLatest().sourceId);
20-
return _sources;
19+
IRepository.Source memory latest = repository.getLatest();
20+
_sources[0] = getContractsIndex().get(latest.sourceId);
21+
return (_sources, repository.repositoryName(),LibSemver.toUint256(latest.version));
2122
}
2223

2324
function getMetadata() public view virtual override returns (string memory) {

src/interfaces/IDistribution.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface IDistribution {
66

77
function instantiate() external returns (address[] memory instances);
88

9-
function getSources() external view returns (address[] memory);
9+
function get() external view returns (address[] memory sources, bytes32 distributionName, uint256 distributionVersion);
1010

1111
function getMetadata() external view returns (string memory);
1212
}

src/interfaces/IInitializer.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ interface IInitializer {
55
event Initialized(address indexed container, bytes32 indexed codeHash);
66
error initializationFailed(bytes32 id, string reason);
77

8-
function initialize(bytes32 id, address[] memory instances, bytes calldata args) external;
8+
function initialize(bytes32 distributionId, address[] memory instances, string memory distributionName, string memory distributionVersion, bytes calldata args) external;
99
}

src/interfaces/IRepository.sol

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ interface IRepository is IERC165 {
2020
event ReleaseMetadataUpdated(uint256 indexed version, bytes releaseMetadata);
2121

2222
function updateReleaseMetadata(LibSemver.Version memory version, bytes calldata releaseMetadata) external;
23+
function repositoryName() external view returns (bytes32);
2324
function newRelease(bytes32 sourceId, bytes memory metadata, LibSemver.Version memory version) external;
2425
function getLatest() external view returns (Source memory);
2526
function get(

src/mocks/MockCloneDistribution.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ contract MockCloneDistribution is CloneDistribution {
88
return "MockCloneDistribution";
99
}
1010

11-
function sources() internal view override returns (address[] memory) {
11+
function sources() internal view override returns (address[] memory, bytes32, uint256) {
1212
address[] memory source = new address[](1);
1313
source[0] = address(this);
14-
return source;
14+
return (source, bytes32(abi.encodePacked("MockCloneDistribution")), 1);
1515
}
1616
}

src/repositories/OwnableRepository.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "../abstracts/Repository.sol";
55
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
66
import "../interfaces/IRepository.sol";
77
contract OwnableRepository is Repository, Ownable, ERC165 {
8-
constructor(address owner) Ownable(owner) {}
8+
constructor(address owner, bytes32 name) Ownable(owner) Repository(name) {}
99

1010
function updateReleaseMetadata(LibSemver.Version memory version, bytes calldata releaseMetadata) public onlyOwner {
1111
super._updateReleaseMetadata(version, releaseMetadata);

test/eds/CloneDistribution.ts

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
1-
import { ethers } from 'hardhat';
2-
import { Signer } from 'ethers';
3-
import { expect } from 'chai';
1+
import { ethers } from "hardhat";
2+
import { Signer } from "ethers";
3+
import { expect } from "chai";
44

5-
describe('CloneDistribution', function () {
5+
describe("CloneDistribution", function () {
66
let cloneDistribution: any;
77
let owner: Signer;
88
let addr1: Signer;
99
let addr2: Signer;
1010

1111
beforeEach(async function () {
12-
const CloneDistribution = await ethers.getContractFactory('MockCloneDistribution');
12+
const CloneDistribution = await ethers.getContractFactory(
13+
"MockCloneDistribution"
14+
);
1315
[owner, addr1, addr2] = await ethers.getSigners();
1416
cloneDistribution = await CloneDistribution.deploy();
1517
await cloneDistribution.deployed();
1618
});
1719

18-
it('should emit Distributed event', async function () {
19-
expect(await cloneDistribution.instantiate()).to.emit(cloneDistribution, 'Distributed');
20+
it("should emit Distributed event", async function () {
21+
expect(await cloneDistribution.instantiate()).to.emit(
22+
cloneDistribution,
23+
"Distributed"
24+
);
2025
});
2126

22-
it('Should read metadata', async function () {
27+
it("Should read metadata", async function () {
2328
const metadata = await cloneDistribution.getMetadata();
24-
expect(metadata).to.equal('MockCloneDistribution');
29+
expect(metadata).to.equal("MockCloneDistribution");
30+
});
31+
32+
it("returns contract name and version", async function () {
33+
const { name, version } = await cloneDistribution.get();
34+
expect(ethers.utils.parseBytes32String(name)).to.be.equal(
35+
"MockCloneDistribution"
36+
);
37+
expect(version).to.be.equal(1);
2538
});
2639
});

test/eds/CodeHashDistribution.ts

+29-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { ethers } from "hardhat";
2-
import { Signer } from "ethers";
32
import { expect } from "chai";
43
import {
54
CodeHashDistribution,
65
CodeHashDistribution__factory,
76
CodeIndex,
87
} from "../../types";
9-
import hre, { deployments } from "hardhat";
8+
import { deployments } from "hardhat";
109
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
1110
import utils from "../utils";
1211

@@ -36,7 +35,9 @@ describe("CloneHashDistribution", function () {
3635
const codeHash = ethers.utils.keccak256(code);
3736
const codeHashDistribution = (await CodeHashDistribution.deploy(
3837
codeHash,
39-
ethers.utils.formatBytes32String("DiamondProxy")
38+
ethers.utils.formatBytes32String("DiamondProxy"),
39+
ethers.utils.formatBytes32String("testDistribution"),
40+
0
4041
)) as CodeHashDistribution;
4142
expect(await codeHashDistribution.instantiate()).to.emit(
4243
codeHashDistribution,
@@ -54,7 +55,9 @@ describe("CloneHashDistribution", function () {
5455
const codeHash = ethers.utils.keccak256(code);
5556
const codeHashDistribution = (await CodeHashDistribution.deploy(
5657
codeHash,
57-
ethers.utils.formatBytes32String("DiamondProxy")
58+
ethers.utils.formatBytes32String("DiamondProxy"),
59+
ethers.utils.formatBytes32String("testDistribution"),
60+
0
5861
)) as CodeHashDistribution;
5962
const receipt = await (await codeHashDistribution.instantiate()).wait();
6063

@@ -70,4 +73,26 @@ describe("CloneHashDistribution", function () {
7073
testFacet.address.slice(2).toLowerCase()
7174
);
7275
});
76+
it("returns contract name and version", async function () {
77+
const TestFacet = await ethers.getContractFactory("TestFacet");
78+
const testFacet = await TestFacet.deploy();
79+
codeIndex.register(testFacet.address);
80+
const CodeHashDistribution = (await ethers.getContractFactory(
81+
"CodeHashDistribution"
82+
)) as CodeHashDistribution__factory;
83+
const code = await testFacet.provider.getCode(testFacet.address);
84+
const codeHash = ethers.utils.keccak256(code);
85+
const codeHashDistribution = (await CodeHashDistribution.deploy(
86+
codeHash,
87+
ethers.utils.formatBytes32String("DiamondProxy"),
88+
ethers.utils.formatBytes32String("testDistribution"),
89+
0
90+
)) as CodeHashDistribution;
91+
92+
const { src, name, version } = await codeHashDistribution.get();
93+
expect(ethers.utils.parseBytes32String(name)).to.be.equal(
94+
"testDistribution"
95+
);
96+
expect(version).to.be.equal(0);
97+
});
7398
});

test/eds/CodeIndex.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ethers } from "hardhat";
2-
import { Signer } from "ethers";
32
import { expect } from "chai";
43
import { CodeIndex, TestFacet } from "../../types";
54
import hre, { deployments } from "hardhat";

test/eds/Distributor.ts

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import { ethers } from "hardhat";
2-
import { Signer } from "ethers";
32
import { expect } from "chai";
43
import {
5-
CodeHashDistribution,
6-
CodeHashDistribution__factory,
7-
CodeIndex,
8-
Distributor,
9-
Distributor__factory,
10-
MockCloneDistribution__factory,
11-
OwnableDistributor__factory,
12-
TestFacet,
13-
TestFacet__factory,
4+
CodeIndex,
5+
Distributor, MockCloneDistribution__factory,
6+
OwnableDistributor__factory, TestFacet__factory
147
} from "../../types";
15-
import hre, { deployments } from "hardhat";
8+
import { deployments } from "hardhat";
169
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
1710
import utils from "../utils";
1811

test/eds/Installer.ts

+8-16
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
import { ethers } from "hardhat";
2-
import { Signer } from "ethers";
32
import { expect } from "chai";
43
import {
5-
CodeHashDistribution,
6-
CodeHashDistribution__factory,
7-
CodeIndex,
8-
Distributor,
9-
Distributor__factory,
10-
MockCloneDistribution,
11-
MockCloneDistribution__factory,
12-
MockInstaller,
13-
MockInstaller__factory,
14-
OwnableDistributor__factory,
15-
TestFacet,
16-
TestFacet__factory,
4+
CodeIndex,
5+
Distributor, MockCloneDistribution,
6+
MockCloneDistribution__factory,
7+
MockInstaller,
8+
MockInstaller__factory,
9+
OwnableDistributor__factory
1710
} from "../../types";
18-
import hre, { deployments } from "hardhat";
11+
import { deployments } from "hardhat";
1912
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
20-
import utils from "../utils";
2113

2214
describe("Installer", function () {
2315
let codeIndex: CodeIndex;
@@ -118,7 +110,7 @@ describe("Installer", function () {
118110
"MockCloneDistribution",
119111
instanceAddress
120112
)) as MockCloneDistribution;
121-
const src = await instance.getSources();
113+
const { src } = await instance.get();
122114
expect(src[0]).to.be.equal(instance.address);
123115
});
124116

test/eds/Repository.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ describe("Installer", function () {
4848
const Repository = (await ethers.getContractFactory(
4949
"OwnableRepository"
5050
)) as OwnableRepository__factory;
51-
repository = await Repository.deploy(owner.address);
51+
repository = await Repository.deploy(
52+
owner.address,
53+
ethers.utils.formatBytes32String("testRepository")
54+
);
5255
const repositoryCode = await repository.provider.getCode(
5356
repository.address
5457
);

test/eds/VersionDistributor.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ describe("Version Distributor", function () {
4242
const Repository = (await ethers.getContractFactory(
4343
"OwnableRepository"
4444
)) as OwnableRepository__factory;
45-
repository = await Repository.deploy(owner.address);
45+
repository = await Repository.deploy(
46+
owner.address,
47+
ethers.utils.formatBytes32String("testRepository")
48+
);
4649
const repositoryCode = await repository.provider.getCode(
4750
repository.address
4851
);

0 commit comments

Comments
 (0)