Skip to content

Commit

Permalink
feat: reto gelopfalcon#4 abilities +
Browse files Browse the repository at this point in the history
  • Loading branch information
RavilcoDev committed Mar 15, 2023
1 parent 7ddb41a commit ac9df16
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
30 changes: 29 additions & 1 deletion contracts/PokemonFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,31 @@ contract PokemonFactory {
struct Pokemon {
uint id;
string name;
uint[4] abilities;
}

struct Ability {
string name;
string description;
}

Pokemon[] private pokemons;

mapping(uint => address) public pokemonToOwner;
mapping(address => uint) ownerPokemonCount;
mapping(uint => Ability) abilitys;

event eventNewPokemon(uint _id, string _name);
event eventNewAbility(uint _id, string _name, string _description);

function createPokemon(uint _id, string memory _name) public {
require(_id > 0, "_id must to be greater than 0.");
require(
bytes(_name).length > 2,
"_name must to have a character lenght > 2."
);
pokemons.push(Pokemon(_id, _name));
uint ZERO = 0;
pokemons.push(Pokemon(_id, _name, [ZERO, ZERO, ZERO, ZERO]));
pokemonToOwner[_id] = msg.sender;
ownerPokemonCount[msg.sender]++;
emit eventNewPokemon(_id, _name);
Expand All @@ -37,4 +46,23 @@ contract PokemonFactory {
product = a * b;
sum = a + b;
}

function createAbilitys(
uint _id,
string memory _name,
string memory _description
) public {
require(_id > 0, "_id must to be greater than 0.");
require(
bytes(_name).length > 2,
"_name must to have a character lenght > 2."
);
require(
bytes(_description).length > 2,
"_description must to have a character lenght > 2."
);

abilitys[_id] = Ability(_name, _description);
emit eventNewAbility(_id, _name, _description);
}
}
4 changes: 2 additions & 2 deletions test/PokemonFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ describe("PokemonFactory", function () {
.to.be.revertedWith(
"_name must to have a character lenght > 2."
);

})

})

describe("Reto 3: ")

})

0 comments on commit ac9df16

Please sign in to comment.