From 5c945f08f95d85ad297838594af0925a02c2337d Mon Sep 17 00:00:00 2001 From: Wil Wade Date: Wed, 14 Jul 2021 13:20:44 -0400 Subject: [PATCH] Rename the fields in DSNP Batch Publication (#38) dsnpUrl -> fileUrl dsnpHash -> fileHash dsnpType -> announcementType --- contracts/IPublish.sol | 20 ++++++++++---------- contracts/Publisher.sol | 10 +++++----- test/Publisher.test.ts | 10 ++++++++-- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/contracts/IPublish.sol b/contracts/IPublish.sol index b7ef678..4debf8a 100644 --- a/contracts/IPublish.sol +++ b/contracts/IPublish.sol @@ -2,22 +2,22 @@ pragma solidity >=0.8.0 <0.9.0; interface IPublish { - struct Batch { - int16 dsnpType; - string url; - bytes32 hash; + struct Publication { + int16 announcementType; + string fileUrl; + bytes32 fileHash; } /** - * @dev Log for each batch published - * @param dsnpType The type of Announcement in the batch file - * @param dsnpHash The keccak hash of the batch file - * @param dsnpUrl A url that resolves to the batch file of Announcements + * @dev Log Event for each batch published + * @param announcementType The type of Announcement in the batch file + * @param fileHash The keccak hash of the batch file + * @param fileUrl A url that resolves to the batch file */ - event DSNPBatchPublication(int16 indexed dsnpType, bytes32 dsnpHash, string dsnpUrl); + event DSNPBatchPublication(int16 indexed announcementType, bytes32 fileHash, string fileUrl); /** * @param publications Array of Batch struct to publish */ - function publish(Batch[] calldata publications) external; + function publish(Publication[] calldata publications) external; } diff --git a/contracts/Publisher.sol b/contracts/Publisher.sol index 7ec50d4..0d4a08d 100644 --- a/contracts/Publisher.sol +++ b/contracts/Publisher.sol @@ -5,15 +5,15 @@ import "./IPublish.sol"; contract Publisher is IPublish { /** - * @param publications Array of Batch structs to publish + * @param publications Array of Publication structs to publish */ - function publish(Batch[] calldata publications) external override { + function publish(Publication[] calldata publications) external override { require(publications.length < 100, "gas consumption is high"); for (uint256 i = 0; i < publications.length; i++) { emit DSNPBatchPublication( - publications[i].dsnpType, - publications[i].hash, - publications[i].url + publications[i].announcementType, + publications[i].fileHash, + publications[i].fileUrl ); } } diff --git a/test/Publisher.test.ts b/test/Publisher.test.ts index 618a530..83f09d5 100644 --- a/test/Publisher.test.ts +++ b/test/Publisher.test.ts @@ -14,13 +14,19 @@ describe("publisher", () => { }); it("batch emits a DSNPBatchPublication event", async () => { - await expect(publisher.publish([{ hash: hash, url: "http://x.com", dsnpType: 1 }])) + await expect( + publisher.publish([{ fileHash: hash, fileUrl: "http://x.com", announcementType: 1 }]) + ) .to.emit(publisher, "DSNPBatchPublication") .withArgs(1, hash, "http://x.com"); }); it("reverts when batch size is greater or equal to 100", async () => { - const batch = Array(100).fill({ hash: hash, url: "http://x.com", dsnpType: 1 }); + const batch = Array(100).fill({ + fileHash: hash, + fileUrl: "http://x.com", + announcementType: 1, + }); await expect(publisher.publish(batch)).to.be.revertedWith("gas consumption is high"); });