Skip to content
Merged
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
6 changes: 3 additions & 3 deletions contracts/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ contract Registry is Initializable, AccessControlEnumerableUpgradeable {
string memory _name,
address _dev,
uint64 flags,
string memory _version,
string[] memory _contentURIs,
string[] memory _tags
string calldata _version,
string[] calldata _contentURIs,
string[] calldata _tags
) external onlyAddPackageRole returns (Repo) {
Repo repo = Repo(ClonesUpgradeable.clone(repoImplementation));

Expand Down
3 changes: 3 additions & 0 deletions contracts/Repo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ contract Repo is Initializable, AccessControlEnumerableUpgradeable {
mapping(bytes32 => uint256) internal versionIdByTag;

event NewVersion(uint256 versionId, string version, string[] contentURIs);
event NewTag(string tag, uint256 versionId);

constructor() initializer {}

Expand Down Expand Up @@ -116,6 +117,8 @@ contract Repo is Initializable, AccessControlEnumerableUpgradeable {
function _setTag(string memory _tag, uint256 _versionId) internal {
bytes32 tagHash = stringHash(_tag);
versionIdByTag[tagHash] = _versionId;

emit NewTag(_tag, _versionId);
}

function stringHash(string memory version) internal pure returns (bytes32) {
Expand Down
28 changes: 16 additions & 12 deletions test/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("Registry", function () {

expect(await registry.registryName()).to.equal(registryName, "Wrong registryName");

// Publish new repo from admin account
// Publish new repo from admin account, versionId = 1
const {repo: newRepoAddress} = await publishRepoVersion(registry, newPackage, newVersion1);

// Assert registry packages
Expand Down Expand Up @@ -68,18 +68,20 @@ describe("Registry", function () {
"REPO_EXISTENT_VERSION"
);

// Publish a version on a different version str
// Publish a version on a different version str, versionId = 2
const newVersionTx = await repoWithDev.newVersion(newVersion2.version, newVersion2.contentURIs, ["latest"], {
from: addr1.address,
});
const newVersionReceipt = await newVersionTx.wait();

const newVersionEvent = getEvent(newVersionReceipt.events, "NewVersion");
expect(newVersionEvent.args!.version).to.equal(newVersion2.version, "Wrong event NewVersion.version");
expect(newVersionEvent.args!.contentURIs).to.deep.equal(
newVersion2.contentURIs,
"Wrong event NewVersion.contentURIs"
);
expect(newVersionEvent.args!.versionId).to.equal(2, "Wrong event NewVersion.versionId");
expect(newVersionEvent.args!.contentURIs).to.deep.equal(newVersion2.contentURIs, "Wrong NewVersion.contentURIs");

const newTagEvent = getEvent(newVersionReceipt.events, "NewTag");
expect(newTagEvent.args!.tag).to.equal("latest", "Wrong event NewTag.tag");
expect(newTagEvent.args!.versionId).to.equal(2, "Wrong event NewTag.versionId");

// Assert that there are two version in the Repo contract
await assertRepoVersions(repoWithDev, [newVersion1, newVersion2]);
Expand Down Expand Up @@ -164,7 +166,7 @@ describe("Registry", function () {

expect(await registry.registryName()).to.equal(registryName, "Wrong registryName");

// Publish new repo from admin account
// Publish new repo from admin account, versionId = 1
const {repo: repoAddress} = await publishRepoVersion(registry, badPackage, badVersion);

// Assert registry packages
Expand All @@ -178,16 +180,18 @@ describe("Registry", function () {

const repoWithDev = (await ethers.getContractAt("Repo", newRepoAddress.address, dev)) as Repo;

// Publish a version on the new repo
// Publish a version on the new repo, versionId = 1
const newVersionTx = await repoWithDev.newVersion(correctVersion.version, correctVersion.contentURIs, ["latest"]);
const newVersionReceipt = await newVersionTx.wait();

const newVersionEvent = getEvent(newVersionReceipt.events, "NewVersion");
expect(newVersionEvent.args!.version).to.equal(correctVersion.version, "Wrong event NewVersion.version");
expect(newVersionEvent.args!.contentURIs).to.deep.equal(
correctVersion.contentURIs,
"Wrong event NewVersion.contentURIs"
);
expect(newVersionEvent.args!.versionId).to.equal(1, "Wrong event NewVersion.versionId");
expect(newVersionEvent.args!.contentURIs).to.deep.equal(correctVersion.contentURIs, "Wrong NewVersion.contentURIs");

const newTagEvent = getEvent(newVersionReceipt.events, "NewTag");
expect(newTagEvent.args!.tag).to.equal("latest", "Wrong event NewTag.tag");
expect(newTagEvent.args!.versionId).to.equal(1, "Wrong event NewTag.versionId");

// Assert that there are one version in the Repo contract
await assertRepoVersions(repoWithDev, [correctVersion]);
Expand Down