My coding Journey: From 0 to mainNet

Hi Julian! I'm also an Industrial Engineer from Argentina! Started my solidity journey 5 months ago but on the python/brownie track. If you want we can chat. Nice work!

1 Like

Nice! You're not from Rosario, right? Hahah. You can join us at our discord and we can talk better there. I'm not sure what you can do with brownie but maybe we can build something cool :slight_smile:

Day 9:
Added 2 more tests to Gov Token. Those are

		it('should reduce votes from delegatee when delegator transfer their funds', async() => {
			
			const balance0 = await this.token.balanceOf(accounts[0]);

			await this.token.delegate(accounts[1], {from: accounts[0]});
			var chPoint1 = await this.token.numCheckpoints.call(accounts[1]);
			var votes1 = await this.token.checkpoints.call(accounts[1], chPoint1 - 1);
			assert.strictEqual(balance0.toString(), votes1.votes.toString());

			const transfer = 250;

			await this.token.transfer(accounts[2], transfer, {from: accounts[0]});

			var chPoint1 = await this.token.numCheckpoints.call(accounts[1]);
			var votes1 = await this.token.checkpoints.call(accounts[1], chPoint1 - 1);

			const balance0_2 = balance0 - transfer;
			assert.strictEqual(balance0_2.toString(), votes1.votes.toString());
		});

		
		it("should have the amount of votes = your balance + delegator's ones", async () => {

			await this.token.transfer(accounts[1], 100, {from: accounts[0]});

			const balance0 = await this.token.balanceOf(accounts[0]);
			const balance1 = await this.token.balanceOf(accounts[1]);

			await this.token.delegate(accounts[1], {from: accounts[0]});

			var chPoint1 = await this.token.numCheckpoints.call(accounts[1]);
			var votes1 = await this.token.checkpoints.call(accounts[1], chPoint1 - 1);
			const votesTotal = parseInt(balance0) + parseInt(balance1)			
			
			assert.strictEqual(votesTotal.toString(), votes1.votes.toString());

		});

Aaaaaaaand, they did't pass :cold_sweat:

image

image

So now we know that in the mapping checkpoints are stored just the delegation votes. I think that this is not a mistake and on the proposals contract they are going to add tokens amount + delegations = voting.

So I jump in the proposals contract. At first just analyzing the propose function

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Proposals {
    /// @notice The name of this contract
    string public constant name = "Proposals";

    /// @notice The number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed
    function quorumVotes() public pure returns (uint) { return 400000e18; } // 400,000 = 4% of Comp
   
    /// @notice The number of votes required in order for a voter to become a proposer
    function proposalThreshold() public pure returns (uint) { return 100000e18; } // 100,000 = 1% of Comp

    /// @notice The maximum number of actions that can be included in a proposal
    function proposalMaxOperations() public pure returns (uint) { return 10; } // 10 actions

    /// @notice The delay before voting on a proposal may take place, once proposed
    function votingDelay() public pure returns (uint) { return 1; } // 1 block

    /// @notice The duration of voting on a proposal, in blocks
    function votingPeriod() public pure returns (uint) { return 17280; } // ~3 days in blocks (assuming 15s blocks)

    /// @notice The address of the governance token
    TokenInterface public token;

    /// @notice The address of the Governor Guardian
    address public guardian;

    /// @notice The total number of proposals
    uint public proposalCount;

    struct Proposal {
        //  Unique id for looking up a proposal
        uint id;

        //  Creator of the proposal
        address proposer;

        //  The timestamp that the proposal will be available for execution, set once the vote succeeds
        uint eta;

        //  the ordered list of target addresses for calls to be made
        address[] targets;

        //  The ordered list of values (i.e. msg.value) to be passed to the calls to be made
        uint[] values;

        //  The ordered list of function signatures to be called
        string[] signatures;

        //  The ordered list of calldata to be passed to each call
        bytes[] calldatas;

        //  The block at which voting begins: holders must delegate their votes prior to this block
        uint startBlock;

        //  The block at which voting ends: votes must be cast prior to this block
        uint endBlock;

        //  Current number of votes in favor of this proposal
        uint forVotes;

        //  Current number of votes in opposition to this proposal
        uint againstVotes;

        //  Flag marking whether the proposal has been canceled
        bool canceled;

        //  Flag marking whether the proposal has been executed
        bool executed;

        //  Receipts of ballots for the entire set of voters
//        mapping (address => Receipt) receipts;
    }

    /// @notice Ballot receipt record for a voter
    struct Receipt {
        //  Whether or not a vote has been cast
        bool hasVoted;

        //  Whether or not the voter supports the proposal
        bool support;

        //  The number of votes the voter had, which were cast
        uint96 votes;
    }

    /// @notice Possible states that a proposal may be in
    enum ProposalState {
        Pending,
        Active,
        Canceled,
        Defeated,
        Succeeded,
        Queued,
        Expired,
        Executed
    }

    /// @notice The official record of all proposals ever proposed
    mapping (uint => Proposal) public proposals;

    /// @notice The latest proposal for each proposer
    mapping (address => uint) public latestProposalIds;

    /// @notice An event emitted when a new proposal is created
    event ProposalCreated(uint id, address proposer, address[] targets, uint[] values, string[] signatures, bytes[] calldatas, uint startBlock, uint endBlock, string description);

    constructor(address token_, address guardian_) {
        token = TokenInterface(token_);
        guardian = guardian_;
    }

    function propose(address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory description) public returns (uint) {
        require(token.getPriorVotes(msg.sender, block.number - 1) > proposalThreshold(), "Proposals::propose: proposer votes below proposal threshold");
        require(targets.length == values.length && targets.length == signatures.length && targets.length == calldatas.length, "Proposals::propose: proposal function information arity mismatch");
        require(targets.length != 0, "Proposals::propose: must provide actions");
        require(targets.length <= proposalMaxOperations(), "Proposals::propose: too many actions");

        uint latestProposalId = latestProposalIds[msg.sender];
        if (latestProposalId != 0) {
          ProposalState proposersLatestProposalState = state(latestProposalId);
          require(proposersLatestProposalState != ProposalState.Active, "Proposals::propose: one live proposal per proposer, found an already active proposal");
          require(proposersLatestProposalState != ProposalState.Pending, "Proposals::propose: one live proposal per proposer, found an already pending proposal");
        }

        uint startBlock = block.number + votingDelay();
        uint endBlock = startBlock + votingPeriod();

        proposalCount++;
        Proposal memory newProposal = Proposal({
            id: proposalCount,
            proposer: msg.sender,
            eta: 0,
            targets: targets,
            values: values,
            signatures: signatures,
            calldatas: calldatas,
            startBlock: startBlock,
            endBlock: endBlock,
            forVotes: 0,
            againstVotes: 0,
            canceled: false,
            executed: false
        });

        proposals[newProposal.id] = newProposal;
        latestProposalIds[newProposal.proposer] = newProposal.id;

        emit ProposalCreated(newProposal.id, msg.sender, targets, values, signatures, calldatas, startBlock, endBlock, description);
        return newProposal.id;
    }

    function state(uint proposalId) public view returns (ProposalState) {
        require(proposalCount >= proposalId && proposalId > 0, "Proposals::state: invalid proposal id");
        Proposal storage proposal = proposals[proposalId];
        if (proposal.canceled) {
            return ProposalState.Canceled;
        } else if (block.number <= proposal.startBlock) {
            return ProposalState.Pending;
        } else if (block.number <= proposal.endBlock) {
            return ProposalState.Active;
        } else if (proposal.forVotes <= proposal.againstVotes || proposal.forVotes < quorumVotes()) {
            return ProposalState.Defeated;
        } else if (proposal.eta == 0) {
            return ProposalState.Succeeded;
        } else if (proposal.executed) {
            return ProposalState.Executed;
//        } else if (block.timestamp >= proposal.eta  + timelock.GRACE_PERIOD())) {
//            return ProposalState.Expired;
        } else {
            return ProposalState.Queued;
        }
    }

}
    
interface TokenInterface {
    function getPriorVotes(address account, uint blockNumber) external view returns (uint256);

} 

The main problem that I've found is that from Solidity 0.7.0 is not allowed anymore to have mappings inside structs. And we have

    struct Proposal {
        //  Unique id for looking up a proposal
        uint id;

        //  Creator of the proposal
        address proposer;

        //  The timestamp that the proposal will be available for execution, set once the vote succeeds
        uint eta;

        //  the ordered list of target addresses for calls to be made
        address[] targets;

        //  The ordered list of values (i.e. msg.value) to be passed to the calls to be made
        uint[] values;

        //  The ordered list of function signatures to be called
        string[] signatures;

        //  The ordered list of calldata to be passed to each call
        bytes[] calldatas;

        //  The block at which voting begins: holders must delegate their votes prior to this block
        uint startBlock;

        //  The block at which voting ends: votes must be cast prior to this block
        uint endBlock;

        //  Current number of votes in favor of this proposal
        uint forVotes;

        //  Current number of votes in opposition to this proposal
        uint againstVotes;

        //  Flag marking whether the proposal has been canceled
        bool canceled;

        //  Flag marking whether the proposal has been executed
        bool executed;

        //  Receipts of ballots for the entire set of voters
        mapping (address => Receipt) receipts;
    }

Being

    struct Receipt {
        //  Whether or not a vote has been cast
        bool hasVoted;

        //  Whether or not the voter supports the proposal
        bool support;

        //  The number of votes the voter had, which were cast
        uint96 votes;
    }

I think that with

    // Receipts by Id
    mapping (uint => mapping (address => Receipt)) public receiptsById;

This problem would be solved, but until I don't reach the voting function I'm not gonna be sure.
For now I'm gonna do some testing proposals and then keep digging in the contract

See you tomorrow :green_heart:

Day 10:
This days were FULL of doubts and without being able to realize many stuff. They are all on the testing environment.

On proposals' contract I have declared a struct:

struct Proposal {
        //  Unique id for looking up a proposal
        uint id;

        //  Creator of the proposal
        address proposer;

        //  The timestamp that the proposal will be available for execution, set once the vote succeeds
        uint eta;

        //  the ordered list of target addresses for calls to be made
        address[] targets;

        //  The ordered list of values (i.e. msg.value) to be passed to the calls to be made
        uint[] values;

        //  The ordered list of function signatures to be called
        string[] signatures;

        //  The ordered list of calldata to be passed to each call
        bytes[] calldatas;

        //  The block at which voting begins: holders must delegate their votes prior to this block
        uint startBlock;

        //  The block at which voting ends: votes must be cast prior to this block
        uint endBlock;

        //  Current number of votes in favor of this proposal
        uint forVotes;

        //  Current number of votes in opposition to this proposal
        uint againstVotes;

        //  Flag marking whether the proposal has been canceled
        bool canceled;

        //  Flag marking whether the proposal has been executed
        bool executed;

        //  Receipts of ballots for the entire set of voters
        //mapping (address => Receipt) receipts;

    }

And a mapping that collects its info:

/// @notice The official record of all proposals ever proposed
    mapping (uint => Proposal) public proposals;

This record is being made - after some requirements - on the propose function:

function propose(address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory description) public returns (uint) {
        require(token.getPriorVotes(msg.sender, block.number - 1) > proposalThreshold(), "Proposals::propose: proposer votes below proposal threshold");
        require(targets.length == values.length && targets.length == signatures.length && targets.length == calldatas.length, "Proposals::propose: proposal function information arity mismatch");
        require(targets.length != 0, "Proposals::propose: must provide actions");
        require(targets.length <= proposalMaxOperations(), "Proposals::propose: too many actions");

        uint latestProposalId = latestProposalIds[msg.sender];
        if (latestProposalId != 0) {
          ProposalState proposersLatestProposalState = state(latestProposalId);
          require(proposersLatestProposalState != ProposalState.Active, "Proposals::propose: one live proposal per proposer, found an already active proposal");
          require(proposersLatestProposalState != ProposalState.Pending, "Proposals::propose: one live proposal per proposer, found an already pending proposal");
        }

        uint startBlock = block.number + votingDelay();
        uint endBlock = startBlock + votingPeriod();

//HERE!!!!!!!!! 

        proposalCount++;
        Proposal memory newProposal = Proposal({
            id: proposalCount,
            proposer: msg.sender,
            eta: 0,
            targets: targets, // I'M PRETTY SURE THAT THE MISTAKE IS TRYING TO STORE AN ARRAY LIKE THIS
            values: values, //THIS
            signatures: signatures, //THIS
            calldatas: calldatas, //THIS
            startBlock: startBlock,
            endBlock: endBlock,
            forVotes: 0,
            againstVotes: 0,
            canceled: false,
            executed: false
        });

        proposals[newProposal.id] = newProposal;
        latestProposalIds[newProposal.proposer] = newProposal.id;

        emit ProposalCreated(newProposal.id, msg.sender, targets, values, signatures, calldatas, startBlock, endBlock, description);
        return newProposal.id;
    }

Until here everything looks fine. Then, when I start the testing:

it('should create new proposal', async () => {
			
			await this.token.delegate(proposer, {from: deployer})
			
// TO CHECK IF THE EVENT IS REGISTERED PROPERLY
            const res = await proposal.propose(targets, values, signatures, calldatas, description, {from: proposer});
			const proposalLog = res.logs.find(
				element => element.event.match('ProposalCreated'));

// TO CHECK IF IT'S STORED ON PROPOSALS MAPPING PROPERLY
			const propId = await proposal.proposalCount();
			const newProp = await proposal.proposals.call(propId);

			console.log('mapping: ', newProp)
			console.log('log: ', proposalLog)
		});

The output that I have is all the values that aren't arrays. I've try different syntaxes on the contract when it's stored and when I call console.log. I'm pretty sure that it's a matter when its stored because on the mapping that I have as an output it's not their keyword. The output that I'm getting is:

mapping:  Result {
  '0': BN {
    negative: 0,
    words: [ 1, <1 empty item> ],
    length: 1,
    red: null
  },
  '1': '0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef',
  '2': BN {
    negative: 0,
    words: [ 0, <1 empty item> ],
    length: 1,
    red: null
  },
  '3': BN {
    negative: 0,
    words: [ 9, <1 empty item> ],
    length: 1,
    red: null
  },
  '4': BN {
    negative: 0,
    words: [ 17289, <1 empty item> ],
    length: 1,
    red: null
  },
  '5': BN {
    negative: 0,
    words: [ 0, <1 empty item> ],
    length: 1,
    red: null
  },
  '6': BN {
    negative: 0,
    words: [ 0, <1 empty item> ],
    length: 1,
    red: null
  },
  '7': false,
  '8': false,
  id: BN {
    negative: 0,
    words: [ 1, <1 empty item> ],
    length: 1,
    red: null
  },
  proposer: '0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef',
  eta: BN {
    negative: 0,
    words: [ 0, <1 empty item> ],
    length: 1,
    red: null
  },
  startBlock: BN {
    negative: 0,
    words: [ 9, <1 empty item> ],
    length: 1,
    red: null
  },
  endBlock: BN {
    negative: 0,
    words: [ 17289, <1 empty item> ],
    length: 1,
    red: null
  },
  forVotes: BN {
    negative: 0,
    words: [ 0, <1 empty item> ],
    length: 1,
    red: null
  },
  againstVotes: BN {
    negative: 0,
    words: [ 0, <1 empty item> ],
    length: 1,
    red: null
  },
  canceled: false,
  executed: false
}



log:  {
  logIndex: 0,
  transactionIndex: 0,
  transactionHash: '0xced35652286867c314af814cf364c28bca5c9c3fefbbfd35f8a7ebd279da9f67',
  blockHash: '0x83b12bed2d24678ff218205ca8d7c1e8d1b39eec7c580c2183bcd305de6798ea',
  blockNumber: 8,
  address: '0x9FBDa871d559710256a2502A2517b794B482Db40',
  type: 'mined',
  id: 'log_f9a2330b',
  event: 'ProposalCreated',
  args: Result {
    '0': BN { negative: 0, words: [Array], length: 1, red: null },
    '1': '0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef',
    '2': [
      '0x821aEa9a577a9b44299B9c15c88cf3087F3b5544',
      '0x0d1d4e623D10F9FBA5Db95830F7d3839406C6AF2',
      '0x2932b7A2355D6fecc4b5c0B6BD44cC31df247a2e',
      '0x2191eF87E392377ec08E7c08Eb105Ef5448eCED5'
    ],
    '3': [ [BN], [BN], [BN], [BN] ],
    '4': [ '1AAA1AAA', '2BBB2BBB', '3CCC3CCC', '4DDDD4D' ],
    '5': [ '0x64', '0xc8', '0x012c', '0x0190' ],
    '6': BN { negative: 0, words: [Array], length: 1, red: null },
    '7': BN { negative: 0, words: [Array], length: 1, red: null },
    '8': 'description of the proposal',
    __length__: 9,
    id: BN { negative: 0, words: [Array], length: 1, red: null },
    proposer: '0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef',
    targets: [
      '0x821aEa9a577a9b44299B9c15c88cf3087F3b5544',
      '0x0d1d4e623D10F9FBA5Db95830F7d3839406C6AF2',
      '0x2932b7A2355D6fecc4b5c0B6BD44cC31df247a2e',
      '0x2191eF87E392377ec08E7c08Eb105Ef5448eCED5'
    ],
    values: [ [BN], [BN], [BN], [BN] ],
    signatures: [ '1AAA1AAA', '2BBB2BBB', '3CCC3CCC', '4DDDD4D' ],
    calldatas: [ '0x64', '0xc8', '0x012c', '0x0190' ],
    startBlock: BN { negative: 0, words: [Array], length: 1, red: null },
    endBlock: BN { negative: 0, words: [Array], length: 1, red: null },
    description: 'description of the proposal'
  }
}

You can find the full codes on Github.

Day 11:
I've sync Git to GitHub so we can start team working with collaborators.

Since they are not important to the core, I've left commented the things that are not working properly or idk how to do and then I'll check them again. Today I continued with the voting system, on the proposal contract.

I've added:

/// @notice An event emitted when a vote has been cast on a proposal
    event VoteCast(address voter, uint proposalId, bool support, uint votes);

function castVote(uint proposalId, bool support) public {
        return _castVote(msg.sender, proposalId, support);
    }

    function _castVote(address voter, uint proposalId, bool support) internal {
        require(state(proposalId) == ProposalState.Active, "Proposals::_castVote: voting is closed");
        Proposal storage proposal = proposals[proposalId];
        Receipt storage receipt = receiptsById[proposal.id][voter];

        require(receipt.hasVoted == false, "Proposals::_castVote: voter already voted");

        uint256 votes = token.getPriorVotes(voter, proposal.startBlock);
// check when votes restart
        if (support) {
            proposal.forVotes = proposal.forVotes + votes;
        } else {
            proposal.againstVotes = proposal.againstVotes + votes;
        }

        receipt.hasVoted = true;
        receipt.support = support;
        receipt.votes = votes;

        emit VoteCast(voter, proposalId, support, votes);
    }

Some tests:

it('should not allow to vote proposals that are not Active', async() => {
//change this delegation, it should be amount + delegates
			const amountToVote = 1000;
			await this.token.transfer(target2, amountToVote, {from: deployer});
			await this.token.delegate(target1, {from: target2});
			
			await this.token.delegate(proposer, {from: deployer});
			await proposal.propose(targets, values, signatures, calldatas, description, {from: proposer});
			
			try {
		    	await proposal.castVote(1, true, {from: target1});
		      } catch (e) {
		      threw = true;
		    }
		    assert.equal(threw, true);
		    
//I would like to do assert.equal(e, "Proposals::_castVote: voting is closed"); but IDK how to handle e 		    
		    
			await time.increase(time.duration.days(2));

			await proposal.castVote(1, true, {from: target1});

			const proposalVoted = await proposal.proposals.call(1);
			const amountVoted = proposalVoted.forVotes.toString();
			assert.equal(amountVoted, amountToVote.toString());			

		});

		it('checking positive and negative voting', async() => {
//change this delegation, it should be amount + delegates
			const amountToVoteFor = 1000;
			const amountToVoteAgainst = 750;
			
			await this.token.transfer(target3, amountToVoteFor, {from: deployer});
			await this.token.delegate(target1, {from: target3});
			
			await this.token.transfer(target4, amountToVoteAgainst, {from: deployer});
			await this.token.delegate(target2, {from: target4});
			
			await this.token.delegate(proposer, {from: deployer});
			await proposal.propose(targets, values, signatures, calldatas, description, {from: proposer});
		    
			await time.increase(time.duration.days(2));

			await proposal.castVote(1, true, {from: target1});
			await proposal.castVote(1, false, {from: target2});

			const proposalVoted = await proposal.proposals.call(1);
			
			const amountVotedFor = proposalVoted.forVotes.toString();
			const amountVotedAgainst = proposalVoted.againstVotes.toString();
			assert.equal(amountVotedFor, amountToVoteFor.toString());
			assert.equal(amountVotedAgainst, amountToVoteAgainst.toString());
		});

Questions:

try {
		    	await proposal.castVote(1, true, {from: target1});
		      } catch (e) {
		      threw = true;
		    }
		    assert.equal(threw, true);
		    
//I would like to do assert.equal(e, "Proposals::_castVote: voting is closed"); but IDK how to handle e 		    

I think the next step it's going to be that the amount of votes it's the balance of the account + delegates.

Any feedback is welcome !

Day 12:

  • I've added that total voting power it's the delegation + tokens owned.
function _castVote(address voter, uint proposalId, bool support) internal {
        require(state(proposalId) == ProposalState.Active, "Proposals::_castVote: voting is closed");
        Proposal storage proposal = proposals[proposalId];
        Receipt storage receipt = receiptsById[proposal.id][voter];

        require(receipt.hasVoted == false, "Proposals::_castVote: voter already voted");
        uint256 votes = token.getPriorVotes(voter, proposal.startBlock) + token.balanceOf(voter); //OIP 1
        if (support) {
            proposal.forVotes = proposal.forVotes + votes;
        } else {
            proposal.againstVotes = proposal.againstVotes + votes;
        }

        receipt.hasVoted = true;
        receipt.support = support;
        receipt.votes = votes;

        emit VoteCast(voter, proposalId, support, votes);
    }
}

And also on:

function propose(
        address[] memory targets, 
        uint[] memory values, 
        string[] memory signatures, 
        bytes[] memory calldatas, 
        string memory description
    ) 
        public returns (uint) {
        uint256 votingPower = (token.getPriorVotes(msg.sender, block.number - 1) + token.balanceOf(msg.sender)); //OIP 1
        require( votingPower >= proposalThreshold()/10e17, "Proposals::propose: proposer votes below proposal threshold"); //OIP 1
        require(targets.length == values.length && targets.length == signatures.length && targets.length == calldatas.length, "Proposals::propose: proposal function information arity mismatch");
        require(targets.length != 0, "Proposals::propose: must provide actions");
        require(targets.length <= proposalMaxOperations(), "Proposals::propose: too many actions");
(...)

On the OIP1 (Omens Improvement Proposition) lines.

  • I've also added some auxiliar functions
function getActions(uint proposalId) public view returns (address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas) {
        Proposal storage p = proposals[proposalId];
        return (p.targets, p.values, p.signatures, p.calldatas);
    }

    function getReceipt(uint proposalId, address voter) public view returns (Receipt memory) {
        return receiptsById[proposalId][voter];
    }

With their tests working:

describe('auxiliar functions', () => {

			it('should return actions from proposal', async () => {
			await this.token.delegate(proposer, {from: deployer});
			await proposal.propose(targets, values, signatures, calldatas, description, {from: proposer});			
			const act = await proposal.getActions(1);
			console.log(act);
// we should make a function to compare arrays, but I can check on the console that's apparently working 
		});

		it('should return actions from proposal', async () => {
			await this.token.transfer(target1, 1000, {from: deployer});
			await this.token.transfer(target2, 500, {from: deployer});
			await this.token.transfer(target3, 700, {from: deployer});
			await this.token.transfer(target4, 300, {from: deployer});
			
			await this.token.delegate(proposer, {from: deployer});
			await proposal.propose(targets, values, signatures, calldatas, description, {from: proposer});
			
			await time.increase(time.duration.days(2));

			await proposal.castVote(1, true, {from: target1});
			await proposal.castVote(1, false, {from: target2});
			await proposal.castVote(1, true, {from: target3});
			await proposal.castVote(1, false, {from: target4});


			const rec1 = await proposal.getReceipt(1, target1);
			const rec2 = await proposal.getReceipt(1, target2);
			const rec3 = await proposal.getReceipt(1, target3);
			const rec4 = await proposal.getReceipt(1, target4);
			
			console.log(rec1);
			console.log(rec2);
			console.log(rec3);
			console.log(rec4);
// we should make a function to compare arrays, but I can check on the console that's apparently working 
		});

Is there any function made to compare arrays? I couldn't find any.

Everything from this days.

Day 13.
It's been a while since my last update. I was getting more into web3 to have a general full stack knowledge.
I've found buildspace that has some awesome projects.
I was building a simple NFT game, with it's smart contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/Strings.sol";

import 'base64-sol/base64.sol';
import "hardhat/console.sol";

contract MyEpicGame is ERC721 {

  struct WeaponAttributes {
    uint weaponIndex;
    string name;
    string imageURI;        
    uint hp;
    uint maxHp;
    uint attackDamage;
  }

  WeaponAttributes[] defaultWeapons;

  using Counters for Counters.Counter;
  Counters.Counter private _tokenIds;

  mapping(uint256 => WeaponAttributes) public nftHolderAttributes;

  mapping(address => uint256) public nftHolders;

  event CharacterNFTMinted(address sender, uint256 tokenId, uint256 characterIndex);
  event AttackComplete(uint newBossHp, uint newPlayerHp);

  struct BigBoss {
    string name;
    string imageURI;
    uint hp;
    uint maxHp;
    uint attackDamage;
  }

  BigBoss public bigBoss;


  constructor(
    string[] memory weaponNames,
    string[] memory weaponImagesURIs,
    uint[] memory weaponHp,
    uint[] memory weaponAttackDmg,
    string memory bossName,
    string memory bossImageURI,
    uint bossHp,
    uint bossAttackDamage
  )
    ERC721("Weapons", "WPN")
  {
    for(uint i = 0; i < weaponNames.length; i += 1) {
      defaultWeapons.push(WeaponAttributes({
        weaponIndex: i,
        name: weaponNames[i],
        imageURI: weaponImagesURIs[i],
        hp: weaponHp[i],
        maxHp: weaponHp[i],
        attackDamage: weaponAttackDmg[i]
      }));

      WeaponAttributes memory c = defaultWeapons[i];
      
      console.log("Done initializing %s w/ HP %s", c.name, c.hp);
    }

    _tokenIds.increment();

     bigBoss = BigBoss({
      name: bossName,
      imageURI: bossImageURI,
      hp: bossHp,
      maxHp: bossHp,
      attackDamage: bossAttackDamage
    });

    console.log("Done initializing boss %s w/ HP %s", bigBoss.name, bigBoss.hp);
  }

  function checkIfUserHasNFT() public view returns (WeaponAttributes memory) {
    // Get the tokenId of the user's character NFT
    uint256 userNftTokenId = nftHolders[msg.sender];
    // If the user has a tokenId in the map, return their character.
    if (userNftTokenId > 0) {
      return nftHolderAttributes[userNftTokenId];
    }
    // Else, return an empty character.
    else {
      WeaponAttributes memory emptyStruct;
      return emptyStruct;
     }
  }

  function getAllDefaultCharacters() public view returns (WeaponAttributes[] memory) {
    return defaultWeapons;
  }

  function getBigBoss() public view returns (BigBoss memory) {
    return bigBoss;
  } 

  function attackBoss() public {
    uint256 tokenIdOfPlayer = nftHolders[msg.sender];
    WeaponAttributes storage player = nftHolderAttributes[tokenIdOfPlayer];
    console.log("\nPlayer w/ %s weapon about to attack. Has %s HP and %s AD", player.name, player.hp, player.attackDamage);
    console.log("Boss %s has %s HP and %s AD", bigBoss.name, bigBoss.hp, bigBoss.attackDamage);

    require(
      player.hp>0,
      'You are already dead. Sorry not sorry.'
    );

    require(
      bigBoss.hp>0,
      'The boss is already dead. Nice work!!'
    );

    if (player.attackDamage > bigBoss.hp) {
      bigBoss.hp = 0;
    } else {
      bigBoss.hp = bigBoss.hp - player.attackDamage;  
    }

    if (bigBoss.attackDamage > player.hp) {
      player.hp = 0;
    } else {
      player.hp = player.hp - bigBoss.attackDamage;  
    }

    console.log("Player attacked boss. New boss hp: %s", bigBoss.hp);
    console.log("Boss attacked player. New player hp: %s\n", player.hp);

    emit AttackComplete(bigBoss.hp, player.hp);
  }

  function mintWeaponNFT(uint _weaponIndex) external {
    uint256 newItemId = _tokenIds.current();

    _safeMint(msg.sender, newItemId);

    nftHolderAttributes[newItemId] = WeaponAttributes({
      weaponIndex: _weaponIndex,
      name: defaultWeapons[_weaponIndex].name,
      imageURI: defaultWeapons[_weaponIndex].imageURI,
      hp: defaultWeapons[_weaponIndex].hp,
      maxHp: defaultWeapons[_weaponIndex].maxHp,
      attackDamage: defaultWeapons[_weaponIndex].attackDamage
    });

    console.log("Minted NFT w/ tokenId %s and weaponIndex %s", newItemId, _weaponIndex);
    
    nftHolders[msg.sender] = newItemId;

    _tokenIds.increment();

    emit CharacterNFTMinted(msg.sender, newItemId, _weaponIndex);
  }

  function tokenURI(uint256 _tokenId) public view override returns (string memory) {
    WeaponAttributes memory weapAttributes = nftHolderAttributes[_tokenId];

    string memory strHp = Strings.toString(weapAttributes.hp);
    string memory strMaxHp = Strings.toString(weapAttributes.maxHp);
    string memory strAttackDamage = Strings.toString(weapAttributes.attackDamage);

    string memory json = Base64.encode(
      bytes(
        string(
          abi.encodePacked(
            '{"name": "',
            weapAttributes.name,
            ' -- NFT #: ',
            Strings.toString(_tokenId),
            '", "description": "This is an NFT that lets people play in the game Metaverse Dragons!", "image": "',
            weapAttributes.imageURI,
            '", "attributes": [ { "trait_type": "Health Points", "value": ',strHp,', "max_value":',strMaxHp,'}, { "trait_type": "Attack Damage", "value": ',
            strAttackDamage,'} ]}'
          )
        )
      )
    );

    string memory output = string(
      abi.encodePacked("data:application/json;base64,", json)
    );
    
    return output;
  }
}

Now I'm working on the UI.

On the platform there are more projects (in solana and avalance). Also, on Sunday 19 december is starting a project to build a DAO that I'm gonna take.

I've been places but I'm still learning. Let's see how it keeps going :muscle:

1 Like