chittiError: CompileError: Error parsing /Users/rahul/pet-shop-tutorial/test/TestAdoption.sol: ParsedContract.sol:10:1: ParserError: Expected pragma, import directive or contract/interface/library definition.
function testUserCanAdoptPet() public {
^------^
Compilation failed. See above.
at async.whilst.error (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-compile/profiler.js:369:1)
at /usr/local/lib/node_modules/truffle/build/webpack:/~/async/dist/async.js:969:1
at next (/usr/local/lib/node_modules/truffle/build/webpack:/~/async/dist/async.js:5222:1)
at Promise.all.then.results (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-compile/profiler.js:351:1)
Truffle v5.0.7 (core: 5.0.7)
Node v10.15.3发布于 2019-03-10 18:24:09
我看到了混乱。本教程要求您将该方法添加到本教程中先前创建的契约中。因此,在这个步骤中,您的所有文件都应该如下所示:
pragma solidity ^0.5.0;
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/Adoption.sol";
contract TestAdoption {
// The address of the adoption contract to be tested
Adoption adoption = Adoption(DeployedAddresses.Adoption());
// The id of the pet that will be used for testing
uint expectedPetId = 8;
//The expected owner of adopted pet is this contract
address expectedAdopter = address(this);
// Testing the adopt() function
function testUserCanAdoptPet() public {
uint returnedId = adoption.adopt(expectedPetId);
Assert.equal(returnedId, expectedPetId, "Adoption of the expected pet should match what is returned.");
}
}https://ethereum.stackexchange.com/questions/68156
复制相似问题