Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Commit

Permalink
Rename the fields in DSNP Batch Publication (#38)
Browse files Browse the repository at this point in the history
dsnpUrl -> fileUrl
dsnpHash -> fileHash
dsnpType -> announcementType
  • Loading branch information
wilwade authored Jul 14, 2021
1 parent 6223667 commit 5c945f0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
20 changes: 10 additions & 10 deletions contracts/IPublish.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 5 additions & 5 deletions contracts/Publisher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
Expand Down
10 changes: 8 additions & 2 deletions test/Publisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand Down

0 comments on commit 5c945f0

Please sign in to comment.