Skip to content

Commit

Permalink
Adding solidity code coverage for tests and writing some tests relate…
Browse files Browse the repository at this point in the history
…d to adopt pet functionality
  • Loading branch information
riadelimemmedov committed Jan 28, 2024
1 parent 16206ef commit 0a16fc3
Show file tree
Hide file tree
Showing 7 changed files with 1,182 additions and 259 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/blockchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@ jobs:
run: npm install --force
- name: Run tests
run: npm run test
- name: Run tests coverage
run: npm run coverage
- name: Run ESLint Check Code Quality
run: npm run lint
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions blockchain/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"parserOptions": {
"ecmaVersion": "latest"
},
"ignorePatterns": ["prettify.js","sorter.js","coverage.json"],
"rules": {
"indent": [
"error",
Expand Down
18 changes: 14 additions & 4 deletions blockchain/contracts/PetAdoption.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,30 @@ pragma solidity ^0.8.9;
contract PetAdoption {
address public owner;
uint public petIndex = 0;
uint[] allAdoptedPets;

mapping(uint => address) public petIdxToOwnerAddress;
mapping(address => uint[]) public ownerAddressToPetList;

constructor(uint initialPetIndex) {
owner = msg.sender;
petIndex = initialPetIndex;
}

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!");

petIdxToOwnerAddress[adoptIdx] = msg.sender;
ownerAddressToPetList[msg.sender].push(adoptIdx);
allAdoptedPets.push(adoptIdx);
}

function getOwner() public view returns (address) {
return owner;
}
Expand Down
1 change: 1 addition & 0 deletions blockchain/coverage.json
Original file line number Diff line number Diff line change
@@ -0,0 +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}}]}}}}
Loading

0 comments on commit 0a16fc3

Please sign in to comment.