Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

application manager #4

Merged
merged 12 commits into from
Jul 20, 2024
42 changes: 42 additions & 0 deletions contracts/ApplicationManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

Check warning

Code scanning / Slither

Incorrect versions of Solidity Warning

Version constraint ^0.8.24 contains known severe issues (https://solidity.readthedocs.io/en/latest/bugs.html)
.
It is used by:
- ^0.8.24
- ^0.8.24
- ^0.8.24
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the Solidity version.

The specified Solidity version (^0.8.24) has known severe issues. Update to a more recent stable version.

- pragma solidity ^0.8.24;
+ pragma solidity ^0.8.25;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.25;
Tools
GitHub Check: Slither

[warning] 2-2: Incorrect versions of Solidity
Version constraint ^0.8.24 contains known severe issues (https://solidity.readthedocs.io/en/latest/bugs.html)
.
It is used by:
- ^0.8.24 (contracts/ApplicationManager.sol#2)
- ^0.8.24 (contracts/IApplicationManager.sol#2)
- ^0.8.24 (contracts/Lock.sol#2)


import {IApplicationManager} from "./IApplicationManager.sol";

contract ApplicationManager is IApplicationManager {
mapping(uint => Application) private applications_;
uint private nextApplicationId_;

constructor() {}

function nextApplicationId() external view returns (uint) {
return nextApplicationId_;
}

function createApplication(Application memory _application) external {

Check warning

Code scanning / Slither

Conformance to Solidity naming conventions Warning

applications_[nextApplicationId_] = _application;
emit ApplicationCreated(
nextApplicationId_,
applications_[nextApplicationId_]
);
nextApplicationId_++;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conform to Solidity naming conventions.

Parameters should follow mixedCase naming conventions.

- function createApplication(Application memory _application) external {
- applications_[nextApplicationId_] = _application;
+ function createApplication(Application memory application) external {
+ applications_[nextApplicationId_] = application;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function nextApplicationId() external view returns (uint) {
return nextApplicationId_;
}
function createApplication(Application memory _application) external {
applications_[nextApplicationId_] = _application;
emit ApplicationCreated(
nextApplicationId_,
applications_[nextApplicationId_]
);
nextApplicationId_++;
function nextApplicationId() external view returns (uint) {
return nextApplicationId_;
}
function createApplication(Application memory application) external {
applications_[nextApplicationId_] = application;
emit ApplicationCreated(
nextApplicationId_,
applications_[nextApplicationId_]
);
nextApplicationId_++;
Tools
GitHub Check: Slither

[warning] 16-16: Conformance to Solidity naming conventions
Parameter ApplicationManager.createApplication(IApplicationManager.Application)._application (contracts/ApplicationManager.sol#16) is not in mixedCase

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conform to Solidity naming conventions.

Parameters should follow mixedCase naming conventions.

- function createApplication(Application memory _application) external {
- applications_[nextApplicationId_] = _application;
+ function createApplication(Application memory application) external {
+ applications_[nextApplicationId_] = application;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function createApplication(Application memory _application) external {
applications_[nextApplicationId_] = _application;
emit ApplicationCreated(
nextApplicationId_,
applications_[nextApplicationId_]
);
nextApplicationId_++;
function createApplication(Application memory application) external {
applications_[nextApplicationId_] = application;
emit ApplicationCreated(
nextApplicationId_,
applications_[nextApplicationId_]
);
nextApplicationId_++;
Tools
GitHub Check: Slither

[warning] 16-16: Conformance to Solidity naming conventions
Parameter ApplicationManager.createApplication(IApplicationManager.Application)._application (contracts/ApplicationManager.sol#16) is not in mixedCase

}

function updateApplication(
uint _id,
Application memory _application
) external override {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement the updateApplication function and conform to Solidity naming conventions.

The updateApplication function is currently empty and needs implementation. Parameters should follow mixedCase naming conventions.

- function updateApplication(uint _id, Application memory _application) external override {}
+ function updateApplication(uint id, Application memory application) external override {
+   applications_[id] = application;
+   emit ApplicationUpdated(id, application);
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function updateApplication(
uint _id,
Application memory _application
) external override {}
function updateApplication(uint id, Application memory application) external override {
applications_[id] = application;
emit ApplicationUpdated(id, application);
}


function deleteApplication(uint _id) external override {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement the deleteApplication function and conform to Solidity naming conventions.

The deleteApplication function is currently empty and needs implementation. Parameters should follow mixedCase naming conventions.

- function deleteApplication(uint _id) external override {}
+ function deleteApplication(uint id) external override {
+   Application memory application = applications_[id];
+   delete applications_[id];
+   emit ApplicationDeleted(id, application);
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function deleteApplication(uint _id) external override {}
function deleteApplication(uint id) external override {
Application memory application = applications_[id];
delete applications_[id];
emit ApplicationDeleted(id, application);
}


function getApplication(
uint _id

Check warning

Code scanning / Slither

Conformance to Solidity naming conventions Warning

Parameter ApplicationManager.getApplication(uint256)._id is not in mixedCase
) external view returns (Application memory) {
return applications_[_id];
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement the updateApplication and deleteApplication functions.

The updateApplication and deleteApplication functions are currently empty and need implementation.

- function updateApplication(uint _id, Application memory _application) external override {}
+ function updateApplication(uint id, Application memory application) external override {
+   applications_[id] = application;
+   emit ApplicationUpdated(id, application);
+ }

- function deleteApplication(uint _id) external override {}
+ function deleteApplication(uint id) external override {
+   Application memory application = applications_[id];
+   delete applications_[id];
+   emit ApplicationDeleted(id, application);
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function updateApplication(
uint _id,
Application memory _application
) external override {}
function deleteApplication(uint _id) external override {}
function getApplication(
uint _id
) external view returns (Application memory) {
return applications_[_id];
}
function updateApplication(uint id, Application memory application) external override {
applications_[id] = application;
emit ApplicationUpdated(id, application);
}
function deleteApplication(uint id) external override {
Application memory application = applications_[id];
delete applications_[id];
emit ApplicationDeleted(id, application);
}
function getApplication(
uint _id
) external view returns (Application memory) {
return applications_[_id];
}
Tools
GitHub Check: Slither

[warning] 33-33: Conformance to Solidity naming conventions
Parameter ApplicationManager.getApplication(uint256)._id (contracts/ApplicationManager.sol#33) is not in mixedCase

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conform to Solidity naming conventions.

Parameters should follow mixedCase naming conventions.

- function getApplication(uint _id) external view returns (Application memory) {
-   return applications_[_id];
+ function getApplication(uint id) external view returns (Application memory) {
+   return applications_[id];
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function getApplication(
uint _id
) external view returns (Application memory) {
return applications_[_id];
}
function getApplication(
uint id
) external view returns (Application memory) {
return applications_[id];
}
Tools
GitHub Check: Slither

[warning] 33-33: Conformance to Solidity naming conventions
Parameter ApplicationManager.getApplication(uint256)._id (contracts/ApplicationManager.sol#33) is not in mixedCase


function getApplications(
uint _start,
uint _limit
) external override returns (Application[] memory application) {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement the getApplications function and conform to Solidity naming conventions.

The getApplications function is currently empty and needs implementation. Parameters should follow mixedCase naming conventions.

- function getApplications(uint _start, uint _limit) external override returns (Application[] memory application) {}
+ function getApplications(uint start, uint limit) external override returns (Application[] memory applications) {
+   Application[] memory apps = new Application[](limit);
+   for (uint i = 0; i < limit; i++) {
+       apps[i] = applications_[start + i];
+   }
+   return apps;
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function getApplications(
uint _start,
uint _limit
) external override returns (Application[] memory application) {}
function getApplications(
uint start,
uint limit
) external override returns (Application[] memory applications) {
Application[] memory apps = new Application[](limit);
for (uint i = 0; i < limit; i++) {
apps[i] = applications_[start + i];
}
return apps;
}

}
33 changes: 33 additions & 0 deletions contracts/IApplicationManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the Solidity version.

The specified Solidity version (^0.8.24) has known severe issues. Update to a more recent stable version.

- pragma solidity ^0.8.24;
+ pragma solidity ^0.8.25;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.25;


interface IApplicationManager {
struct Application {
string name;
address account;
}

event ApplicationCreated(uint id, Application application);
event ApplicationUpdated(uint id, Application application);
event ApplicationDeleted(uint id, Application application);

function nextApplicationId() external view returns (uint);

function createApplication(Application memory _application) external;

function updateApplication(
uint _id,
Application memory _application
) external;

function deleteApplication(uint _id) external;

function getApplication(
uint _id
) external view returns (Application memory);

function getApplications(
uint _start,
uint _limit
) external returns (Application[] memory application);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conform to Solidity naming conventions.

Parameters should follow mixedCase naming conventions.

- function createApplication(Application memory _application) external;
+ function createApplication(Application memory application) external;

- function updateApplication(uint _id, Application memory _application) external;
+ function updateApplication(uint id, Application memory application) external;

- function deleteApplication(uint _id) external;
+ function deleteApplication(uint id) external;

- function getApplication(uint _id) external view returns (Application memory);
+ function getApplication(uint id) external view returns (Application memory);

- function getApplications(uint _start, uint _limit) external returns (Application[] memory application);
+ function getApplications(uint start, uint limit) external returns (Application[] memory applications);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function nextApplicationId() external view returns (uint);
function createApplication(Application memory _application) external;
function updateApplication(
uint _id,
Application memory _application
) external;
function deleteApplication(uint _id) external;
function getApplication(
uint _id
) external view returns (Application memory);
function getApplications(
uint _start,
uint _limit
) external returns (Application[] memory application);
function nextApplicationId() external view returns (uint);
function createApplication(Application memory application) external;
function updateApplication(
uint id,
Application memory application
) external;
function deleteApplication(uint id) external;
function getApplication(
uint id
) external view returns (Application memory);
function getApplications(
uint start,
uint limit
) external returns (Application[] memory applications);

}
89 changes: 89 additions & 0 deletions test/ApplicationManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { loadFixture } from "@nomicfoundation/hardhat-toolbox-viem/network-helpers";
import { expect } from "chai";
import hre from "hardhat";
import { type Address, getAddress, parseUnits } from "viem";

interface Application {
name: string;
account: Address;
}

describe("ApplicationManager", () => {
// We define a fixture to reuse the same setup in every test.
// We use loadFixture to run this setup once, snapshot that state,
// and reset Hardhat Network to that snapshot in every test.
async function deploy() {
// Contracts are deployed using the first signer/account by default
const [owner, otherAccount, app1Account] =
await hre.viem.getWalletClients();

const contract = await hre.viem.deployContract("ApplicationManager");

const publicClient = await hre.viem.getPublicClient();

return {
contract,
owner,
otherAccount,
app1Account,
publicClient,
};
}

describe("Deployment", () => {
it("Should set the nextxApplicationId to 0", async () => {
const { contract } = await loadFixture(deploy);
expect(await contract.read.nextApplicationId()).to.equal(
parseUnits("0", 0),
);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the typo in the test description.

There is a typo in the test description: "nextxApplicationId" should be "nextApplicationId".

- it("Should set the nextxApplicationId to 0", async () => {
+ it("Should set the nextApplicationId to 0", async () => {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
describe("Deployment", () => {
it("Should set the nextxApplicationId to 0", async () => {
const { contract } = await loadFixture(deploy);
expect(await contract.read.nextApplicationId()).to.equal(
parseUnits("0", 0),
);
});
describe("Deployment", () => {
it("Should set the nextApplicationId to 0", async () => {
const { contract } = await loadFixture(deploy);
expect(await contract.read.nextApplicationId()).to.equal(
parseUnits("0", 0),
);
});

});

describe("createApplication", () => {
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
let contract: any;
let app: Application;

beforeEach(async () => {
const fixture = await loadFixture(deploy);
contract = fixture.contract;

app = {
name: "app",
account: getAddress(fixture.app1Account.account.address),
};
});

it("Should accept name (string) and account (address) as inputs", async () => {
expect(await contract.write.createApplication([app])).to.be.string;
});
it("Should increment nextApplicationId", async () => {
const t0 = await contract.read.nextApplicationId();
expect(t0).to.equal(parseUnits("0", 0));
await contract.write.createApplication([app]);
const t1 = await contract.read.nextApplicationId();
expect(t1).to.equal(parseUnits("1", 0));
});
it("Should create a new Application", async () => {
const applicationId = await contract.read.nextApplicationId();
await contract.write.createApplication([app]);
expect(await contract.read.getApplication([applicationId])).to.contain(
app,
);
});
it("Should emit the ApplicationCreated event with the new application's details", async () => {
const applicationId = await contract.read.nextApplicationId();
const txHash = await contract.write.createApplication([app]);

const events = await contract.getEvents.ApplicationCreated();

expect(events.length).to.be.equal(1);

const event = events[0];
expect(event.eventName).to.be.equal("ApplicationCreated");
expect(event.transactionHash).to.be.equal(txHash);
expect(event.args.id).to.be.equal(applicationId);
expect(event.args.application).to.contain(app);
});
});
});