Truffle Compile failing ParserError Expected token LParen got Identifier function

0 votes

truffle compile fails with the following error:

Error parsing /Users/rdelrosario/ron-eth-pet-shop/test/TestAdoption.sol: ParsedContract.sol:19:14: ParserError: Expected token LParen got 'Identifier'function testGetAdopterAddressByPetId() public {

Code is below:

pragma solidity ^0.4.17;

import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/Adoption.sol";

contract TestAdoption {
  Adoption adoption = Adoption(DeployedAddresses.Adoption());

  // Testing the adopt() function
  function testUserCanAdoptPet() public {
    uint returnedId = adoption.adopt(8);

    uint expected = 8;

    Assert.equal(returnedId, expected, "Adoption of pet ID 8 should be recorded.");

    // Testing retrieval of a single pet's owner
    function testGetAdopterAddressByPetId() public {
      // Expected owner is this contract
      address expected = this;

      address adopter = adoption.adopters(8);

      Assert.equal(adopter, expected, "Owner of pet ID 8 should be recorded.");

    // Testing retrieval of all pet owners
    function testGetAdopterAddressByPetIdInArray() public {
      // Expected owner is this contract
      address expected = this;

      // Store adopters in memory rather than contract's storage
      address[16] memory adopters = adoption.getAdopters();

      Assert.equal(adopters[8], expected, "Owner of pet ID 8 should be recorded.");
      }
    }
  }
}

Oct 9, 2018 in Blockchain by slayer
• 29,350 points
2,221 views

1 answer to this question.

0 votes

Your parentheses are mismatched.

pragma solidity ^0.4.17;

import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/Adoption.sol";

contract TestAdoption {
  Adoption adoption = Adoption(DeployedAddresses.Adoption());

  // Testing the adopt() function
  function testUserCanAdoptPet() public {
    uint returnedId = adoption.adopt(8);

    uint expected = 8;

    Assert.equal(returnedId, expected, "Adoption of pet ID 8 should be recorded.");
  }

  // Testing retrieval of a single pet's owner
  function testGetAdopterAddressByPetId() public {
    // Expected owner is this contract
    address expected = this;

    address adopter = adoption.adopters(8);

    Assert.equal(adopter, expected, "Owner of pet ID 8 should be recorded.");
  }

  // Testing retrieval of all pet owners
  function testGetAdopterAddressByPetIdInArray() public {
    // Expected owner is this contract
    address expected = this;

    // Store adopters in memory rather than contract's storage
    address[16] memory adopters = adoption.getAdopters();

    Assert.equal(adopters[8], expected, "Owner of pet ID 8 should be recorded.");
  }

}
answered Oct 9, 2018 by Omkar
• 69,210 points

Related Questions In Blockchain

0 votes
1 answer

truffle compile shows error: TypeError: Invalid type for argument in function call.

You are getting this error because you ...READ MORE

answered Dec 5, 2018 in Blockchain by Omkar
• 69,210 points
1,886 views
0 votes
1 answer

Truffle Error: Migrations contract constructor expected

You are not using constructor() public { ...READ MORE

answered Aug 10, 2018 in Blockchain by digger
• 26,740 points
1,327 views
0 votes
1 answer

Can't call contract function in truffle console

Inspect the object adoption within the console. You will ...READ MORE

answered Sep 28, 2018 in Blockchain by slayer
• 29,350 points
2,887 views
0 votes
1 answer

Truffle migrate fails due to missing function, but it exists in node_modules

deployer.deploy(password1, password2, deadline, {value: 100, from: accounts[0]}); ...READ MORE

answered Oct 3, 2018 in Blockchain by digger
• 26,740 points
1,636 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,663 views
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 69,210 points
1,237 views
0 votes
2 answers

Why is network already up to date while trying to deploy a contract on truffle?

I guess you have ganache running already ...READ MORE

answered Apr 24, 2018 in Blockchain by Shashank
• 10,400 points
4,109 views
0 votes
1 answer

How can I deploy a HelloWorld contract on my testrpc network?

The problem lies in the command: truffle migrate Your truffle migrate command ...READ MORE

answered Apr 27, 2018 in Blockchain by Perry
• 17,100 points

edited Aug 10, 2018 by Omkar 2,430 views
0 votes
1 answer

Solidity ParserError: Expected identifier but got '='

Hey, the solidity grammar doesn't allow assignments ...READ MORE

answered Oct 9, 2018 in Blockchain by Omkar
• 69,210 points
8,897 views
0 votes
1 answer

Truffle compile shows DeclarationError: Undeclared identifier.

Hey. You might have missed declaring the "myaddress"  ...READ MORE

answered Dec 4, 2018 in Blockchain by Omkar
• 69,210 points
2,142 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP