Skip to content

Commit

Permalink
Finished all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
riadelimemmedov committed Jan 28, 2024
1 parent 0a16fc3 commit 10ee421
Show file tree
Hide file tree
Showing 8 changed files with 1,099 additions and 31 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/blockchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ jobs:
run: npm run test
- name: Run tests coverage
run: npm run coverage
- name: Run ESLint Check Code Quality
run: npm run lint
- name: Check typing problem on code
run: npx eslint --fix .
- name: Format solidity code
run: npx prettier --write "**/*.sol"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
Expand Down
14 changes: 14 additions & 0 deletions blockchain/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"plugins": ["prettier-plugin-solidity"],
"overrides": [{
"files": "*.sol",
"options": {
"parser": "solidity-parse",
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false
}
}]
}
24 changes: 20 additions & 4 deletions blockchain/contracts/PetAdoption.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;

// import "hardhat/console.sol"; //If you want use console.log inside the smart contract you need to install hardhat

contract PetAdoption {
address public owner;
uint public petIndex = 0;
uint[] allAdoptedPets;
uint[] public allAdoptedPets;

mapping(uint => address) public petIdxToOwnerAddress;
mapping(address => uint[]) public ownerAddressToPetList;
Expand All @@ -15,13 +17,19 @@ contract PetAdoption {
}

function addPet() public {
require(owner == msg.sender,"Only a contract owner can be add a new pet!");
require(
owner == msg.sender,
"Only a contract owner can be add a new pet!"
);
petIndex++;
}

function adoptPet(uint adoptIdx) public {
require(adoptIdx < petIndex,"Pet index out of the bounds!");
require(petIdxToOwnerAddress[adoptIdx] == address(0),"Pet is already adopted!");
require(adoptIdx < petIndex, "Pet index out of the bounds!");
require(
petIdxToOwnerAddress[adoptIdx] == address(0),
"Pet is already adopted!"
);

petIdxToOwnerAddress[adoptIdx] = msg.sender;
ownerAddressToPetList[msg.sender].push(adoptIdx);
Expand All @@ -31,4 +39,12 @@ contract PetAdoption {
function getOwner() public view returns (address) {
return owner;
}

function getAllAdoptedPetsByOwner() public view returns (uint[] memory) {
return ownerAddressToPetList[msg.sender];
}

function getAllAdoptedPets() public view returns (uint[] memory) {
return allAdoptedPets;
}
}
2 changes: 1 addition & 1 deletion blockchain/coverage.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"contracts\\PetAdoption.sol":{"l":{"13":3,"14":3,"18":2,"19":1,"23":3,"24":2,"26":1,"27":1,"28":1,"32":1},"path":"C:\\Users\\riade\\OneDrive\\Документы\\adopt-pet\\blockchain\\contracts\\PetAdoption.sol","s":{"1":2,"2":3,"3":2,"4":1,"5":1,"6":1},"b":{"1":[1,1],"2":[2,1],"3":[1,1]},"f":{"1":3,"2":2,"3":3,"4":1},"fnMap":{"1":{"name":"constructor","line":12,"loc":{"start":{"line":12,"column":4},"end":{"line":15,"column":4}}},"2":{"name":"addPet","line":17,"loc":{"start":{"line":17,"column":4},"end":{"line":20,"column":4}}},"3":{"name":"adoptPet","line":22,"loc":{"start":{"line":22,"column":4},"end":{"line":29,"column":4}}},"4":{"name":"getOwner","line":31,"loc":{"start":{"line":31,"column":4},"end":{"line":33,"column":4}}}},"statementMap":{"1":{"start":{"line":18,"column":8},"end":{"line":18,"column":81}},"2":{"start":{"line":23,"column":8},"end":{"line":23,"column":66}},"3":{"start":{"line":24,"column":8},"end":{"line":24,"column":86}},"4":{"start":{"line":27,"column":8},"end":{"line":27,"column":55}},"5":{"start":{"line":28,"column":8},"end":{"line":28,"column":36}},"6":{"start":{"line":32,"column":8},"end":{"line":32,"column":20}}},"branchMap":{"1":{"line":18,"type":"if","locations":[{"start":{"line":18,"column":8},"end":{"line":18,"column":8}},{"start":{"line":18,"column":8},"end":{"line":18,"column":8}}]},"2":{"line":23,"type":"if","locations":[{"start":{"line":23,"column":8},"end":{"line":23,"column":8}},{"start":{"line":23,"column":8},"end":{"line":23,"column":8}}]},"3":{"line":24,"type":"if","locations":[{"start":{"line":24,"column":8},"end":{"line":24,"column":8}},{"start":{"line":24,"column":8},"end":{"line":24,"column":8}}]}}}}
{"contracts\\PetAdoption.sol":{"l":{"15":3,"16":3,"20":2,"24":1,"28":5,"29":4,"34":3,"35":3,"36":3,"40":1,"44":1,"48":1},"path":"C:\\Users\\riade\\OneDrive\\Документы\\adopt-pet\\blockchain\\contracts\\PetAdoption.sol","s":{"1":2,"2":5,"3":4,"4":3,"5":3,"6":1,"7":1,"8":1},"b":{"1":[1,1],"2":[4,1],"3":[3,1]},"f":{"1":3,"2":2,"3":5,"4":1,"5":1,"6":1},"fnMap":{"1":{"name":"constructor","line":14,"loc":{"start":{"line":14,"column":4},"end":{"line":17,"column":4}}},"2":{"name":"addPet","line":19,"loc":{"start":{"line":19,"column":4},"end":{"line":25,"column":4}}},"3":{"name":"adoptPet","line":27,"loc":{"start":{"line":27,"column":4},"end":{"line":37,"column":4}}},"4":{"name":"getOwner","line":39,"loc":{"start":{"line":39,"column":4},"end":{"line":41,"column":4}}},"5":{"name":"getAllAdoptedPetsByOwner","line":43,"loc":{"start":{"line":43,"column":4},"end":{"line":45,"column":4}}},"6":{"name":"getAllAdoptedPets","line":47,"loc":{"start":{"line":47,"column":4},"end":{"line":49,"column":4}}}},"statementMap":{"1":{"start":{"line":20,"column":8},"end":{"line":20,"column":575}},"2":{"start":{"line":28,"column":8},"end":{"line":28,"column":67}},"3":{"start":{"line":29,"column":8},"end":{"line":29,"column":837}},"4":{"start":{"line":35,"column":8},"end":{"line":35,"column":55}},"5":{"start":{"line":36,"column":8},"end":{"line":36,"column":36}},"6":{"start":{"line":40,"column":8},"end":{"line":40,"column":20}},"7":{"start":{"line":44,"column":8},"end":{"line":44,"column":48}},"8":{"start":{"line":48,"column":8},"end":{"line":48,"column":29}}},"branchMap":{"1":{"line":20,"type":"if","locations":[{"start":{"line":20,"column":8},"end":{"line":20,"column":8}},{"start":{"line":20,"column":8},"end":{"line":20,"column":8}}]},"2":{"line":28,"type":"if","locations":[{"start":{"line":28,"column":8},"end":{"line":28,"column":8}},{"start":{"line":28,"column":8},"end":{"line":28,"column":8}}]},"3":{"line":29,"type":"if","locations":[{"start":{"line":29,"column":8},"end":{"line":29,"column":8}},{"start":{"line":29,"column":8},"end":{"line":29,"column":8}}]}}}}
Loading

0 comments on commit 10ee421

Please sign in to comment.